jeudi 31 octobre 2019

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

to test my CorDapp, I used the instructions of the API: Testing documentation and the FlowTest.java file from the cordapp-template-java project. You will find my code below. I struggle with the StartedNodeServices.startFlow() function. The documentation states that it should take in a FlowLogic<T>, which would be the instance of the class InitiatorFlow in my example. However, the testing documentation shows two inputs. The code below results in the following error:

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

I am not sure how to deal with this since the first input that is shown in the testing documentation is no FlowLogic. If I switch the arguments, the same error occurs.

Maybe you can give me a hint on how to deal with this. Thank you for your help!

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();
    }
}

Aucun commentaire:

Enregistrer un commentaire