为了测试我的 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();
}
}
最佳答案
可以使用以下测试方法解决此问题:
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>
.
关于java - FlowStarter 类型中的方法 startFlow(FlowLogic<? extends T>, InvocationContext) 不适用于参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58648904/