FlowStarter 类型中的方法 startFlow

为了测试我的 CorDapp,我使用了 API 的说明:测试文档和cordapp-template-java 项目中的 FlowTest.java 文件。您将在下面找到我的代码。我对这个StartedNodeServices.startFlow()功能很挣扎。文档指出它应该接受 a FlowLogic<T>,这将是我的示例中的类的实例InitiatorFlow。然而,测试文档显示了两个输入。下面的代码会导致以下错误:

The method startFlow(FlowLogic<? extends T>, InvocationContext) in the type FlowStarter is not applicable for the arguments (ServiceHub, InitiatorFlow)

我不知道如何处理这个问题,因为测试文档中显示的第一个输入不是 FlowLogic。如果我切换参数,也会发生同样的错误。

也许你可以给我一些如何处理这个问题的提示。感谢您的帮助!

package com.template;


import com.google.common.collect.ImmutableList;

import com.template.flows.InitiatorFlow;

import com.template.flows.Responder;

import com.template.states.MyState;


import net.corda.core.concurrent.CordaFuture;

import net.corda.core.context.InvocationContext;

import net.corda.core.flows.InitiatedBy;

import net.corda.core.identity.AbstractParty;

import net.corda.core.identity.CordaX500Name;

import net.corda.core.transactions.SignedTransaction;

import net.corda.testing.node.MockNetwork;

import net.corda.testing.node.MockNetworkParameters;

import net.corda.testing.node.StartedMockNode;

import net.corda.testing.node.TestCordapp;

import org.junit.After;

import org.junit.Before;

import org.junit.Test;

import net.corda.node.services.api.StartedNodeServices;

import net.corda.node.services.statemachine.ExternalEvent.ExternalStartFlowEvent;

import net.corda.node.services.api.StartedNodeServices.*;




public class FlowTests {

    private final MockNetwork network = new MockNetwork(new MockNetworkParameters(ImmutableList.of(

        TestCordapp.findCordapp("com.template.contracts"),

        TestCordapp.findCordapp("com.template.flows")

    )));

    private final StartedMockNode alice = network.createPartyNode(new CordaX500Name("Alice", "London", "GB"));

    private final StartedMockNode bob = network.createPartyNode(new CordaX500Name("Bob", "Paris", "FR"));




    public FlowTests() {

        alice.registerInitiatedFlow(InitiatorFlow.class);

        bob.registerInitiatedFlow(InitiatorFlow.class);

    }





九州编程
浏览 38回答 1
1回答

回首忆惘然

可以使用以下测试方法修复此问题:public void dummyTest() throws InterruptedException, ExecutionException {&nbsp; &nbsp; &nbsp; &nbsp;InitiatorFlow flow = new InitiatorFlow(5, 100, bob.getInfo().getLegalIdentitiesAndCerts().get(0).getParty());&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CordaFuture<SignedTransaction> future = alice.startFlow(flow);&nbsp; &nbsp; &nbsp; &nbsp; network.runNetwork();&nbsp; &nbsp; &nbsp; &nbsp; SignedTransaction signedTransaction = future.get();&nbsp; &nbsp; }确保InitiatorFlow延伸FlowLogic <SignedTransaction>.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java