为了测试我的CorDapp,我使用了API: Testing documentation和cordapp-template-java project中FlowTest.java文件的说明。您将在下面找到我的代码。我在StartedNodeServices.startFlow()
函数中苦苦挣扎。文档指出它应该包含一个FlowLogic<T>
,在我的示例中它将是类InitiatorFlow
的实例。但是,testing documentation显示两个输入。下面的代码导致以下错误:
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);
}
@Before
public void setup() {
network.runNetwork();
}
@After
public void tearDown() {
network.stopNodes();
}
@Test
public void dummyTest() {
CordaFuture<SignedTransaction> future = StartedNodeServices.startFlow(alice.getServices(), new InitiatorFlow(5, 100, bob.getInfo().getLegalIdentities().get(0)));
network.runNetwork();
SignedTransaction signedTransaction = future.get();
}
}
答案 0 :(得分:0)
可以使用以下测试方法解决此问题:
public void dummyTest() throws InterruptedException, ExecutionException {
InitiatorFlow flow = new InitiatorFlow(5, 100, bob.getInfo().getLegalIdentitiesAndCerts().get(0).getParty());
CordaFuture<SignedTransaction> future = alice.startFlow(flow);
network.runNetwork();
SignedTransaction signedTransaction = future.get();
}
请确保InitiatorFlow
扩展了FlowLogic <SignedTransaction>
。