mirror of
https://github.com/corda/corda.git
synced 2025-06-16 14:18:20 +00:00
CORDA-1304 - Remove superfluous registerInitiatedFlow calls from tutorial and example tests (#2944) (#3035)
This commit is contained in:
committed by
Katelyn Baker
parent
503071a9fc
commit
59bdc5862c
@ -1,6 +1,7 @@
|
|||||||
package net.corda.core.flows;
|
package net.corda.core.flows;
|
||||||
|
|
||||||
import co.paralleluniverse.fibers.Suspendable;
|
import co.paralleluniverse.fibers.Suspendable;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.primitives.Primitives;
|
import com.google.common.primitives.Primitives;
|
||||||
import net.corda.core.identity.Party;
|
import net.corda.core.identity.Party;
|
||||||
import net.corda.testing.core.TestConstants;
|
import net.corda.testing.core.TestConstants;
|
||||||
@ -13,13 +14,12 @@ import org.junit.Test;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
|
||||||
import static net.corda.testing.core.TestUtils.singleIdentity;
|
import static net.corda.testing.core.TestUtils.singleIdentity;
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class FlowsInJavaTest {
|
public class FlowsInJavaTest {
|
||||||
private final MockNetwork mockNet = new MockNetwork(emptyList());
|
private final MockNetwork mockNet = new MockNetwork(ImmutableList.of("net.corda.core.flows"));
|
||||||
private StartedMockNode aliceNode;
|
private StartedMockNode aliceNode;
|
||||||
private StartedMockNode bobNode;
|
private StartedMockNode bobNode;
|
||||||
private Party bob;
|
private Party bob;
|
||||||
@ -38,7 +38,6 @@ public class FlowsInJavaTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void suspendableActionInsideUnwrap() throws Exception {
|
public void suspendableActionInsideUnwrap() throws Exception {
|
||||||
bobNode.registerInitiatedFlow(SendHelloAndThenReceive.class);
|
|
||||||
Future<String> result = aliceNode.startFlow(new SendInUnwrapFlow(bob));
|
Future<String> result = aliceNode.startFlow(new SendInUnwrapFlow(bob));
|
||||||
mockNet.runNetwork();
|
mockNet.runNetwork();
|
||||||
assertThat(result.get()).isEqualTo("Hello");
|
assertThat(result.get()).isEqualTo("Hello");
|
||||||
|
@ -41,7 +41,7 @@ class CollectSignaturesFlowTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
mockNet = InternalMockNetwork(cordappPackages = listOf("net.corda.testing.contracts"))
|
mockNet = InternalMockNetwork(cordappPackages = listOf("net.corda.testing.contracts", "net.corda.core.flows"))
|
||||||
aliceNode = mockNet.createPartyNode(ALICE_NAME)
|
aliceNode = mockNet.createPartyNode(ALICE_NAME)
|
||||||
bobNode = mockNet.createPartyNode(BOB_NAME)
|
bobNode = mockNet.createPartyNode(BOB_NAME)
|
||||||
charlieNode = mockNet.createPartyNode(CHARLIE_NAME)
|
charlieNode = mockNet.createPartyNode(CHARLIE_NAME)
|
||||||
@ -56,12 +56,6 @@ class CollectSignaturesFlowTests {
|
|||||||
mockNet.stopNodes()
|
mockNet.stopNodes()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun registerFlowOnAllNodes(flowClass: KClass<out FlowLogic<*>>) {
|
|
||||||
listOf(aliceNode, bobNode, charlieNode).forEach {
|
|
||||||
it.registerInitiatedFlow(flowClass.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// With this flow, the initiator starts the "CollectTransactionFlow". It is then the responders responsibility to
|
// With this flow, the initiator starts the "CollectTransactionFlow". It is then the responders responsibility to
|
||||||
// override "checkTransaction" and add whatever logic their require to verify the SignedTransaction they are
|
// override "checkTransaction" and add whatever logic their require to verify the SignedTransaction they are
|
||||||
// receiving off the wire.
|
// receiving off the wire.
|
||||||
@ -110,7 +104,6 @@ class CollectSignaturesFlowTests {
|
|||||||
// Normally this is handled by TransactionKeyFlow, but here we have to manually let A know about the identity
|
// Normally this is handled by TransactionKeyFlow, but here we have to manually let A know about the identity
|
||||||
aliceNode.services.identityService.verifyAndRegisterIdentity(bConfidentialIdentity)
|
aliceNode.services.identityService.verifyAndRegisterIdentity(bConfidentialIdentity)
|
||||||
}
|
}
|
||||||
registerFlowOnAllNodes(TestFlow.Responder::class)
|
|
||||||
val magicNumber = 1337
|
val magicNumber = 1337
|
||||||
val parties = listOf(alice, bConfidentialIdentity.party, charlie)
|
val parties = listOf(alice, bConfidentialIdentity.party, charlie)
|
||||||
val state = DummyContract.MultiOwnerState(magicNumber, parties)
|
val state = DummyContract.MultiOwnerState(magicNumber, parties)
|
||||||
|
@ -38,12 +38,10 @@ class ResolveTransactionsFlowTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
mockNet = InternalMockNetwork(cordappPackages = listOf("net.corda.testing.contracts"))
|
mockNet = InternalMockNetwork(cordappPackages = listOf("net.corda.testing.contracts", "net.corda.core.internal"))
|
||||||
notaryNode = mockNet.defaultNotaryNode
|
notaryNode = mockNet.defaultNotaryNode
|
||||||
megaCorpNode = mockNet.createPartyNode(CordaX500Name("MegaCorp", "London", "GB"))
|
megaCorpNode = mockNet.createPartyNode(CordaX500Name("MegaCorp", "London", "GB"))
|
||||||
miniCorpNode = mockNet.createPartyNode(CordaX500Name("MiniCorp", "London", "GB"))
|
miniCorpNode = mockNet.createPartyNode(CordaX500Name("MiniCorp", "London", "GB"))
|
||||||
megaCorpNode.registerInitiatedFlow(TestResponseFlow::class.java)
|
|
||||||
miniCorpNode.registerInitiatedFlow(TestResponseFlow::class.java)
|
|
||||||
notary = mockNet.defaultNotaryIdentity
|
notary = mockNet.defaultNotaryIdentity
|
||||||
megaCorp = megaCorpNode.info.singleIdentity()
|
megaCorp = megaCorpNode.info.singleIdentity()
|
||||||
miniCorp = miniCorpNode.info.singleIdentity()
|
miniCorp = miniCorpNode.info.singleIdentity()
|
||||||
|
@ -165,24 +165,6 @@ Nodes are created on the ``MockNetwork`` using:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Registering a node's initiated flows
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Regular Corda nodes automatically register any response flows defined in their installed CorDapps. When using a
|
|
||||||
``MockNetwork``, each ``StartedMockNode`` must manually register any responder flows it wishes to use.
|
|
||||||
|
|
||||||
Responder flows are registered as follows:
|
|
||||||
|
|
||||||
.. container:: codeset
|
|
||||||
|
|
||||||
.. sourcecode:: kotlin
|
|
||||||
|
|
||||||
nodeA.registerInitiatedFlow(ExampleFlow.Acceptor::class.java)
|
|
||||||
|
|
||||||
.. sourcecode:: java
|
|
||||||
|
|
||||||
nodeA.registerInitiatedFlow(ExampleFlow.Acceptor.class);
|
|
||||||
|
|
||||||
Running the network
|
Running the network
|
||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.corda.docs.tutorial.mocknetwork
|
package net.corda.docs.tutorial.mocknetwork
|
||||||
|
|
||||||
import co.paralleluniverse.fibers.Suspendable
|
import co.paralleluniverse.fibers.Suspendable
|
||||||
|
import com.google.common.collect.ImmutableList
|
||||||
import net.corda.core.contracts.requireThat
|
import net.corda.core.contracts.requireThat
|
||||||
import net.corda.core.flows.FlowLogic
|
import net.corda.core.flows.FlowLogic
|
||||||
import net.corda.core.flows.FlowSession
|
import net.corda.core.flows.FlowSession
|
||||||
@ -62,10 +63,9 @@ class TutorialMockNetwork {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
mockNet = MockNetwork(emptyList())
|
mockNet = MockNetwork(ImmutableList.of("net.corda.docs.tutorial.mocknetwork"))
|
||||||
nodeA = mockNet.createPartyNode()
|
nodeA = mockNet.createPartyNode()
|
||||||
nodeB = mockNet.createPartyNode()
|
nodeB = mockNet.createPartyNode()
|
||||||
nodeB.registerInitiatedFlow(FlowB::class.java)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -61,10 +61,6 @@ transactions are valid) inside a ``database.transaction``. All node flows run w
|
|||||||
nodes themselves, but any time we need to use the database directly from a unit test, you need to provide a database
|
nodes themselves, but any time we need to use the database directly from a unit test, you need to provide a database
|
||||||
transaction as shown here.
|
transaction as shown here.
|
||||||
|
|
||||||
With regards to initiated flows (see :doc:`flow-state-machines` for information on initiated and initiating flows), the
|
|
||||||
full node automatically registers them by scanning the CorDapp jars. In a unit test environment this is not possible so
|
|
||||||
``MockNode`` has the ``registerInitiatedFlow`` method to manually register an initiated flow.
|
|
||||||
|
|
||||||
.. MockNetwork message manipulation
|
.. MockNetwork message manipulation
|
||||||
.. --------------------------------
|
.. --------------------------------
|
||||||
.. The MockNetwork has the ability to manipulate message streams. You can use this to test your flows behaviour on corrupted,
|
.. The MockNetwork has the ability to manipulate message streams. You can use this to test your flows behaviour on corrupted,
|
||||||
|
@ -39,7 +39,6 @@ class TraderDemoTest {
|
|||||||
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = listOf(demoUser)),
|
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = listOf(demoUser)),
|
||||||
startNode(providedName = BOC_NAME, rpcUsers = listOf(bankUser))
|
startNode(providedName = BOC_NAME, rpcUsers = listOf(bankUser))
|
||||||
).map { (it.getOrThrow() as InProcess) }
|
).map { (it.getOrThrow() as InProcess) }
|
||||||
nodeA.registerInitiatedFlow(BuyerFlow::class.java)
|
|
||||||
val (nodeARpc, nodeBRpc) = listOf(nodeA, nodeB).map {
|
val (nodeARpc, nodeBRpc) = listOf(nodeA, nodeB).map {
|
||||||
val client = CordaRPCClient(it.rpcAddress)
|
val client = CordaRPCClient(it.rpcAddress)
|
||||||
client.start(demoUser.username, demoUser.password).proxy
|
client.start(demoUser.username, demoUser.password).proxy
|
||||||
|
Reference in New Issue
Block a user