diff --git a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java index e596a61418..714b0d4316 100644 --- a/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java +++ b/client/rpc/src/integration-test/java/net/corda/client/rpc/CordaRPCJavaClientTest.java @@ -28,11 +28,13 @@ import static kotlin.test.AssertionsKt.assertEquals; import static net.corda.finance.Currencies.DOLLARS; import static net.corda.finance.contracts.GetBalances.getCashBalance; import static net.corda.node.services.FlowPermissions.startFlowPermission; -import static net.corda.testing.CoreTestUtils.setCordappPackages; -import static net.corda.testing.CoreTestUtils.unsetCordappPackages; import static net.corda.testing.TestConstants.getALICE; public class CordaRPCJavaClientTest extends NodeBasedTest { + public CordaRPCJavaClientTest() { + super(Collections.singletonList("net.corda.finance.contracts")); + } + private List perms = Arrays.asList(startFlowPermission(CashPaymentFlow.class), startFlowPermission(CashIssueFlow.class)); private Set permSet = new HashSet<>(perms); private User rpcUser = new User("user1", "test", permSet); @@ -49,7 +51,6 @@ public class CordaRPCJavaClientTest extends NodeBasedTest { @Before public void setUp() throws ExecutionException, InterruptedException { - setCordappPackages("net.corda.finance.contracts"); CordaFuture> nodeFuture = startNotaryNode(getALICE().getName(), singletonList(rpcUser), true); node = nodeFuture.get(); node.getInternals().registerCustomSchemas(Collections.singleton(CashSchemaV1.INSTANCE)); @@ -59,7 +60,6 @@ public class CordaRPCJavaClientTest extends NodeBasedTest { @After public void done() throws IOException { connection.close(); - unsetCordappPackages(); } @Test diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt index 776b96f87f..89264f2e05 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/BlacklistKotlinClosureTest.kt @@ -23,7 +23,7 @@ import org.junit.rules.ExpectedException @CordaSerializable data class Packet(val x: () -> Long) -class BlacklistKotlinClosureTest : NodeBasedTest() { +class BlacklistKotlinClosureTest : NodeBasedTest(listOf("net.corda.client.rpc")) { companion object { @Suppress("UNUSED") val logger = loggerFor() const val EVIL: Long = 666 @@ -66,7 +66,6 @@ class BlacklistKotlinClosureTest : NodeBasedTest() { @Before fun setUp() { - setCordappPackages("net.corda.client.rpc") aliceNode = startNode(ALICE.name, rpcUsers = listOf(rpcUser)).getOrThrow() bobNode = startNode(BOB.name, rpcUsers = listOf(rpcUser)).getOrThrow() bobNode.registerInitiatedFlow(RemoteFlowC::class.java) @@ -78,7 +77,6 @@ class BlacklistKotlinClosureTest : NodeBasedTest() { connection?.close() bobNode.internals.stop() aliceNode.internals.stop() - unsetCordappPackages() } @Test diff --git a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt index 422f08f8f3..be6f05715a 100644 --- a/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt +++ b/client/rpc/src/integration-test/kotlin/net/corda/client/rpc/CordaRPCClientTest.kt @@ -23,8 +23,6 @@ import net.corda.nodeapi.User import net.corda.testing.ALICE import net.corda.testing.chooseIdentity import net.corda.testing.node.NodeBasedTest -import net.corda.testing.setCordappPackages -import net.corda.testing.unsetCordappPackages import org.apache.activemq.artemis.api.core.ActiveMQSecurityException import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.junit.After @@ -34,7 +32,7 @@ import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue -class CordaRPCClientTest : NodeBasedTest() { +class CordaRPCClientTest : NodeBasedTest(listOf("net.corda.finance.contracts")) { private val rpcUser = User("user1", "test", permissions = setOf( startFlowPermission(), startFlowPermission() @@ -49,7 +47,6 @@ class CordaRPCClientTest : NodeBasedTest() { @Before fun setUp() { - setCordappPackages("net.corda.finance.contracts") node = startNotaryNode(ALICE.name, rpcUsers = listOf(rpcUser)).getOrThrow() node.internals.registerCustomSchemas(setOf(CashSchemaV1)) client = CordaRPCClient(node.internals.configuration.rpcAddress!!) @@ -58,7 +55,6 @@ class CordaRPCClientTest : NodeBasedTest() { @After fun done() { connection?.close() - unsetCordappPackages() } @Test diff --git a/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt b/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt index 7482825440..ef276ef07e 100644 --- a/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt +++ b/confidential-identities/src/test/kotlin/net/corda/confidential/IdentitySyncFlowTests.kt @@ -28,15 +28,13 @@ class IdentitySyncFlowTests { @Before fun before() { - setCordappPackages("net.corda.finance.contracts.asset") // We run this in parallel threads to help catch any race conditions that may exist. - mockNet = MockNetwork(networkSendManuallyPumped = false, threadPerNode = true) + mockNet = MockNetwork(networkSendManuallyPumped = false, threadPerNode = true, cordappPackages = listOf("net.corda.finance.contracts.asset")) } @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test 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 619ddec8a6..984646750c 100644 --- a/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/CollectSignaturesFlowTests.kt @@ -23,6 +23,10 @@ import kotlin.reflect.KClass import kotlin.test.assertFailsWith class CollectSignaturesFlowTests { + companion object { + private val cordappPackages = listOf("net.corda.testing.contracts") + } + lateinit var mockNet: MockNetwork lateinit var aliceNode: StartedNode lateinit var bobNode: StartedNode @@ -31,8 +35,7 @@ class CollectSignaturesFlowTests { @Before fun setup() { - setCordappPackages("net.corda.testing.contracts") - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = cordappPackages) val notaryNode = mockNet.createNotaryNode() aliceNode = mockNet.createPartyNode(ALICE.name) bobNode = mockNet.createPartyNode(BOB.name) @@ -45,7 +48,6 @@ class CollectSignaturesFlowTests { @After fun tearDown() { mockNet.stopNodes() - unsetCordappPackages() } private fun registerFlowOnAllNodes(flowClass: KClass>) { @@ -174,7 +176,7 @@ class CollectSignaturesFlowTests { @Test fun `fails when not signed by initiator`() { val onePartyDummyContract = DummyContract.generateInitial(1337, notary, aliceNode.info.chooseIdentity().ref(1)) - val miniCorpServices = MockServices(MINI_CORP_KEY) + val miniCorpServices = MockServices(cordappPackages, MINI_CORP_KEY) val ptx = miniCorpServices.signInitialTransaction(onePartyDummyContract) val flow = aliceNode.services.startFlow(CollectSignaturesFlow(ptx, emptySet())) mockNet.runNetwork() 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 0720557b1f..782d3ee35f 100644 --- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt @@ -40,8 +40,7 @@ class ContractUpgradeFlowTest { @Before fun setup() { - setCordappPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset", "net.corda.core.flows") - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = listOf("net.corda.testing.contracts", "net.corda.finance.contracts.asset", "net.corda.core.flows")) val notaryNode = mockNet.createNotaryNode() aliceNode = mockNet.createPartyNode(ALICE.name) bobNode = mockNet.createPartyNode(BOB.name) @@ -56,7 +55,6 @@ class ContractUpgradeFlowTest { @After fun tearDown() { mockNet.stopNodes() - unsetCordappPackages() } @Test 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 fb865fd291..e17da0775b 100644 --- a/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/FinalityFlowTests.kt @@ -23,8 +23,7 @@ class FinalityFlowTests { @Before fun setup() { - setCordappPackages("net.corda.finance.contracts.asset") - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = listOf("net.corda.finance.contracts.asset")) mockNet.createNotaryNode() aliceNode = mockNet.createPartyNode(ALICE.name) bobNode = mockNet.createPartyNode(BOB.name) @@ -36,7 +35,6 @@ class FinalityFlowTests { @After fun tearDown() { mockNet.stopNodes() - unsetCordappPackages() } @Test 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 bf16c93f53..e7f43c3096 100644 --- a/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt +++ b/core/src/test/kotlin/net/corda/core/internal/ResolveTransactionsFlowTest.kt @@ -36,8 +36,7 @@ class ResolveTransactionsFlowTest { @Before fun setup() { - setCordappPackages("net.corda.testing.contracts") - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = listOf("net.corda.testing.contracts")) notaryNode = mockNet.createNotaryNode() megaCorpNode = mockNet.createPartyNode(MEGA_CORP.name) miniCorpNode = mockNet.createPartyNode(MINI_CORP.name) @@ -52,7 +51,6 @@ class ResolveTransactionsFlowTest { @After fun tearDown() { mockNet.stopNodes() - unsetCordappPackages() } // DOCEND 3 diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt index d313217f40..847675db13 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/CustomVaultQueryTest.kt @@ -26,8 +26,7 @@ class CustomVaultQueryTest { @Before fun setup() { - setCordappPackages("net.corda.finance.contracts.asset") - mockNet = MockNetwork(threadPerNode = true) + mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.finance.contracts.asset")) mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name) nodeA = mockNet.createPartyNode() nodeB = mockNet.createPartyNode() @@ -42,7 +41,6 @@ class CustomVaultQueryTest { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt index be28ddbec0..97ddbc598c 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/FxTransactionBuildTutorialTest.kt @@ -24,8 +24,7 @@ class FxTransactionBuildTutorialTest { @Before fun setup() { - setCordappPackages("net.corda.finance.contracts.asset") - mockNet = MockNetwork(threadPerNode = true) + mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.finance.contracts.asset")) mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name) nodeA = mockNet.createPartyNode() nodeB = mockNet.createPartyNode() @@ -38,7 +37,6 @@ class FxTransactionBuildTutorialTest { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt index 6b9f0d279d..089885d5f5 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/WorkflowTransactionBuildTutorialTest.kt @@ -12,8 +12,6 @@ import net.corda.node.internal.StartedNode import net.corda.testing.DUMMY_NOTARY import net.corda.testing.chooseIdentity import net.corda.testing.node.MockNetwork -import net.corda.testing.setCordappPackages -import net.corda.testing.unsetCordappPackages import org.junit.After import org.junit.Before import org.junit.Test @@ -32,8 +30,7 @@ class WorkflowTransactionBuildTutorialTest { @Before fun setup() { - setCordappPackages("net.corda.docs") - mockNet = MockNetwork(threadPerNode = true) + mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.docs")) mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name) nodeA = mockNet.createPartyNode() nodeB = mockNet.createPartyNode() @@ -43,7 +40,6 @@ class WorkflowTransactionBuildTutorialTest { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt index 95c7e983fd..bedc953058 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Cap.kt @@ -5,16 +5,18 @@ import net.corda.finance.contracts.FixOf import net.corda.finance.contracts.Frequency import net.corda.finance.contracts.Tenor import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before +import net.corda.testing.EnforceVerifyOrFail +import net.corda.testing.TransactionDSL +import net.corda.testing.TransactionDSLInterpreter import org.junit.Ignore import org.junit.Test import java.time.Instant import java.time.LocalDate +fun transaction(script: TransactionDSL.() -> EnforceVerifyOrFail) = run { + net.corda.testing.transaction(cordappPackages = listOf("net.corda.finance.contracts.universal"), dsl = script) +} + class Cap { val TEST_TX_TIME_1: Instant get() = Instant.parse("2017-09-02T12:00:00.00Z") @@ -167,16 +169,6 @@ class Cap { } } - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun issue() { transaction { diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt index 8793dd65b9..390ea97154 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Caplet.kt @@ -3,11 +3,6 @@ package net.corda.finance.contracts.universal import net.corda.finance.contracts.FixOf import net.corda.finance.contracts.Tenor import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Ignore import org.junit.Test import java.time.Instant @@ -53,17 +48,6 @@ class Caplet { val stateFixed = UniversalContract.State(listOf(DUMMY_NOTARY), contractFixed) val stateFinal = UniversalContract.State(listOf(DUMMY_NOTARY), contractFinal) - - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun issue() { transaction { diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt index ec78fc1b0c..7117b22b74 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXFwdTimeOption.kt @@ -1,11 +1,6 @@ package net.corda.finance.contracts.universal import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Ignore import org.junit.Test import java.time.Instant @@ -50,17 +45,6 @@ class FXFwdTimeOption val inState = UniversalContract.State(listOf(DUMMY_NOTARY), initialContract) val outState1 = UniversalContract.State(listOf(DUMMY_NOTARY), outContract1) val outState2 = UniversalContract.State(listOf(DUMMY_NOTARY), outContract2) - - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun `issue - signature`() { transaction { diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt index 26189d2424..67983a6c0e 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/FXSwap.kt @@ -1,11 +1,6 @@ package net.corda.finance.contracts.universal import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Ignore import org.junit.Test import java.time.Instant @@ -41,17 +36,6 @@ class FXSwap { val outStateBad3 = UniversalContract.State(listOf(DUMMY_NOTARY), transferBad3) val inState = UniversalContract.State(listOf(DUMMY_NOTARY), contract) - - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun `issue - signature`() { diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt index ae55271902..9239146e8c 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/IRS.kt @@ -4,11 +4,6 @@ import net.corda.finance.contracts.FixOf import net.corda.finance.contracts.Frequency import net.corda.finance.contracts.Tenor import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Ignore import org.junit.Test import java.time.Instant @@ -132,17 +127,6 @@ class IRS { val stateAfterExecutionFirst = UniversalContract.State(listOf(DUMMY_NOTARY), contractAfterExecutionFirst) val statePaymentFirst = UniversalContract.State(listOf(DUMMY_NOTARY), paymentFirst) - - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun issue() { transaction { diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt index 40d4b7bb94..3a86f41cfa 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/RollOutTests.kt @@ -2,11 +2,6 @@ package net.corda.finance.contracts.universal import net.corda.finance.contracts.Frequency import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Test import java.time.Instant import kotlin.test.assertEquals @@ -122,16 +117,6 @@ class RollOutTests { next() } - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun `arrangement equality transfer`() { assertEquals(contract_transfer1, contract_transfer2) diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt index 590e7a47ac..c0b464af33 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/Swaption.kt @@ -3,11 +3,6 @@ package net.corda.finance.contracts.universal import net.corda.finance.contracts.Frequency import net.corda.finance.contracts.Tenor import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Ignore import org.junit.Test import java.time.Instant @@ -59,17 +54,6 @@ class Swaption { } val stateInitial = UniversalContract.State(listOf(DUMMY_NOTARY), contractInitial) - - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun issue() { transaction { diff --git a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt index 3d79d0df1b..8692518724 100644 --- a/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt +++ b/experimental/src/test/kotlin/net/corda/finance/contracts/universal/ZeroCouponBond.kt @@ -1,11 +1,6 @@ package net.corda.finance.contracts.universal import net.corda.testing.DUMMY_NOTARY -import net.corda.testing.setCordappPackages -import net.corda.testing.transaction -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Test import java.time.Instant import kotlin.test.assertEquals @@ -43,17 +38,6 @@ class ZeroCouponBond { val outStateWrong = UniversalContract.State(listOf(DUMMY_NOTARY), transferWrong) val outStateMove = UniversalContract.State(listOf(DUMMY_NOTARY), contractMove) - - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.universal") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun basic() { assertEquals(Zero(), Zero()) diff --git a/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt b/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt index 6175bca1b7..d1d6751aa1 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt @@ -231,7 +231,6 @@ class CommercialPaperTestsGeneric { // @Test @Ignore fun `issue move and then redeem`() { - setCordappPackages("net.corda.finance.contracts") initialiseTestSerialization() val aliceDatabaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(ALICE_KEY)) val databaseAlice = aliceDatabaseAndServices.first diff --git a/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt b/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt index d5aa6d8cdc..c2d683a74b 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/asset/ObligationTests.kt @@ -593,7 +593,6 @@ class ObligationTests { } // Try defaulting an obligation that is now in the past - unsetCordappPackages() ledger { transaction("Settlement") { attachments(Obligation.PROGRAM_ID) diff --git a/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt b/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt index c8c92fad91..94b3f83658 100644 --- a/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/flows/CashExitFlowTests.kt @@ -28,8 +28,7 @@ class CashExitFlowTests { @Before fun start() { - setCordappPackages("net.corda.finance.contracts.asset") - mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin()) + mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), cordappPackages = listOf("net.corda.finance.contracts.asset")) notaryNode = mockNet.createNotaryNode() bankOfCordaNode = mockNet.createPartyNode(BOC.name) notary = notaryNode.services.getDefaultNotary() @@ -45,7 +44,6 @@ class CashExitFlowTests { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test diff --git a/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt b/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt index 3aeb782a1d..911a014d5f 100644 --- a/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/flows/CashIssueFlowTests.kt @@ -10,11 +10,9 @@ import net.corda.node.internal.StartedNode import net.corda.testing.chooseIdentity import net.corda.testing.getDefaultNotary import net.corda.testing.BOC -import net.corda.testing.DUMMY_NOTARY import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.MockNetwork import net.corda.testing.node.MockNetwork.MockNode -import net.corda.testing.setCordappPackages import org.junit.After import org.junit.Before import org.junit.Test @@ -30,8 +28,7 @@ class CashIssueFlowTests { @Before fun start() { - setCordappPackages("net.corda.finance.contracts.asset") - mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin()) + mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), cordappPackages = listOf("net.corda.finance.contracts.asset")) notaryNode = mockNet.createNotaryNode() bankOfCordaNode = mockNet.createPartyNode(BOC.name) bankOfCorda = bankOfCordaNode.info.chooseIdentity() diff --git a/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt b/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt index a9b1352646..0c5b1e5efa 100644 --- a/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/flows/CashPaymentFlowTests.kt @@ -31,8 +31,7 @@ class CashPaymentFlowTests { @Before fun start() { - setCordappPackages("net.corda.finance.contracts.asset") - mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin()) + mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), cordappPackages = listOf("net.corda.finance.contracts.asset")) notaryNode = mockNet.createNotaryNode() bankOfCordaNode = mockNet.createPartyNode(BOC.name) bankOfCorda = bankOfCordaNode.info.chooseIdentity() diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt index ce95ac21d8..3e72b1d0d4 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderStaticContractTests.kt @@ -9,7 +9,6 @@ import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.TransactionBuilder import net.corda.testing.* import net.corda.testing.node.MockServices -import org.junit.After import org.junit.Assert.* import org.junit.Before import org.junit.Test @@ -48,11 +47,6 @@ class AttachmentsClassLoaderStaticContractTests : TestDependencyInjectionBase() serviceHub = MockServices(cordappPackages = listOf("net.corda.nodeapi.internal")) } - @After - fun `clear packages`() { - unsetCordappPackages() - } - @Test fun `test serialization of WireTransaction with statically loaded contract`() { val tx = AttachmentDummyContract().generateInitial(MEGA_CORP.ref(0), 42, DUMMY_NOTARY) diff --git a/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt index 0b5d72d858..3ba78ff7bd 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/RaftNotaryServiceTests.kt @@ -16,26 +16,14 @@ import net.corda.node.services.transactions.RaftValidatingNotaryService import net.corda.testing.* import net.corda.testing.contracts.DummyContract import net.corda.testing.node.NodeBasedTest -import org.junit.After -import org.junit.Before import org.junit.Test import java.util.* import kotlin.test.assertEquals import kotlin.test.assertFailsWith -class RaftNotaryServiceTests : NodeBasedTest() { +class RaftNotaryServiceTests : NodeBasedTest(listOf("net.corda.testing.contracts")) { private val notaryName = CordaX500Name(RaftValidatingNotaryService.id, "RAFT Notary Service", "London", "GB") - @Before - fun setup() { - setCordappPackages("net.corda.testing.contracts") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun `detect double spend`() { val (bankA) = listOf( diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index 0d92fe6df5..e08b457c37 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -102,6 +102,7 @@ import net.corda.core.crypto.generateKeyPair as cryptoGenerateKeyPair abstract class AbstractNode(config: NodeConfiguration, val platformClock: Clock, protected val versionInfo: VersionInfo, + protected val cordappLoader: CordappLoader, @VisibleForTesting val busyNodeLatch: ReusableLatch = ReusableLatch()) : SingletonSerializeAsToken() { open val configuration = config.apply { require(minimumPlatformVersion <= versionInfo.platformVersion) { @@ -151,8 +152,6 @@ abstract class AbstractNode(config: NodeConfiguration, protected val runOnStop = ArrayList<() -> Any?>() protected lateinit var database: CordaPersistence lateinit var cordappProvider: CordappProviderImpl - protected val cordappLoader by lazy { makeCordappLoader() } - protected val _nodeReadyFuture = openFuture() /** Completes once the node has successfully registered with the network map service * or has loaded network map data from local database */ @@ -472,19 +471,6 @@ abstract class AbstractNode(config: NodeConfiguration, return tokenizableServices } - private fun makeCordappLoader(): CordappLoader { - val scanPackages = System.getProperty("net.corda.node.cordapp.scan.packages") - return if (CordappLoader.testPackages.isNotEmpty()) { - check(configuration.devMode) { "Package scanning can only occur in dev mode" } - CordappLoader.createDefaultWithTestPackages(configuration.baseDirectory, CordappLoader.testPackages) - } else if (scanPackages != null) { - check(configuration.devMode) { "Package scanning can only occur in dev mode" } - CordappLoader.createDefaultWithTestPackages(configuration.baseDirectory, scanPackages.split(",")) - } else { - CordappLoader.createDefault(configuration.baseDirectory) - } - } - protected open fun makeTransactionStorage(): WritableTransactionStorage = DBTransactionStorage() private fun makeVaultObservers() { diff --git a/node/src/main/kotlin/net/corda/node/internal/Node.kt b/node/src/main/kotlin/net/corda/node/internal/Node.kt index 84b126980a..7257eea773 100644 --- a/node/src/main/kotlin/net/corda/node/internal/Node.kt +++ b/node/src/main/kotlin/net/corda/node/internal/Node.kt @@ -15,6 +15,7 @@ import net.corda.core.node.ServiceHub import net.corda.core.serialization.SerializationDefaults import net.corda.core.utilities.* import net.corda.node.VersionInfo +import net.corda.node.internal.cordapp.CordappLoader import net.corda.node.serialization.KryoServerSerializationScheme import net.corda.node.serialization.NodeClock import net.corda.node.services.RPCUserService @@ -22,6 +23,7 @@ import net.corda.node.services.RPCUserServiceImpl import net.corda.node.services.api.NetworkMapCacheInternal import net.corda.node.services.api.SchemaService import net.corda.node.services.config.FullNodeConfiguration +import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.messaging.ArtemisMessagingServer import net.corda.node.services.messaging.ArtemisMessagingServer.Companion.ipDetectRequestProperty import net.corda.node.services.messaging.ArtemisMessagingServer.Companion.ipDetectResponseProperty @@ -62,8 +64,9 @@ import kotlin.system.exitProcess */ open class Node(override val configuration: FullNodeConfiguration, versionInfo: VersionInfo, - val initialiseSerialization: Boolean = true -) : AbstractNode(configuration, createClock(configuration), versionInfo) { + val initialiseSerialization: Boolean = true, + cordappLoader: CordappLoader = makeCordappLoader(configuration) +) : AbstractNode(configuration, createClock(configuration), versionInfo, cordappLoader) { companion object { private val logger = loggerFor() var renderBasicInfoToConsole = true @@ -86,6 +89,13 @@ open class Node(override val configuration: FullNodeConfiguration, } private val sameVmNodeCounter = AtomicInteger() + val scanPackagesSystemProperty = "net.corda.node.cordapp.scan.packages" + val scanPackagesSeparator = "," + private fun makeCordappLoader(configuration: NodeConfiguration): CordappLoader { + return System.getProperty(scanPackagesSystemProperty)?.let { scanPackages -> + CordappLoader.createDefaultWithTestPackages(configuration, scanPackages.split(scanPackagesSeparator)) + } ?: CordappLoader.createDefault(configuration.baseDirectory) + } } override val log: Logger get() = logger diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt index 493b965ba6..7cdba9ca71 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappLoader.kt @@ -14,6 +14,7 @@ import net.corda.core.serialization.SerializationWhitelist import net.corda.core.serialization.SerializeAsToken import net.corda.core.utilities.loggerFor import net.corda.node.internal.classloading.requireAnnotation +import net.corda.node.services.config.NodeConfiguration import net.corda.nodeapi.internal.serialization.DefaultWhitelist import java.io.File import java.io.FileOutputStream @@ -64,14 +65,12 @@ class CordappLoader private constructor(private val cordappJarPaths: List) /** * Create a dev mode CordappLoader for test environments that creates and loads cordapps from the classpath * and plugins directory. This is intended mostly for use by the driver. - * - * @param baseDir See [createDefault.baseDir] - * @param testPackages See [createWithTestPackages.testPackages] */ @VisibleForTesting - @JvmOverloads - fun createDefaultWithTestPackages(baseDir: Path, testPackages: List = CordappLoader.testPackages) - = CordappLoader(getCordappsInDirectory(getPluginsPath(baseDir)) + testPackages.flatMap(this::createScanPackage)) + fun createDefaultWithTestPackages(configuration: NodeConfiguration, testPackages: List): CordappLoader { + check(configuration.devMode) { "Package scanning can only occur in dev mode" } + return CordappLoader(getCordappsInDirectory(getPluginsPath(configuration.baseDirectory)) + testPackages.flatMap(this::createScanPackage)) + } /** * Create a dev mode CordappLoader for test environments that creates and loads cordapps from the classpath. @@ -81,8 +80,7 @@ class CordappLoader private constructor(private val cordappJarPaths: List) * CorDapps. */ @VisibleForTesting - @JvmOverloads - fun createWithTestPackages(testPackages: List = CordappLoader.testPackages) + fun createWithTestPackages(testPackages: List) = CordappLoader(testPackages.flatMap(this::createScanPackage)) /** @@ -147,11 +145,6 @@ class CordappLoader private constructor(private val cordappJarPaths: List) } } - /** - * A list of test packages that will be scanned as CorDapps and compiled into CorDapp JARs for use in tests only. - */ - @VisibleForTesting - var testPackages: List = emptyList() private val generatedCordapps = mutableMapOf() /** A list of the core RPC flows present in Corda */ diff --git a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java index 97dab2aaa7..0568b45a3e 100644 --- a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java +++ b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -43,15 +43,15 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { @Before public void setUp() { - setCordappPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset"); + List cordappPackages = Arrays.asList("net.corda.testing.contracts", "net.corda.finance.contracts.asset"); ArrayList keys = new ArrayList<>(); keys.add(getMEGA_CORP_KEY()); keys.add(getDUMMY_NOTARY_KEY()); Set requiredSchemas = Collections.singleton(CashSchemaV1.INSTANCE); IdentityService identitySvc = makeTestIdentityService(); @SuppressWarnings("unchecked") - Pair databaseAndServices = makeTestDatabaseAndMockServices(requiredSchemas, keys, () -> identitySvc, Collections.EMPTY_LIST); - issuerServices = new MockServices(getDUMMY_CASH_ISSUER_KEY(), getBOC_KEY()); + Pair databaseAndServices = makeTestDatabaseAndMockServices(requiredSchemas, keys, () -> identitySvc, cordappPackages); + issuerServices = new MockServices(cordappPackages, getDUMMY_CASH_ISSUER_KEY(), getBOC_KEY()); database = databaseAndServices.getFirst(); services = databaseAndServices.getSecond(); vaultService = services.getVaultService(); @@ -60,7 +60,6 @@ public class VaultQueryJavaTests extends TestDependencyInjectionBase { @After public void cleanUp() throws IOException { database.close(); - unsetCordappPackages(); } /** diff --git a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt index e03fd6972c..0020970296 100644 --- a/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt +++ b/node/src/test/kotlin/net/corda/node/CordaRPCOpsImplTest.kt @@ -62,9 +62,7 @@ class CordaRPCOpsImplTest { @Before fun setup() { - setCordappPackages("net.corda.finance.contracts.asset") - - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = listOf("net.corda.finance.contracts.asset")) aliceNode = mockNet.createNode() notaryNode = mockNet.createNotaryNode(validating = false) rpc = CordaRPCOpsImpl(aliceNode.services, aliceNode.smm, aliceNode.database) @@ -81,7 +79,6 @@ class CordaRPCOpsImplTest { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test @@ -100,7 +97,6 @@ class CordaRPCOpsImplTest { } // Tell the monitoring service node to issue some cash - val recipient = aliceNode.info.chooseIdentity() val result = rpc.startFlow(::CashIssueFlow, Amount(quantity, GBP), ref, notary) mockNet.runNetwork() 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 1a08a04e76..6135863388 100644 --- a/node/src/test/kotlin/net/corda/node/internal/CordaServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/internal/CordaServiceTest.kt @@ -15,8 +15,6 @@ import net.corda.finance.flows.CashIssueFlow import net.corda.node.internal.cordapp.DummyRPCFlow import net.corda.testing.DUMMY_NOTARY import net.corda.testing.node.MockNetwork -import net.corda.testing.setCordappPackages -import net.corda.testing.unsetCordappPackages import org.junit.After import org.junit.Before import org.junit.Test @@ -74,9 +72,7 @@ class TestCordaService2(val appServiceHub: AppServiceHub): SingletonSerializeAsT } @CordaService -class LegacyCordaService(val simpleServiceHub: ServiceHub): SingletonSerializeAsToken() { - -} +class LegacyCordaService(@Suppress("UNUSED_PARAMETER") simpleServiceHub: ServiceHub) : SingletonSerializeAsToken() class CordaServiceTest { lateinit var mockNet: MockNetwork @@ -85,8 +81,7 @@ class CordaServiceTest { @Before fun start() { - setCordappPackages("net.corda.node.internal","net.corda.finance") - mockNet = MockNetwork(threadPerNode = true) + mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.node.internal","net.corda.finance")) notaryNode = mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name, validating = true) nodeA = mockNet.createNode() mockNet.startNodes() @@ -95,7 +90,6 @@ class CordaServiceTest { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test 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 1d19ed5833..9677213a16 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -45,6 +45,7 @@ import net.corda.testing.* import net.corda.testing.contracts.fillWithSomeTestCash import net.corda.testing.node.InMemoryMessagingNetwork import net.corda.testing.node.MockNetwork +import net.corda.testing.node.MockServices import net.corda.testing.node.pumpReceive import org.assertj.core.api.Assertions.assertThat import org.junit.After @@ -73,6 +74,7 @@ import kotlin.test.assertTrue @RunWith(Parameterized::class) class TwoPartyTradeFlowTests(val anonymous: Boolean) { companion object { + private val cordappPackages = listOf("net.corda.finance.contracts") @JvmStatic @Parameterized.Parameters fun data(): Collection { @@ -84,7 +86,6 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { @Before fun before() { - setCordappPackages("net.corda.finance.contracts") LogHelper.setLevel("platform.trade", "core.contract.TransactionGroup", "recordingmap") } @@ -92,7 +93,6 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { fun after() { mockNet.stopNodes() LogHelper.reset("platform.trade", "core.contract.TransactionGroup", "recordingmap") - unsetCordappPackages() } @Test @@ -100,9 +100,8 @@ class TwoPartyTradeFlowTests(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 = MockNetwork(false, true) - - ledger(initialiseSerialization = false) { + mockNet = MockNetwork(false, true, cordappPackages = cordappPackages) + ledger(MockServices(cordappPackages), initialiseSerialization = false) { val notaryNode = mockNet.createNotaryNode() val aliceNode = mockNet.createPartyNode(ALICE.name) val bobNode = mockNet.createPartyNode(BOB.name) @@ -149,9 +148,8 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { @Test(expected = InsufficientBalanceException::class) fun `trade cash for commercial paper fails using soft locking`() { - mockNet = MockNetwork(false, true) - - ledger(initialiseSerialization = false) { + mockNet = MockNetwork(false, true, cordappPackages = cordappPackages) + ledger(MockServices(cordappPackages), initialiseSerialization = false) { val notaryNode = mockNet.createNotaryNode() val aliceNode = mockNet.createPartyNode(ALICE.name) val bobNode = mockNet.createPartyNode(BOB.name) @@ -204,8 +202,8 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { @Test fun `shutdown and restore`() { - mockNet = MockNetwork(false) - ledger(initialiseSerialization = false) { + mockNet = MockNetwork(false, cordappPackages = cordappPackages) + ledger(MockServices(cordappPackages), initialiseSerialization = false) { val notaryNode = mockNet.createNotaryNode() val aliceNode = mockNet.createPartyNode(ALICE.name) var bobNode = mockNet.createPartyNode(BOB.name) @@ -222,8 +220,6 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { bobNode.internals.disableDBCloseOnStop() val bobAddr = bobNode.network.myAddress as InMemoryMessagingNetwork.PeerHandle - val networkMapAddress = notaryNode.network.myAddress - mockNet.runNetwork() // Clear network map registration messages val notary = aliceNode.services.getDefaultNotary() @@ -331,8 +327,7 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { @Test fun `check dependencies of sale asset are resolved`() { - mockNet = MockNetwork(false) - + mockNet = MockNetwork(false, cordappPackages = cordappPackages) val notaryNode = mockNet.createNotaryNode() val aliceNode = makeNodeWithTracking(ALICE.name) val bobNode = makeNodeWithTracking(BOB.name) @@ -436,8 +431,7 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { @Test fun `track works`() { - mockNet = MockNetwork(false) - + mockNet = MockNetwork(false, cordappPackages = cordappPackages) val notaryNode = mockNet.createNotaryNode() val aliceNode = makeNodeWithTracking(ALICE.name) val bobNode = makeNodeWithTracking(BOB.name) @@ -517,16 +511,16 @@ class TwoPartyTradeFlowTests(val anonymous: Boolean) { @Test fun `dependency with error on buyer side`() { - mockNet = MockNetwork(false) - ledger(initialiseSerialization = false) { + mockNet = MockNetwork(false, cordappPackages = cordappPackages) + ledger(MockServices(cordappPackages), initialiseSerialization = false) { runWithError(true, false, "at least one cash input") } } @Test fun `dependency with error on seller side`() { - mockNet = MockNetwork(false) - ledger(initialiseSerialization = false) { + mockNet = MockNetwork(false, cordappPackages = cordappPackages) + ledger(MockServices(cordappPackages), initialiseSerialization = false) { runWithError(false, true, "Issuances have a time-window") } } 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 a758655ff8..957d6ac442 100644 --- a/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/NotaryChangeTests.kt @@ -35,8 +35,7 @@ class NotaryChangeTests { @Before fun setUp() { - setCordappPackages("net.corda.testing.contracts") - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = listOf("net.corda.testing.contracts")) oldNotaryNode = mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name) clientNodeA = mockNet.createNode() clientNodeB = mockNet.createNode() @@ -50,7 +49,6 @@ class NotaryChangeTests { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test diff --git a/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt index ad05ba1ad2..d5c966d31c 100644 --- a/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/events/NodeSchedulerServiceTest.kt @@ -72,7 +72,6 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() { @Before fun setup() { - setCordappPackages("net.corda.testing.contracts") initialiseTestSerialization() countDown = CountDownLatch(1) smmHasRemovedAllFlows = CountDownLatch(1) @@ -98,7 +97,7 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() { network = mockMessagingService), TestReference { override val vaultService: VaultServiceInternal = NodeVaultService(testClock, kms, stateLoader, database.hibernateConfig) override val testReference = this@NodeSchedulerServiceTest - override val cordappProvider: CordappProviderImpl = CordappProviderImpl(CordappLoader.createWithTestPackages()).start(attachments) + override val cordappProvider = CordappProviderImpl(CordappLoader.createWithTestPackages(listOf("net.corda.testing.contracts"))).start(attachments) } smmExecutor = AffinityExecutor.ServiceAffinityExecutor("test", 1) scheduler = NodeSchedulerService(services, schedulerGatedExecutor, serverThread = smmExecutor) @@ -124,7 +123,6 @@ class NodeSchedulerServiceTest : SingletonSerializeAsToken() { smmExecutor.awaitTermination(60, TimeUnit.SECONDS) database.close() resetTestSerialization() - unsetCordappPackages() } class TestState(val flowLogicRef: FlowLogicRef, val instant: Instant, val myIdentity: Party) : LinearState, SchedulableState { 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 013eea5d74..be2fc12b96 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 @@ -91,8 +91,7 @@ class ScheduledFlowTests { @Before fun setup() { - setCordappPackages("net.corda.testing.contracts") - mockNet = MockNetwork(threadPerNode = true) + mockNet = MockNetwork(threadPerNode = true, cordappPackages = listOf("net.corda.testing.contracts")) notaryNode = mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name) val a = mockNet.createUnstartedNode() val b = mockNet.createUnstartedNode() @@ -107,7 +106,6 @@ class ScheduledFlowTests { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test diff --git a/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt b/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt index e554ea59be..f0a381c411 100644 --- a/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/persistence/HibernateConfigurationTest.kt @@ -73,14 +73,14 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { @Before fun setUp() { - setCordappPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset") - issuerServices = MockServices(DUMMY_CASH_ISSUER_KEY, BOB_KEY, BOC_KEY) + val cordappPackages = listOf("net.corda.testing.contracts", "net.corda.finance.contracts.asset") + issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_KEY, BOB_KEY, BOC_KEY) val dataSourceProps = makeTestDataSourceProperties() val defaultDatabaseProperties = makeTestDatabaseProperties() database = configureDatabase(dataSourceProps, defaultDatabaseProperties, NodeSchemaService(), ::makeTestIdentityService) database.transaction { hibernateConfig = database.hibernateConfig - services = object : MockServices(BOB_KEY, BOC_KEY, DUMMY_NOTARY_KEY) { + services = object : MockServices(cordappPackages, BOB_KEY, BOC_KEY, DUMMY_NOTARY_KEY) { override val vaultService = makeVaultService(database.hibernateConfig) override fun recordTransactions(notifyVault: Boolean, txs: Iterable) { for (stx in txs) { @@ -105,7 +105,6 @@ class HibernateConfigurationTest : TestDependencyInjectionBase() { @After fun cleanUp() { database.close() - unsetCordappPackages() } private fun setUpDb() { 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 00b66b30b9..d4391109e3 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 @@ -65,8 +65,7 @@ class FlowFrameworkTests { @Before fun start() { - setCordappPackages("net.corda.finance.contracts", "net.corda.testing.contracts") - mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin()) + mockNet = MockNetwork(servicePeerAllocationStrategy = RoundRobin(), cordappPackages = listOf("net.corda.finance.contracts", "net.corda.testing.contracts")) node1 = mockNet.createNode() node2 = mockNet.createNode() @@ -87,7 +86,6 @@ class FlowFrameworkTests { fun cleanUp() { mockNet.stopNodes() receivedSessionMessages.clear() - unsetCordappPackages() } @Test 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 579f653018..f30063aac8 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 @@ -33,8 +33,7 @@ class NotaryServiceTests { @Before fun setup() { - setCordappPackages("net.corda.testing.contracts") - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = listOf("net.corda.testing.contracts")) notaryNode = mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name, validating = false) clientNode = mockNet.createNode() mockNet.runNetwork() // Clear network map registration messages @@ -45,7 +44,6 @@ class NotaryServiceTests { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test 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 87410fecb8..740c51be74 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 @@ -33,8 +33,7 @@ class ValidatingNotaryServiceTests { @Before fun setup() { - setCordappPackages("net.corda.testing.contracts") - mockNet = MockNetwork() + mockNet = MockNetwork(cordappPackages = listOf("net.corda.testing.contracts")) notaryNode = mockNet.createNotaryNode(legalName = DUMMY_NOTARY.name) clientNode = mockNet.createNode() mockNet.runNetwork() // Clear network map registration messages @@ -45,7 +44,6 @@ class ValidatingNotaryServiceTests { @After fun cleanUp() { mockNet.stopNodes() - unsetCordappPackages() } @Test diff --git a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt index 5250e7f500..4740ac776d 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/NodeVaultServiceTest.kt @@ -45,27 +45,30 @@ import kotlin.test.assertFalse import kotlin.test.assertTrue class NodeVaultServiceTest : TestDependencyInjectionBase() { + companion object { + private val cordappPackages = listOf("net.corda.finance.contracts.asset") + } + lateinit var services: MockServices - lateinit var issuerServices: MockServices + private lateinit var issuerServices: MockServices val vaultService get() = services.vaultService as NodeVaultService lateinit var database: CordaPersistence @Before fun setUp() { - setCordappPackages("net.corda.finance.contracts.asset") LogHelper.setLevel(NodeVaultService::class) val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(BOC_KEY, DUMMY_CASH_ISSUER_KEY), - customSchemas = setOf(CashSchemaV1)) + customSchemas = setOf(CashSchemaV1), + cordappPackages = cordappPackages) database = databaseAndServices.first services = databaseAndServices.second - issuerServices = MockServices(DUMMY_CASH_ISSUER_KEY, BOC_KEY) + issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_KEY, BOC_KEY) } @After fun tearDown() { database.close() LogHelper.reset(NodeVaultService::class) - unsetCordappPackages() } @Suspendable @@ -440,8 +443,7 @@ class NodeVaultServiceTest : TestDependencyInjectionBase() { @Test fun addNoteToTransaction() { - val megaCorpServices = MockServices(MEGA_CORP_KEY) - + val megaCorpServices = MockServices(cordappPackages, MEGA_CORP_KEY) database.transaction { val freshKey = services.myInfo.chooseIdentity().owningKey diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index 9e484833d6..56d6e90992 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -45,6 +45,9 @@ import java.time.temporal.ChronoUnit import java.util.* class VaultQueryTests : TestDependencyInjectionBase() { + companion object { + private val cordappPackages = listOf("net.corda.testing.contracts", "net.corda.finance.contracts") + } private lateinit var services: MockServices private lateinit var notaryServices: MockServices @@ -59,23 +62,21 @@ class VaultQueryTests : TestDependencyInjectionBase() { @Before fun setUp() { - setCordappPackages("net.corda.testing.contracts", "net.corda.finance.contracts") - // register additional identities identitySvc.verifyAndRegisterIdentity(CASH_NOTARY_IDENTITY) identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(MEGA_CORP_KEY, DUMMY_NOTARY_KEY), createIdentityService = { identitySvc }, - customSchemas = setOf(CashSchemaV1, CommercialPaperSchemaV1, DummyLinearStateSchemaV1)) + customSchemas = setOf(CashSchemaV1, CommercialPaperSchemaV1, DummyLinearStateSchemaV1), + cordappPackages = cordappPackages) database = databaseAndServices.first services = databaseAndServices.second - notaryServices = MockServices(DUMMY_NOTARY_KEY, DUMMY_CASH_ISSUER_KEY, BOC_KEY, MEGA_CORP_KEY) + notaryServices = MockServices(cordappPackages, DUMMY_NOTARY_KEY, DUMMY_CASH_ISSUER_KEY, BOC_KEY, MEGA_CORP_KEY) } @After fun tearDown() { database.close() - unsetCordappPackages() } /** @@ -1490,18 +1491,16 @@ class VaultQueryTests : TestDependencyInjectionBase() { // GBP issuer val gbpCashIssuerKey = entropyToKeyPair(BigInteger.valueOf(1001)) val gbpCashIssuer = Party(CordaX500Name(organisation = "British Pounds Cash Issuer", locality = "London", country = "GB"), gbpCashIssuerKey.public).ref(1) - val gbpCashIssuerServices = MockServices(gbpCashIssuerKey) + val gbpCashIssuerServices = MockServices(cordappPackages, gbpCashIssuerKey) // USD issuer val usdCashIssuerKey = entropyToKeyPair(BigInteger.valueOf(1002)) val usdCashIssuer = Party(CordaX500Name(organisation = "US Dollars Cash Issuer", locality = "New York", country = "US"), usdCashIssuerKey.public).ref(1) - val usdCashIssuerServices = MockServices(usdCashIssuerKey) + val usdCashIssuerServices = MockServices(cordappPackages, usdCashIssuerKey) // CHF issuer val chfCashIssuerKey = entropyToKeyPair(BigInteger.valueOf(1003)) val chfCashIssuer = Party(CordaX500Name(organisation = "Swiss Francs Cash Issuer", locality = "Zurich", country = "CH"), chfCashIssuerKey.public).ref(1) - val chfCashIssuerServices = MockServices(chfCashIssuerKey) - + val chfCashIssuerServices = MockServices(cordappPackages, chfCashIssuerKey) database.transaction { - services.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (gbpCashIssuer)) services.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (usdCashIssuer)) services.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (chfCashIssuer)) diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index 60e853d023..a42e13d55c 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -1,4 +1,4 @@ -package net.corda.node.services.vaultService +package net.corda.node.services.vault import net.corda.core.contracts.ContractState import net.corda.core.contracts.LinearState @@ -34,6 +34,10 @@ import kotlin.test.assertEquals // TODO: Move this to the cash contract tests once mock services are further split up. class VaultWithCashTest : TestDependencyInjectionBase() { + companion object { + private val cordappPackages = listOf("net.corda.testing.contracts", "net.corda.finance.contracts.asset") + } + lateinit var services: MockServices lateinit var issuerServices: MockServices val vaultService: VaultService get() = services.vaultService @@ -42,22 +46,20 @@ class VaultWithCashTest : TestDependencyInjectionBase() { @Before fun setUp() { - setCordappPackages("net.corda.testing.contracts", "net.corda.finance.contracts.asset") - LogHelper.setLevel(VaultWithCashTest::class) val databaseAndServices = makeTestDatabaseAndMockServices(keys = listOf(DUMMY_CASH_ISSUER_KEY, DUMMY_NOTARY_KEY), - customSchemas = setOf(CashSchemaV1)) + customSchemas = setOf(CashSchemaV1), + cordappPackages = cordappPackages) database = databaseAndServices.first services = databaseAndServices.second - issuerServices = MockServices(DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY) - notaryServices = MockServices(DUMMY_NOTARY_KEY) + issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY) + notaryServices = MockServices(cordappPackages, DUMMY_NOTARY_KEY) } @After fun tearDown() { LogHelper.reset(VaultWithCashTest::class) database.close() - unsetCordappPackages() } @Test @@ -81,7 +83,7 @@ class VaultWithCashTest : TestDependencyInjectionBase() { @Test fun `issue and spend total correctly and irrelevant ignored`() { - val megaCorpServices = MockServices(MEGA_CORP_KEY) + val megaCorpServices = MockServices(cordappPackages, MEGA_CORP_KEY) val freshKey = services.keyManagementService.freshKey() val usefulTX = diff --git a/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt b/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt index 3af7044caa..4e9d129c26 100644 --- a/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt +++ b/samples/irs-demo/src/test/kotlin/net/corda/irs/api/NodeInterestRatesTest.kt @@ -14,7 +14,6 @@ import net.corda.finance.contracts.Fix import net.corda.finance.contracts.FixOf import net.corda.finance.contracts.asset.CASH import net.corda.finance.contracts.asset.Cash -import net.corda.finance.contracts.asset.ownedBy import net.corda.irs.flows.RatesFixFlow import net.corda.node.utilities.CordaPersistence import net.corda.node.utilities.configureDatabase @@ -63,7 +62,6 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() { @Before fun setUp() { - setCordappPackages("net.corda.finance.contracts") database = configureDatabase(makeTestDataSourceProperties(), makeTestDatabaseProperties(), createIdentityService = ::makeTestIdentityService) database.transaction { oracle = createMockCordaService(services, NodeInterestRates::Oracle) @@ -74,7 +72,6 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() { @After fun tearDown() { database.close() - unsetCordappPackages() } @Test @@ -203,7 +200,7 @@ class NodeInterestRatesTest : TestDependencyInjectionBase() { @Test fun `network tearoff`() { - val mockNet = MockNetwork(initialiseSerialization = false) + val mockNet = MockNetwork(initialiseSerialization = false, cordappPackages = listOf("net.corda.finance.contracts")) val n1 = mockNet.createNotaryNode() val oracleNode = mockNet.createNode().apply { internals.registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java) diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt index 6c929c47b7..90a3ca2d8b 100644 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt +++ b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt @@ -141,7 +141,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, } } - val mockNet = MockNetwork(networkSendManuallyPumped, runAsync) + val mockNet = MockNetwork(networkSendManuallyPumped, runAsync, cordappPackages = listOf("net.corda.irs.contract", "net.corda.finance.contract")) // This one must come first. val networkMap = mockNet.startNetworkMapNode(nodeFactory = NetworkMapNodeFactory) val notary = mockNet.createNotaryNode(validating = false, nodeFactory = NotaryNodeFactory) @@ -255,7 +255,6 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, val networkInitialisationFinished = allOf(*mockNet.nodes.map { it.nodeReadyFuture.toCompletableFuture() }.toTypedArray()) fun start(): Future { - setCordappPackages("net.corda.irs.contract", "net.corda.finance.contract") mockNet.startNodes() // Wait for all the nodes to have finished registering with the network map service. return networkInitialisationFinished.thenCompose { startMainSimulation() } diff --git a/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt b/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt index 4bd32364a4..6da9d13091 100644 --- a/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt +++ b/samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt @@ -2,25 +2,10 @@ package net.corda.netmap.simulation import net.corda.core.utilities.getOrThrow import net.corda.testing.LogHelper -import net.corda.testing.setCordappPackages -import net.corda.testing.unsetCordappPackages -import org.junit.After -import org.junit.Before import org.junit.Test class IRSSimulationTest { // TODO: These tests should be a lot more complete. - - @Before - fun setup() { - setCordappPackages("net.corda.irs.contract") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun `runs to completion`() { LogHelper.setLevel("+messages") // FIXME: Don't manipulate static state in tests. diff --git a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt index e113f235b7..87b9fa7839 100644 --- a/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt +++ b/samples/simm-valuation-demo/src/integration-test/kotlin/net/corda/vega/SimmValuationTest.kt @@ -11,8 +11,6 @@ import net.corda.vega.api.PortfolioApiUtils import net.corda.vega.api.SwapDataModel import net.corda.vega.api.SwapDataView import org.assertj.core.api.Assertions.assertThat -import org.junit.After -import org.junit.Before import org.junit.Test import java.math.BigDecimal import java.time.LocalDate @@ -26,19 +24,9 @@ class SimmValuationTest : IntegrationTestCategory { val testTradeId = "trade1" } - @Before - fun setup() { - setCordappPackages("net.corda.vega.contracts") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - @Test fun `runs SIMM valuation demo`() { - driver(isDebug = true) { + driver(isDebug = true, extraCordappPackagesToScan = listOf("net.corda.vega.contracts")) { startNotaryNode(DUMMY_NOTARY.name, validating = false).getOrThrow() val nodeAFuture = startNode(providedName = nodeALegalName) val nodeBFuture = startNode(providedName = nodeBLegalName) diff --git a/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt b/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt index 0efa101ec7..6fb3556c25 100644 --- a/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt +++ b/samples/trader-demo/src/integration-test/kotlin/net/corda/traderdemo/TraderDemoTest.kt @@ -17,23 +17,10 @@ import net.corda.traderdemo.flow.BuyerFlow import net.corda.traderdemo.flow.CommercialPaperIssueFlow import net.corda.traderdemo.flow.SellerFlow import org.assertj.core.api.Assertions.assertThat -import org.junit.After -import org.junit.Before import org.junit.Test import java.util.concurrent.Executors -class TraderDemoTest : NodeBasedTest() { - - @Before - fun setup() { - setCordappPackages("net.corda.finance.contracts.asset", "net.corda.finance.contracts") - } - - @After - fun tearDown() { - unsetCordappPackages() - } - +class TraderDemoTest : NodeBasedTest(listOf("net.corda.finance.contracts.asset", "net.corda.finance.contracts")) { @Test fun `runs trader demo`() { val demoUser = User("demo", "demo", setOf(startFlowPermission())) diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt index 7fe3ee5c09..551a8075b8 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/NodeTestUtils.kt @@ -46,8 +46,9 @@ fun transaction( transactionLabel: String? = null, transactionBuilder: TransactionBuilder = TransactionBuilder(notary = DUMMY_NOTARY), initialiseSerialization: Boolean = true, + cordappPackages: List = emptyList(), dsl: TransactionDSL.() -> EnforceVerifyOrFail -) = ledger(initialiseSerialization = initialiseSerialization) { +) = ledger(services = MockServices(cordappPackages), initialiseSerialization = initialiseSerialization) { dsl(TransactionDSL(TestTransactionDSLInterpreter(this.interpreter, transactionBuilder))) } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt index 9a1ce481ca..0a8cf4ecbe 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/driver/Driver.kt @@ -24,6 +24,7 @@ import net.corda.core.utilities.* import net.corda.node.internal.Node import net.corda.node.internal.NodeStartup import net.corda.node.internal.StartedNode +import net.corda.node.internal.cordapp.CordappLoader import net.corda.node.services.config.* import net.corda.node.services.network.NetworkMapService import net.corda.node.utilities.ServiceIdentityGenerator @@ -511,7 +512,6 @@ class ShutdownManager(private val executorService: ExecutorService) { } fun shutdown() { - unsetCordappPackages() val shutdownActionFutures = state.locked { if (isShutdown) { emptyList Unit>>() @@ -595,14 +595,14 @@ class DriverDSL( val isDebug: Boolean, val networkMapStartStrategy: NetworkMapStartStrategy, val startNodesInProcess: Boolean, - val extraCordappPackagesToScan: List + extraCordappPackagesToScan: List ) : DriverDSLInternalInterface { private val dedicatedNetworkMapAddress = portAllocation.nextHostAndPort() private var _executorService: ScheduledExecutorService? = null val executorService get() = _executorService!! private var _shutdownManager: ShutdownManager? = null override val shutdownManager get() = _shutdownManager!! - private val packagesToScanString = extraCordappPackagesToScan + getCallerPackage() + private val cordappPackages = extraCordappPackagesToScan + getCallerPackage() class State { val processes = ArrayList>() @@ -821,8 +821,6 @@ class DriverDSL( override fun start() { _executorService = Executors.newScheduledThreadPool(2, ThreadFactoryBuilder().setNameFormat("driver-pool-thread-%d").build()) _shutdownManager = ShutdownManager(executorService) - // We set this property so that in-process nodes find cordapps. Out-of-process nodes need this passed in when started. - setCordappPackages(*packagesToScanString.toTypedArray()) if (networkMapStartStrategy.startDedicated) { startDedicatedNetworkMapService().andForget(log) // Allow it to start concurrently with other nodes. } @@ -859,7 +857,7 @@ class DriverDSL( private fun startNodeInternal(config: Config, webAddress: NetworkHostAndPort, startInProcess: Boolean?, maximumHeapSize: String): CordaFuture { val nodeConfiguration = config.parseAs() if (startInProcess ?: startNodesInProcess) { - val nodeAndThreadFuture = startInProcessNode(executorService, nodeConfiguration, config) + val nodeAndThreadFuture = startInProcessNode(executorService, nodeConfiguration, config, cordappPackages) shutdownManager.registerShutdown( nodeAndThreadFuture.map { (node, thread) -> { @@ -877,7 +875,7 @@ class DriverDSL( } } else { val debugPort = if (isDebug) debugPortAllocation.nextPort() else null - val processFuture = startOutOfProcessNode(executorService, nodeConfiguration, config, quasarJarPath, debugPort, systemProperties, packagesToScanString.joinToString(","), maximumHeapSize) + val processFuture = startOutOfProcessNode(executorService, nodeConfiguration, config, quasarJarPath, debugPort, systemProperties, cordappPackages, maximumHeapSize) registerProcess(processFuture) return processFuture.flatMap { process -> val processDeathFuture = poll(executorService, "process death") { @@ -920,14 +918,15 @@ class DriverDSL( private fun startInProcessNode( executorService: ScheduledExecutorService, nodeConf: FullNodeConfiguration, - config: Config + config: Config, + cordappPackages: List ): CordaFuture, Thread>> { return executorService.fork { log.info("Starting in-process Node ${nodeConf.myLegalName.organisation}") // Write node.conf writeConfig(nodeConf.baseDirectory, "node.conf", config) // TODO pass the version in? - val node = Node(nodeConf, MOCK_VERSION_INFO, initialiseSerialization = false).start() + val node = Node(nodeConf, MOCK_VERSION_INFO, initialiseSerialization = false, cordappLoader = CordappLoader.createDefaultWithTestPackages(nodeConf, cordappPackages)).start() val nodeThread = thread(name = nodeConf.myLegalName.organisation) { node.internals.run() } @@ -942,7 +941,7 @@ class DriverDSL( quasarJarPath: String, debugPort: Int?, overriddenSystemProperties: Map, - packagesToScanString: String, + cordappPackages: List, maximumHeapSize: String ): CordaFuture { val processFuture = executorService.fork { @@ -953,7 +952,7 @@ class DriverDSL( val systemProperties = overriddenSystemProperties + mapOf( "name" to nodeConf.myLegalName, "visualvm.display.name" to "corda-${nodeConf.myLegalName}", - "net.corda.node.cordapp.scan.packages" to packagesToScanString, + Node.scanPackagesSystemProperty to cordappPackages.joinToString(Node.scanPackagesSeparator), "java.io.tmpdir" to System.getProperty("java.io.tmpdir") // Inherit from parent process ) // See experimental/quasar-hook/README.md for how to generate. diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt index 88824e118e..84dc90fe02 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockNode.kt @@ -26,6 +26,7 @@ import net.corda.core.utilities.loggerFor import net.corda.finance.utils.WorldMapLocation import net.corda.node.internal.AbstractNode import net.corda.node.internal.StartedNode +import net.corda.node.internal.cordapp.CordappLoader import net.corda.node.services.api.NetworkMapCacheInternal import net.corda.node.services.api.SchemaService import net.corda.node.services.config.BFTSMaRtConfiguration @@ -82,7 +83,8 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, servicePeerAllocationStrategy: InMemoryMessagingNetwork.ServicePeerAllocationStrategy = InMemoryMessagingNetwork.ServicePeerAllocationStrategy.Random(), private val defaultFactory: Factory<*> = MockNetwork.DefaultFactory, - private val initialiseSerialization: Boolean = true) : Closeable { + private val initialiseSerialization: Boolean = true, + private val cordappPackages: List = emptyList()) : Closeable { companion object { // TODO In future PR we're removing the concept of network map node so the details of this mock are not important. val MOCK_NET_MAP = Party(CordaX500Name(organisation = "Mock Network Map", locality = "Madrid", country = "ES"), DUMMY_KEY_1.public) @@ -160,7 +162,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, val id: Int, internal val notaryIdentity: Pair?, val entropyRoot: BigInteger = BigInteger.valueOf(random63BitValue())) : - AbstractNode(config, TestClock(), MOCK_VERSION_INFO, mockNet.busyLatch) { + AbstractNode(config, TestClock(), MOCK_VERSION_INFO, CordappLoader.createDefaultWithTestPackages(config, mockNet.cordappPackages), mockNet.busyLatch) { var counter = entropyRoot override val log: Logger = loggerFor() override val serverThread: AffinityExecutor = diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt index ae838119a2..47fd8589a3 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/MockServices.kt @@ -167,9 +167,8 @@ open class MockServices( return NodeInfo(emptyList(), listOf(identity), 1, serial = 1L) } override val transactionVerifierService: TransactionVerifierService get() = InMemoryTransactionVerifierService(2) - val mockCordappProvider: MockCordappProvider = MockCordappProvider(CordappLoader.createWithTestPackages(cordappPackages + CordappLoader.testPackages)).start(attachments) as MockCordappProvider - override val cordappProvider: CordappProvider = mockCordappProvider - + val mockCordappProvider = MockCordappProvider(CordappLoader.createWithTestPackages(cordappPackages)).start(attachments) as MockCordappProvider + override val cordappProvider: CordappProvider get() = mockCordappProvider lateinit var hibernatePersister: HibernateObserver fun makeVaultService(hibernateConfig: HibernateConfiguration = HibernateConfiguration(NodeSchemaService(), makeTestDatabaseProperties(), { identityService })): VaultServiceInternal { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt index 3d4d4e9d63..36dfb43a45 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt @@ -9,6 +9,7 @@ import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.getOrThrow import net.corda.node.internal.Node import net.corda.node.internal.StartedNode +import net.corda.node.internal.cordapp.CordappLoader import net.corda.node.services.config.* import net.corda.node.utilities.ServiceIdentityGenerator import net.corda.nodeapi.User @@ -31,7 +32,7 @@ import kotlin.concurrent.thread * purposes. Use the driver if you need to run the nodes in separate processes otherwise this class will suffice. */ // TODO Some of the logic here duplicates what's in the driver -abstract class NodeBasedTest : TestDependencyInjectionBase() { +abstract class NodeBasedTest(private val cordappPackages: List = emptyList()) : TestDependencyInjectionBase() { companion object { private val WHITESPACE = "\\s++".toRegex() } @@ -193,7 +194,8 @@ abstract class NodeBasedTest : TestDependencyInjectionBase() { val node = Node( parsedConfig, MOCK_VERSION_INFO.copy(platformVersion = platformVersion), - initialiseSerialization = false).start() + initialiseSerialization = false, + cordappLoader = CordappLoader.createDefaultWithTestPackages(parsedConfig, cordappPackages)).start() nodes += node thread(name = legalName.organisation) { node.internals.run() diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt index 4e20194249..385b195e04 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt @@ -17,7 +17,6 @@ import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.loggerFor import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER -import net.corda.node.internal.cordapp.CordappLoader import net.corda.node.services.config.configureDevKeyAndTrustStores import net.corda.node.services.identity.InMemoryIdentityService import net.corda.node.utilities.CertificateAndKeyPair @@ -169,18 +168,3 @@ fun NodeInfo.chooseIdentityAndCert(): PartyAndCertificate = legalIdentitiesAndCe fun NodeInfo.chooseIdentity(): Party = chooseIdentityAndCert().party /** Returns the identity of the first notary found on the network */ fun ServiceHub.getDefaultNotary(): Party = networkMapCache.notaryIdentities.first() - -/** - * Set the package to scan for cordapps - this overrides the default behaviour of scanning the cordapps directory - * @param packageNames A package name that you wish to scan for cordapps - */ -fun setCordappPackages(vararg packageNames: String) { - CordappLoader.testPackages = packageNames.toList() -} - -/** - * Unsets the default overriding behaviour of [setCordappPackages] - */ -fun unsetCordappPackages() { - CordappLoader.testPackages = emptyList() -} \ No newline at end of file