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 b64b9ccc88..e4056fe36c 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt @@ -240,7 +240,7 @@ class CommercialPaperTestsGeneric { aliceVaultService = aliceServices.vaultService databaseAlice.transaction { - alicesVault = VaultFiller(aliceServices).fillWithSomeTestCash(9000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) + alicesVault = VaultFiller(aliceServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random).fillWithSomeTestCash(9000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) aliceVaultService = aliceServices.vaultService } @@ -250,7 +250,7 @@ class CommercialPaperTestsGeneric { bigCorpVaultService = bigCorpServices.vaultService databaseBigCorp.transaction { - bigCorpVault = VaultFiller(bigCorpServices).fillWithSomeTestCash(13000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) + bigCorpVault = VaultFiller(bigCorpServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random).fillWithSomeTestCash(13000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) bigCorpVaultService = bigCorpServices.vaultService } diff --git a/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt b/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt index 86f15f5bfa..c3c17c6661 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/asset/CashTests.kt @@ -82,15 +82,11 @@ class CashTests { // Create some cash. Any attempt to spend >$500 will require multiple issuers to be involved. database.transaction { - val vaultFiller = VaultFiller(ourServices) - vaultFiller.fillWithSomeTestCash(howMuch = 100.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - owner = ourIdentity, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) - vaultFiller.fillWithSomeTestCash(howMuch = 400.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - owner = ourIdentity, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) - vaultFiller.fillWithSomeTestCash(howMuch = 80.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - owner = ourIdentity, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices) - vaultFiller.fillWithSomeTestCash(howMuch = 80.SWISS_FRANCS, atLeastThisManyStates = 1, atMostThisManyStates = 1, - owner = ourIdentity, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices) + val vaultFiller = VaultFiller(ourServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, megaCorpServices, 1, MEGA_CORP.ref(1), ourIdentity) + vaultFiller.fillWithSomeTestCash(400.DOLLARS, megaCorpServices, 1, MEGA_CORP.ref(1), ourIdentity) + vaultFiller.fillWithSomeTestCash(80.DOLLARS, miniCorpServices, 1, MINI_CORP.ref(1), ourIdentity) + vaultFiller.fillWithSomeTestCash(80.SWISS_FRANCS, miniCorpServices, 1, MINI_CORP.ref(1), ourIdentity) } database.transaction { vaultStatesUnconsumed = ourServices.vaultService.queryBy().states 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 4ade7ae074..be124c6bd0 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 @@ -18,13 +18,11 @@ import net.corda.core.utilities.EncodingUtils; import net.corda.core.utilities.OpaqueBytes; import net.corda.finance.contracts.DealState; import net.corda.finance.contracts.asset.Cash; -import net.corda.finance.contracts.asset.CashUtilities; import net.corda.finance.schemas.CashSchemaV1; import net.corda.node.services.identity.InMemoryIdentityService; import net.corda.node.utilities.CordaPersistence; import net.corda.node.utilities.DatabaseTransaction; import net.corda.testing.SerializationEnvironmentRule; -import net.corda.testing.TestConstants; import net.corda.testing.contracts.DummyLinearContract; import net.corda.testing.contracts.VaultFiller; import net.corda.testing.node.MockServices; @@ -74,7 +72,7 @@ public class VaultQueryJavaTests { issuerServices = new MockServices(cordappPackages, getDUMMY_CASH_ISSUER_NAME(), getDUMMY_CASH_ISSUER_KEY(), getBOC_KEY()); database = databaseAndServices.getFirst(); MockServices services = databaseAndServices.getSecond(); - vaultFiller = new VaultFiller(services); + vaultFiller = new VaultFiller(services, getDUMMY_NOTARY(), getDUMMY_NOTARY_KEY()); vaultService = services.getVaultService(); } @@ -139,18 +137,16 @@ public class VaultQueryJavaTests { Amount amount = new Amount<>(100, Currency.getInstance("USD")); database.transaction(tx -> { vaultFiller.fillWithSomeTestCash( - new Amount(100, Currency.getInstance("USD")), + new Amount<>(100, Currency.getInstance("USD")), issuerServices, - TestConstants.getDUMMY_NOTARY(), 3, - 3, - new Random(), + getDUMMY_CASH_ISSUER(), null, - CashUtilities.getDUMMY_CASH_ISSUER()); + new Random()); return tx; }); database.transaction(tx -> { - vaultFiller.consumeCash(amount, getDUMMY_NOTARY()); + vaultFiller.consumeCash(amount, getCHARLIE()); return tx; }); database.transaction(tx -> { @@ -179,8 +175,8 @@ public class VaultQueryJavaTests { }); database.transaction(tx -> { // consume states - vaultFiller.consumeDeals((List>) ids.getThird().getStates(), getDUMMY_NOTARY()); - vaultFiller.consumeLinearStates(Collections.singletonList(ids.getFirst()), getDUMMY_NOTARY()); + vaultFiller.consumeDeals((List>) ids.getThird().getStates()); + vaultFiller.consumeLinearStates(Collections.singletonList(ids.getFirst())); return tx; }); database.transaction(tx -> { @@ -219,10 +215,10 @@ public class VaultQueryJavaTests { Amount dollars100 = new Amount<>(100, Currency.getInstance("USD")); Amount dollars10 = new Amount<>(10, Currency.getInstance("USD")); Amount dollars1 = new Amount<>(1, Currency.getInstance("USD")); - vaultFiller.fillWithSomeTestCash(pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars10, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars1, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(pounds, issuerServices, 1, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars10, issuerServices, 1, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars1, issuerServices, 1, getDUMMY_CASH_ISSUER()); return tx; }); database.transaction(tx -> { @@ -262,12 +258,10 @@ public class VaultQueryJavaTests { vaultFiller.fillWithSomeTestCash( new Amount<>(100, Currency.getInstance("USD")), issuerServices, - TestConstants.getDUMMY_NOTARY(), 3, - 3, - new Random(), + getDUMMY_CASH_ISSUER(), null, - getDUMMY_CASH_ISSUER()); + new Random()); return tx; }); database.transaction(tx -> { @@ -339,11 +333,11 @@ public class VaultQueryJavaTests { Amount dollars300 = new Amount<>(300, Currency.getInstance("USD")); Amount pounds = new Amount<>(400, Currency.getInstance("GBP")); Amount swissfrancs = new Amount<>(500, Currency.getInstance("CHF")); - vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), null, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, 3, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(pounds, issuerServices, 4, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, 5, getDUMMY_CASH_ISSUER()); return tx; }); database.transaction(tx -> { @@ -385,11 +379,11 @@ public class VaultQueryJavaTests { Amount dollars300 = new Amount<>(300, Currency.getInstance("USD")); Amount pounds = new Amount<>(400, Currency.getInstance("GBP")); Amount swissfrancs = new Amount<>(500, Currency.getInstance("CHF")); - vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), null, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, 3, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(pounds, issuerServices, 4, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, 5, getDUMMY_CASH_ISSUER()); return tx; }); database.transaction(tx -> { @@ -409,21 +403,21 @@ public class VaultQueryJavaTests { // DOCEND VaultJavaQueryExample22 assertThat(results.getOtherResults()).hasSize(18); - /** CHF */ + /* CHF */ assertThat(results.getOtherResults().get(0)).isEqualTo(500L); assertThat(results.getOtherResults().get(1)).isEqualTo(5L); assertThat(results.getOtherResults().get(2)).isEqualTo(102L); assertThat(results.getOtherResults().get(3)).isEqualTo(94L); assertThat(results.getOtherResults().get(4)).isEqualTo(100.00); assertThat(results.getOtherResults().get(5)).isEqualTo("CHF"); - /** GBP */ + /* GBP */ assertThat(results.getOtherResults().get(6)).isEqualTo(400L); assertThat(results.getOtherResults().get(7)).isEqualTo(4L); assertThat(results.getOtherResults().get(8)).isEqualTo(103L); assertThat(results.getOtherResults().get(9)).isEqualTo(93L); assertThat(results.getOtherResults().get(10)).isEqualTo(100.0); assertThat(results.getOtherResults().get(11)).isEqualTo("GBP"); - /** USD */ + /* USD */ assertThat(results.getOtherResults().get(12)).isEqualTo(600L); assertThat(results.getOtherResults().get(13)).isEqualTo(6L); assertThat(results.getOtherResults().get(14)).isEqualTo(113L); @@ -446,10 +440,10 @@ public class VaultQueryJavaTests { Amount dollars200 = new Amount<>(200, Currency.getInstance("USD")); Amount pounds300 = new Amount<>(300, Currency.getInstance("GBP")); Amount pounds400 = new Amount<>(400, Currency.getInstance("GBP")); - vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); - vaultFiller.fillWithSomeTestCash(pounds300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); - vaultFiller.fillWithSomeTestCash(pounds400, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); + vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, getBOC().ref(new OpaqueBytes("1".getBytes()))); + vaultFiller.fillWithSomeTestCash(pounds300, issuerServices, 3, getDUMMY_CASH_ISSUER()); + vaultFiller.fillWithSomeTestCash(pounds400, issuerServices, 4, getBOC().ref(new OpaqueBytes("1".getBytes()))); return tx; }); database.transaction(tx -> { 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 16b2947647..7696190b3c 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -106,8 +106,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { bobNode.internals.disableDBCloseOnStop() bobNode.database.transaction { - VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, - issuedBy = cashIssuer) + VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, cashIssuer) } val alicesFakePaper = aliceNode.database.transaction { @@ -156,8 +155,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { bobNode.internals.disableDBCloseOnStop() val cashStates = bobNode.database.transaction { - VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, notary, 3, 3, - issuedBy = issuer) + VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, issuer) } val alicesFakePaper = aliceNode.database.transaction { @@ -216,8 +214,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { val issuer = bank.ref(1, 2, 3) bobNode.database.transaction { - VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, - issuedBy = issuer) + VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, issuer) } val alicesFakePaper = aliceNode.database.transaction { fillUpForSeller(false, issuer, alice, 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 8a399b394b..3709de0e4b 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 @@ -3,6 +3,7 @@ package net.corda.node.services.persistence import com.nhaarman.mockito_kotlin.any import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever +import net.corda.core.contracts.Amount import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateRef import net.corda.core.contracts.TransactionState @@ -82,6 +83,7 @@ class HibernateConfigurationTest { bankServices = MockServices(cordappPackages, BOC.name, BOC_KEY) issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY) notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY) + notary = notaryServices.myInfo.singleIdentity() val dataSourceProps = makeTestDataSourceProperties() val identityService = rigorousMock().also { mock -> doReturn(null).whenever(mock).wellKnownPartyFromAnonymous(any()) @@ -106,18 +108,15 @@ class HibernateConfigurationTest { override fun jdbcSession() = database.createSession() } - vaultFiller = VaultFiller(services) + vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random) hibernatePersister = services.hibernatePersister } identity = services.myInfo.singleIdentity() issuer = issuerServices.myInfo.singleIdentity() - notary = notaryServices.myInfo.singleIdentity() - database.transaction { val numStates = 10 - cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, numStates, numStates, Random(0L), issuedBy = issuer.ref(1)) - .states.toList() + cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, numStates, issuer.ref(1), rng = Random(0L)).states.toList() } sessionFactory = sessionFactoryForSchemas(VaultSchemaV1, CashSchemaV1, SampleCashSchemaV2, SampleCashSchemaV3) @@ -126,7 +125,7 @@ class HibernateConfigurationTest { } private fun sessionFactoryForSchemas(vararg schemas: MappedSchema) = hibernateConfig.sessionFactoryForSchemas(schemas.toSet()) - + private fun consumeCash(amount: Amount) = vaultFiller.consumeCash(amount, CHARLIE) @After fun cleanUp() { database.close() @@ -147,7 +146,7 @@ class HibernateConfigurationTest { @Test fun `consumed states`() { database.transaction { - vaultFiller.consumeCash(50.DOLLARS, notary = notary) + consumeCash(50.DOLLARS) } // structure query @@ -228,11 +227,7 @@ class HibernateConfigurationTest { fun `with sorting by state ref desc and asc`() { // generate additional state ref indexes database.transaction { - vaultFiller.consumeCash(1.DOLLARS, notary = notary) - vaultFiller.consumeCash(2.DOLLARS, notary = notary) - vaultFiller.consumeCash(3.DOLLARS, notary = notary) - vaultFiller.consumeCash(4.DOLLARS, notary = notary) - vaultFiller.consumeCash(5.DOLLARS, notary = notary) + (1..5).forEach { consumeCash(it.DOLLARS) } } // structure query @@ -258,11 +253,7 @@ class HibernateConfigurationTest { fun `with sorting by state ref index and txId desc and asc`() { // generate additional state ref indexes database.transaction { - vaultFiller.consumeCash(1.DOLLARS, notary = notary) - vaultFiller.consumeCash(2.DOLLARS, notary = notary) - vaultFiller.consumeCash(3.DOLLARS, notary = notary) - vaultFiller.consumeCash(4.DOLLARS, notary = notary) - vaultFiller.consumeCash(5.DOLLARS, notary = notary) + (1..5).forEach { consumeCash(it.DOLLARS) } } // structure query @@ -289,7 +280,7 @@ class HibernateConfigurationTest { fun `with pagination`() { // add 100 additional cash entries database.transaction { - vaultFiller.fillWithSomeTestCash(1000.POUNDS, issuerServices, notary, 100, 100, Random(0L), issuedBy = issuer.ref(1)) + vaultFiller.fillWithSomeTestCash(1000.POUNDS, issuerServices, 100, issuer.ref(1), rng = Random(0L)) } // structure query @@ -389,11 +380,11 @@ class HibernateConfigurationTest { @Test fun `calculate cash balances`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 10, issuer.ref(1)) // +$100 = $200 - vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // £50 = £50 - vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // +£25 = £175 - vaultFiller.fillWithSomeTestCash(500.SWISS_FRANCS, issuerServices, notary, 10, issuer.ref(1)) // CHF500 = CHF500 - vaultFiller.fillWithSomeTestCash(250.SWISS_FRANCS, issuerServices, notary, 5, issuer.ref(1)) // +CHF250 = CHF750 + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 10, issuer.ref(1)) // +$100 = $200 + vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, 5, issuer.ref(1)) // £50 = £50 + vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, 5, issuer.ref(1)) // +£25 = £175 + vaultFiller.fillWithSomeTestCash(500.SWISS_FRANCS, issuerServices, 10, issuer.ref(1)) // CHF500 = CHF500 + vaultFiller.fillWithSomeTestCash(250.SWISS_FRANCS, issuerServices, 5, issuer.ref(1)) // +CHF250 = CHF750 } // structure query @@ -422,8 +413,8 @@ class HibernateConfigurationTest { @Test fun `calculate cash balance for single currency`() { database.transaction { - vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // £50 = £50 - vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // +£25 = £175 + vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, 5, issuer.ref(1)) // £50 = £50 + vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, 5, issuer.ref(1)) // +£25 = £175 } // structure query @@ -453,9 +444,9 @@ class HibernateConfigurationTest { fun `calculate and order by cash balance for owner and currency`() { database.transaction { val bank = bankServices.myInfo.legalIdentities.single() - vaultFiller.fillWithSomeTestCash(200.DOLLARS, bankServices, notary, 2, bank.ref(1)) - vaultFiller.fillWithSomeTestCash(300.POUNDS, issuerServices, notary, 3, issuer.ref(1)) - vaultFiller.fillWithSomeTestCash(400.POUNDS, bankServices, notary, 4, bank.ref(2)) + vaultFiller.fillWithSomeTestCash(200.DOLLARS, bankServices, 2, bank.ref(1)) + vaultFiller.fillWithSomeTestCash(300.POUNDS, issuerServices, 3, issuer.ref(1)) + vaultFiller.fillWithSomeTestCash(400.POUNDS, bankServices, 4, bank.ref(2)) } // structure query @@ -640,9 +631,8 @@ class HibernateConfigurationTest { val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), - issuedBy = issuer.ref(1), owner = ALICE) - val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, notary, 2, identity.ref(0)).states + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 2, issuer.ref(1), ALICE, Random(0L)) + val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, 2, identity.ref(0)).states // persist additional cash states explicitly with V3 schema cashStates.forEach { val cashState = it.state.data @@ -718,15 +708,14 @@ class HibernateConfigurationTest { val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - val moreCash = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, notary, 2, 2, Random(0L), - issuedBy = identity.ref(0), owner = identity).states + val moreCash = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, 2, identity.ref(0), identity, Random(0L)).states // persist additional cash states explicitly with V3 schema moreCash.forEach { val cashState = it.state.data val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), owner = ALICE, issuedBy = issuer.ref(1)).states + val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 2, issuer.ref(1), ALICE, Random(0L)).states // persist additional cash states explicitly with V3 schema cashStates.forEach { val cashState = it.state.data 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 c24f563b85..4ffdfd05d1 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 @@ -75,7 +75,7 @@ class NodeVaultServiceTest { val databaseAndServices = MockServices.makeTestDatabaseAndMockServices(cordappPackages = cordappPackages) database = databaseAndServices.first services = databaseAndServices.second - vaultFiller = VaultFiller(services) + vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY) // This is safe because MockServices only ever have a single identity identity = services.myInfo.singleIdentityAndCert() issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY) @@ -113,7 +113,7 @@ class NodeVaultServiceTest { @Test fun `states not local to instance`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } database.transaction { val w1 = vaultService.queryBy().states @@ -138,7 +138,7 @@ class NodeVaultServiceTest { @Test fun `states for refs`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } database.transaction { val w1 = vaultService.queryBy().states @@ -152,7 +152,7 @@ class NodeVaultServiceTest { @Test fun `states soft locking reserve and release`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } database.transaction { @@ -205,7 +205,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() println("State Refs:: $stateRefsToSoftLock") @@ -260,7 +260,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } val stateRefsToSoftLock = vaultStates.states.map { it.ref } println("State Refs:: $stateRefsToSoftLock") @@ -288,7 +288,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() println("State Refs:: $stateRefsToSoftLock") @@ -315,7 +315,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } val stateRefsToSoftLock = vaultStates.states.map { it.ref } println("State Refs:: $stateRefsToSoftLock") @@ -336,7 +336,7 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending exact amount`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) } database.transaction { @@ -355,8 +355,8 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending from two issuer parties`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(1)) } database.transaction { val spendableStatesUSD = vaultService.unconsumedCashStatesForSpending(200.DOLLARS, @@ -372,10 +372,10 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending from specific issuer party and refs`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(2)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(3)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(1)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(2)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(3)) } database.transaction { val unconsumedStates = vaultService.queryBy().states @@ -394,7 +394,7 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending insufficient amount`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER) } database.transaction { val unconsumedStates = vaultService.queryBy().states @@ -411,7 +411,7 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending small amount`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 2, DUMMY_CASH_ISSUER) } database.transaction { val unconsumedStates = vaultService.queryBy().states @@ -429,9 +429,9 @@ class NodeVaultServiceTest { @Test fun `states soft locking query granularity`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), issuerServices, 10, DUMMY_CASH_ISSUER) + } } database.transaction { var unlockedStates = 30 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 20ea02690f..6586686921 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 @@ -23,6 +23,7 @@ import net.corda.finance.contracts.DealState import net.corda.finance.contracts.asset.Cash import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER_KEY +import net.corda.finance.contracts.asset.DUMMY_OBLIGATION_ISSUER import net.corda.finance.schemas.CashSchemaV1 import net.corda.finance.schemas.CashSchemaV1.PersistentCashState import net.corda.finance.schemas.CommercialPaperSchemaV1 @@ -64,6 +65,7 @@ class VaultQueryTests { DummyLinearStateSchemaV1::class.packageName) private lateinit var services: MockServices private lateinit var vaultFiller: VaultFiller + private lateinit var vaultFillerCashNotary: VaultFiller private lateinit var notaryServices: MockServices private val vaultService: VaultService get() = services.vaultService private lateinit var identitySvc: IdentityService @@ -81,7 +83,8 @@ class VaultQueryTests { cordappPackages = cordappPackages) database = databaseAndServices.first services = databaseAndServices.second - vaultFiller = VaultFiller(services) + vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY) + vaultFillerCashNotary = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, CASH_NOTARY) notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY, DUMMY_CASH_ISSUER_KEY, BOC_KEY, MEGA_CORP_KEY) identitySvc = services.identityService // Register all of the identities we're going to use @@ -107,10 +110,11 @@ class VaultQueryTests { database.close() } + private fun consumeCash(amount: Amount) = vaultFiller.consumeCash(amount, CHARLIE) private fun setUpDb(_database: CordaPersistence, delay: Long = 0) { _database.transaction { // create new states - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER) val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL") vaultFiller.fillWithSomeTestLinearStates(3, "ABC") @@ -119,10 +123,10 @@ class VaultQueryTests { sleep(delay) // consume some states - vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) - vaultFiller.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList()) + vaultFiller.consumeLinearStates(linearStatesJKL.states.toList()) + vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }) + consumeCash(50.DOLLARS) // Total unconsumed states = 4 + 3 + 2 + 1 (new cash change) = 10 // Total consumed states = 6 + 1 + 2 + 1 = 10 } @@ -147,7 +151,7 @@ class VaultQueryTests { @Test fun `unconsumed states simple`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // DOCSTART VaultQueryExample1 @@ -172,7 +176,7 @@ class VaultQueryTests { @Test fun `unconsumed states verbose`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val criteria = VaultQueryCriteria() // default is UNCONSUMED @@ -186,16 +190,15 @@ class VaultQueryTests { @Test fun `unconsumed states with count`() { database.transaction { - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + repeat(4) { + vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) + } val paging = PageSpecification(DEFAULT_PAGE_NUM, 10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val resultsBeforeConsume = vaultService.queryBy(criteria, paging) assertThat(resultsBeforeConsume.states).hasSize(4) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4) - vaultFiller.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) + consumeCash(75.DOLLARS) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.UNCONSUMED) val resultsAfterConsume = vaultService.queryBy(consumedCriteria, paging) assertThat(resultsAfterConsume.states).hasSize(1) @@ -206,7 +209,7 @@ class VaultQueryTests { @Test fun `unconsumed cash states simple`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val result = vaultService.queryBy() @@ -219,7 +222,7 @@ class VaultQueryTests { @Test fun `unconsumed cash states verbose`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val criteria = VaultQueryCriteria() // default is UNCONSUMED @@ -234,12 +237,12 @@ class VaultQueryTests { fun `unconsumed cash states sorted by state ref`() { val stateRefs: MutableList = mutableListOf() database.transaction { - val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER) val issuedStateRefs = issuedStates.states.map { it.ref }.toList() stateRefs.addAll(issuedStateRefs) } database.transaction { - val spentStates = vaultFiller.consumeCash(25.DOLLARS, notary = DUMMY_NOTARY) + val spentStates = consumeCash(25.DOLLARS) val consumedStateRefs = spentStates.consumed.map { it.ref }.toList() val producedStateRefs = spentStates.produced.map { it.ref }.toList() stateRefs.addAll(consumedStateRefs.plus(producedStateRefs)) @@ -265,11 +268,11 @@ class VaultQueryTests { fun `unconsumed cash states sorted by state ref txnId and index`() { val consumed = mutableSetOf() database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER) } database.transaction { - vaultFiller.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).consumed.forEach { consumed += it.ref.txhash } - vaultFiller.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).consumed.forEach { consumed += it.ref.txhash } + consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash } + consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash } val sortAttributeTxnId = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_TXN_ID) val sortAttributeIndex = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_INDEX) val sortBy = Sort(setOf(Sort.SortColumn(sortAttributeTxnId, Sort.Direction.ASC), @@ -311,7 +314,7 @@ class VaultQueryTests { @Test fun `unconsumed states for contract state types`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // default State.Status is UNCONSUMED @@ -326,13 +329,13 @@ class VaultQueryTests { @Test fun `consumed states`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId vaultFiller.fillWithSomeTestLinearStates(8) val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) - vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.states.toList()) + vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }) + consumeCash(50.DOLLARS) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(5) @@ -342,16 +345,15 @@ class VaultQueryTests { @Test fun `consumed states with count`() { database.transaction { - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + repeat(4) { + vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) + } val paging = PageSpecification(DEFAULT_PAGE_NUM, 10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val resultsBeforeConsume = vaultService.queryBy(criteria, paging) assertThat(resultsBeforeConsume.states).hasSize(4) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4) - vaultFiller.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) + consumeCash(75.DOLLARS) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val resultsAfterConsume = vaultService.queryBy(consumedCriteria, paging) assertThat(resultsAfterConsume.states).hasSize(3) @@ -362,13 +364,13 @@ class VaultQueryTests { @Test fun `all states`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 results with same UID vaultFiller.fillWithSomeTestLinearStates(8) val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) - vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // generates a new change state! + vaultFiller.consumeLinearStates(linearStates.states.toList()) + vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }) + consumeCash(50.DOLLARS) // generates a new change state! val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(17) @@ -378,14 +380,14 @@ class VaultQueryTests { @Test fun `all states with count`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val paging = PageSpecification(DEFAULT_PAGE_NUM, 10) val resultsBeforeConsume = vaultService.queryBy(criteria, paging) assertThat(resultsBeforeConsume.states).hasSize(1) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(1) - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // consumed 100 (spent), produced 50 (change) + consumeCash(50.DOLLARS) // consumed 100 (spent), produced 50 (change) val resultsAfterConsume = vaultService.queryBy(criteria, paging) assertThat(resultsAfterConsume.states).hasSize(2) assertThat(resultsAfterConsume.totalStatesAvailable).isEqualTo(2) @@ -395,7 +397,7 @@ class VaultQueryTests { @Test fun `unconsumed states by notary`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) + vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // DOCSTART VaultQueryExample4 @@ -438,7 +440,7 @@ class VaultQueryTests { @Test fun `unconsumed states with soft locking`() { database.transaction { - val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)).states.toList() + val issuedStates = vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER).states.toList() vaultService.softLockReserve(UUID.randomUUID(), NonEmptySet.of(issuedStates[1].ref, issuedStates[2].ref, issuedStates[3].ref)) val lockId1 = UUID.randomUUID() vaultService.softLockReserve(lockId1, NonEmptySet.of(issuedStates[4].ref, issuedStates[5].ref)) @@ -481,9 +483,9 @@ class VaultQueryTests { @Test fun `logical operator EQUAL`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -494,9 +496,9 @@ class VaultQueryTests { @Test fun `logical operator NOT EQUAL`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notEqual(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -507,9 +509,9 @@ class VaultQueryTests { @Test fun `logical operator GREATER_THAN`() { database.transaction { - vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach { + vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThan(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -520,9 +522,9 @@ class VaultQueryTests { @Test fun `logical operator GREATER_THAN_OR_EQUAL`() { database.transaction { - vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach { + vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThanOrEqual(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -533,9 +535,9 @@ class VaultQueryTests { @Test fun `logical operator LESS_THAN`() { database.transaction { - vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach { + vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThan(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -546,9 +548,9 @@ class VaultQueryTests { @Test fun `logical operator LESS_THAN_OR_EQUAL`() { database.transaction { - vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach { + vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThanOrEqual(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -559,9 +561,9 @@ class VaultQueryTests { @Test fun `logical operator BETWEEN`() { database.transaction { - vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach { + vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.between(500L, 1500L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -572,9 +574,9 @@ class VaultQueryTests { @Test fun `logical operator IN`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.`in`(currencies) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -586,9 +588,9 @@ class VaultQueryTests { @Test fun `logical operator NOT IN`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notIn(currencies) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -600,9 +602,9 @@ class VaultQueryTests { @Test fun `logical operator LIKE`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.like("%BP") } // GPB val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -613,9 +615,9 @@ class VaultQueryTests { @Test fun `logical operator NOT LIKE`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notLike("%BP") } // GPB val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -626,9 +628,9 @@ class VaultQueryTests { @Test fun `logical operator IS_NULL`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.isNull() } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -639,9 +641,9 @@ class VaultQueryTests { @Test fun `logical operator NOT_NULL`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER) + } val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.notNull() } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -652,11 +654,9 @@ class VaultQueryTests { @Test fun `aggregate functions without group clause`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - vaultFiller.fillWithSomeTestCash(300.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - vaultFiller.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) - vaultFiller.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + listOf(100.DOLLARS, 200.DOLLARS, 300.DOLLARS, 400.POUNDS, 500.SWISS_FRANCS).zip(1..5).forEach { (howMuch, states) -> + vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER) + } // DOCSTART VaultQueryExample21 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum() } val sumCriteria = VaultCustomQueryCriteria(sum) @@ -692,11 +692,9 @@ class VaultQueryTests { @Test fun `aggregate functions with single group clause`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - vaultFiller.fillWithSomeTestCash(300.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - vaultFiller.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) - vaultFiller.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + listOf(100.DOLLARS, 200.DOLLARS, 300.DOLLARS, 400.POUNDS, 500.SWISS_FRANCS).zip(1..5).forEach { (howMuch, states) -> + vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER) + } // DOCSTART VaultQueryExample22 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val sumCriteria = VaultCustomQueryCriteria(sum) @@ -742,10 +740,10 @@ class VaultQueryTests { fun `aggregate functions sum by issuer and currency and sort by aggregate sum`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1)) - vaultFiller.fillWithSomeTestCash(300.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - vaultFiller.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L), issuedBy = BOC.ref(2)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, 2, BOC.ref(1)) + vaultFiller.fillWithSomeTestCash(300.POUNDS, notaryServices, 3, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(400.POUNDS, notaryServices, 4, BOC.ref(2)) // DOCSTART VaultQueryExample23 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::issuerPartyHash, @@ -777,7 +775,7 @@ class VaultQueryTests { fun `aggregate functions count by contract type`() { database.transaction { // create new states - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)) + vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") vaultFiller.fillWithSomeTestLinearStates(2, "JKL") vaultFiller.fillWithSomeTestLinearStates(3, "ABC") @@ -802,7 +800,7 @@ class VaultQueryTests { fun `aggregate functions count by contract type and state status`() { database.transaction { // create new states - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER) val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL") vaultFiller.fillWithSomeTestLinearStates(3, "ABC") @@ -823,10 +821,10 @@ class VaultQueryTests { assertThat(dealStateCount).isEqualTo(3L) // consume some states - vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) - vaultFiller.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - val cashUpdates = vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList()) + vaultFiller.consumeLinearStates(linearStatesJKL.states.toList()) + vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }) + val cashUpdates = consumeCash(50.DOLLARS) // UNCONSUMED states (default) // count fungible assets @@ -864,7 +862,7 @@ class VaultQueryTests { @Test fun `unconsumed states recorded between two time intervals`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) + vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) // DOCSTART VaultQueryExample6 val start = TODAY val end = TODAY.plus(30, ChronoUnit.DAYS) @@ -888,12 +886,12 @@ class VaultQueryTests { @Test fun `states consumed after time`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) } database.transaction { - vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + consumeCash(100.DOLLARS) val asOfDateTime = TODAY val consumedAfterExpression = TimeCondition( QueryCriteria.TimeInstantType.CONSUMED, ColumnPredicate.BinaryComparison(BinaryComparisonOperator.GREATER_THAN_OR_EQUAL, asOfDateTime)) @@ -909,7 +907,7 @@ class VaultQueryTests { @Test fun `all states with paging specification - first page`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER) // DOCSTART VaultQueryExample7 val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, 10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -924,7 +922,7 @@ class VaultQueryTests { @Test fun `all states with paging specification - last`() { database.transaction { - vaultFiller.fillWithSomeTestCash(95.DOLLARS, notaryServices, DUMMY_NOTARY, 95, 95, Random(0L)) + vaultFiller.fillWithSomeTestCash(95.DOLLARS, notaryServices, 95, DUMMY_CASH_ISSUER) // Last page implies we need to perform a row count for the Query first, // and then re-query for a given offset defined by (count - pageSize) val pagingSpec = PageSpecification(10, 10) @@ -943,7 +941,7 @@ class VaultQueryTests { expectedEx.expectMessage("Page specification: invalid page number") database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER) val pagingSpec = PageSpecification(0, 10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -958,7 +956,7 @@ class VaultQueryTests { expectedEx.expectMessage("Page specification: invalid page size") database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER) @Suppress("EXPECTED_CONDITION") val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, @Suppress("INTEGER_OVERFLOW") MAX_PAGE_SIZE + 1) // overflow = -2147483648 val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -973,7 +971,7 @@ class VaultQueryTests { expectedEx.expectMessage("Please specify a `PageSpecification`") database.transaction { - vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, DUMMY_NOTARY, 201, 201, Random(0L)) + vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, 201, DUMMY_CASH_ISSUER) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) vaultService.queryBy(criteria) } @@ -1011,8 +1009,8 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1)) vaultFiller.fillWithSomeTestLinearStates(10) val results = vaultService.queryBy>() assertThat(results.states).hasSize(4) @@ -1022,11 +1020,11 @@ class VaultQueryTests { @Test fun `consumed fungible assets`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) } database.transaction { - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) - vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) + consumeCash(50.DOLLARS) + vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1)) vaultFiller.fillWithSomeTestLinearStates(10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy>(criteria) @@ -1037,7 +1035,7 @@ class VaultQueryTests { @Test fun `unconsumed cash fungible assets`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) val results = vaultService.queryBy() assertThat(results.states).hasSize(3) @@ -1047,10 +1045,10 @@ class VaultQueryTests { @Test fun `unconsumed cash fungible assets after spending`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) } database.transaction { - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + consumeCash(50.DOLLARS) // should now have x2 CONSUMED + x2 UNCONSUMED (one spent + one change) val results = vaultService.queryBy(FungibleAssetQueryCriteria()) assertThat(results.statesMetadata).hasSize(2) @@ -1061,12 +1059,12 @@ class VaultQueryTests { @Test fun `consumed cash fungible assets`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) } database.transaction { - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + consumeCash(50.DOLLARS) val linearStates = vaultFiller.fillWithSomeTestLinearStates(10) - vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.states.toList()) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(2) @@ -1076,7 +1074,7 @@ class VaultQueryTests { @Test fun `unconsumed linear heads`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val results = vaultService.queryBy() @@ -1087,13 +1085,13 @@ class VaultQueryTests { @Test fun `consumed linear heads`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId vaultFiller.fillWithSomeTestLinearStates(8) val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) - vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.states.toList()) + vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }) + consumeCash(50.DOLLARS) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(3) @@ -1146,9 +1144,9 @@ class VaultQueryTests { database.transaction { val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST") val linearState = txns.states.first() - vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference - vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference - vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference + repeat(3) { + vaultFiller.evolveLinearState(linearState) // consume current and produce new state reference + } val linearId = linearState.state.data.linearId // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" @@ -1166,9 +1164,9 @@ class VaultQueryTests { database.transaction { val txns = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") val linearStates = txns.states.toList() - vaultFiller.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference - vaultFiller.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference - vaultFiller.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference + repeat(3) { + vaultFiller.evolveLinearStates(linearStates) // consume current and produce new state reference + } // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" val linearStateCriteria = LinearStateQueryCriteria(uuid = linearStates.map { it.state.data.linearId.id }, status = Vault.StateStatus.ALL) val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -1234,9 +1232,9 @@ class VaultQueryTests { database.transaction { val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST") val linearState = txns.states.first() - val linearState2 = vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference - val linearState3 = vaultFiller.evolveLinearState(linearState2, DUMMY_NOTARY) // consume current and produce new state reference - vaultFiller.evolveLinearState(linearState3, DUMMY_NOTARY) // consume current and produce new state reference + val linearState2 = vaultFiller.evolveLinearState(linearState) // consume current and produce new state reference + val linearState3 = vaultFiller.evolveLinearState(linearState2) // consume current and produce new state reference + vaultFiller.evolveLinearState(linearState3) // consume current and produce new state reference // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" val linearStateCriteria = LinearStateQueryCriteria(linearId = txns.states.map { it.state.data.linearId }, status = Vault.StateStatus.CONSUMED) val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) @@ -1308,10 +1306,9 @@ class VaultQueryTests { fun `unconsumed fungible assets for specific issuer party and refs`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(2)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(3)) + listOf(DUMMY_CASH_ISSUER, BOC.ref(1), BOC.ref(2), BOC.ref(3)).forEach { + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, it) + } val criteria = FungibleAssetQueryCriteria(issuer = listOf(BOC), issuerRef = listOf(BOC.ref(1).reference, BOC.ref(2).reference)) val results = vaultService.queryBy>(criteria) @@ -1337,9 +1334,9 @@ class VaultQueryTests { services.identityService.verifyAndRegisterIdentity(identity) } database.transaction { - vaultFiller.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = gbpCashIssuer.party.ref(1)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = usdCashIssuer.party.ref(1)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = chfCashIssuer.party.ref(1)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, 1, gbpCashIssuer.party.ref(1)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, 1, usdCashIssuer.party.ref(1)) + vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, 1, chfCashIssuer.party.ref(1)) } database.transaction { val criteria = FungibleAssetQueryCriteria(issuer = listOf(gbpCashIssuer.party, usdCashIssuer.party)) @@ -1351,9 +1348,8 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets by owner`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), - issuedBy = MEGA_CORP.ref(0), owner = (MINI_CORP)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, BOC.ref(1)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, MEGA_CORP.ref(0), MINI_CORP) } database.transaction { val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP)) @@ -1365,11 +1361,9 @@ class VaultQueryTests { @Test fun `unconsumed fungible states for owners`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), - issuedBy = MEGA_CORP.ref(0), owner = (MEGA_CORP)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), - issuedBy = BOC.ref(0), owner = MINI_CORP) // irrelevant to this vault + vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, MEGA_CORP.ref(0), MEGA_CORP) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, BOC.ref(0), MINI_CORP) // irrelevant to this vault } database.transaction { // DOCSTART VaultQueryExample5.2 @@ -1386,9 +1380,9 @@ class VaultQueryTests { fun `unconsumed fungible assets for single currency`() { database.transaction { vaultFiller.fillWithSomeTestLinearStates(10) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + listOf(USD, GBP, CHF).forEach { + vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 3, DUMMY_CASH_ISSUER) + } // DOCSTART VaultQueryExample12 val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(USD.currencyCode) } val criteria = VaultCustomQueryCriteria(ccyIndex) @@ -1402,8 +1396,9 @@ class VaultQueryTests { @Test fun `unconsumed cash balance for single currency`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) + listOf(100, 200).zip(1..2).forEach { (howMuch, states) -> + vaultFiller.fillWithSomeTestCash(howMuch.DOLLARS, notaryServices, states, DUMMY_CASH_ISSUER) + } val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val sumCriteria = VaultCustomQueryCriteria(sum) @@ -1421,12 +1416,9 @@ class VaultQueryTests { @Test fun `unconsumed cash balances for all currencies`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - vaultFiller.fillWithSomeTestCash(300.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - vaultFiller.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) - vaultFiller.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) - vaultFiller.fillWithSomeTestCash(600.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 6, 6, Random(0L)) + listOf(100.DOLLARS, 200.DOLLARS, 300.POUNDS, 400.POUNDS, 500.SWISS_FRANCS, 600.SWISS_FRANCS).zip(1..6).forEach { (howMuch, states) -> + vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER) + } val ccyIndex = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val criteria = VaultCustomQueryCriteria(ccyIndex) val results = vaultService.queryBy>(criteria) @@ -1444,10 +1436,9 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets for quantity greater than`() { database.transaction { - vaultFiller.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - vaultFiller.fillWithSomeTestCash(25.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(50.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + listOf(10.DOLLARS, 25.POUNDS, 50.POUNDS, 100.SWISS_FRANCS).zip(listOf(3, 1, 1, 3)).forEach { (howMuch, states) -> + vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER) + } // DOCSTART VaultQueryExample13 val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(2500L) }) val results = vaultService.queryBy(fungibleAssetCriteria) @@ -1461,8 +1452,9 @@ class VaultQueryTests { fun `unconsumed fungible assets for issuer party`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1))) + listOf(DUMMY_CASH_ISSUER, BOC.ref(1)).forEach { + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, it) + } // DOCSTART VaultQueryExample14 val criteria = FungibleAssetQueryCriteria(issuer = listOf(BOC)) val results = vaultService.queryBy>(criteria) @@ -1475,10 +1467,9 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets for single currency and quantity greater than`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(50.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + listOf(100.DOLLARS, 100.POUNDS, 50.POUNDS, 100.SWISS_FRANCS).forEach { + vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER) + } val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) } val customCriteria = VaultCustomQueryCriteria(ccyIndex) val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(5000L) }) @@ -1578,9 +1569,9 @@ class VaultQueryTests { cordappPackages -= SampleCashSchemaV3::class.packageName setUp() database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, 1, DUMMY_CASH_ISSUER) // CashSchemaV3 NOT registered with NodeSchemaService val logicalExpression = builder { SampleCashSchemaV3.PersistentCashState::currency.equal(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -1597,10 +1588,10 @@ class VaultQueryTests { @Test fun `custom - all cash states with amount of currency greater or equal than`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(10.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER) // DOCSTART VaultQueryExample20 val generalCriteria = VaultQueryCriteria(Vault.StateStatus.ALL) @@ -1690,7 +1681,7 @@ class VaultQueryTests { database.transaction { vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") val aState = vaultFiller.fillWithSomeTestLinearStates(1, "TEST2").states - vaultFiller.consumeLinearStates(aState.toList(), DUMMY_NOTARY) + vaultFiller.consumeLinearStates(aState.toList()) val uuid = vaultFiller.fillWithSomeTestLinearStates(1, "TEST1").states.first().state.data.linearId.id // 2 unconsumed states with same external ID, 1 consumed with different external ID val results = builder { @@ -1777,8 +1768,8 @@ class VaultQueryTests { @Test fun `enriched and overridden composite query handles defaults correctly`() { database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 2, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1)) vaultFiller.fillWithSomeTestLinearStates(1, "ABC") vaultFiller.fillWithSomeTestDeals(listOf("123")) // Base criteria @@ -1813,20 +1804,20 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER) // add another deal vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + consumeCash(100.DOLLARS) + vaultFiller.consumeDeals(dealStates.toList()) + vaultFiller.consumeLinearStates(linearStates.toList()) } updates.expectEvents { @@ -1854,24 +1845,24 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER) // add another deal vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - vaultFiller.consumeCash(100.POUNDS, notary = DUMMY_NOTARY) + consumeCash(100.POUNDS) } database.transaction { // consume more stuff - vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + consumeCash(100.DOLLARS) + vaultFiller.consumeDeals(dealStates.toList()) + vaultFiller.consumeLinearStates(linearStates.toList()) } updates.expectEvents { @@ -1899,24 +1890,24 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER) // add another deal vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - vaultFiller.consumeCash(99.POUNDS, notary = DUMMY_NOTARY) + consumeCash(99.POUNDS) } database.transaction { // consume more stuff - vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + consumeCash(100.DOLLARS) + vaultFiller.consumeDeals(dealStates.toList()) + vaultFiller.consumeLinearStates(linearStates.toList()) } updates.expectEvents { @@ -1957,20 +1948,20 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER) // add another deal vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + consumeCash(100.DOLLARS) + vaultFiller.consumeDeals(dealStates.toList()) + vaultFiller.consumeLinearStates(linearStates.toList()) } updates.expectEvents { @@ -2006,20 +1997,20 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER) val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER) // add another deal vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + consumeCash(100.DOLLARS) + vaultFiller.consumeDeals(dealStates.toList()) + vaultFiller.consumeLinearStates(linearStates.toList()) } updates.expectEvents { 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 1146b79b96..361519e41d 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 @@ -35,7 +35,6 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test -import java.util.* import java.util.concurrent.Executors import kotlin.test.assertEquals import kotlin.test.fail @@ -64,7 +63,7 @@ class VaultWithCashTest { val databaseAndServices = makeTestDatabaseAndMockServices(cordappPackages = cordappPackages, keys = listOf(generateKeyPair(), DUMMY_NOTARY_KEY)) database = databaseAndServices.first services = databaseAndServices.second - vaultFiller = VaultFiller(services) + vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY) issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY) notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY) notary = notaryServices.myInfo.legalIdentitiesAndCerts.single().party @@ -80,7 +79,7 @@ class VaultWithCashTest { fun splits() { database.transaction { // Fix the PRNG so that we get the same splits every time. - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER) } database.transaction { val w = vaultService.queryBy().states @@ -150,8 +149,7 @@ class VaultWithCashTest { database.transaction { // A tx that sends us money. - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L), owner = AnonymousParty(freshKey), - issuedBy = MEGA_CORP.ref(1)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 10, MEGA_CORP.ref(1), AnonymousParty(freshKey)) println("Cash balance: ${services.getCashBalance(USD)}") } database.transaction { @@ -300,9 +298,9 @@ class VaultWithCashTest { val freshKey = services.keyManagementService.freshKey() database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), owner = AnonymousParty(freshKey)) - vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) - vaultFiller.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER, AnonymousParty(freshKey)) + vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, 2, DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.POUNDS, issuerServices, 1, DUMMY_CASH_ISSUER) } database.transaction { val cash = vaultService.queryBy().states diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt index 9f9fac4ac7..b16ca113fb 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/contracts/VaultFiller.kt @@ -8,28 +8,39 @@ import net.corda.core.crypto.SignatureMetadata 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.node.ServiceHub import net.corda.core.node.services.Vault import net.corda.core.toFuture import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.TransactionBuilder -import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.getOrThrow import net.corda.finance.contracts.Commodity import net.corda.finance.contracts.DealState import net.corda.finance.contracts.asset.Cash import net.corda.finance.contracts.asset.CommodityContract -import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER -import net.corda.finance.contracts.asset.DUMMY_OBLIGATION_ISSUER -import net.corda.testing.* +import net.corda.testing.chooseIdentity +import net.corda.testing.chooseIdentityAndCert +import net.corda.testing.dummyCommand +import net.corda.testing.singleIdentity +import java.security.KeyPair import java.security.PublicKey import java.time.Duration import java.time.Instant import java.time.Instant.now import java.util.* -class VaultFiller(private val services: ServiceHub) { +/** + * The service hub should provide at least a key management service and a storage service. + * @param defaultNotary used in [fillWithSomeTestDeals] and [fillWithSomeTestLinearStates]. + * @param altNotary used in [fillWithSomeTestCash], [fillWithSomeTestCommodity] and consume/evolve methods. If not specified, same as [defaultNotary]. + * @param rngFactory used by [fillWithSomeTestCash] if no custom [Random] provided. + */ +class VaultFiller @JvmOverloads constructor( + private val services: ServiceHub, + private val defaultNotary: Party, + private val defaultNotaryKeyPair: KeyPair, + private val altNotary: Party = defaultNotary, + private val rngFactory: () -> Random = { Random(0L) }) { companion object { fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, max: Int, rng: Random): LongArray { val numSlots = min + Math.floor(rng.nextDouble() * (max - min)).toInt() @@ -60,22 +71,25 @@ class VaultFiller(private val services: ServiceHub) { } } + init { + require(defaultNotary.owningKey == defaultNotaryKeyPair.public) { "Default notary public keys must match." } + } + @JvmOverloads fun fillWithSomeTestDeals(dealIds: List, issuerServices: ServiceHub = services, - participants: List = emptyList(), - notary: Party = DUMMY_NOTARY): Vault { + participants: List = emptyList()): Vault { val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey val me = AnonymousParty(myKey) val transactions: List = dealIds.map { // Issue a deal state - val dummyIssue = TransactionBuilder(notary = notary).apply { + val dummyIssue = TransactionBuilder(notary = defaultNotary).apply { addOutputState(DummyDealContract.State(ref = it, participants = participants.plus(me)), DUMMY_DEAL_PROGRAM_ID) addCommand(dummyCommand()) } val stx = issuerServices.signInitialTransaction(dummyIssue) - return@map services.addSignature(stx, notary.owningKey) + return@map services.addSignature(stx, defaultNotaryKeyPair.public) } services.recordTransactions(transactions) // Get all the StateAndRefs of all the generated transactions. @@ -96,11 +110,11 @@ class VaultFiller(private val services: ServiceHub) { linearTimestamp: Instant = now()): Vault { val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey val me = AnonymousParty(myKey) - val issuerKey = DUMMY_NOTARY_KEY + val issuerKey = defaultNotaryKeyPair val signatureMetadata = SignatureMetadata(services.myInfo.platformVersion, Crypto.findSignatureScheme(issuerKey.public).schemeNumberID) val transactions: List = (1..numberToCreate).map { // Issue a Linear state - val dummyIssue = TransactionBuilder(notary = DUMMY_NOTARY).apply { + val dummyIssue = TransactionBuilder(notary = defaultNotary).apply { addOutputState(DummyLinearContract.State( linearId = UniqueIdentifier(externalId), participants = participants.plus(me), @@ -121,49 +135,35 @@ class VaultFiller(private val services: ServiceHub) { return Vault(states) } + @JvmOverloads + fun fillWithSomeTestCash(howMuch: Amount, + issuerServices: ServiceHub, + thisManyStates: Int, + issuedBy: PartyAndReference, + owner: AbstractParty? = null, + rng: Random? = null) = fillWithSomeTestCash(howMuch, issuerServices, thisManyStates, thisManyStates, issuedBy, owner, rng) + /** - * Creates a random set of cash states that add up to the given amount and adds them to the vault. This is intended for - * unit tests. The cash is owned by the legal identity key from the storage service. - * - * The service hub needs to provide at least a key management service and a storage service. + * Creates a random set of between (by default) 3 and 10 cash states that add up to the given amount and adds them + * to the vault. This is intended for unit tests. By default the cash is owned by the legal + * identity key from the storage service. * * @param issuerServices service hub of the issuer node, which will be used to sign the transaction. - * @param outputNotary the notary to use for output states. The transaction is NOT signed by this notary. * @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!). */ fun fillWithSomeTestCash(howMuch: Amount, issuerServices: ServiceHub, - outputNotary: Party, - states: Int, - issuedBy: PartyAndReference): Vault - = fillWithSomeTestCash(howMuch, issuerServices, outputNotary, states, states, issuedBy = issuedBy) - - /** - * Creates a random set of between (by default) 3 and 10 cash states that add up to the given amount and adds them - * to the vault. This is intended for unit tests. By default the cash is issued by [DUMMY_CASH_ISSUER] and owned by the legal - * identity key from the storage service. - * - * The service hub needs to provide at least a key management service and a storage service. - * - * @param issuerServices service hub of the issuer node, which will be used to sign the transaction. - * @param outputNotary the notary to use for output states. The transaction is NOT signed by this notary. - * @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!). - */ - fun fillWithSomeTestCash(howMuch: Amount, - issuerServices: ServiceHub = services, - outputNotary: Party = DUMMY_NOTARY, - atLeastThisManyStates: Int = 3, - atMostThisManyStates: Int = 10, - rng: Random = Random(), + atLeastThisManyStates: Int, + atMostThisManyStates: Int, + issuedBy: PartyAndReference, owner: AbstractParty? = null, - issuedBy: PartyAndReference = DUMMY_CASH_ISSUER): Vault { - val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng) - + rng: Random? = null): Vault { + val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng ?: rngFactory()) // We will allocate one state to one transaction, for simplicities sake. val cash = Cash() val transactions: List = amounts.map { pennies -> val issuance = TransactionBuilder(null as Party?) - cash.generateIssue(issuance, Amount(pennies, Issued(issuedBy, howMuch.token)), owner ?: services.myInfo.singleIdentity(), outputNotary) + cash.generateIssue(issuance, Amount(pennies, Issued(issuedBy, howMuch.token)), owner ?: services.myInfo.singleIdentity(), altNotary) return@map issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) } services.recordTransactions(transactions) @@ -178,88 +178,74 @@ class VaultFiller(private val services: ServiceHub) { /** * * @param issuerServices service hub of the issuer node, which will be used to sign the transaction. - * @param outputNotary the notary to use for output states. The transaction is NOT signed by this notary. * @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!). */ // TODO: need to make all FungibleAsset commands (issue, move, exit) generic - fun fillWithSomeTestCommodity(amount: Amount, - issuerServices: ServiceHub = services, - outputNotary: Party = DUMMY_NOTARY, - ref: OpaqueBytes = OpaqueBytes(ByteArray(1, { 1 })), - ownedBy: AbstractParty? = null, - issuedBy: PartyAndReference = DUMMY_OBLIGATION_ISSUER.ref(1)): Vault { - val myKey: PublicKey = ownedBy?.owningKey ?: services.myInfo.chooseIdentity().owningKey + fun fillWithSomeTestCommodity(amount: Amount, issuerServices: ServiceHub, issuedBy: PartyAndReference): Vault { + val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey val me = AnonymousParty(myKey) val commodity = CommodityContract() val issuance = TransactionBuilder(null as Party?) - commodity.generateIssue(issuance, Amount(amount.quantity, Issued(issuedBy.copy(reference = ref), amount.token)), me, outputNotary) + commodity.generateIssue(issuance, Amount(amount.quantity, Issued(issuedBy, amount.token)), me, altNotary) val transaction = issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) services.recordTransactions(transaction) return Vault(setOf(transaction.tx.outRef(0))) } - fun consume(states: List>, notary: Party) { + private fun consume(states: List>) { // Create a txn consuming different contract types states.forEach { - val builder = TransactionBuilder(notary = notary).apply { + val builder = TransactionBuilder(notary = altNotary).apply { addInputState(it) - addCommand(dummyCommand(notary.owningKey)) + addCommand(dummyCommand(altNotary.owningKey)) } - val consumedTx = services.signInitialTransaction(builder, notary.owningKey) + val consumedTx = services.signInitialTransaction(builder, altNotary.owningKey) services.recordTransactions(consumedTx) } } - private fun consumeAndProduce(stateAndRef: StateAndRef, notary: Party): StateAndRef { + private fun consumeAndProduce(stateAndRef: StateAndRef): StateAndRef { // Create a txn consuming different contract types - var builder = TransactionBuilder(notary = notary).apply { + var builder = TransactionBuilder(notary = altNotary).apply { addInputState(stateAndRef) - addCommand(dummyCommand(notary.owningKey)) + addCommand(dummyCommand(altNotary.owningKey)) } - val consumedTx = services.signInitialTransaction(builder, notary.owningKey) + val consumedTx = services.signInitialTransaction(builder, altNotary.owningKey) services.recordTransactions(consumedTx) // Create a txn consuming different contract types - builder = TransactionBuilder(notary = notary).apply { + builder = TransactionBuilder(notary = altNotary).apply { addOutputState(DummyLinearContract.State(linearId = stateAndRef.state.data.linearId, participants = stateAndRef.state.data.participants), DUMMY_LINEAR_CONTRACT_PROGRAM_ID) - addCommand(dummyCommand(notary.owningKey)) + addCommand(dummyCommand(altNotary.owningKey)) } - val producedTx = services.signInitialTransaction(builder, notary.owningKey) + val producedTx = services.signInitialTransaction(builder, altNotary.owningKey) services.recordTransactions(producedTx) return producedTx.tx.outRef(0) } - private fun consumeAndProduce(states: List>, notary: Party) { + private fun consumeAndProduce(states: List>) { states.forEach { - consumeAndProduce(it, notary) + consumeAndProduce(it) } } - fun consumeDeals(dealStates: List>, notary: Party) = consume(dealStates, notary) - fun consumeLinearStates(linearStates: List>, notary: Party) = consume(linearStates, notary) - fun evolveLinearStates(linearStates: List>, notary: Party) = consumeAndProduce(linearStates, notary) - fun evolveLinearState(linearState: StateAndRef, notary: Party): StateAndRef = consumeAndProduce(linearState, notary) - + fun consumeDeals(dealStates: List>) = consume(dealStates) + fun consumeLinearStates(linearStates: List>) = consume(linearStates) + fun evolveLinearStates(linearStates: List>) = consumeAndProduce(linearStates) + fun evolveLinearState(linearState: StateAndRef): StateAndRef = consumeAndProduce(linearState) /** * Consume cash, sending any change to the default identity for this node. Only suitable for use in test scenarios, * where nodes have a default identity. */ - @JvmOverloads - fun consumeCash(amount: Amount, to: Party = CHARLIE, notary: Party): Vault.Update { - return consumeCash(amount, services.myInfo.chooseIdentityAndCert(), to, notary) - } - - /** - * Consume cash, sending any change to the specified identity. - */ - private fun consumeCash(amount: Amount, ourIdentity: PartyAndCertificate, to: Party = CHARLIE, notary: Party): Vault.Update { + fun consumeCash(amount: Amount, to: AbstractParty): Vault.Update { + val ourIdentity = services.myInfo.chooseIdentityAndCert() val update = services.vaultService.rawUpdates.toFuture() // A tx that spends our money. - val builder = TransactionBuilder(notary).apply { + val builder = TransactionBuilder(altNotary).apply { Cash.generateSpend(services, this, amount, ourIdentity, to) } - val spendTx = services.signInitialTransaction(builder, notary.owningKey) + val spendTx = services.signInitialTransaction(builder, altNotary.owningKey) services.recordTransactions(spendTx) return update.getOrThrow(Duration.ofSeconds(3)) }