diff --git a/build.gradle b/build.gradle index 53d5f7953f..e2491b742e 100644 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,7 @@ buildscript { ext.commons_cli_version = '1.4' ext.protonj_version = '0.27.1' // This is now aligned with the Artemis version, but retaining in case we ever need to diverge again for a bug fix. ext.snappy_version = '0.4' - ext.class_graph_version = '4.2.12' + ext.class_graph_version = '4.6.12' ext.jcabi_manifests_version = '1.1' ext.picocli_version = '3.8.0' ext.commons_io_version = '2.6' diff --git a/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt index 95b0664c98..a9a8775d47 100644 --- a/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt +++ b/confidential-identities/src/test/kotlin/net/corda/confidential/SwapIdentitiesFlowTests.kt @@ -14,15 +14,11 @@ import net.corda.core.identity.AbstractParty import net.corda.core.identity.AnonymousParty import net.corda.core.identity.Party import net.corda.core.identity.PartyAndCertificate -import net.corda.core.internal.packageName import net.corda.testing.core.* import net.corda.testing.internal.matchers.allOf import net.corda.testing.internal.matchers.flow.willReturn import net.corda.testing.internal.matchers.hasOnlyEntries -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.TestStartedNode -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.AfterClass import org.junit.Test @@ -33,7 +29,7 @@ class SwapIdentitiesFlowTests { private val mockNet = InternalMockNetwork( networkSendManuallyPumped = false, threadPerNode = true, - cordappsForAllNodes = cordappsForPackages(this::class.packageName) + cordappsForAllNodes = listOf(enclosedCordapp()) ) @AfterClass @@ -166,18 +162,19 @@ class SwapIdentitiesFlowTests { private fun TestStartedNode.holdsOwningKey() = HoldsOwningKeyMatcher(this) //endregion -} -@InitiatingFlow -private class SwapIdentitiesInitiator(private val otherSide: Party) : FlowLogic>() { - @Suspendable - override fun call(): Map = subFlow(SwapIdentitiesFlow(initiateFlow(otherSide))) -} + @InitiatingFlow + private class SwapIdentitiesInitiator(private val otherSide: Party) : FlowLogic>() { + @Suspendable + override fun call(): Map = subFlow(SwapIdentitiesFlow(initiateFlow(otherSide))) -@InitiatedBy(SwapIdentitiesInitiator::class) -private class SwapIdentitiesResponder(private val otherSide: FlowSession) : FlowLogic() { - @Suspendable - override fun call() { - subFlow(SwapIdentitiesFlow(otherSide)) + } + + @InitiatedBy(SwapIdentitiesInitiator::class) + private class SwapIdentitiesResponder(private val otherSide: FlowSession) : FlowLogic() { + @Suspendable + override fun call() { + subFlow(SwapIdentitiesFlow(otherSide)) + } } } diff --git a/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java b/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java index 6237084f69..6dce0bb36a 100644 --- a/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java +++ b/core/src/test/java/net/corda/core/flows/FlowsInJavaTest.java @@ -14,14 +14,15 @@ import org.junit.Test; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import static java.util.Collections.singletonList; import static net.corda.testing.core.TestUtils.singleIdentity; -import static net.corda.testing.node.internal.InternalTestUtilsKt.cordappsForPackages; +import static net.corda.testing.node.internal.InternalTestUtilsKt.enclosedCordapp; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.Assert.fail; public class FlowsInJavaTest { private final MockNetwork mockNet = new MockNetwork( - new MockNetworkParameters().withCordappsForAllNodes(cordappsForPackages("net.corda.core.flows")) + new MockNetworkParameters().withCordappsForAllNodes(singletonList(enclosedCordapp(this))) ); private StartedMockNode aliceNode; private StartedMockNode bobNode; diff --git a/core/src/test/kotlin/net/corda/core/contracts/ContractHierarchyTest.kt b/core/src/test/kotlin/net/corda/core/contracts/ContractHierarchyTest.kt index 29ba8f1e8b..c2e5aa6c1b 100644 --- a/core/src/test/kotlin/net/corda/core/contracts/ContractHierarchyTest.kt +++ b/core/src/test/kotlin/net/corda/core/contracts/ContractHierarchyTest.kt @@ -13,7 +13,7 @@ import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.enclosedCordapp import net.corda.testing.node.internal.startFlow import org.junit.After import org.junit.Before @@ -25,7 +25,7 @@ class ContractHierarchyTest { @Before fun before() { // We run this in parallel threads to help catch any race conditions that may exist. - mockNet = InternalMockNetwork(networkSendManuallyPumped = false, threadPerNode = true, cordappsForAllNodes = cordappsForPackages("net.corda.core.contracts")) + mockNet = InternalMockNetwork(networkSendManuallyPumped = false, threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp())) } @After diff --git a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt index 12112d3460..5e18e0af6f 100644 --- a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt @@ -19,9 +19,10 @@ import net.corda.testing.internal.matchers.flow.willReturn import net.corda.testing.internal.matchers.flow.willThrow import net.corda.testing.internal.rigorousMock import net.corda.testing.node.MockServices +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.TestStartedNode -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.enclosedCordapp import org.junit.AfterClass import org.junit.Test @@ -29,7 +30,7 @@ class CollectSignaturesFlowTests : WithContracts { companion object { private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB")) private val miniCorpServices = MockServices(listOf("net.corda.testing.contracts"), miniCorp, rigorousMock()) - private val classMockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.core.flows")) + private val classMockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp())) private const val MAGIC_NUMBER = 1337 diff --git a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt index 585e269de1..d3282aff6c 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowRPCTest.kt @@ -8,8 +8,6 @@ import com.natpryce.hamkrest.isA import net.corda.core.CordaRuntimeException import net.corda.core.contracts.ContractState import net.corda.core.contracts.StateAndRef -import net.corda.testing.internal.matchers.rpc.willReturn -import net.corda.testing.internal.matchers.rpc.willThrow import net.corda.core.flows.mixins.WithContracts import net.corda.core.flows.mixins.WithFinality import net.corda.core.messaging.CordaRPCOps @@ -21,6 +19,8 @@ import net.corda.testing.contracts.DummyContractV2 import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity +import net.corda.testing.internal.matchers.rpc.willReturn +import net.corda.testing.internal.matchers.rpc.willThrow import net.corda.testing.node.User import net.corda.testing.node.internal.* import org.junit.AfterClass @@ -28,7 +28,7 @@ import org.junit.Test class ContractUpgradeFlowRPCTest : WithContracts, WithFinality { companion object { - private val classMockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset", "net.corda.core.flows")) + private val classMockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp())) @JvmStatic @AfterClass diff --git a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt index a6e7f5d106..5203764053 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt @@ -23,17 +23,15 @@ import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.internal.matchers.flow.willReturn import net.corda.testing.internal.matchers.flow.willThrow -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.TestStartedNode -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.AfterClass import org.junit.Test import java.util.* class ContractUpgradeFlowTest : WithContracts, WithFinality { + companion object { - private val classMockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset", "net.corda.core.flows", "net.corda.finance.schemas")) + private val classMockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP, DUMMY_CONTRACTS_CORDAPP, enclosedCordapp())) @JvmStatic @AfterClass diff --git a/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt index 76251376bf..0452b9cddd 100644 --- a/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt @@ -26,11 +26,7 @@ class FinalityFlowTests : WithFinality { private val CHARLIE = TestIdentity(CHARLIE_NAME, 90).party } - override val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages( - "net.corda.finance.contracts.asset", - "net.corda.finance.schemas", - "net.corda.core.flows.mixins" - )) + override val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP, enclosedCordapp())) private val aliceNode = makeNode(ALICE_NAME) diff --git a/core/src/test/kotlin/net/corda/core/flows/WithReferencedStatesFlowTests.kt b/core/src/test/kotlin/net/corda/core/flows/WithReferencedStatesFlowTests.kt index c956924351..b88fbab7fb 100644 --- a/core/src/test/kotlin/net/corda/core/flows/WithReferencedStatesFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/WithReferencedStatesFlowTests.kt @@ -14,111 +14,16 @@ import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.getOrThrow import net.corda.node.VersionInfo import net.corda.testing.common.internal.testNetworkParameters -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.InternalMockNodeParameters -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.After import org.junit.Test import kotlin.test.assertEquals -// A dummy reference state contract. -internal class RefState : Contract { - companion object { - const val CONTRACT_ID = "net.corda.core.flows.RefState" - } - - override fun verify(tx: LedgerTransaction) = Unit - - data class State(val owner: Party, val version: Int = 0, override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState { - override val participants: List get() = listOf(owner) - fun update() = copy(version = version + 1) - } - - class Create : CommandData - class Update : CommandData -} - -// A flow to create a reference state. -internal class CreateRefState : FlowLogic() { - @Suspendable - override fun call(): SignedTransaction { - val notary = serviceHub.networkMapCache.notaryIdentities.first() - val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply { - addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID) - addCommand(RefState.Create(), listOf(ourIdentity.owningKey)) - }) - return subFlow(FinalityFlow(stx, emptyList())) - } -} - -// A flow to update a specific reference state. -internal class UpdateRefState(private val stateAndRef: StateAndRef) : FlowLogic() { - @Suspendable - override fun call(): SignedTransaction { - val notary = serviceHub.networkMapCache.notaryIdentities.first() - val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply { - addInputState(stateAndRef) - addOutputState(stateAndRef.state.data.update(), RefState.CONTRACT_ID) - addCommand(RefState.Update(), listOf(ourIdentity.owningKey)) - }) - return subFlow(FinalityFlow(stx, emptyList())) - } -} - -// A set of flows to share a stateref with all other nodes in the mock network. -internal object ShareRefState { - @InitiatingFlow - class Initiator(private val stateAndRef: StateAndRef) : FlowLogic() { - @Suspendable - override fun call() { - val sessions = serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentities }.map { initiateFlow(it) } - val transactionId = stateAndRef.ref.txhash - val transaction = serviceHub.validatedTransactions.getTransaction(transactionId) - ?: throw FlowException("Cannot find $transactionId.") - sessions.forEach { subFlow(SendTransactionFlow(it, transaction)) } - } - } - - @InitiatedBy(ShareRefState.Initiator::class) - class Responder(private val otherSession: FlowSession) : FlowLogic() { - @Suspendable - override fun call() { - logger.info("Receiving dependencies.") - subFlow(ReceiveTransactionFlow( - otherSideSession = otherSession, - checkSufficientSignatures = true, - statesToRecord = StatesToRecord.ALL_VISIBLE - )) - } - } -} - -// A flow to use a reference state in another transaction. -internal class UseRefState(private val linearId: UniqueIdentifier) : FlowLogic() { - @Suspendable - override fun call(): SignedTransaction { - val notary = serviceHub.networkMapCache.notaryIdentities.first() - val query = QueryCriteria.LinearStateQueryCriteria( - linearId = listOf(linearId), - relevancyStatus = Vault.RelevancyStatus.ALL - ) - val referenceState = serviceHub.vaultService.queryBy(query).states.single() - - val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply { - addReferenceState(referenceState.referenced()) - addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID) - addCommand(RefState.Create(), listOf(ourIdentity.owningKey)) - }) - return subFlow(FinalityFlow(stx, emptyList())) - } -} - class WithReferencedStatesFlowTests { companion object { @JvmStatic private val mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.core.flows", "net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), threadPerNode = true, initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4) ) @@ -142,7 +47,7 @@ class WithReferencedStatesFlowTests { val newRefState = newRefTx.tx.outRefsOfType().single() // 2. Share it with others. - nodes[0].services.startFlow(ShareRefState.Initiator(newRefState)).resultFuture.getOrThrow() + nodes[0].services.startFlow(Initiator(newRefState)).resultFuture.getOrThrow() // 3. Update the reference state but don't share the update. val updatedRefTx = nodes[0].services.startFlow(UpdateRefState(newRefState)).resultFuture.getOrThrow() @@ -152,10 +57,100 @@ class WithReferencedStatesFlowTests { val useRefTx = nodes[1].services.startFlow(WithReferencedStatesFlow { UseRefState(newRefState.state.data.linearId) }).resultFuture // 5. Share the update reference state. - nodes[0].services.startFlow(ShareRefState.Initiator(updatedRefState)).resultFuture.getOrThrow() + nodes[0].services.startFlow(Initiator(updatedRefState)).resultFuture.getOrThrow() // 6. Check that we have a valid signed transaction with the updated reference state. val result = useRefTx.getOrThrow() assertEquals(updatedRefState.ref, result.tx.references.single()) } + + // A dummy reference state contract. + class RefState : Contract { + companion object { + val CONTRACT_ID: String = RefState::class.java.name + } + + override fun verify(tx: LedgerTransaction) = Unit + + data class State(val owner: Party, val version: Int = 0, override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState { + override val participants: List get() = listOf(owner) + fun update() = copy(version = version + 1) + } + + class Create : CommandData + class Update : CommandData + } + + // A flow to create a reference state. + class CreateRefState : FlowLogic() { + @Suspendable + override fun call(): SignedTransaction { + val notary = serviceHub.networkMapCache.notaryIdentities.first() + val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply { + addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID) + addCommand(RefState.Create(), listOf(ourIdentity.owningKey)) + }) + return subFlow(FinalityFlow(stx, emptyList())) + } + } + + // A flow to update a specific reference state. + class UpdateRefState(private val stateAndRef: StateAndRef) : FlowLogic() { + @Suspendable + override fun call(): SignedTransaction { + val notary = serviceHub.networkMapCache.notaryIdentities.first() + val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply { + addInputState(stateAndRef) + addOutputState(stateAndRef.state.data.update(), RefState.CONTRACT_ID) + addCommand(RefState.Update(), listOf(ourIdentity.owningKey)) + }) + return subFlow(FinalityFlow(stx, emptyList())) + } + } + + // A set of flows to share a stateref with all other nodes in the mock network. + @InitiatingFlow + class Initiator(private val stateAndRef: StateAndRef) : FlowLogic() { + @Suspendable + override fun call() { + val sessions = serviceHub.networkMapCache.allNodes.flatMap { it.legalIdentities }.map { initiateFlow(it) } + val transactionId = stateAndRef.ref.txhash + val transaction = serviceHub.validatedTransactions.getTransaction(transactionId) + ?: throw FlowException("Cannot find $transactionId.") + sessions.forEach { subFlow(SendTransactionFlow(it, transaction)) } + } + } + + @InitiatedBy(Initiator::class) + class Responder(private val otherSession: FlowSession) : FlowLogic() { + @Suspendable + override fun call() { + logger.info("Receiving dependencies.") + subFlow(ReceiveTransactionFlow( + otherSideSession = otherSession, + checkSufficientSignatures = true, + statesToRecord = StatesToRecord.ALL_VISIBLE + )) + } + } + + // A flow to use a reference state in another transaction. + class UseRefState(private val linearId: UniqueIdentifier) : FlowLogic() { + @Suspendable + override fun call(): SignedTransaction { + val notary = serviceHub.networkMapCache.notaryIdentities.first() + val query = QueryCriteria.LinearStateQueryCriteria( + linearId = listOf(linearId), + relevancyStatus = Vault.RelevancyStatus.ALL + ) + val referenceState = serviceHub.vaultService.queryBy(query).states.single() + + val stx = serviceHub.signInitialTransaction(TransactionBuilder(notary = notary).apply { + addReferenceState(referenceState.referenced()) + addOutputState(RefState.State(ourIdentity), RefState.CONTRACT_ID) + addCommand(RefState.Create(), listOf(ourIdentity.owningKey)) + }) + return subFlow(FinalityFlow(stx, emptyList())) + } + } } diff --git a/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt b/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt index e83fa8cfa3..da27807e1b 100644 --- a/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt @@ -15,7 +15,8 @@ import net.corda.testing.core.singleIdentity import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.StartedMockNode -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP +import net.corda.testing.node.internal.enclosedCordapp import org.junit.After import org.junit.Before import org.junit.Test @@ -40,7 +41,7 @@ class ResolveTransactionsFlowTest { @Before fun setup() { - mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", javaClass.packageName))) + mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()))) notaryNode = mockNet.defaultNotaryNode megaCorpNode = mockNet.createPartyNode(CordaX500Name("MegaCorp", "London", "GB")) miniCorpNode = mockNet.createPartyNode(CordaX500Name("MiniCorp", "London", "GB")) diff --git a/finance/workflows/src/test/kotlin/net/corda/finance/contracts/asset/selection/CashSelectionH2ImplTest.kt b/finance/workflows/src/test/kotlin/net/corda/finance/contracts/asset/selection/CashSelectionH2ImplTest.kt index 2a30e5bc01..fe1904d6d0 100644 --- a/finance/workflows/src/test/kotlin/net/corda/finance/contracts/asset/selection/CashSelectionH2ImplTest.kt +++ b/finance/workflows/src/test/kotlin/net/corda/finance/contracts/asset/selection/CashSelectionH2ImplTest.kt @@ -9,8 +9,10 @@ import net.corda.finance.flows.CashException import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashPaymentFlow import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.MockNodeConfigOverrides import net.corda.testing.node.MockNodeParameters +import net.corda.testing.node.internal.FINANCE_CORDAPPS import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.After import org.junit.Test @@ -18,7 +20,7 @@ import java.util.Collections.nCopies import kotlin.test.assertNotNull class CashSelectionH2ImplTest { - private val mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.finance")) + private val mockNet = MockNetwork(MockNetworkParameters(threadPerNode = true, cordappsForAllNodes = FINANCE_CORDAPPS)) @After fun cleanUp() { diff --git a/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt b/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt index 7d4ed7687c..87bb3ac51b 100644 --- a/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt +++ b/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt @@ -9,7 +9,9 @@ import net.corda.finance.contracts.asset.Cash import net.corda.testing.core.BOC_NAME import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.StartedMockNode +import net.corda.testing.node.internal.FINANCE_CORDAPPS import org.junit.After import org.junit.Before import org.junit.Test @@ -26,8 +28,7 @@ class CashExitFlowTests { @Before fun start() { - mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), - cordappPackages = listOf("net.corda.finance.contracts.asset", "net.corda.finance.schemas")) + mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS)) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) notary = mockNet.defaultNotaryIdentity diff --git a/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt b/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt index 83ab2b4a28..5be31773f1 100644 --- a/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt +++ b/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt @@ -9,7 +9,9 @@ import net.corda.finance.contracts.asset.Cash import net.corda.testing.core.BOC_NAME import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.StartedMockNode +import net.corda.testing.node.internal.FINANCE_CORDAPPS import org.junit.After import org.junit.Before import org.junit.Test @@ -24,9 +26,7 @@ class CashIssueFlowTests { @Before fun start() { - mockNet = MockNetwork( - servicePeerAllocationStrategy = RoundRobin(), - cordappPackages = listOf("net.corda.finance.contracts", "net.corda.finance.schemas")) + mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS)) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) notary = mockNet.defaultNotaryIdentity diff --git a/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt b/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt index 75eaa6242e..6e7e54f366 100644 --- a/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt +++ b/finance/workflows/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt @@ -12,7 +12,9 @@ import net.corda.finance.contracts.asset.Cash import net.corda.testing.core.* import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.StartedMockNode +import net.corda.testing.node.internal.FINANCE_CORDAPPS import org.assertj.core.api.Assertions.assertThat import org.junit.After import org.junit.Before @@ -30,7 +32,7 @@ class CashPaymentFlowTests { @Before fun start() { - mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), cordappPackages = listOf("net.corda.finance")) + mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS)) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) aliceNode = mockNet.createPartyNode(ALICE_NAME) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt index c4f5525eec..0240c542a1 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt @@ -23,7 +23,7 @@ import net.corda.testing.driver.DriverDSL import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.driver import net.corda.testing.node.NotarySpec -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.enclosedCordapp import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Test import java.net.URL @@ -50,7 +50,7 @@ class AttachmentLoadingTests { driver(DriverParameters( startNodesInProcess = false, notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)), - cordappsForAllNodes = cordappsForPackages(javaClass.packageName) + cordappsForAllNodes = listOf(enclosedCordapp()) )) { installIsolatedCordapp(ALICE_NAME) @@ -73,7 +73,7 @@ class AttachmentLoadingTests { driver(DriverParameters( startNodesInProcess = false, notarySpecs = listOf(NotarySpec(DUMMY_NOTARY_NAME, validating = false)), - cordappsForAllNodes = cordappsForPackages(javaClass.packageName) + cordappsForAllNodes = listOf(enclosedCordapp()) )) { installIsolatedCordapp(ALICE_NAME) installIsolatedCordapp(BOB_NAME) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/distributed/DistributedServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/distributed/DistributedServiceTests.kt index 183f61553d..82eaec0d59 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/distributed/DistributedServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/distributed/DistributedServiceTests.kt @@ -23,6 +23,7 @@ import net.corda.testing.node.NotarySpec import net.corda.testing.node.User import net.corda.testing.node.internal.DummyClusterSpec import net.corda.testing.node.internal.FINANCE_CORDAPPS +import net.corda.testing.node.internal.cordappWithPackages import org.assertj.core.api.Assertions.assertThat import org.junit.Test import rx.Observable @@ -43,8 +44,7 @@ class DistributedServiceTests { invokeRpc(CordaRPCOps::stateMachinesFeed)) ) driver(DriverParameters( - extraCordappPackagesToScan = listOf("net.corda.notary.raft"), - cordappsForAllNodes = FINANCE_CORDAPPS, + cordappsForAllNodes = FINANCE_CORDAPPS + cordappWithPackages("net.corda.notary.raft"), notarySpecs = listOf(NotarySpec( DUMMY_NOTARY_NAME, rpcUsers = listOf(testUser), diff --git a/node/src/integration-test/kotlin/net/corda/node/services/events/ScheduledFlowIntegrationTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/events/ScheduledFlowIntegrationTests.kt index 4c98256aa8..e8bfd69dcd 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/events/ScheduledFlowIntegrationTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/events/ScheduledFlowIntegrationTests.kt @@ -23,6 +23,9 @@ import net.corda.testing.core.dummyCommand import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.driver import net.corda.testing.node.User +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP +import net.corda.testing.node.internal.cordappWithPackages +import net.corda.testing.node.internal.enclosedCordapp import org.junit.Test import java.time.Instant import java.util.* @@ -97,7 +100,7 @@ class ScheduledFlowIntegrationTests { fun `test that when states are being spent at the same time that schedules trigger everything is processed`() { driver(DriverParameters( startNodesInProcess = true, - extraCordappPackagesToScan = listOf("net.corda.testing.contracts", "net.corda.testMessage") + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, cordappWithPackages("net.corda.testMessage"), enclosedCordapp()) )) { val N = 23 val rpcUser = User("admin", "admin", setOf("ALL")) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt index 178ef87750..532b6ca141 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/statemachine/LargeTransactionsTest.kt @@ -20,6 +20,8 @@ import net.corda.testing.core.dummyCommand import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.driver import net.corda.testing.node.User +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP +import net.corda.testing.node.internal.enclosedCordapp import org.junit.Test import kotlin.test.assertEquals @@ -76,9 +78,10 @@ class LargeTransactionsTest { val bigFile2 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 1, "b") val bigFile3 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 2, "c") val bigFile4 = InputStreamAndHash.createInMemoryTestZip(3.MB.toInt(), 3, "d") + driver(DriverParameters( startNodesInProcess = true, - extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), networkParameters = testNetworkParameters(maxMessageSize = 15.MB.toInt(), maxTransactionSize = 13.MB.toInt()) )) { val rpcUser = User("admin", "admin", setOf("ALL")) diff --git a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt index 233705771a..f7f5f37eaa 100644 --- a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt +++ b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt @@ -47,10 +47,10 @@ import net.corda.testing.core.expect import net.corda.testing.core.expectEvents import net.corda.testing.core.sequence import net.corda.testing.internal.fromUserList +import net.corda.testing.node.internal.FINANCE_CORDAPPS import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNodeParameters import net.corda.testing.node.internal.TestStartedNode -import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.testActor import org.apache.commons.io.IOUtils import org.assertj.core.api.Assertions.* @@ -94,7 +94,7 @@ class CordaRPCOpsImplTest { @Before fun setup() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.finance")) + mockNet = InternalMockNetwork(cordappsForAllNodes = FINANCE_CORDAPPS) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) rpc = aliceNode.rpcOps CURRENT_RPC_CONTEXT.set(RpcAuthContext(InvocationContext.rpc(testActor()), buildSubject("TEST_USER", emptySet()))) diff --git a/node/src/test/kotlin/net/corda/node/internal/CordaServiceTest.kt b/node/src/test/kotlin/net/corda/node/internal/CordaServiceTest.kt index 2a3b3b4a72..a9c09ca681 100644 --- a/node/src/test/kotlin/net/corda/node/internal/CordaServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/internal/CordaServiceTest.kt @@ -1,11 +1,11 @@ package net.corda.node.internal import co.paralleluniverse.fibers.Suspendable -import net.corda.core.flows.FlowLogic -import net.corda.core.flows.StartableByService import net.corda.core.context.InvocationContext import net.corda.core.context.InvocationOrigin import net.corda.core.contracts.ContractState +import net.corda.core.flows.FlowLogic +import net.corda.core.flows.StartableByService import net.corda.core.node.AppServiceHub import net.corda.core.node.ServiceHub import net.corda.core.node.services.CordaService @@ -18,7 +18,10 @@ import net.corda.finance.DOLLARS import net.corda.finance.flows.CashIssueFlow import net.corda.node.internal.cordapp.DummyRPCFlow import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.StartedMockNode +import net.corda.testing.node.internal.FINANCE_CONTRACTS_CORDAPP +import net.corda.testing.node.internal.enclosedCordapp import org.junit.After import org.junit.Before import org.junit.Test @@ -28,69 +31,13 @@ import kotlin.test.assertFailsWith import kotlin.test.assertNotEquals import kotlin.test.assertTrue -@StartableByService -class DummyServiceFlow : FlowLogic() { - companion object { - object TEST_STEP : ProgressTracker.Step("Custom progress step") - } - override val progressTracker: ProgressTracker = ProgressTracker(TEST_STEP) - - @Suspendable - override fun call(): InvocationContext { - // We call a subFlow, otehrwise there is no chance to subscribe to the ProgressTracker - subFlow(CashIssueFlow(100.DOLLARS, OpaqueBytes.of(1), serviceHub.networkMapCache.notaryIdentities.first())) - progressTracker.currentStep = TEST_STEP - return stateMachine.context - } -} - -@CordaService -class TestCordaService(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() { - fun startServiceFlow() { - val handle = appServiceHub.startFlow(DummyServiceFlow()) - val context = handle.returnValue.get() - assertEquals(this.javaClass.name, (context.origin as InvocationOrigin.Service).serviceClassName) - } - - fun startServiceFlowAndTrack() { - val handle = appServiceHub.startTrackedFlow(DummyServiceFlow()) - val count = AtomicInteger(0) - val subscriber = handle.progress.subscribe { count.incrementAndGet() } - handle.returnValue.get() - // Simply prove some progress was made. - // The actual number is currently 11, but don't want to hard code an implementation detail. - assertTrue(count.get() > 1) - subscriber.unsubscribe() - } -} - -@CordaService -class TestCordaService2(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() { - fun startInvalidRPCFlow() { - val handle = appServiceHub.startFlow(DummyRPCFlow()) - handle.returnValue.get() - } - -} - -@CordaService -class LegacyCordaService(@Suppress("UNUSED_PARAMETER") simpleServiceHub: ServiceHub) : SingletonSerializeAsToken() - -@CordaService -class VaultQueryService(val serviceHub: AppServiceHub): SingletonSerializeAsToken() { - init { - val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED) - serviceHub.vaultService.trackBy(ContractState::class.java, criteria) - } -} - class CordaServiceTest { private lateinit var mockNet: MockNetwork private lateinit var nodeA: StartedMockNode @Before fun start() { - mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.node.internal","net.corda.finance")) + mockNet = MockNetwork(MockNetworkParameters(threadPerNode = true, cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP, enclosedCordapp()))) nodeA = mockNet.createNode() mockNet.startNodes() } @@ -139,4 +86,60 @@ class CordaServiceTest { fun `Can query vault service in constructor`() { nodeA.services.cordaService(VaultQueryService::class.java) } + + @StartableByService + class DummyServiceFlow : FlowLogic() { + companion object { + object TEST_STEP : ProgressTracker.Step("Custom progress step") + } + override val progressTracker: ProgressTracker = ProgressTracker(TEST_STEP) + + @Suspendable + override fun call(): InvocationContext { + // We call a subFlow, otehrwise there is no chance to subscribe to the ProgressTracker + subFlow(CashIssueFlow(100.DOLLARS, OpaqueBytes.of(1), serviceHub.networkMapCache.notaryIdentities.first())) + progressTracker.currentStep = TEST_STEP + return stateMachine.context + } + } + + @CordaService + class TestCordaService(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() { + fun startServiceFlow() { + val handle = appServiceHub.startFlow(DummyServiceFlow()) + val context = handle.returnValue.get() + assertEquals(this.javaClass.name, (context.origin as InvocationOrigin.Service).serviceClassName) + } + + fun startServiceFlowAndTrack() { + val handle = appServiceHub.startTrackedFlow(DummyServiceFlow()) + val count = AtomicInteger(0) + val subscriber = handle.progress.subscribe { count.incrementAndGet() } + handle.returnValue.get() + // Simply prove some progress was made. + // The actual number is currently 11, but don't want to hard code an implementation detail. + assertTrue(count.get() > 1) + subscriber.unsubscribe() + } + } + + @CordaService + class TestCordaService2(val appServiceHub: AppServiceHub): SingletonSerializeAsToken() { + fun startInvalidRPCFlow() { + val handle = appServiceHub.startFlow(DummyRPCFlow()) + handle.returnValue.get() + } + + } + + @CordaService + class LegacyCordaService(@Suppress("UNUSED_PARAMETER") simpleServiceHub: ServiceHub) : SingletonSerializeAsToken() + + @CordaService + class VaultQueryService(val serviceHub: AppServiceHub): SingletonSerializeAsToken() { + init { + val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED) + serviceHub.vaultService.trackBy(ContractState::class.java, criteria) + } + } } \ No newline at end of file diff --git a/node/src/test/kotlin/net/corda/node/internal/NodeUnloadHandlerTests.kt b/node/src/test/kotlin/net/corda/node/internal/NodeUnloadHandlerTests.kt index 614045efca..336fcf4f67 100644 --- a/node/src/test/kotlin/net/corda/node/internal/NodeUnloadHandlerTests.kt +++ b/node/src/test/kotlin/net/corda/node/internal/NodeUnloadHandlerTests.kt @@ -1,12 +1,11 @@ package net.corda.node.internal -import net.corda.core.internal.packageName import net.corda.core.node.ServiceHub import net.corda.core.node.services.CordaService import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.utilities.contextLogger import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.enclosedCordapp import org.junit.After import org.junit.Assert.assertTrue import org.junit.Test @@ -19,7 +18,7 @@ class NodeUnloadHandlerTests { val shutdownLatch = CountDownLatch(1) } - private val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(javaClass.packageName), notarySpecs = emptyList()) + private val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(enclosedCordapp()), notarySpecs = emptyList()) @After fun cleanUp() { diff --git a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt index 600cbde014..a6945a069f 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -70,13 +70,11 @@ import kotlin.test.assertTrue @RunWith(Parameterized::class) class TwoPartyTradeFlowTests(private val anonymous: Boolean) { companion object { - private val cordappPackages = listOf("net.corda.finance.contracts", "net.corda.finance.schemas") @JvmStatic @Parameterized.Parameters(name = "Anonymous = {0}") fun data(): Collection = listOf(true, false) private val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20) - private val DUMMY_NOTARY get() = dummyNotary.party } private lateinit var mockNet: InternalMockNetwork @@ -99,7 +97,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { // We run this in parallel threads to help catch any race conditions that may exist. The other tests // we run in the unit test thread exclusively to speed things up, ensure deterministic results and // allow interruption half way through. - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages), threadPerNode = true) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP), threadPerNode = true) val notaryNode = mockNet.defaultNotaryNode val notary = mockNet.defaultNotaryIdentity notaryNode.services.ledger(notary) { @@ -149,7 +147,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { @Test(expected = InsufficientBalanceException::class) fun `trade cash for commercial paper fails using soft locking`() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages), threadPerNode = true) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP), threadPerNode = true) val notaryNode = mockNet.defaultNotaryNode notaryNode.services.ledger(notaryNode.info.singleIdentity()) { val aliceNode = mockNet.createPartyNode(ALICE_NAME) @@ -205,7 +203,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { @Test fun `shutdown and restore`() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP)) val notaryNode = mockNet.defaultNotaryNode val notary = mockNet.defaultNotaryIdentity notaryNode.services.ledger(notary) { @@ -314,7 +312,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { @Test fun `check dependencies of sale asset are resolved`() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP)) val notaryNode = mockNet.defaultNotaryNode val aliceNode = makeNodeWithTracking(ALICE_NAME) val bobNode = makeNodeWithTracking(BOB_NAME) @@ -417,7 +415,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { @Test fun `track works`() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP)) val notaryNode = mockNet.defaultNotaryNode val aliceNode = makeNodeWithTracking(ALICE_NAME) val bobNode = makeNodeWithTracking(BOB_NAME) @@ -498,7 +496,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { @Test fun `dependency with error on buyer side`() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP)) mockNet.defaultNotaryNode.services.ledger(mockNet.defaultNotaryIdentity) { runWithError(true, false, "at least one cash input") } @@ -506,7 +504,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { @Test fun `dependency with error on seller side`() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(cordappPackages)) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP)) mockNet.defaultNotaryNode.services.ledger(mockNet.defaultNotaryIdentity) { runWithError(false, true, "Issuances have a time-window") } diff --git a/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt b/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt index 55b9b4d4c8..5c0fe3f861 100644 --- a/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt +++ b/node/src/test/kotlin/net/corda/node/modes/draining/ScheduledFlowsDrainingModeTest.kt @@ -4,7 +4,6 @@ import co.paralleluniverse.fibers.Suspendable import net.corda.core.contracts.* import net.corda.core.flows.* import net.corda.core.identity.Party -import net.corda.core.internal.packageName import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.contextLogger import net.corda.core.utilities.getOrThrow @@ -42,7 +41,7 @@ class ScheduledFlowsDrainingModeTest { @Before fun setup() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", javaClass.packageName), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), threadPerNode = true ) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) diff --git a/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt b/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt index 6bb4af859f..5615d44597 100644 --- a/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/FinalityHandlerTest.kt @@ -6,7 +6,6 @@ import net.corda.core.crypto.SecureHash import net.corda.core.flows.FinalityFlow import net.corda.core.flows.StateMachineRunId import net.corda.core.internal.cordapp.CordappResolver -import net.corda.core.internal.packageName import net.corda.core.toFuture import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder @@ -43,7 +42,7 @@ class FinalityHandlerTest { legalName = BOB_NAME, // The node disables the FinalityHandler completely if there are no old CorDapps loaded, so we need to add // a token old CorDapp to keep the handler running. - additionalCordapps = setOf(cordappWithPackages(javaClass.packageName).copy(targetPlatformVersion = 3)) + additionalCordapps = setOf(DUMMY_CONTRACTS_CORDAPP.copy(targetPlatformVersion = 3)) )) val stx = alice.issueCashTo(bob) diff --git a/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt b/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt index 9181ba1d35..6dbd003217 100644 --- a/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt @@ -19,10 +19,8 @@ import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.dummyCommand import net.corda.testing.core.singleIdentity -import net.corda.testing.node.MockNetwork -import net.corda.testing.node.MockNetworkNotarySpec -import net.corda.testing.node.MockNodeParameters -import net.corda.testing.node.StartedMockNode +import net.corda.testing.node.* +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.junit.After import org.junit.Before @@ -47,10 +45,10 @@ class NotaryChangeTests { @Before fun setUp() { - mockNet = MockNetwork( + mockNet = MockNetwork(MockNetworkParameters( notarySpecs = listOf(MockNetworkNotarySpec(oldNotaryName), MockNetworkNotarySpec(newNotaryName)), - cordappPackages = listOf("net.corda.testing.contracts") - ) + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP) + )) clientNodeA = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME)) clientNodeB = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME)) clientA = clientNodeA.info.singleIdentity() diff --git a/node/src/test/kotlin/net/corda/node/services/ServiceHubConcurrentUsageTest.kt b/node/src/test/kotlin/net/corda/node/services/ServiceHubConcurrentUsageTest.kt index 68e9a8d02d..030e289a53 100644 --- a/node/src/test/kotlin/net/corda/node/services/ServiceHubConcurrentUsageTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/ServiceHubConcurrentUsageTest.kt @@ -5,7 +5,6 @@ import net.corda.core.contracts.ContractState import net.corda.core.flows.FinalityFlow import net.corda.core.flows.FlowLogic import net.corda.core.identity.Party -import net.corda.core.internal.packageName import net.corda.core.node.services.queryBy import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder @@ -14,7 +13,7 @@ import net.corda.core.utilities.getOrThrow import net.corda.finance.DOLLARS import net.corda.finance.contracts.asset.Cash import net.corda.finance.issuedBy -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.FINANCE_CONTRACTS_CORDAPP import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.startFlow import org.assertj.core.api.Assertions.assertThat @@ -24,11 +23,7 @@ import rx.schedulers.Schedulers import java.util.concurrent.CountDownLatch class ServiceHubConcurrentUsageTest { - private val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages( - "net.corda.finance.schemas", - "net.corda.node.services.vault.VaultQueryExceptionsTests", - Cash::class.packageName - )) + private val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(FINANCE_CONTRACTS_CORDAPP)) @After fun stopNodes() { @@ -42,7 +37,7 @@ class ServiceHubConcurrentUsageTest { val initiatingFlow = TestFlow(mockNet.defaultNotaryIdentity) val node = mockNet.createPartyNode() - node.services.validatedTransactions.updates.observeOn(Schedulers.io()).subscribe { _ -> + node.services.validatedTransactions.updates.observeOn(Schedulers.io()).subscribe { try { node.services.vaultService.queryBy().states successful = true diff --git a/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt index 1aeddd0256..f06adb451f 100644 --- a/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/TimedFlowTests.kt @@ -75,7 +75,7 @@ class TimedFlowTests { @JvmStatic fun setup() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.node.services"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), defaultParameters = MockNetworkParameters().withServicePeerAllocationStrategy(InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin()), threadPerNode = true ) diff --git a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt index 4ce505abbd..aa4a522656 100644 --- a/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/events/ScheduledFlowTests.kt @@ -6,7 +6,6 @@ import net.corda.core.context.InvocationOrigin import net.corda.core.contracts.* import net.corda.core.flows.* import net.corda.core.identity.Party -import net.corda.core.internal.packageName import net.corda.core.node.services.VaultService import net.corda.core.node.services.queryBy import net.corda.core.node.services.vault.QueryCriteria.VaultQueryCriteria @@ -112,7 +111,7 @@ class ScheduledFlowTests { @Before fun setup() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", javaClass.packageName), threadPerNode = true) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), threadPerNode = true) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) bobNode = mockNet.createNode(InternalMockNodeParameters(legalName = BOB_NAME)) notary = mockNet.defaultNotaryIdentity diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/ExposeJpaToFlowsTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/ExposeJpaToFlowsTests.kt index b359a32fdf..ff7df92e60 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/ExposeJpaToFlowsTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/ExposeJpaToFlowsTests.kt @@ -13,7 +13,7 @@ import net.corda.testing.core.TestIdentity import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.MockServices -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.enclosedCordapp import net.corda.testing.node.makeTestIdentityService import org.junit.After import org.junit.Before @@ -43,7 +43,7 @@ class ExposeJpaToFlowsTests { @Before fun setUp() { - mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = cordappsForPackages(javaClass.packageName))) + mockNet = MockNetwork(MockNetworkParameters(cordappsForAllNodes = listOf(enclosedCordapp()))) val (db, mockServices) = MockServices.makeTestDatabaseAndMockServices( cordappPackages = listOf(javaClass.packageName), identityService = makeTestIdentityService(myself.identity), diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/HibernateColumnConverterTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/HibernateColumnConverterTests.kt index 47e0c82cfd..b4e3c1bcd2 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/HibernateColumnConverterTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/HibernateColumnConverterTests.kt @@ -2,8 +2,6 @@ package net.corda.node.services.persistence import co.paralleluniverse.fibers.Suspendable import net.corda.core.contracts.Amount -import net.corda.core.flows.FlowLogic -import net.corda.core.flows.StartableByRPC import net.corda.core.identity.Party import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.OpaqueBytes @@ -17,9 +15,11 @@ import net.corda.node.services.identity.PersistentIdentityService import net.corda.node.services.keys.E2ETestKeyManagementService import net.corda.testing.core.BOC_NAME import net.corda.testing.internal.TestingNamedCacheFactory -import net.corda.testing.node.InMemoryMessagingNetwork +import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.StartedMockNode +import net.corda.testing.node.internal.FINANCE_CORDAPPS import org.junit.After import org.junit.Before import org.junit.Test @@ -48,9 +48,7 @@ class HibernateColumnConverterTests { @Before fun start() { - mockNet = MockNetwork( - servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin(), - cordappPackages = listOf("net.corda.finance.contracts.asset", "net.corda.finance.schemas")) + mockNet = MockNetwork(MockNetworkParameters(servicePeerAllocationStrategy = RoundRobin(), cordappsForAllNodes = FINANCE_CORDAPPS)) bankOfCordaNode = mockNet.createPartyNode(BOC_NAME) bankOfCorda = bankOfCordaNode.info.identityFromX500Name(BOC_NAME) notary = mockNet.defaultNotaryIdentity diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/ObserverNodeTransactionTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/ObserverNodeTransactionTests.kt index f244e2dc17..e681b7cac7 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/ObserverNodeTransactionTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/ObserverNodeTransactionTests.kt @@ -6,17 +6,21 @@ import net.corda.core.contracts.StateAndContract import net.corda.core.contracts.StateAndRef import net.corda.core.flows.* import net.corda.core.identity.Party -import net.corda.core.internal.packageName import net.corda.core.node.StatesToRecord import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.getOrThrow +import net.corda.node.testing.MESSAGE_CHAIN_CONTRACT_PROGRAM_ID +import net.corda.node.testing.MessageChainContract +import net.corda.node.testing.MessageChainState +import net.corda.node.testing.MessageData import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.core.singleIdentity import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.cordappWithPackages +import net.corda.testing.node.internal.enclosedCordapp import net.corda.testing.node.internal.startFlow import org.junit.After import org.junit.Before @@ -25,15 +29,15 @@ import kotlin.test.assertEquals import kotlin.test.assertNotNull class ObserverNodeTransactionTests { - private lateinit var mockNet: InternalMockNetwork @Before fun start() { mockNet = InternalMockNetwork( - cordappsForAllNodes = listOf(cordappWithPackages(MessageChainState::class.packageName)), + cordappsForAllNodes = listOf(cordappWithPackages("net.corda.node.testing"), enclosedCordapp()), networkSendManuallyPumped = false, - threadPerNode = true) + threadPerNode = true + ) } @After @@ -50,15 +54,15 @@ class ObserverNodeTransactionTests { fun buildTransactionChain(initialMessage: MessageData, chainLength: Int) { node.services.startFlow(StartMessageChainFlow(initialMessage, notary)).resultFuture.getOrThrow() - var result = node.services.vaultService.queryBy(MessageChainState::class.java).states.filter { + var result = node.services.vaultService.queryBy(MessageChainState::class.java).states.singleOrNull { it.state.data.message.value.startsWith(initialMessage.value) - }.singleOrNull() + } for (_i in 0.until(chainLength -1 )) { node.services.startFlow(ContinueMessageChainFlow(result!!, notary)).resultFuture.getOrThrow() - result = node.services.vaultService.queryBy(MessageChainState::class.java).states.filter { + result = node.services.vaultService.queryBy(MessageChainState::class.java).states.singleOrNull { it.state.data.message.value.startsWith(initialMessage.value) - }.singleOrNull() + } } } @@ -86,101 +90,98 @@ class ObserverNodeTransactionTests { val outputMessage = MessageData("AAAA") checkObserverTransactions(outputMessage) } -} -@StartableByRPC -class StartMessageChainFlow(private val message: MessageData, private val notary: Party) : FlowLogic() { - companion object { - object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.") - object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.") - object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.") - object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") { - override fun childProgressTracker() = FinalityFlow.tracker() + + @StartableByRPC + class StartMessageChainFlow(private val message: MessageData, private val notary: Party) : FlowLogic() { + companion object { + object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.") + object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.") + object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.") + object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") { + override fun childProgressTracker() = FinalityFlow.tracker() + } + + fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION) } - fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION) + override val progressTracker = tracker() + + @Suspendable + override fun call(): SignedTransaction { + progressTracker.currentStep = GENERATING_TRANSACTION + + val messageState = MessageChainState(message = message, by = ourIdentity) + val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey }) + val txBuilder = TransactionBuilder(notary).withItems(StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID), txCommand) + + progressTracker.currentStep = VERIFYING_TRANSACTION + txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify() + + progressTracker.currentStep = SIGNING_TRANSACTION + val signedTx = serviceHub.signInitialTransaction(txBuilder) + + progressTracker.currentStep = FINALISING_TRANSACTION + return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker())) + } } - override val progressTracker = tracker() + @StartableByRPC + class ContinueMessageChainFlow(private val stateRef: StateAndRef, + private val notary: Party) : FlowLogic() { + companion object { + object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.") + object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.") + object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.") + object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") { + override fun childProgressTracker() = FinalityFlow.tracker() + } - @Suspendable - override fun call(): SignedTransaction { - progressTracker.currentStep = GENERATING_TRANSACTION - - val messageState = MessageChainState(message = message, by = ourIdentity) - val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey }) - val txBuilder = TransactionBuilder(notary).withItems(StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID), txCommand) - - progressTracker.currentStep = VERIFYING_TRANSACTION - txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify() - - progressTracker.currentStep = SIGNING_TRANSACTION - val signedTx = serviceHub.signInitialTransaction(txBuilder) - - progressTracker.currentStep = FINALISING_TRANSACTION - return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker())) - } -} - -@StartableByRPC -class ContinueMessageChainFlow(private val stateRef: StateAndRef, - private val notary: Party) : FlowLogic() { - companion object { - object GENERATING_TRANSACTION : ProgressTracker.Step("Generating transaction based on the message.") - object VERIFYING_TRANSACTION : ProgressTracker.Step("Verifying contract constraints.") - object SIGNING_TRANSACTION : ProgressTracker.Step("Signing transaction with our private key.") - object FINALISING_TRANSACTION : ProgressTracker.Step("Obtaining notary signature and recording transaction.") { - override fun childProgressTracker() = FinalityFlow.tracker() + fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION) } - fun tracker() = ProgressTracker(GENERATING_TRANSACTION, VERIFYING_TRANSACTION, SIGNING_TRANSACTION, FINALISING_TRANSACTION) + override val progressTracker = tracker() + + @Suspendable + override fun call(): SignedTransaction { + progressTracker.currentStep = GENERATING_TRANSACTION + + val oldMessageState = stateRef.state.data + val messageState = MessageChainState(MessageData(oldMessageState.message.value + "A"), + ourIdentity, + stateRef.state.data.linearId) + val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey }) + val txBuilder = TransactionBuilder(notary).withItems( + StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID), + txCommand, + stateRef) + + progressTracker.currentStep = VERIFYING_TRANSACTION + txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify() + + progressTracker.currentStep = SIGNING_TRANSACTION + val signedTx = serviceHub.signInitialTransaction(txBuilder) + + progressTracker.currentStep = FINALISING_TRANSACTION + return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker())) + } } - override val progressTracker = tracker() + @InitiatingFlow + @StartableByRPC + class ReportToCounterparty(private val regulator: Party, private val signedTx: SignedTransaction) : FlowLogic() { + @Suspendable + override fun call() { + val session = initiateFlow(regulator) + subFlow(SendTransactionFlow(session, signedTx)) + } + } - @Suspendable - override fun call(): SignedTransaction { - progressTracker.currentStep = GENERATING_TRANSACTION - - val oldMessageState = stateRef.state.data - val messageState = MessageChainState(MessageData(oldMessageState.message.value + "A"), - ourIdentity, - stateRef.state.data.linearId) - val txCommand = Command(MessageChainContract.Commands.Send(), messageState.participants.map { it.owningKey }) - val txBuilder = TransactionBuilder(notary).withItems( - StateAndContract(messageState, MESSAGE_CHAIN_CONTRACT_PROGRAM_ID), - txCommand, - stateRef) - - progressTracker.currentStep = VERIFYING_TRANSACTION - txBuilder.toWireTransaction(serviceHub).toLedgerTransaction(serviceHub).verify() - - progressTracker.currentStep = SIGNING_TRANSACTION - val signedTx = serviceHub.signInitialTransaction(txBuilder) - - progressTracker.currentStep = FINALISING_TRANSACTION - return subFlow(FinalityFlow(signedTx, emptyList(), FINALISING_TRANSACTION.childProgressTracker())) + @InitiatedBy(ReportToCounterparty::class) + class ReceiveReportedTransaction(private val otherSideSession: FlowSession) : FlowLogic() { + @Suspendable + override fun call() { + subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE)) + } } } - -@InitiatingFlow -@StartableByRPC -class ReportToCounterparty( - private val regulator: Party, - private val signedTx: SignedTransaction) : FlowLogic() { - - @Suspendable - override fun call() { - val session = initiateFlow(regulator) - subFlow(SendTransactionFlow(session, signedTx)) - } -} - -@InitiatedBy(ReportToCounterparty::class) -class ReceiveReportedTransaction(private val otherSideSession: FlowSession) : FlowLogic() { - - @Suspendable - override fun call() { - subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ALL_VISIBLE)) - } -} \ No newline at end of file diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/TransactionOrderingTests.kt b/node/src/test/kotlin/net/corda/node/services/persistence/TransactionOrderingTests.kt index 507c72bd03..7ec1eba568 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/TransactionOrderingTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/TransactionOrderingTests.kt @@ -7,17 +7,21 @@ import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef import net.corda.core.flows.* import net.corda.core.identity.Party -import net.corda.core.internal.packageName import net.corda.core.node.StatesToRecord import net.corda.core.node.services.Vault import net.corda.core.node.services.vault.QueryCriteria import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.core.utilities.getOrThrow +import net.corda.node.testing.MESSAGE_CHAIN_CONTRACT_PROGRAM_ID +import net.corda.node.testing.MessageChainContract +import net.corda.node.testing.MessageChainState +import net.corda.node.testing.MessageData import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.BOB_NAME import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.cordappWithPackages +import net.corda.testing.node.internal.enclosedCordapp import net.corda.testing.node.internal.startFlow import org.junit.After import org.junit.Before @@ -30,9 +34,10 @@ class TransactionOrderingTests { @Before fun start() { mockNet = InternalMockNetwork( - cordappsForAllNodes = listOf(cordappWithPackages(MessageChainState::class.packageName)), + cordappsForAllNodes = listOf(cordappWithPackages("net.corda.node.testing"), enclosedCordapp()), networkSendManuallyPumped = false, - threadPerNode = true) + threadPerNode = true + ) } @After @@ -91,25 +96,26 @@ class TransactionOrderingTests { val bobStates = bob.services.vaultService.queryBy(MessageChainState::class.java, queryCriteria) assertEquals(3, bobStates.states.size) } -} -@InitiatingFlow -@StartableByRPC -class SendTx(private val party: Party, - private val stx: SignedTransaction) : FlowLogic() { - @Suspendable - override fun call() { - val session = initiateFlow(party) - subFlow(SendTransactionFlow(session, stx)) - session.receive() + + @InitiatingFlow + @StartableByRPC + class SendTx(private val party: Party, + private val stx: SignedTransaction) : FlowLogic() { + @Suspendable + override fun call() { + val session = initiateFlow(party) + subFlow(SendTransactionFlow(session, stx)) + session.receive() + } + } + + @InitiatedBy(SendTx::class) + class ReceiveTx(private val otherSideSession: FlowSession) : FlowLogic() { + @Suspendable + override fun call() { + subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ONLY_RELEVANT)) + otherSideSession.send(Unit) + } } } - -@InitiatedBy(SendTx::class) -class ReceiveTx(private val otherSideSession: FlowSession) : FlowLogic() { - @Suspendable - override fun call() { - subFlow(ReceiveTransactionFlow(otherSideSession, true, StatesToRecord.ONLY_RELEVANT)) - otherSideSession.send(Unit) - } -} \ No newline at end of file diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowAsyncOperationTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowAsyncOperationTests.kt index 21765af86b..73e5bc6c9d 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowAsyncOperationTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowAsyncOperationTests.kt @@ -11,10 +11,7 @@ import net.corda.core.internal.executeAsync import net.corda.core.node.AppServiceHub import net.corda.core.node.services.CordaService import net.corda.core.serialization.SingletonSerializeAsToken -import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.TestStartedNode -import net.corda.testing.node.internal.cordappsForPackages -import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.internal.* import org.junit.After import org.junit.Before import org.junit.Test @@ -28,7 +25,7 @@ class FlowAsyncOperationTests { @Before fun setup() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts", "net.corda.node.services.statemachine"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), notarySpecs = emptyList() ) aliceNode = mockNet.createNode() diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkPersistenceTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkPersistenceTests.kt index 8a9156af4a..dc960b59af 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkPersistenceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkPersistenceTests.kt @@ -43,7 +43,7 @@ class FlowFrameworkPersistenceTests { @Before fun start() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.finance.contracts", "net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin() ) aliceFlowManager = MockNodeFlowManager() diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt index 57ab6419d8..3d3c28a3c4 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt @@ -66,7 +66,7 @@ class FlowFrameworkTests { @Before fun setUpMockNet() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts") + FINANCE_CORDAPPS, + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), servicePeerAllocationStrategy = RoundRobin() ) diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTripartyTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTripartyTests.kt index eb7be9531f..4f731c889b 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTripartyTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTripartyTests.kt @@ -40,7 +40,7 @@ class FlowFrameworkTripartyTests { @Before fun setUpGlobalMockNet() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.finance.contracts", "net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), servicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin() ) diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt index c6706d77b4..38a43a4534 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/IdempotentFlowTests.kt @@ -9,7 +9,6 @@ import net.corda.core.flows.InitiatingFlow import net.corda.core.identity.CordaX500Name import net.corda.core.internal.IdempotentFlow import net.corda.core.internal.TimedFlow -import net.corda.core.internal.packageName import net.corda.core.utilities.seconds import net.corda.node.services.config.FlowTimeoutConfiguration import net.corda.testing.node.internal.* @@ -33,7 +32,7 @@ class IdempotentFlowTests { @Before fun start() { - mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = cordappsForPackages(this.javaClass.packageName)) + mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp())) nodeA = mockNet.createNode(InternalMockNodeParameters( legalName = CordaX500Name("Alice", "AliceCorp", "GB"), configOverrides = { diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt index 4255224d16..a092a58de1 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/RetryFlowMockTest.kt @@ -7,7 +7,6 @@ import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.internal.FlowStateMachine import net.corda.core.internal.concurrent.flatMap -import net.corda.core.internal.packageName import net.corda.core.messaging.MessageRecipients import net.corda.core.utilities.UntrustworthyData import net.corda.core.utilities.getOrThrow @@ -39,7 +38,7 @@ class RetryFlowMockTest { @Before fun start() { - mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = cordappsForPackages(this.javaClass.packageName)) + mockNet = InternalMockNetwork(threadPerNode = true, cordappsForAllNodes = listOf(enclosedCordapp())) nodeA = mockNet.createNode() nodeB = mockNet.createNode() mockNet.startNodes() @@ -180,108 +179,109 @@ class RetryFlowMockTest { nodeA.smm.killFlow(flow.id) assertThat(nodeA.smm.flowHospital.track().snapshot).isEmpty() } -} -class LimitedRetryCausingError : ConstraintViolationException("Test message", SQLException(), "Test constraint") -class RetryCausingError : SQLException("deadlock") + class LimitedRetryCausingError : ConstraintViolationException("Test message", SQLException(), "Test constraint") -class RetryFlow(private val i: Int) : FlowLogic() { - companion object { - @Volatile - var count = 0 + class RetryCausingError : SQLException("deadlock") + + class RetryFlow(private val i: Int) : FlowLogic() { + companion object { + @Volatile + var count = 0 + } + + @Suspendable + override fun call() { + logger.info("Hello $count") + if (count++ < i) { + if (i == Int.MAX_VALUE) { + throw LimitedRetryCausingError() + } else { + throw RetryCausingError() + } + } + } } - @Suspendable - override fun call() { - logger.info("Hello $count") - if (count++ < i) { - if (i == Int.MAX_VALUE) { - throw LimitedRetryCausingError() - } else { + @InitiatingFlow + class SendAndRetryFlow(private val i: Int, private val other: Party) : FlowLogic() { + companion object { + @Volatile + var count = 0 + } + + @Suspendable + override fun call() { + logger.info("Sending...") + val session = initiateFlow(other) + session.send("Boo") + if (count++ < i) { throw RetryCausingError() } } } -} -@InitiatingFlow -class SendAndRetryFlow(private val i: Int, private val other: Party) : FlowLogic() { - companion object { - @Volatile - var count = 0 - } - - @Suspendable - override fun call() { - logger.info("Sending...") - val session = initiateFlow(other) - session.send("Boo") - if (count++ < i) { - throw RetryCausingError() - } - } -} - -@Suppress("unused") -@InitiatedBy(SendAndRetryFlow::class) -class ReceiveFlow2(private val other: FlowSession) : FlowLogic() { - @Suspendable - override fun call() { - val received = other.receive().unwrap { it } - logger.info("Received... $received") - } -} - -@InitiatingFlow -class KeepSendingFlow(private val i: Int, private val other: Party) : FlowLogic() { - companion object { - val count = AtomicInteger(0) - } - - @Suspendable - override fun call() { - val session = initiateFlow(other) - session.send(i.toString()) - do { - logger.info("Sending... $count") - session.send("Boo") - } while (count.getAndIncrement() < i) - } -} - -@Suppress("unused") -@InitiatedBy(KeepSendingFlow::class) -class ReceiveFlow3(private val other: FlowSession) : FlowLogic() { - @Suspendable - override fun call() { - var count = other.receive().unwrap { it.toInt() } - while (count-- > 0) { + @Suppress("unused") + @InitiatedBy(SendAndRetryFlow::class) + class ReceiveFlow2(private val other: FlowSession) : FlowLogic() { + @Suspendable + override fun call() { val received = other.receive().unwrap { it } - logger.info("Received... $received $count") + logger.info("Received... $received") } } -} -class RetryInsertFlow(private val i: Int) : FlowLogic() { - companion object { - @Volatile - var count = 0 + @InitiatingFlow + class KeepSendingFlow(private val i: Int, private val other: Party) : FlowLogic() { + companion object { + val count = AtomicInteger(0) + } + + @Suspendable + override fun call() { + val session = initiateFlow(other) + session.send(i.toString()) + do { + logger.info("Sending... $count") + session.send("Boo") + } while (count.getAndIncrement() < i) + } } - @Suspendable - override fun call() { - logger.info("Hello") - doInsert() - // Checkpoint so we roll back to here - FlowLogic.sleep(Duration.ofSeconds(0)) - if (count++ < i) { + @Suppress("unused") + @InitiatedBy(KeepSendingFlow::class) + class ReceiveFlow3(private val other: FlowSession) : FlowLogic() { + @Suspendable + override fun call() { + var count = other.receive().unwrap { it.toInt() } + while (count-- > 0) { + val received = other.receive().unwrap { it } + logger.info("Received... $received $count") + } + } + } + + class RetryInsertFlow(private val i: Int) : FlowLogic() { + companion object { + @Volatile + var count = 0 + } + + @Suspendable + override fun call() { + logger.info("Hello") doInsert() + // Checkpoint so we roll back to here + FlowLogic.sleep(Duration.ofSeconds(0)) + if (count++ < i) { + doInsert() + } + } + + private fun doInsert() { + val tx = DBTransactionStorage.DBTransaction("Foo") + contextTransaction.session.save(tx) } } - - private fun doInsert() { - val tx = DBTransactionStorage.DBTransaction("Foo") - contextTransaction.session.save(tx) - } } diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/MaxTransactionSizeTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/MaxTransactionSizeTests.kt index 1f495e95c0..2ef7dd9fca 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/MaxTransactionSizeTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/MaxTransactionSizeTests.kt @@ -16,9 +16,13 @@ import net.corda.testing.core.BOB_NAME import net.corda.testing.core.dummyCommand import net.corda.testing.core.singleIdentity import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockNetworkParameters import net.corda.testing.node.MockNodeParameters import net.corda.testing.node.StartedMockNode +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP +import net.corda.testing.node.internal.enclosedCordapp import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.After import org.junit.Before import org.junit.Test @@ -37,10 +41,12 @@ class MaxTransactionSizeTests { @Before fun setup() { - mockNet = MockNetwork(listOf("net.corda.testing.contracts"), networkParameters = testNetworkParameters(maxTransactionSize = 3_000_000)) + mockNet = MockNetwork(MockNetworkParameters( + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP, enclosedCordapp()), + networkParameters = testNetworkParameters(maxTransactionSize = 3_000_000) + )) aliceNode = mockNet.createNode(MockNodeParameters(legalName = ALICE_NAME)) bobNode = mockNet.createNode(MockNodeParameters(legalName = BOB_NAME)) - bobNode.registerInitiatedFlow(ReceiveLargeTransactionFlow::class.java) notaryNode = mockNet.defaultNotaryNode notary = mockNet.defaultNotaryIdentity alice = aliceNode.info.singleIdentity() @@ -90,11 +96,10 @@ class MaxTransactionSizeTests { assertEquals(hash1, bigFile1.sha256) SendLargeTransactionFlow(notary, bob, hash1, hash2, hash3, hash4, verify = false) } - assertFailsWith { - val future = aliceNode.startFlow(flow) - mockNet.runNetwork() - future.getOrThrow() - } + + val future = aliceNode.startFlow(flow) + mockNet.runNetwork() + assertThatThrownBy { future.getOrThrow() }.hasMessageContaining("Transaction exceeded network's maximum transaction size limit") } private fun StartedMockNode.importAttachment(inputStream: InputStream): AttachmentId { @@ -133,7 +138,11 @@ class MaxTransactionSizeTests { class ReceiveLargeTransactionFlow(private val otherSide: FlowSession) : FlowLogic() { @Suspendable override fun call() { - subFlow(ReceiveTransactionFlow(otherSide)) + try { + subFlow(ReceiveTransactionFlow(otherSide)) + } catch (e: IllegalArgumentException) { + throw FlowException(e.message) + } // Unblock the other side by sending some dummy object (Unit is fine here as it's a singleton). otherSide.send(Unit) } diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/NonValidatingNotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/NonValidatingNotaryServiceTests.kt index a8603d9a0b..c3b1ed81b1 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/NonValidatingNotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/NonValidatingNotaryServiceTests.kt @@ -46,8 +46,10 @@ class NonValidatingNotaryServiceTests { @Before fun setup() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), - notarySpecs = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME, false))) + mockNet = InternalMockNetwork( + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), + notarySpecs = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME, false)) + ) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) notaryNode = mockNet.defaultNotaryNode notary = mockNet.defaultNotaryIdentity diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt index d57fa9c465..5ef14c1e3c 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryServiceTests.kt @@ -35,7 +35,7 @@ class NotaryServiceTests { @Before fun setup() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), notarySpecs = listOf(MockNetworkNotarySpec(DUMMY_NOTARY_NAME, validating = false)), initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4) ) diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryWhitelistTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryWhitelistTests.kt index 7f78e0c3ef..48218cf19d 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/NotaryWhitelistTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/NotaryWhitelistTests.kt @@ -60,7 +60,7 @@ class NotaryWhitelistTests( @Before fun setup() { mockNet = InternalMockNetwork( - cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), notarySpecs = listOf(MockNetworkNotarySpec(oldNotaryName, validating = isValidating), MockNetworkNotarySpec(newNotaryName, validating = isValidating)), initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4) ) diff --git a/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt b/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt index 615124672f..7686568d14 100644 --- a/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/transactions/ValidatingNotaryServiceTests.kt @@ -48,8 +48,10 @@ class ValidatingNotaryServiceTests { @Before fun setup() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts"), - initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4)) + mockNet = InternalMockNetwork( + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), + initialNetworkParameters = testNetworkParameters(minimumPlatformVersion = 4) + ) aliceNode = mockNet.createNode(InternalMockNodeParameters(legalName = ALICE_NAME)) notaryNode = mockNet.defaultNotaryNode notary = mockNet.defaultNotaryIdentity diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt index 184993c947..bf50cf17c8 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultSoftLockManagerTest.kt @@ -6,7 +6,6 @@ import net.corda.core.contracts.* import net.corda.core.flows.* import net.corda.core.identity.AbstractParty import net.corda.core.internal.FlowStateMachine -import net.corda.core.internal.packageName import net.corda.core.internal.uncheckedCast import net.corda.core.node.ServicesForResolution import net.corda.core.node.services.KeyManagementService @@ -26,7 +25,7 @@ import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.testing.core.singleIdentity import net.corda.testing.internal.rigorousMock import net.corda.testing.node.internal.InternalMockNetwork -import net.corda.testing.node.internal.cordappsForPackages +import net.corda.testing.node.internal.enclosedCordapp import net.corda.testing.node.internal.startFlow import org.junit.After import org.junit.Test @@ -79,7 +78,7 @@ class VaultSoftLockManagerTest { doNothing().whenever(it).softLockRelease(any(), anyOrNull()) } - private val mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages(ContractImpl::class.packageName), defaultFactory = { args -> + private val mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(enclosedCordapp()), defaultFactory = { args -> object : InternalMockNetwork.MockNode(args) { override fun makeVaultService(keyManagementService: KeyManagementService, services: ServicesForResolution, diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/MessageChainState.kt b/node/src/test/kotlin/net/corda/node/testing/MessageChainState.kt similarity index 94% rename from node/src/test/kotlin/net/corda/node/services/persistence/MessageChainState.kt rename to node/src/test/kotlin/net/corda/node/testing/MessageChainState.kt index 37dfdbb61e..d34eb8ab20 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/MessageChainState.kt +++ b/node/src/test/kotlin/net/corda/node/testing/MessageChainState.kt @@ -1,4 +1,4 @@ -package net.corda.node.services.persistence +package net.corda.node.testing import net.corda.core.contracts.* import net.corda.core.identity.AbstractParty @@ -48,7 +48,7 @@ object MessageChainSchemaV1 : MappedSchema( ) : PersistentState() } -const val MESSAGE_CHAIN_CONTRACT_PROGRAM_ID = "net.corda.node.services.persistence.MessageChainContract" +const val MESSAGE_CHAIN_CONTRACT_PROGRAM_ID = "net.corda.node.testing.MessageChainContract" open class MessageChainContract : Contract { override fun verify(tx: LedgerTransaction) { @@ -67,4 +67,3 @@ open class MessageChainContract : Contract { class Send : Commands } } - diff --git a/node/src/test/kotlin/net/corda/notary/experimental/bftsmart/BFTNotaryServiceTests.kt b/node/src/test/kotlin/net/corda/notary/experimental/bftsmart/BFTNotaryServiceTests.kt index fe3298b704..5511b44fda 100644 --- a/node/src/test/kotlin/net/corda/notary/experimental/bftsmart/BFTNotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/notary/experimental/bftsmart/BFTNotaryServiceTests.kt @@ -24,9 +24,6 @@ import net.corda.core.utilities.seconds import net.corda.node.services.config.NotaryConfig import net.corda.nodeapi.internal.DevIdentityGenerator import net.corda.nodeapi.internal.network.NetworkParametersCopier -import net.corda.notary.experimental.bftsmart.BFTSmartConfig -import net.corda.notary.experimental.bftsmart.minClusterSize -import net.corda.notary.experimental.bftsmart.minCorrectReplicas import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.contracts.DummyContract import net.corda.testing.core.dummyCommand @@ -60,7 +57,7 @@ class BFTNotaryServiceTests { @BeforeClass @JvmStatic fun before() { - mockNet = InternalMockNetwork(cordappsForAllNodes = cordappsForPackages("net.corda.testing.contracts")) + mockNet = InternalMockNetwork(cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP)) val clusterSize = minClusterSize(1) val started = startBftClusterAndNode(clusterSize, mockNet) notary = started.first diff --git a/node/src/test/kotlin/net/corda/notary/experimental/raft/RaftNotaryServiceTests.kt b/node/src/test/kotlin/net/corda/notary/experimental/raft/RaftNotaryServiceTests.kt index d0454487a5..d8bc9a71a9 100644 --- a/node/src/test/kotlin/net/corda/notary/experimental/raft/RaftNotaryServiceTests.kt +++ b/node/src/test/kotlin/net/corda/notary/experimental/raft/RaftNotaryServiceTests.kt @@ -20,6 +20,7 @@ import net.corda.testing.driver.InProcess import net.corda.testing.driver.driver import net.corda.testing.node.ClusterSpec import net.corda.testing.node.NotarySpec +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP import org.junit.Test import java.util.* import kotlin.test.assertEquals @@ -32,7 +33,7 @@ class RaftNotaryServiceTests { fun `detect double spend`() { driver(DriverParameters( startNodesInProcess = true, - extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3))) )) { val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow() @@ -65,7 +66,7 @@ class RaftNotaryServiceTests { fun `notarise issue tx with time-window`() { driver(DriverParameters( startNodesInProcess = true, - extraCordappPackagesToScan = listOf("net.corda.testing.contracts"), + cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP), notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3))) )) { val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow() diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/CustomCordapp.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/CustomCordapp.kt index 00ecf42dd5..aa96e1549b 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/CustomCordapp.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/CustomCordapp.kt @@ -25,7 +25,7 @@ import java.util.zip.ZipEntry * disparate classes. The CorDapp metadata that's present in the MANIFEST can also be tailored. */ data class CustomCordapp( - val packages: Set, + val packages: Set = emptySet(), val name: String = "custom-cordapp", val versionId: Int = 1, val targetPlatformVersion: Int = PLATFORM_VERSION, diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt index da13ab9e7f..5b29bfc515 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/InternalTestUtils.kt @@ -28,6 +28,7 @@ import net.corda.testing.node.InMemoryMessagingNetwork import net.corda.testing.node.TestCordapp import net.corda.testing.node.User import net.corda.testing.node.testContext +import org.apache.commons.lang.ClassUtils import org.slf4j.LoggerFactory import rx.Observable import rx.subjects.AsyncSubject @@ -65,6 +66,13 @@ val FINANCE_WORKFLOWS_CORDAPP: TestCordappImpl = findCordapp("net.corda.finance. @JvmField val FINANCE_CORDAPPS: Set = setOf(FINANCE_CONTRACTS_CORDAPP, FINANCE_WORKFLOWS_CORDAPP) +/** + * *Custom* CorDapp containing the contents of the `net.corda.testing.contracts` package, i.e. the dummy contracts. This is not a real CorDapp + * in the way that [FINANCE_CONTRACTS_CORDAPP] and [FINANCE_WORKFLOWS_CORDAPP] are. + */ +@JvmField +val DUMMY_CONTRACTS_CORDAPP: CustomCordapp = cordappWithPackages("net.corda.testing.contracts") + fun cordappsForPackages(vararg packageNames: String): Set = cordappsForPackages(packageNames.asList()) fun cordappsForPackages(packageNames: Iterable): Set { @@ -88,6 +96,25 @@ fun cordappForClasses(vararg classes: Class<*>): CustomCordapp = CustomCordapp(p */ fun findCordapp(scanPackage: String): TestCordappImpl = TestCordapp.findCordapp(scanPackage) as TestCordappImpl +/** Create a *custom* CorDapp which just contains the enclosed classes of the receiver class. */ +fun Any.enclosedCordapp(): CustomCordapp { + val receiverClass = javaClass.enclosingClass ?: javaClass // In case this is called in the companion object + val classes = HashSet>() + receiverClass.collectEnclosedClasses(classes) + ClassUtils.getAllSuperclasses(receiverClass).forEach { (it as Class<*>).collectEnclosedClasses(classes) } + ClassUtils.getAllInterfaces(receiverClass).forEach { (it as Class<*>).collectEnclosedClasses(classes) } + require(classes.isNotEmpty()) { "${receiverClass.name} does not contain any enclosed classes to build a CorDapp out of" } + return CustomCordapp(name = receiverClass.name, classes = classes) +} + +private fun Class<*>.collectEnclosedClasses(classes: MutableSet>) { + val enclosedClasses = declaredClasses + if (enclosedClasses.isNotEmpty() || enclosingClass != null) { + classes += this + } + enclosedClasses.forEach { it.collectEnclosedClasses(classes) } +} + private fun getCallerClass(directCallerClass: KClass<*>): Class<*>? { val stackTrace = Throwable().stackTrace val index = stackTrace.indexOfLast { it.className == directCallerClass.java.name } diff --git a/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt b/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt index e679c53002..e71a4bde3b 100644 --- a/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt +++ b/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt @@ -19,6 +19,7 @@ import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.NodeHandle import net.corda.testing.driver.driver import net.corda.testing.node.User +import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP import org.bouncycastle.util.io.Streams import org.junit.Ignore import org.junit.Test @@ -30,7 +31,7 @@ class HashLookupCommandTest { fun `hash lookup command returns correct response`() { val user = User("u", "p", setOf(Permissions.all())) - driver(DriverParameters(notarySpecs = emptyList(), extraCordappPackagesToScan = listOf("net.corda.testing.contracts"))) { + driver(DriverParameters(notarySpecs = emptyList(), cordappsForAllNodes = listOf(DUMMY_CONTRACTS_CORDAPP))) { val nodeFuture = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), startInSameProcess = true) val node = nodeFuture.getOrThrow() val txId = issueTransaction(node)