为了测试我的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 <?扩展T>,InvocationContext)不适用于该参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58648904/

10-10 12:47