From dbe2dca7b92a8f6dc0e1da7dba3313d01eae4380 Mon Sep 17 00:00:00 2001 From: Andrzej Cichocki Date: Wed, 29 Nov 2017 09:49:34 +0000 Subject: [PATCH] CORDA-654 Make VaultFiller a class so I can change its hardcoded bits (#2141) --- .../finance/contracts/CommercialPaperTests.kt | 6 +- .../finance/contracts/asset/CashTests.kt | 13 +- .../services/vault/VaultQueryJavaTests.java | 74 +- .../node/messaging/TwoPartyTradeFlowTests.kt | 8 +- .../persistence/HibernateConfigurationTest.kt | 107 ++- .../services/vault/NodeVaultServiceTest.kt | 42 +- .../node/services/vault/VaultQueryTests.kt | 723 ++++++++---------- .../node/services/vault/VaultWithCashTest.kt | 18 +- .../corda/traderdemo/TraderDemoClientApi.kt | 2 +- .../corda/testing/contracts/VaultFiller.kt | 445 ++++++----- 10 files changed, 660 insertions(+), 778 deletions(-) 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 5f925966e0..b64b9ccc88 100644 --- a/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt +++ b/finance/src/test/kotlin/net/corda/finance/contracts/CommercialPaperTests.kt @@ -13,7 +13,7 @@ import net.corda.finance.DOLLARS import net.corda.finance.`issued by` import net.corda.finance.contracts.asset.* import net.corda.testing.* -import net.corda.testing.contracts.fillWithSomeTestCash +import net.corda.testing.contracts.VaultFiller import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServices import org.junit.Ignore @@ -240,7 +240,7 @@ class CommercialPaperTestsGeneric { aliceVaultService = aliceServices.vaultService databaseAlice.transaction { - alicesVault = aliceServices.fillWithSomeTestCash(9000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) + alicesVault = VaultFiller(aliceServices).fillWithSomeTestCash(9000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) aliceVaultService = aliceServices.vaultService } @@ -250,7 +250,7 @@ class CommercialPaperTestsGeneric { bigCorpVaultService = bigCorpServices.vaultService databaseBigCorp.transaction { - bigCorpVault = bigCorpServices.fillWithSomeTestCash(13000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) + bigCorpVault = VaultFiller(bigCorpServices).fillWithSomeTestCash(13000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = 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 db35907d50..86f15f5bfa 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 @@ -19,7 +19,7 @@ import net.corda.node.services.vault.NodeVaultService import net.corda.node.utilities.CordaPersistence import net.corda.testing.* import net.corda.testing.contracts.DummyState -import net.corda.testing.contracts.fillWithSomeTestCash +import net.corda.testing.contracts.VaultFiller import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServices import org.junit.After @@ -81,14 +81,15 @@ class CashTests { } // Create some cash. Any attempt to spend >$500 will require multiple issuers to be involved. - database.transaction { - ourServices.fillWithSomeTestCash(howMuch = 100.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + database.transaction { + val vaultFiller = VaultFiller(ourServices) + vaultFiller.fillWithSomeTestCash(howMuch = 100.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, owner = ourIdentity, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) - ourServices.fillWithSomeTestCash(howMuch = 400.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + vaultFiller.fillWithSomeTestCash(howMuch = 400.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, owner = ourIdentity, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) - ourServices.fillWithSomeTestCash(howMuch = 80.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + vaultFiller.fillWithSomeTestCash(howMuch = 80.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, owner = ourIdentity, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices) - ourServices.fillWithSomeTestCash(howMuch = 80.SWISS_FRANCS, atLeastThisManyStates = 1, atMostThisManyStates = 1, + vaultFiller.fillWithSomeTestCash(howMuch = 80.SWISS_FRANCS, atLeastThisManyStates = 1, atMostThisManyStates = 1, owner = ourIdentity, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices) } database.transaction { 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 93c4ae5da4..4ade7ae074 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 @@ -55,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class VaultQueryJavaTests { @Rule public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); - private MockServices services; + private VaultFiller vaultFiller; private MockServices issuerServices; private VaultService vaultService; private CordaPersistence database; @@ -73,7 +73,8 @@ public class VaultQueryJavaTests { cordappPackages); issuerServices = new MockServices(cordappPackages, getDUMMY_CASH_ISSUER_NAME(), getDUMMY_CASH_ISSUER_KEY(), getBOC_KEY()); database = databaseAndServices.getFirst(); - services = databaseAndServices.getSecond(); + MockServices services = databaseAndServices.getSecond(); + vaultFiller = new VaultFiller(services); vaultService = services.getVaultService(); } @@ -93,7 +94,7 @@ public class VaultQueryJavaTests { @Test public void unconsumedLinearStates() throws VaultQueryException { database.transaction(tx -> { - VaultFiller.fillWithSomeTestLinearStates(services, 3); + vaultFiller.fillWithSomeTestLinearStates(3); return tx; }); database.transaction(tx -> { @@ -111,8 +112,8 @@ public class VaultQueryJavaTests { public void unconsumedStatesForStateRefsSortedByTxnId() { Vault issuedStates = database.transaction(tx -> { - VaultFiller.fillWithSomeTestLinearStates(services, 8); - return VaultFiller.fillWithSomeTestLinearStates(services, 2); + vaultFiller.fillWithSomeTestLinearStates(8); + return vaultFiller.fillWithSomeTestLinearStates(2); }); database.transaction(tx -> { Stream stateRefsStream = StreamSupport.stream(issuedStates.getStates().spliterator(), false).map(StateAndRef::getRef); @@ -137,7 +138,7 @@ public class VaultQueryJavaTests { public void consumedCashStates() { Amount amount = new Amount<>(100, Currency.getInstance("USD")); database.transaction(tx -> { - VaultFiller.fillWithSomeTestCash(services, + vaultFiller.fillWithSomeTestCash( new Amount(100, Currency.getInstance("USD")), issuerServices, TestConstants.getDUMMY_NOTARY(), @@ -149,7 +150,7 @@ public class VaultQueryJavaTests { return tx; }); database.transaction(tx -> { - VaultFiller.consumeCash(services, amount, getDUMMY_NOTARY()); + vaultFiller.consumeCash(amount, getDUMMY_NOTARY()); return tx; }); database.transaction(tx -> { @@ -170,17 +171,16 @@ public class VaultQueryJavaTests { @SuppressWarnings("unchecked") Triple, UniqueIdentifier, Vault> ids = database.transaction((DatabaseTransaction tx) -> { - Vault states = VaultFiller.fillWithSomeTestLinearStates(services, 10, null); + Vault states = vaultFiller.fillWithSomeTestLinearStates(10, null); StateAndRef linearState = states.getStates().iterator().next(); UniqueIdentifier uid = linearState.component1().getData().getLinearId(); - - Vault dealStates = VaultFiller.fillWithSomeTestDeals(services, dealIds); + Vault dealStates = vaultFiller.fillWithSomeTestDeals(dealIds); return new Triple(linearState, uid, dealStates); }); database.transaction(tx -> { // consume states - VaultFiller.consumeDeals(services, (List>) ids.getThird().getStates(), getDUMMY_NOTARY()); - VaultFiller.consumeLinearStates(services, Collections.singletonList(ids.getFirst()), getDUMMY_NOTARY()); + vaultFiller.consumeDeals((List>) ids.getThird().getStates(), getDUMMY_NOTARY()); + vaultFiller.consumeLinearStates(Collections.singletonList(ids.getFirst()), getDUMMY_NOTARY()); return tx; }); database.transaction(tx -> { @@ -219,11 +219,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(services, pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars10, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars1, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); + 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()); return tx; }); database.transaction(tx -> { @@ -260,7 +259,7 @@ public class VaultQueryJavaTests { @Test public void trackCashStates() { database.transaction(tx -> { - VaultFiller.fillWithSomeTestCash(services, + vaultFiller.fillWithSomeTestCash( new Amount<>(100, Currency.getInstance("USD")), issuerServices, TestConstants.getDUMMY_NOTARY(), @@ -294,10 +293,9 @@ public class VaultQueryJavaTests { List dealIds = Arrays.asList("123", "456", "789"); UniqueIdentifier uid = database.transaction(tx -> { - Vault states = VaultFiller.fillWithSomeTestLinearStates(services, 10, null); + Vault states = vaultFiller.fillWithSomeTestLinearStates(10, null); UniqueIdentifier _uid = states.getStates().iterator().next().component1().getData().getLinearId(); - - VaultFiller.fillWithSomeTestDeals(services, dealIds); + vaultFiller.fillWithSomeTestDeals(dealIds); return _uid; }); database.transaction(tx -> { @@ -341,13 +339,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(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, 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(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()); return tx; }); database.transaction(tx -> { @@ -389,13 +385,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(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, 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(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()); return tx; }); database.transaction(tx -> { @@ -452,12 +446,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(services, dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); - VaultFiller.fillWithSomeTestCash(services, pounds300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); - VaultFiller.fillWithSomeTestCash(services, pounds400, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); - + 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()))); 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 5b17b6b368..16b2947647 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -38,7 +38,7 @@ import net.corda.node.services.persistence.DBTransactionStorage import net.corda.node.services.persistence.checkpoints import net.corda.node.utilities.CordaPersistence import net.corda.testing.* -import net.corda.testing.contracts.fillWithSomeTestCash +import net.corda.testing.contracts.VaultFiller import net.corda.testing.node.* import org.assertj.core.api.Assertions.assertThat import org.junit.After @@ -106,7 +106,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { bobNode.internals.disableDBCloseOnStop() bobNode.database.transaction { - bobNode.services.fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, + VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, issuedBy = cashIssuer) } @@ -156,7 +156,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { bobNode.internals.disableDBCloseOnStop() val cashStates = bobNode.database.transaction { - bobNode.services.fillWithSomeTestCash(2000.DOLLARS, bankNode.services, notary, 3, 3, + VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, notary, 3, 3, issuedBy = issuer) } @@ -216,7 +216,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { val issuer = bank.ref(1, 2, 3) bobNode.database.transaction { - bobNode.services.fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, + VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, issuedBy = issuer) } val alicesFakePaper = aliceNode.database.transaction { 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 24d872b0f2..8a399b394b 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 @@ -33,10 +33,7 @@ import net.corda.node.services.vault.VaultSchemaV1 import net.corda.node.utilities.CordaPersistence import net.corda.node.utilities.configureDatabase import net.corda.testing.* -import net.corda.testing.contracts.consumeCash -import net.corda.testing.contracts.fillWithSomeTestCash -import net.corda.testing.contracts.fillWithSomeTestDeals -import net.corda.testing.contracts.fillWithSomeTestLinearStates +import net.corda.testing.contracts.* import net.corda.testing.node.MockServices import net.corda.testing.node.MockServices.Companion.makeTestDataSourceProperties import net.corda.testing.schemas.DummyLinearStateSchemaV1 @@ -57,6 +54,7 @@ class HibernateConfigurationTest { @JvmField val testSerialization = SerializationEnvironmentRule() lateinit var services: MockServices + private lateinit var vaultFiller: VaultFiller lateinit var bankServices: MockServices lateinit var issuerServices: MockServices lateinit var notaryServices: MockServices @@ -108,6 +106,7 @@ class HibernateConfigurationTest { override fun jdbcSession() = database.createSession() } + vaultFiller = VaultFiller(services) hibernatePersister = services.hibernatePersister } @@ -117,7 +116,7 @@ class HibernateConfigurationTest { database.transaction { val numStates = 10 - cashStates = services.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, numStates, numStates, Random(0L), issuedBy = issuer.ref(1)) + cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, numStates, numStates, Random(0L), issuedBy = issuer.ref(1)) .states.toList() } @@ -148,7 +147,7 @@ class HibernateConfigurationTest { @Test fun `consumed states`() { database.transaction { - services.consumeCash(50.DOLLARS, notary = notary) + vaultFiller.consumeCash(50.DOLLARS, notary = notary) } // structure query @@ -160,7 +159,7 @@ class HibernateConfigurationTest { // execute query val queryResults = entityManager.createQuery(criteriaQuery).resultList val coins = queryResults.map { - (services.loadState(toStateRef(it.stateRef!!)) as TransactionState).data + services.loadState(toStateRef(it.stateRef!!)).data }.sumCash() assertThat(coins.toDecimal() >= BigDecimal("50.00")) } @@ -169,8 +168,8 @@ class HibernateConfigurationTest { fun `select by composite primary key`() { val issuedStates = database.transaction { - services.fillWithSomeTestLinearStates(8) - services.fillWithSomeTestLinearStates(2) + vaultFiller.fillWithSomeTestLinearStates(8) + vaultFiller.fillWithSomeTestLinearStates(2) } val persistentStateRefs = issuedStates.states.map { PersistentStateRef(it.ref) }.toList() @@ -194,8 +193,8 @@ class HibernateConfigurationTest { fun `distinct contract types`() { database.transaction { // add 2 more contract types - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) } // structure query @@ -229,11 +228,11 @@ class HibernateConfigurationTest { fun `with sorting by state ref desc and asc`() { // generate additional state ref indexes database.transaction { - services.consumeCash(1.DOLLARS, notary = notary) - services.consumeCash(2.DOLLARS, notary = notary) - services.consumeCash(3.DOLLARS, notary = notary) - services.consumeCash(4.DOLLARS, notary = notary) - services.consumeCash(5.DOLLARS, notary = notary) + 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) } // structure query @@ -259,11 +258,11 @@ class HibernateConfigurationTest { fun `with sorting by state ref index and txId desc and asc`() { // generate additional state ref indexes database.transaction { - services.consumeCash(1.DOLLARS, notary = notary) - services.consumeCash(2.DOLLARS, notary = notary) - services.consumeCash(3.DOLLARS, notary = notary) - services.consumeCash(4.DOLLARS, notary = notary) - services.consumeCash(5.DOLLARS, notary = notary) + 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) } // structure query @@ -290,7 +289,7 @@ class HibernateConfigurationTest { fun `with pagination`() { // add 100 additional cash entries database.transaction { - services.fillWithSomeTestCash(1000.POUNDS, issuerServices, notary, 100, 100, Random(0L), issuedBy = issuer.ref(1)) + vaultFiller.fillWithSomeTestCash(1000.POUNDS, issuerServices, notary, 100, 100, Random(0L), issuedBy = issuer.ref(1)) } // structure query @@ -321,7 +320,7 @@ class HibernateConfigurationTest { @Test fun `select by composite primary key on LinearStates`() { database.transaction { - services.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestLinearStates(10) } // structure query @@ -372,8 +371,7 @@ class HibernateConfigurationTest { @Test fun `select and join by composite primary key on CashStates`() { database.transaction { - services.fillWithSomeTestLinearStates(5) - + vaultFiller.fillWithSomeTestLinearStates(5) // structure query val criteriaQuery = criteriaBuilder.createQuery(VaultSchemaV1.VaultStates::class.java) val vaultStates = criteriaQuery.from(VaultSchemaV1.VaultStates::class.java) @@ -391,12 +389,11 @@ class HibernateConfigurationTest { @Test fun `calculate cash balances`() { database.transaction { - - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 10, issuer.ref(1)) // +$100 = $200 - services.fillWithSomeTestCash(50.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // £50 = £50 - services.fillWithSomeTestCash(25.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // +£25 = £175 - services.fillWithSomeTestCash(500.SWISS_FRANCS, issuerServices, notary, 10, issuer.ref(1)) // CHF500 = CHF500 - services.fillWithSomeTestCash(250.SWISS_FRANCS, issuerServices, notary, 5, issuer.ref(1)) // +CHF250 = CHF750 + 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 } // structure query @@ -425,8 +422,8 @@ class HibernateConfigurationTest { @Test fun `calculate cash balance for single currency`() { database.transaction { - services.fillWithSomeTestCash(50.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // £50 = £50 - services.fillWithSomeTestCash(25.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // +£25 = £175 + vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // £50 = £50 + vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // +£25 = £175 } // structure query @@ -456,9 +453,9 @@ class HibernateConfigurationTest { fun `calculate and order by cash balance for owner and currency`() { database.transaction { val bank = bankServices.myInfo.legalIdentities.single() - services.fillWithSomeTestCash(200.DOLLARS, bankServices, notary, 2, bank.ref(1)) - services.fillWithSomeTestCash(300.POUNDS, issuerServices, notary, 3, issuer.ref(1)) - services.fillWithSomeTestCash(400.POUNDS, bankServices, notary, 4, bank.ref(2)) + 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)) } // structure query @@ -518,8 +515,7 @@ class HibernateConfigurationTest { @Test fun `select by composite primary key on CashStates in V2`() { database.transaction { - services.fillWithSomeTestLinearStates(5) - + vaultFiller.fillWithSomeTestLinearStates(5) // persist cash states explicitly with V2 schema cashStates.forEach { val cashState = it.state.data @@ -554,9 +550,9 @@ class HibernateConfigurationTest { @Test fun `select by composite primary between VaultStates, VaultLinearStates and DummyLinearStates`() { database.transaction { - services.fillWithSomeTestLinearStates(8) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - services.fillWithSomeTestLinearStates(2) + vaultFiller.fillWithSomeTestLinearStates(8) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) + vaultFiller.fillWithSomeTestLinearStates(2) } val sessionFactory = sessionFactoryForSchemas(VaultSchemaV1, DummyLinearStateSchemaV1) val criteriaBuilder = sessionFactory.criteriaBuilder @@ -585,9 +581,9 @@ class HibernateConfigurationTest { @Test fun `three way join by composite primary between VaultStates, VaultLinearStates and DummyLinearStates`() { database.transaction { - services.fillWithSomeTestLinearStates(8) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - services.fillWithSomeTestLinearStates(2) + vaultFiller.fillWithSomeTestLinearStates(8) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) + vaultFiller.fillWithSomeTestLinearStates(2) } val sessionFactory = sessionFactoryForSchemas(VaultSchemaV1, DummyLinearStateSchemaV2) val criteriaBuilder = sessionFactory.criteriaBuilder @@ -644,10 +640,9 @@ class HibernateConfigurationTest { val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), issuedBy = issuer.ref(1), owner = ALICE) - val cashStates = services.fillWithSomeTestCash(100.DOLLARS, services, notary, 2, identity.ref(0)).states + val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, notary, 2, identity.ref(0)).states // persist additional cash states explicitly with V3 schema cashStates.forEach { val cashState = it.state.data @@ -723,8 +718,7 @@ class HibernateConfigurationTest { val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - - val moreCash = services.fillWithSomeTestCash(100.DOLLARS, services, notary, 2, 2, Random(0L), + val moreCash = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, notary, 2, 2, Random(0L), issuedBy = identity.ref(0), owner = identity).states // persist additional cash states explicitly with V3 schema moreCash.forEach { @@ -732,8 +726,7 @@ class HibernateConfigurationTest { val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) } - - val cashStates = services.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), owner = ALICE, issuedBy = issuer.ref(1)).states + val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), owner = ALICE, issuedBy = issuer.ref(1)).states // persist additional cash states explicitly with V3 schema cashStates.forEach { val cashState = it.state.data @@ -777,9 +770,9 @@ class HibernateConfigurationTest { fun `with sorting on attribute from common table`() { database.transaction { - services.fillWithSomeTestLinearStates(1, externalId = "111") - services.fillWithSomeTestLinearStates(2, externalId = "222") - services.fillWithSomeTestLinearStates(3, externalId = "333") + vaultFiller.fillWithSomeTestLinearStates(1, externalId = "111") + vaultFiller.fillWithSomeTestLinearStates(2, externalId = "222") + vaultFiller.fillWithSomeTestLinearStates(3, externalId = "333") } val sessionFactory = sessionFactoryForSchemas(VaultSchemaV1, DummyLinearStateSchemaV2) val criteriaBuilder = sessionFactory.criteriaBuilder @@ -829,9 +822,9 @@ class HibernateConfigurationTest { fun `with sorting on attribute from custom table`() { database.transaction { - services.fillWithSomeTestLinearStates(1, externalId = "111") - services.fillWithSomeTestLinearStates(2, externalId = "222") - services.fillWithSomeTestLinearStates(3, externalId = "333") + vaultFiller.fillWithSomeTestLinearStates(1, externalId = "111") + vaultFiller.fillWithSomeTestLinearStates(2, externalId = "222") + vaultFiller.fillWithSomeTestLinearStates(3, externalId = "333") } val sessionFactory = sessionFactoryForSchemas(VaultSchemaV1, DummyLinearStateSchemaV1) val criteriaBuilder = sessionFactory.criteriaBuilder 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 123335a1de..c24f563b85 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 @@ -36,7 +36,7 @@ import net.corda.finance.schemas.CashSchemaV1 import net.corda.finance.utils.sumCash import net.corda.node.utilities.CordaPersistence import net.corda.testing.* -import net.corda.testing.contracts.fillWithSomeTestCash +import net.corda.testing.contracts.VaultFiller import net.corda.testing.node.MockServices import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatExceptionOfType @@ -62,6 +62,7 @@ class NodeVaultServiceTest { @JvmField val testSerialization = SerializationEnvironmentRule() private lateinit var services: MockServices + private lateinit var vaultFiller: VaultFiller private lateinit var identity: PartyAndCertificate private lateinit var issuerServices: MockServices private lateinit var bocServices: MockServices @@ -74,6 +75,7 @@ class NodeVaultServiceTest { val databaseAndServices = MockServices.makeTestDatabaseAndMockServices(cordappPackages = cordappPackages) database = databaseAndServices.first services = databaseAndServices.second + vaultFiller = VaultFiller(services) // 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) @@ -111,7 +113,7 @@ class NodeVaultServiceTest { @Test fun `states not local to instance`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } database.transaction { val w1 = vaultService.queryBy().states @@ -136,7 +138,7 @@ class NodeVaultServiceTest { @Test fun `states for refs`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } database.transaction { val w1 = vaultService.queryBy().states @@ -150,7 +152,7 @@ class NodeVaultServiceTest { @Test fun `states soft locking reserve and release`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } database.transaction { @@ -203,7 +205,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() println("State Refs:: $stateRefsToSoftLock") @@ -258,7 +260,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = vaultStates.states.map { it.ref } println("State Refs:: $stateRefsToSoftLock") @@ -286,7 +288,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() println("State Refs:: $stateRefsToSoftLock") @@ -313,7 +315,7 @@ class NodeVaultServiceTest { val vaultStates = database.transaction { assertEquals(0.DOLLARS, services.getCashBalance(USD)) - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) } val stateRefsToSoftLock = vaultStates.states.map { it.ref } println("State Refs:: $stateRefsToSoftLock") @@ -334,7 +336,7 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending exact amount`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) } database.transaction { @@ -353,8 +355,8 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending from two issuer parties`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) + 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)) } database.transaction { val spendableStatesUSD = vaultService.unconsumedCashStatesForSpending(200.DOLLARS, @@ -370,10 +372,10 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending from specific issuer party and refs`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) - services.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(2)) - services.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(3)) + 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)) } database.transaction { val unconsumedStates = vaultService.queryBy().states @@ -392,7 +394,7 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending insufficient amount`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) } database.transaction { val unconsumedStates = vaultService.queryBy().states @@ -409,7 +411,7 @@ class NodeVaultServiceTest { @Test fun `unconsumedStatesForSpending small amount`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) } database.transaction { val unconsumedStates = vaultService.queryBy().states @@ -427,9 +429,9 @@ class NodeVaultServiceTest { @Test fun `states soft locking query granularity`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) + 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)) } 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 70629c705c..20ea02690f 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 @@ -63,6 +63,7 @@ class VaultQueryTests { CashSchemaV1::class.packageName, DummyLinearStateSchemaV1::class.packageName) private lateinit var services: MockServices + private lateinit var vaultFiller: VaultFiller private lateinit var notaryServices: MockServices private val vaultService: VaultService get() = services.vaultService private lateinit var identitySvc: IdentityService @@ -80,6 +81,7 @@ class VaultQueryTests { cordappPackages = cordappPackages) database = databaseAndServices.first services = databaseAndServices.second + vaultFiller = VaultFiller(services) 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 @@ -108,19 +110,19 @@ class VaultQueryTests { private fun setUpDb(_database: CordaPersistence, delay: Long = 0) { _database.transaction { // create new states - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) - val linearStatesXYZ = services.fillWithSomeTestLinearStates(1, "XYZ") - val linearStatesJKL = services.fillWithSomeTestLinearStates(2, "JKL") - services.fillWithSomeTestLinearStates(3, "ABC") - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") + val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL") + vaultFiller.fillWithSomeTestLinearStates(3, "ABC") + val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // Total unconsumed states = 10 + 1 + 2 + 3 + 3 = 19 sleep(delay) // consume some states - services.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) - services.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + 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) // Total unconsumed states = 4 + 3 + 2 + 1 (new cash change) = 10 // Total consumed states = 6 + 1 + 2 + 1 = 10 } @@ -145,10 +147,9 @@ class VaultQueryTests { @Test fun `unconsumed states simple`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // DOCSTART VaultQueryExample1 val result = vaultService.queryBy() @@ -171,10 +172,9 @@ class VaultQueryTests { @Test fun `unconsumed states verbose`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val criteria = VaultQueryCriteria() // default is UNCONSUMED val result = vaultService.queryBy(criteria) @@ -186,19 +186,16 @@ class VaultQueryTests { @Test fun `unconsumed states with count`() { database.transaction { - services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.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)) + vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) 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) - - services.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) - + vaultFiller.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.UNCONSUMED) val resultsAfterConsume = vaultService.queryBy(consumedCriteria, paging) assertThat(resultsAfterConsume.states).hasSize(1) @@ -209,10 +206,9 @@ class VaultQueryTests { @Test fun `unconsumed cash states simple`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val result = vaultService.queryBy() assertThat(result.states).hasSize(3) @@ -223,10 +219,9 @@ class VaultQueryTests { @Test fun `unconsumed cash states verbose`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val criteria = VaultQueryCriteria() // default is UNCONSUMED val result = vaultService.queryBy(criteria) @@ -239,12 +234,12 @@ class VaultQueryTests { fun `unconsumed cash states sorted by state ref`() { val stateRefs: MutableList = mutableListOf() database.transaction { - val issuedStates = services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) val issuedStateRefs = issuedStates.states.map { it.ref }.toList() stateRefs.addAll(issuedStateRefs) } database.transaction { - val spentStates = services.consumeCash(25.DOLLARS, notary = DUMMY_NOTARY) + val spentStates = vaultFiller.consumeCash(25.DOLLARS, notary = DUMMY_NOTARY) val consumedStateRefs = spentStates.consumed.map { it.ref }.toList() val producedStateRefs = spentStates.produced.map { it.ref }.toList() stateRefs.addAll(consumedStateRefs.plus(producedStateRefs)) @@ -270,12 +265,11 @@ class VaultQueryTests { fun `unconsumed cash states sorted by state ref txnId and index`() { val consumed = mutableSetOf() database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) } database.transaction { - services.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).consumed.forEach { consumed += it.ref.txhash } - services.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 } + vaultFiller.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).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), @@ -296,8 +290,8 @@ class VaultQueryTests { @Test fun `unconsumed states for state refs`() { database.transaction { - services.fillWithSomeTestLinearStates(8) - val issuedStates = services.fillWithSomeTestLinearStates(2) + vaultFiller.fillWithSomeTestLinearStates(8) + val issuedStates = vaultFiller.fillWithSomeTestLinearStates(2) val stateRefs = issuedStates.states.map { it.ref }.toList() // DOCSTART VaultQueryExample2 @@ -317,10 +311,9 @@ class VaultQueryTests { @Test fun `unconsumed states for contract state types`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // default State.Status is UNCONSUMED // DOCSTART VaultQueryExample3 val criteria = VaultQueryCriteria(contractStateTypes = setOf(Cash.State::class.java, DealState::class.java)) @@ -333,15 +326,13 @@ class VaultQueryTests { @Test fun `consumed states`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId - services.fillWithSomeTestLinearStates(8) - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) - - services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + 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) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(5) @@ -351,19 +342,16 @@ class VaultQueryTests { @Test fun `consumed states with count`() { database.transaction { - services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.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)) + vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) 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) - - services.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) - + vaultFiller.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val resultsAfterConsume = vaultService.queryBy(consumedCriteria, paging) assertThat(resultsAfterConsume.states).hasSize(3) @@ -374,15 +362,13 @@ class VaultQueryTests { @Test fun `all states`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(2, "TEST") // create 2 results with same UID - services.fillWithSomeTestLinearStates(8) - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) - - services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // generates a new change state! - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + 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! val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(17) @@ -392,17 +378,14 @@ class VaultQueryTests { @Test fun `all states with count`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) 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) - - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // consumed 100 (spent), produced 50 (change) - + vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // consumed 100 (spent), produced 50 (change) val resultsAfterConsume = vaultService.queryBy(criteria, paging) assertThat(resultsAfterConsume.states).hasSize(2) assertThat(resultsAfterConsume.totalStatesAvailable).isEqualTo(2) @@ -412,10 +395,9 @@ class VaultQueryTests { @Test fun `unconsumed states by notary`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // DOCSTART VaultQueryExample4 val criteria = VaultQueryCriteria(notary = listOf(CASH_NOTARY)) val results = vaultService.queryBy(criteria) @@ -428,11 +410,9 @@ class VaultQueryTests { fun `unconsumed linear states for single participant`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BIG_CORP_IDENTITY) - - services.fillWithSomeTestLinearStates(2, "TEST", participants = listOf(MEGA_CORP, MINI_CORP)) - services.fillWithSomeTestDeals(listOf("456"), participants = listOf(MEGA_CORP, BIG_CORP)) - services.fillWithSomeTestDeals(listOf("123", "789"), participants = listOf(BIG_CORP)) - + vaultFiller.fillWithSomeTestLinearStates(2, "TEST", participants = listOf(MEGA_CORP, MINI_CORP)) + vaultFiller.fillWithSomeTestDeals(listOf("456"), participants = listOf(MEGA_CORP, BIG_CORP)) + vaultFiller.fillWithSomeTestDeals(listOf("123", "789"), participants = listOf(BIG_CORP)) val criteria = LinearStateQueryCriteria(participants = listOf(BIG_CORP)) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(3) @@ -443,11 +423,9 @@ class VaultQueryTests { fun `unconsumed linear states for two participants`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BIG_CORP_IDENTITY) - - services.fillWithSomeTestLinearStates(2, "TEST", participants = listOf(MEGA_CORP, MINI_CORP)) - services.fillWithSomeTestDeals(listOf("456"), participants = listOf(MEGA_CORP, BIG_CORP)) - services.fillWithSomeTestDeals(listOf("123", "789"), participants = listOf(MEGA_CORP)) - + vaultFiller.fillWithSomeTestLinearStates(2, "TEST", participants = listOf(MEGA_CORP, MINI_CORP)) + vaultFiller.fillWithSomeTestDeals(listOf("456"), participants = listOf(MEGA_CORP, BIG_CORP)) + vaultFiller.fillWithSomeTestDeals(listOf("123", "789"), participants = listOf(MEGA_CORP)) // DOCSTART VaultQueryExample5 val criteria = LinearStateQueryCriteria(participants = listOf(BIG_CORP, MINI_CORP)) val results = vaultService.queryBy(criteria) @@ -460,7 +438,7 @@ class VaultQueryTests { @Test fun `unconsumed states with soft locking`() { database.transaction { - val issuedStates = services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)).states.toList() + val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)).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)) @@ -503,10 +481,9 @@ class VaultQueryTests { @Test fun `logical operator EQUAL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -517,10 +494,9 @@ class VaultQueryTests { @Test fun `logical operator NOT EQUAL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notEqual(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -531,10 +507,9 @@ class VaultQueryTests { @Test fun `logical operator GREATER_THAN`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThan(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -545,10 +520,9 @@ class VaultQueryTests { @Test fun `logical operator GREATER_THAN_OR_EQUAL`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThanOrEqual(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -559,10 +533,9 @@ class VaultQueryTests { @Test fun `logical operator LESS_THAN`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThan(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -573,10 +546,9 @@ class VaultQueryTests { @Test fun `logical operator LESS_THAN_OR_EQUAL`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThanOrEqual(1000L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -587,10 +559,9 @@ class VaultQueryTests { @Test fun `logical operator BETWEEN`() { database.transaction { - services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.between(500L, 1500L) } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -601,10 +572,9 @@ class VaultQueryTests { @Test fun `logical operator IN`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.`in`(currencies) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -616,10 +586,9 @@ class VaultQueryTests { @Test fun `logical operator NOT IN`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notIn(currencies) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -631,10 +600,9 @@ class VaultQueryTests { @Test fun `logical operator LIKE`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.like("%BP") } // GPB val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -645,10 +613,9 @@ class VaultQueryTests { @Test fun `logical operator NOT LIKE`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notLike("%BP") } // GPB val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -659,10 +626,9 @@ class VaultQueryTests { @Test fun `logical operator IS_NULL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.isNull() } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -673,10 +639,9 @@ class VaultQueryTests { @Test fun `logical operator NOT_NULL`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.notNull() } val criteria = VaultCustomQueryCriteria(logicalExpression) val results = vaultService.queryBy(criteria) @@ -687,12 +652,11 @@ class VaultQueryTests { @Test fun `aggregate functions without group clause`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(300.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) - services.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) - + 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)) // DOCSTART VaultQueryExample21 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum() } val sumCriteria = VaultCustomQueryCriteria(sum) @@ -728,12 +692,11 @@ class VaultQueryTests { @Test fun `aggregate functions with single group clause`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(300.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) - services.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) - + 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)) // DOCSTART VaultQueryExample22 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val sumCriteria = VaultCustomQueryCriteria(sum) @@ -779,12 +742,10 @@ class VaultQueryTests { fun `aggregate functions sum by issuer and currency and sort by aggregate sum`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) - - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1)) - services.fillWithSomeTestCash(300.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L), issuedBy = BOC.ref(2)) - + 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)) // DOCSTART VaultQueryExample23 val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::issuerPartyHash, @@ -816,12 +777,11 @@ class VaultQueryTests { fun `aggregate functions count by contract type`() { database.transaction { // create new states - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)) - services.fillWithSomeTestLinearStates(1, "XYZ") - services.fillWithSomeTestLinearStates(2, "JKL") - services.fillWithSomeTestLinearStates(3, "ABC") - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") + vaultFiller.fillWithSomeTestLinearStates(2, "JKL") + vaultFiller.fillWithSomeTestLinearStates(3, "ABC") + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // count fungible assets val count = builder { VaultSchemaV1.VaultStates::recordedTime.count() } val countCriteria = QueryCriteria.VaultCustomQueryCriteria(count) @@ -842,12 +802,11 @@ class VaultQueryTests { fun `aggregate functions count by contract type and state status`() { database.transaction { // create new states - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) - val linearStatesXYZ = services.fillWithSomeTestLinearStates(1, "XYZ") - val linearStatesJKL = services.fillWithSomeTestLinearStates(2, "JKL") - services.fillWithSomeTestLinearStates(3, "ABC") - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) + val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") + val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL") + vaultFiller.fillWithSomeTestLinearStates(3, "ABC") + val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val count = builder { VaultSchemaV1.VaultStates::recordedTime.count() } // count fungible assets @@ -864,11 +823,10 @@ class VaultQueryTests { assertThat(dealStateCount).isEqualTo(3L) // consume some states - services.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) - services.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - val cashUpdates = services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) - + 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) // UNCONSUMED states (default) // count fungible assets @@ -906,8 +864,7 @@ class VaultQueryTests { @Test fun `unconsumed states recorded between two time intervals`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) // DOCSTART VaultQueryExample6 val start = TODAY val end = TODAY.plus(30, ChronoUnit.DAYS) @@ -931,13 +888,12 @@ class VaultQueryTests { @Test fun `states consumed after time`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) } database.transaction { - services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - + vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) val asOfDateTime = TODAY val consumedAfterExpression = TimeCondition( QueryCriteria.TimeInstantType.CONSUMED, ColumnPredicate.BinaryComparison(BinaryComparisonOperator.GREATER_THAN_OR_EQUAL, asOfDateTime)) @@ -953,8 +909,7 @@ class VaultQueryTests { @Test fun `all states with paging specification - first page`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) // DOCSTART VaultQueryExample7 val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, 10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -969,8 +924,7 @@ class VaultQueryTests { @Test fun `all states with paging specification - last`() { database.transaction { - services.fillWithSomeTestCash(95.DOLLARS, notaryServices, DUMMY_NOTARY, 95, 95, Random(0L)) - + vaultFiller.fillWithSomeTestCash(95.DOLLARS, notaryServices, DUMMY_NOTARY, 95, 95, Random(0L)) // 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) @@ -989,8 +943,7 @@ class VaultQueryTests { expectedEx.expectMessage("Page specification: invalid page number") database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) val pagingSpec = PageSpecification(0, 10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) @@ -1005,8 +958,7 @@ class VaultQueryTests { expectedEx.expectMessage("Page specification: invalid page size") database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) @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) @@ -1021,8 +973,7 @@ class VaultQueryTests { expectedEx.expectMessage("Please specify a `PageSpecification`") database.transaction { - services.fillWithSomeTestCash(201.DOLLARS, notaryServices, DUMMY_NOTARY, 201, 201, Random(0L)) - + vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, DUMMY_NOTARY, 201, 201, Random(0L)) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) vaultService.queryBy(criteria) } @@ -1060,10 +1011,9 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) - services.fillWithSomeTestLinearStates(10) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) + vaultFiller.fillWithSomeTestLinearStates(10) val results = vaultService.queryBy>() assertThat(results.states).hasSize(4) } @@ -1072,14 +1022,12 @@ class VaultQueryTests { @Test fun `consumed fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) } database.transaction { - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) - - services.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) - services.fillWithSomeTestLinearStates(10) - + vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) + vaultFiller.fillWithSomeTestLinearStates(10) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy>(criteria) assertThat(results.states).hasSize(2) @@ -1089,9 +1037,8 @@ class VaultQueryTests { @Test fun `unconsumed cash fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) val results = vaultService.queryBy() assertThat(results.states).hasSize(3) } @@ -1100,10 +1047,10 @@ class VaultQueryTests { @Test fun `unconsumed cash fungible assets after spending`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) } database.transaction { - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // should now have x2 CONSUMED + x2 UNCONSUMED (one spent + one change) val results = vaultService.queryBy(FungibleAssetQueryCriteria()) assertThat(results.statesMetadata).hasSize(2) @@ -1114,13 +1061,12 @@ class VaultQueryTests { @Test fun `consumed cash fungible assets`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) } database.transaction { - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) - - val linearStates = services.fillWithSomeTestLinearStates(10) - services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) + vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) + val linearStates = vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(2) @@ -1130,10 +1076,9 @@ class VaultQueryTests { @Test fun `unconsumed linear heads`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val results = vaultService.queryBy() assertThat(results.states).hasSize(13) } @@ -1142,15 +1087,13 @@ class VaultQueryTests { @Test fun `consumed linear heads`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId - services.fillWithSomeTestLinearStates(8) - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")) - - services.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) - services.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) - services.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + 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) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val results = vaultService.queryBy(criteria) assertThat(results.states).hasSize(3) @@ -1162,8 +1105,7 @@ class VaultQueryTests { @Test fun `unconsumed linear heads for linearId without external Id`() { database.transaction { - val issuedStates = services.fillWithSomeTestLinearStates(10) - + val issuedStates = vaultFiller.fillWithSomeTestLinearStates(10) // DOCSTART VaultQueryExample8 val linearIds = issuedStates.states.map { it.state.data.linearId }.toList() val criteria = LinearStateQueryCriteria(linearId = listOf(linearIds.first(), linearIds.last())) @@ -1176,10 +1118,9 @@ class VaultQueryTests { @Test fun `unconsumed linear heads by linearId`() { database.transaction { - val linearState1 = services.fillWithSomeTestLinearStates(1, "ID1") - services.fillWithSomeTestLinearStates(1, "ID2") - val linearState3 = services.fillWithSomeTestLinearStates(1, "ID3") - + val linearState1 = vaultFiller.fillWithSomeTestLinearStates(1, "ID1") + vaultFiller.fillWithSomeTestLinearStates(1, "ID2") + val linearState3 = vaultFiller.fillWithSomeTestLinearStates(1, "ID3") val linearIds = listOf(linearState1.states.first().state.data.linearId, linearState3.states.first().state.data.linearId) val criteria = LinearStateQueryCriteria(linearId = linearIds) val results = vaultService.queryBy(criteria) @@ -1190,10 +1131,9 @@ class VaultQueryTests { @Test fun `unconsumed linear heads for linearId by external Id`() { database.transaction { - val linearState1 = services.fillWithSomeTestLinearStates(1, "ID1") - services.fillWithSomeTestLinearStates(1, "ID2") - val linearState3 = services.fillWithSomeTestLinearStates(1, "ID3") - + val linearState1 = vaultFiller.fillWithSomeTestLinearStates(1, "ID1") + vaultFiller.fillWithSomeTestLinearStates(1, "ID2") + val linearState3 = vaultFiller.fillWithSomeTestLinearStates(1, "ID3") val externalIds = listOf(linearState1.states.first().state.data.linearId.externalId!!, linearState3.states.first().state.data.linearId.externalId!!) val criteria = LinearStateQueryCriteria(externalId = externalIds) val results = vaultService.queryBy(criteria) @@ -1204,11 +1144,11 @@ class VaultQueryTests { @Test fun `all linear states for a given linear id`() { database.transaction { - val txns = services.fillWithSomeTestLinearStates(1, "TEST") + val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST") val linearState = txns.states.first() - services.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference - services.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference - services.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 + vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // 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" @@ -1224,12 +1164,11 @@ class VaultQueryTests { @Test fun `all linear states for a given id sorted by uuid`() { database.transaction { - val txns = services.fillWithSomeTestLinearStates(2, "TEST") + val txns = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") val linearStates = txns.states.toList() - services.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference - services.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference - services.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 + vaultFiller.evolveLinearStates(linearStates, DUMMY_NOTARY) // 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) @@ -1244,10 +1183,9 @@ class VaultQueryTests { @Test fun `unconsumed linear states sorted by external id`() { database.transaction { - services.fillWithSomeTestLinearStates(1, externalId = "111") - services.fillWithSomeTestLinearStates(2, externalId = "222") - services.fillWithSomeTestLinearStates(3, externalId = "333") - + vaultFiller.fillWithSomeTestLinearStates(1, externalId = "111") + vaultFiller.fillWithSomeTestLinearStates(2, externalId = "222") + vaultFiller.fillWithSomeTestLinearStates(3, externalId = "333") val vaultCriteria = VaultQueryCriteria() val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Standard(Sort.LinearStateAttribute.EXTERNAL_ID), Sort.Direction.DESC))) @@ -1260,8 +1198,8 @@ class VaultQueryTests { @Test fun `unconsumed deal states sorted`() { database.transaction { - val linearStates = services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestDeals(listOf("123", "456", "789")) + val linearStates = vaultFiller.fillWithSomeTestLinearStates(10) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val uid = linearStates.states.first().state.data.linearId.id val linearStateCriteria = LinearStateQueryCriteria(uuid = listOf(uid)) @@ -1279,10 +1217,9 @@ class VaultQueryTests { @Test fun `unconsumed linear states sorted by custom attribute`() { database.transaction { - services.fillWithSomeTestLinearStates(1, linearString = "111") - services.fillWithSomeTestLinearStates(2, linearString = "222") - services.fillWithSomeTestLinearStates(3, linearString = "333") - + vaultFiller.fillWithSomeTestLinearStates(1, linearString = "111") + vaultFiller.fillWithSomeTestLinearStates(2, linearString = "222") + vaultFiller.fillWithSomeTestLinearStates(3, linearString = "333") val vaultCriteria = VaultQueryCriteria() val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Custom(DummyLinearStateSchemaV1.PersistentDummyLinearState::class.java, "linearString"), Sort.Direction.DESC))) @@ -1295,14 +1232,11 @@ class VaultQueryTests { @Test fun `return consumed linear states for a given linear id`() { database.transaction { - val txns = services.fillWithSomeTestLinearStates(1, "TEST") + val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST") val linearState = txns.states.first() - - val linearState2 =services.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference - val linearState3 = services.evolveLinearState(linearState2, DUMMY_NOTARY) // consume current and produce new state reference - - services.evolveLinearState(linearState3, DUMMY_NOTARY) // consume current and produce new state reference - + 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 // 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) @@ -1318,8 +1252,7 @@ class VaultQueryTests { @Test fun `unconsumed deals`() { database.transaction { - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val results = vaultService.queryBy() assertThat(results.states).hasSize(3) } @@ -1328,8 +1261,7 @@ class VaultQueryTests { @Test fun `unconsumed deals for ref`() { database.transaction { - services.fillWithSomeTestDeals(listOf("123", "456", "789")) - + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) // DOCSTART VaultQueryExample10 val criteria = LinearStateQueryCriteria(externalId = listOf("456", "789")) val results = vaultService.queryBy(criteria) @@ -1342,10 +1274,9 @@ class VaultQueryTests { @Test fun `latest unconsumed deals for ref`() { database.transaction { - services.fillWithSomeTestLinearStates(2, "TEST") - services.fillWithSomeTestDeals(listOf("456")) - services.fillWithSomeTestDeals(listOf("123", "789")) - + vaultFiller.fillWithSomeTestLinearStates(2, "TEST") + vaultFiller.fillWithSomeTestDeals(listOf("456")) + vaultFiller.fillWithSomeTestDeals(listOf("123", "789")) val all = vaultService.queryBy() all.states.forEach { println(it.state) } @@ -1359,10 +1290,9 @@ class VaultQueryTests { fun `latest unconsumed deals with party`() { val parties = listOf(MINI_CORP) database.transaction { - services.fillWithSomeTestLinearStates(2, "TEST") - services.fillWithSomeTestDeals(listOf("456"), participants = parties) - services.fillWithSomeTestDeals(listOf("123", "789")) - + vaultFiller.fillWithSomeTestLinearStates(2, "TEST") + vaultFiller.fillWithSomeTestDeals(listOf("456"), participants = parties) + vaultFiller.fillWithSomeTestDeals(listOf("123", "789")) // DOCSTART VaultQueryExample11 val criteria = LinearStateQueryCriteria(participants = parties) val results = vaultService.queryBy(criteria) @@ -1378,11 +1308,10 @@ class VaultQueryTests { fun `unconsumed fungible assets for specific issuer party and refs`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) - - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(2)) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(3)) + 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)) val criteria = FungibleAssetQueryCriteria(issuer = listOf(BOC), issuerRef = listOf(BOC.ref(1).reference, BOC.ref(2).reference)) val results = vaultService.queryBy>(criteria) @@ -1408,9 +1337,9 @@ class VaultQueryTests { services.identityService.verifyAndRegisterIdentity(identity) } database.transaction { - services.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = gbpCashIssuer.party.ref(1)) - services.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = usdCashIssuer.party.ref(1)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = chfCashIssuer.party.ref(1)) + 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)) } database.transaction { val criteria = FungibleAssetQueryCriteria(issuer = listOf(gbpCashIssuer.party, usdCashIssuer.party)) @@ -1422,8 +1351,8 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets by owner`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), + 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)) } database.transaction { @@ -1436,10 +1365,10 @@ class VaultQueryTests { @Test fun `unconsumed fungible states for owners`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), + 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)) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(0), owner = MINI_CORP) // irrelevant to this vault } database.transaction { @@ -1456,11 +1385,10 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets for single currency`() { database.transaction { - services.fillWithSomeTestLinearStates(10) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - + 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)) // DOCSTART VaultQueryExample12 val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(USD.currencyCode) } val criteria = VaultCustomQueryCriteria(ccyIndex) @@ -1474,9 +1402,8 @@ class VaultQueryTests { @Test fun `unconsumed cash balance for single currency`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val sumCriteria = VaultCustomQueryCriteria(sum) @@ -1494,13 +1421,12 @@ class VaultQueryTests { @Test fun `unconsumed cash balances for all currencies`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(300.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L)) - services.fillWithSomeTestCash(500.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) - services.fillWithSomeTestCash(600.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 6, 6, Random(0L)) - + 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)) val ccyIndex = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val criteria = VaultCustomQueryCriteria(ccyIndex) val results = vaultService.queryBy>(criteria) @@ -1518,11 +1444,10 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets for quantity greater than`() { database.transaction { - services.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - services.fillWithSomeTestCash(25.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(50.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - + 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)) // DOCSTART VaultQueryExample13 val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(2500L) }) val results = vaultService.queryBy(fungibleAssetCriteria) @@ -1536,10 +1461,8 @@ class VaultQueryTests { fun `unconsumed fungible assets for issuer party`() { database.transaction { identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) - - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) - services.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 = (DUMMY_CASH_ISSUER)) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1))) // DOCSTART VaultQueryExample14 val criteria = FungibleAssetQueryCriteria(issuer = listOf(BOC)) val results = vaultService.queryBy>(criteria) @@ -1552,11 +1475,10 @@ class VaultQueryTests { @Test fun `unconsumed fungible assets for single currency and quantity greater than`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(50.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) } val customCriteria = VaultCustomQueryCriteria(ccyIndex) val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(5000L) }) @@ -1656,10 +1578,9 @@ class VaultQueryTests { cordappPackages -= SampleCashSchemaV3::class.packageName setUp() database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) // CashSchemaV3 NOT registered with NodeSchemaService val logicalExpression = builder { SampleCashSchemaV3.PersistentCashState::currency.equal(GBP.currencyCode) } val criteria = VaultCustomQueryCriteria(logicalExpression) @@ -1676,11 +1597,10 @@ class VaultQueryTests { @Test fun `custom - all cash states with amount of currency greater or equal than`() { database.transaction { - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - services.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) - + 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)) // DOCSTART VaultQueryExample20 val generalCriteria = VaultQueryCriteria(Vault.StateStatus.ALL) @@ -1707,10 +1627,9 @@ class VaultQueryTests { val end = start.plus(1, ChronoUnit.SECONDS) database.transaction { - services.fillWithSomeTestLinearStates(1, "TEST") + vaultFiller.fillWithSomeTestLinearStates(1, "TEST") sleep(1000) - services.fillWithSomeTestLinearStates(1, "TEST") - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST") // 2 unconsumed states with same external ID val recordedBetweenExpression = TimeCondition(TimeInstantType.RECORDED, builder { between(start, end) }) val basicCriteria = VaultQueryCriteria(timeCondition = recordedBetweenExpression) @@ -1725,9 +1644,8 @@ class VaultQueryTests { @Test fun `unconsumed linear heads for a given external id`() { database.transaction { - services.fillWithSomeTestLinearStates(1, "TEST1") - services.fillWithSomeTestLinearStates(1, "TEST2") - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") + vaultFiller.fillWithSomeTestLinearStates(1, "TEST2") // 2 unconsumed states with same external ID val externalIdCondition = builder { VaultSchemaV1.VaultLinearStates::externalId.equal("TEST2") } val externalIdCustomCriteria = VaultCustomQueryCriteria(externalIdCondition) @@ -1745,11 +1663,10 @@ class VaultQueryTests { val end = start.plus(1, ChronoUnit.SECONDS) database.transaction { - services.fillWithSomeTestLinearStates(1, "TEST1") - services.fillWithSomeTestLinearStates(1, "TEST2") + vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") + vaultFiller.fillWithSomeTestLinearStates(1, "TEST2") sleep(1000) - services.fillWithSomeTestLinearStates(1, "TEST3") - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST3") // 2 unconsumed states with same external ID val results = builder { @@ -1771,11 +1688,10 @@ class VaultQueryTests { @Test fun `unconsumed linear heads for a given external id or uuid`() { database.transaction { - services.fillWithSomeTestLinearStates(1, "TEST1") - val aState = services.fillWithSomeTestLinearStates(1, "TEST2").states - services.consumeLinearStates(aState.toList(), DUMMY_NOTARY) - val uuid = services.fillWithSomeTestLinearStates(1, "TEST1").states.first().state.data.linearId.id - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") + val aState = vaultFiller.fillWithSomeTestLinearStates(1, "TEST2").states + vaultFiller.consumeLinearStates(aState.toList(), DUMMY_NOTARY) + 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 { val externalIdCondition = VaultSchemaV1.VaultLinearStates::externalId.equal("TEST1") @@ -1796,10 +1712,9 @@ class VaultQueryTests { fun `unconsumed linear heads for single participant`() { database.transaction { identitySvc.verifyAndRegisterIdentity(ALICE_IDENTITY) - services.fillWithSomeTestLinearStates(1, "TEST1", listOf(ALICE)) - services.fillWithSomeTestLinearStates(1) - services.fillWithSomeTestLinearStates(1, "TEST3") - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST1", listOf(ALICE)) + vaultFiller.fillWithSomeTestLinearStates(1) + vaultFiller.fillWithSomeTestLinearStates(1, "TEST3") val linearStateCriteria = LinearStateQueryCriteria(participants = listOf(ALICE)) val results = vaultService.queryBy(linearStateCriteria) @@ -1814,11 +1729,9 @@ class VaultQueryTests { identitySvc.verifyAndRegisterIdentity(ALICE_IDENTITY) identitySvc.verifyAndRegisterIdentity(BOB_IDENTITY) identitySvc.verifyAndRegisterIdentity(CHARLIE_IDENTITY) - - services.fillWithSomeTestLinearStates(1, "TEST1", listOf(ALICE, BOB, CHARLIE)) - services.fillWithSomeTestLinearStates(1) - services.fillWithSomeTestLinearStates(1, "TEST3") - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST1", listOf(ALICE, BOB, CHARLIE)) + vaultFiller.fillWithSomeTestLinearStates(1) + vaultFiller.fillWithSomeTestLinearStates(1, "TEST3") val linearStateCriteria = LinearStateQueryCriteria(participants = listOf(ALICE, BOB, CHARLIE)) val results = vaultService.queryBy(linearStateCriteria) @@ -1830,10 +1743,9 @@ class VaultQueryTests { @Test fun `unconsumed linear heads where external id is null`() { database.transaction { - services.fillWithSomeTestLinearStates(1, "TEST1") - services.fillWithSomeTestLinearStates(1) - services.fillWithSomeTestLinearStates(1, "TEST3") - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") + vaultFiller.fillWithSomeTestLinearStates(1) + vaultFiller.fillWithSomeTestLinearStates(1, "TEST3") // 3 unconsumed states (one without an external ID) val results = builder { val externalIdCondition = VaultSchemaV1.VaultLinearStates::externalId.isNull() @@ -1848,10 +1760,9 @@ class VaultQueryTests { @Test fun `unconsumed linear heads where external id is not null`() { database.transaction { - services.fillWithSomeTestLinearStates(1, "TEST1") - services.fillWithSomeTestLinearStates(1) - services.fillWithSomeTestLinearStates(1, "TEST3") - + vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") + vaultFiller.fillWithSomeTestLinearStates(1) + vaultFiller.fillWithSomeTestLinearStates(1, "TEST3") // 3 unconsumed states (two with an external ID) val results = builder { val externalIdCondition = VaultSchemaV1.VaultLinearStates::externalId.notNull() @@ -1866,11 +1777,10 @@ class VaultQueryTests { @Test fun `enriched and overridden composite query handles defaults correctly`() { database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) - services.fillWithSomeTestLinearStates(1, "ABC") - services.fillWithSomeTestDeals(listOf("123")) - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) + vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) + vaultFiller.fillWithSomeTestLinearStates(1, "ABC") + vaultFiller.fillWithSomeTestDeals(listOf("123")) // Base criteria val baseCriteria = VaultQueryCriteria(notary = listOf(DUMMY_NOTARY), status = Vault.StateStatus.CONSUMED) @@ -1903,20 +1813,20 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(10).states - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states + val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal - services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) + vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) } updates.expectEvents { @@ -1944,25 +1854,24 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(10).states - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states - + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states + val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal - services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) + vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - services.consumeCash(100.POUNDS, notary = DUMMY_NOTARY) + vaultFiller.consumeCash(100.POUNDS, notary = DUMMY_NOTARY) } database.transaction { // consume more stuff - services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) } updates.expectEvents { @@ -1990,24 +1899,24 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(10).states - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) + val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states + val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal - services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) + vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - services.consumeCash(99.POUNDS, notary = DUMMY_NOTARY) + vaultFiller.consumeCash(99.POUNDS, notary = DUMMY_NOTARY) } database.transaction { // consume more stuff - services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) } updates.expectEvents { @@ -2048,20 +1957,20 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(10).states - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states + val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal - services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) + vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) } updates.expectEvents { @@ -2097,20 +2006,20 @@ class VaultQueryTests { } val (linearStates, dealStates) = database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) - val linearStates = services.fillWithSomeTestLinearStates(10).states - val dealStates = services.fillWithSomeTestDeals(listOf("123", "456", "789")).states + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) + val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states + val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states // add more cash - services.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) + vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) // add another deal - services.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) + vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) Pair(linearStates, dealStates) } database.transaction { // consume stuff - services.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) - services.consumeDeals(dealStates.toList(), DUMMY_NOTARY) - services.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) + vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) + vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) } 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 34b5672736..1146b79b96 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 @@ -51,6 +51,7 @@ class VaultWithCashTest { @JvmField val testSerialization = SerializationEnvironmentRule(true) lateinit var services: MockServices + private lateinit var vaultFiller: VaultFiller lateinit var issuerServices: MockServices val vaultService: VaultService get() = services.vaultService lateinit var database: CordaPersistence @@ -63,6 +64,7 @@ class VaultWithCashTest { val databaseAndServices = makeTestDatabaseAndMockServices(cordappPackages = cordappPackages, keys = listOf(generateKeyPair(), DUMMY_NOTARY_KEY)) database = databaseAndServices.first services = databaseAndServices.second + vaultFiller = VaultFiller(services) 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 @@ -78,7 +80,7 @@ class VaultWithCashTest { fun splits() { database.transaction { // Fix the PRNG so that we get the same splits every time. - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) } database.transaction { val w = vaultService.queryBy().states @@ -148,7 +150,7 @@ class VaultWithCashTest { database.transaction { // A tx that sends us money. - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L), owner = AnonymousParty(freshKey), + vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L), owner = AnonymousParty(freshKey), issuedBy = MEGA_CORP.ref(1)) println("Cash balance: ${services.getCashBalance(USD)}") } @@ -298,16 +300,16 @@ class VaultWithCashTest { val freshKey = services.keyManagementService.freshKey() database.transaction { - services.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), owner = AnonymousParty(freshKey)) - services.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) - services.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) + 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)) } database.transaction { val cash = vaultService.queryBy().states cash.forEach { println(it.state.data.amount) } } database.transaction { - services.fillWithSomeTestDeals(listOf("123", "456", "789"), issuerServices) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"), issuerServices) } database.transaction { val deals = vaultService.queryBy().states @@ -337,14 +339,14 @@ class VaultWithCashTest { val freshKey = services.keyManagementService.freshKey() val freshIdentity = AnonymousParty(freshKey) database.transaction { - services.fillWithSomeTestDeals(listOf("123", "456", "789"), issuerServices) + vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"), issuerServices) } val deals = database.transaction { vaultService.queryBy().states } database.transaction { - services.fillWithSomeTestLinearStates(3) + vaultFiller.fillWithSomeTestLinearStates(3) } database.transaction { val linearStates = vaultService.queryBy().states diff --git a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt index 101171880c..9dde805ec6 100644 --- a/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt +++ b/samples/trader-demo/src/main/kotlin/net/corda/traderdemo/TraderDemoClientApi.kt @@ -18,7 +18,7 @@ import net.corda.finance.contracts.getCashBalance import net.corda.finance.flows.CashIssueFlow import net.corda.finance.flows.CashPaymentFlow import net.corda.node.services.vault.VaultSchemaV1 -import net.corda.testing.contracts.calculateRandomlySizedAmounts +import net.corda.testing.contracts.VaultFiller.Companion.calculateRandomlySizedAmounts import net.corda.traderdemo.flow.CommercialPaperIssueFlow import net.corda.traderdemo.flow.SellerFlow import java.util.* 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 5cdc3f1bfd..9f9fac4ac7 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 @@ -29,255 +29,238 @@ import java.time.Instant import java.time.Instant.now import java.util.* -@JvmOverloads -fun ServiceHub.fillWithSomeTestDeals(dealIds: List, - issuerServices: ServiceHub = this, +class VaultFiller(private val services: ServiceHub) { + companion object { + fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, max: Int, rng: Random): LongArray { + val numSlots = min + Math.floor(rng.nextDouble() * (max - min)).toInt() + val baseSize = howMuch.quantity / numSlots + check(baseSize > 0) { baseSize } + + val amounts = LongArray(numSlots) { baseSize } + var distanceFromGoal = 0L + // If we want 10 slots then max adjust is 0.1, so even if all random numbers come out to the largest downward + // adjustment possible, the last slot ends at zero. With 20 slots, max adjust is 0.05 etc. + val maxAdjust = 1.0 / numSlots + for (i in amounts.indices) { + if (i != amounts.lastIndex) { + val adjustBy = rng.nextDouble() * maxAdjust - (maxAdjust / 2) + val adjustment = (1 + adjustBy) + val adjustTo = (amounts[i] * adjustment).toLong() + amounts[i] = adjustTo + distanceFromGoal += baseSize - adjustTo + } else { + amounts[i] += distanceFromGoal + } + } + + // The desired amount may not have divided equally to start with, so adjust the first value to make up. + amounts[0] += howMuch.quantity - amounts.sum() + + return amounts + } + } + + @JvmOverloads + fun fillWithSomeTestDeals(dealIds: List, + issuerServices: ServiceHub = services, + participants: List = emptyList(), + notary: Party = DUMMY_NOTARY): 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 { + 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) + } + services.recordTransactions(transactions) + // Get all the StateAndRefs of all the generated transactions. + val states = transactions.flatMap { stx -> + stx.tx.outputs.indices.map { i -> stx.tx.outRef(i) } + } + + return Vault(states) + } + + @JvmOverloads + fun fillWithSomeTestLinearStates(numberToCreate: Int, + externalId: String? = null, participants: List = emptyList(), - notary: Party = DUMMY_NOTARY): Vault { - val myKey: PublicKey = myInfo.chooseIdentity().owningKey - val me = AnonymousParty(myKey) - - val transactions: List = dealIds.map { - // Issue a deal state - val dummyIssue = TransactionBuilder(notary = notary).apply { - addOutputState(DummyDealContract.State(ref = it, participants = participants.plus(me)), DUMMY_DEAL_PROGRAM_ID) - addCommand(dummyCommand()) + linearString: String = "", + linearNumber: Long = 0L, + linearBoolean: Boolean = false, + linearTimestamp: Instant = now()): Vault { + val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey + val me = AnonymousParty(myKey) + val issuerKey = DUMMY_NOTARY_KEY + 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 { + addOutputState(DummyLinearContract.State( + linearId = UniqueIdentifier(externalId), + participants = participants.plus(me), + linearString = linearString, + linearNumber = linearNumber, + linearBoolean = linearBoolean, + linearTimestamp = linearTimestamp), DUMMY_LINEAR_CONTRACT_PROGRAM_ID) + addCommand(dummyCommand()) + } + return@map services.signInitialTransaction(dummyIssue).withAdditionalSignature(issuerKey, signatureMetadata) } - val stx = issuerServices.signInitialTransaction(dummyIssue) - return@map addSignature(stx, notary.owningKey) - } - - recordTransactions(transactions) - - // Get all the StateAndRefs of all the generated transactions. - val states = transactions.flatMap { stx -> - stx.tx.outputs.indices.map { i -> stx.tx.outRef(i) } - } - - return Vault(states) -} - -@JvmOverloads -fun ServiceHub.fillWithSomeTestLinearStates(numberToCreate: Int, - externalId: String? = null, - participants: List = emptyList(), - linearString: String = "", - linearNumber: Long = 0L, - linearBoolean: Boolean = false, - linearTimestamp: Instant = now()): Vault { - val myKey: PublicKey = myInfo.chooseIdentity().owningKey - val me = AnonymousParty(myKey) - val issuerKey = DUMMY_NOTARY_KEY - val signatureMetadata = SignatureMetadata(myInfo.platformVersion, Crypto.findSignatureScheme(issuerKey.public).schemeNumberID) - - val transactions: List = (1..numberToCreate).map { - // Issue a Linear state - val dummyIssue = TransactionBuilder(notary = DUMMY_NOTARY).apply { - addOutputState(DummyLinearContract.State( - linearId = UniqueIdentifier(externalId), - participants = participants.plus(me), - linearString = linearString, - linearNumber = linearNumber, - linearBoolean = linearBoolean, - linearTimestamp = linearTimestamp), DUMMY_LINEAR_CONTRACT_PROGRAM_ID) - addCommand(dummyCommand()) + services.recordTransactions(transactions) + // Get all the StateAndRefs of all the generated transactions. + val states = transactions.flatMap { stx -> + stx.tx.outputs.indices.map { i -> stx.tx.outRef(i) } } - return@map signInitialTransaction(dummyIssue).withAdditionalSignature(issuerKey, signatureMetadata) + return Vault(states) } - recordTransactions(transactions) + /** + * 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. + * + * @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) - // Get all the StateAndRefs of all the generated transactions. - val states = transactions.flatMap { stx -> - stx.tx.outputs.indices.map { i -> stx.tx.outRef(i) } + /** + * 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(), + owner: AbstractParty? = null, + issuedBy: PartyAndReference = DUMMY_CASH_ISSUER): Vault { + val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng) + + // 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) + return@map issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) + } + services.recordTransactions(transactions) + // Get all the StateRefs of all the generated transactions. + val states = transactions.flatMap { stx -> + stx.tx.outputs.indices.map { i -> stx.tx.outRef(i) } + } + + return Vault(states) } - return Vault(states) -} + /** + * + * @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 + val me = AnonymousParty(myKey) -/** - * 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. - * - * @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 ServiceHub.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 ServiceHub.fillWithSomeTestCash(howMuch: Amount, - issuerServices: ServiceHub = this, - outputNotary: Party = DUMMY_NOTARY, - atLeastThisManyStates: Int = 3, - atMostThisManyStates: Int = 10, - rng: Random = Random(), - owner: AbstractParty? = null, - issuedBy: PartyAndReference = DUMMY_CASH_ISSUER): Vault { - val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng) - - // We will allocate one state to one transaction, for simplicities sake. - val cash = Cash() - val transactions: List = amounts.map { pennies -> + val commodity = CommodityContract() val issuance = TransactionBuilder(null as Party?) - cash.generateIssue(issuance, Amount(pennies, Issued(issuedBy, howMuch.token)),owner ?: myInfo.singleIdentity(), outputNotary) - - return@map issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) + commodity.generateIssue(issuance, Amount(amount.quantity, Issued(issuedBy.copy(reference = ref), amount.token)), me, outputNotary) + val transaction = issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) + services.recordTransactions(transaction) + return Vault(setOf(transaction.tx.outRef(0))) } - recordTransactions(transactions) - - // Get all the StateRefs of all the generated transactions. - val states = transactions.flatMap { stx -> - stx.tx.outputs.indices.map { i -> stx.tx.outRef(i) } - } - - return Vault(states) -} - -/** - * - * @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 ServiceHub.fillWithSomeTestCommodity(amount: Amount, - issuerServices: ServiceHub = this, - 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 ?: 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) - val transaction = issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) - - recordTransactions(transaction) - - return Vault(setOf(transaction.tx.outRef(0))) -} - -fun calculateRandomlySizedAmounts(howMuch: Amount, min: Int, max: Int, rng: Random): LongArray { - val numSlots = min + Math.floor(rng.nextDouble() * (max - min)).toInt() - val baseSize = howMuch.quantity / numSlots - check(baseSize > 0) { baseSize } - - val amounts = LongArray(numSlots) { baseSize } - var distanceFromGoal = 0L - // If we want 10 slots then max adjust is 0.1, so even if all random numbers come out to the largest downward - // adjustment possible, the last slot ends at zero. With 20 slots, max adjust is 0.05 etc. - val maxAdjust = 1.0 / numSlots - for (i in amounts.indices) { - if (i != amounts.lastIndex) { - val adjustBy = rng.nextDouble() * maxAdjust - (maxAdjust / 2) - val adjustment = (1 + adjustBy) - val adjustTo = (amounts[i] * adjustment).toLong() - amounts[i] = adjustTo - distanceFromGoal += baseSize - adjustTo - } else { - amounts[i] += distanceFromGoal + fun consume(states: List>, notary: Party) { + // Create a txn consuming different contract types + states.forEach { + val builder = TransactionBuilder(notary = notary).apply { + addInputState(it) + addCommand(dummyCommand(notary.owningKey)) + } + val consumedTx = services.signInitialTransaction(builder, notary.owningKey) + services.recordTransactions(consumedTx) } } - // The desired amount may not have divided equally to start with, so adjust the first value to make up. - amounts[0] += howMuch.quantity - amounts.sum() - - return amounts -} - -fun ServiceHub.consume(states: List>, notary: Party) { - // Create a txn consuming different contract types - states.forEach { - val builder = TransactionBuilder(notary = notary).apply { - addInputState(it) + private fun consumeAndProduce(stateAndRef: StateAndRef, notary: Party): StateAndRef { + // Create a txn consuming different contract types + var builder = TransactionBuilder(notary = notary).apply { + addInputState(stateAndRef) addCommand(dummyCommand(notary.owningKey)) } - val consumedTx = signInitialTransaction(builder, notary.owningKey) + val consumedTx = services.signInitialTransaction(builder, notary.owningKey) + services.recordTransactions(consumedTx) + // Create a txn consuming different contract types + builder = TransactionBuilder(notary = notary).apply { + addOutputState(DummyLinearContract.State(linearId = stateAndRef.state.data.linearId, + participants = stateAndRef.state.data.participants), DUMMY_LINEAR_CONTRACT_PROGRAM_ID) + addCommand(dummyCommand(notary.owningKey)) + } + val producedTx = services.signInitialTransaction(builder, notary.owningKey) + services.recordTransactions(producedTx) + return producedTx.tx.outRef(0) + } - recordTransactions(consumedTx) + private fun consumeAndProduce(states: List>, notary: Party) { + states.forEach { + consumeAndProduce(it, notary) + } + } + + 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) + + /** + * 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 { + val update = services.vaultService.rawUpdates.toFuture() + // A tx that spends our money. + val builder = TransactionBuilder(notary).apply { + Cash.generateSpend(services, this, amount, ourIdentity, to) + } + val spendTx = services.signInitialTransaction(builder, notary.owningKey) + services.recordTransactions(spendTx) + return update.getOrThrow(Duration.ofSeconds(3)) } } - -fun ServiceHub.consumeAndProduce(stateAndRef: StateAndRef, notary: Party): StateAndRef { - // Create a txn consuming different contract types - var builder = TransactionBuilder(notary = notary).apply { - addInputState(stateAndRef) - addCommand(dummyCommand(notary.owningKey)) - } - val consumedTx = signInitialTransaction(builder, notary.owningKey) - - recordTransactions(consumedTx) - - // Create a txn consuming different contract types - builder = TransactionBuilder(notary = notary).apply { - addOutputState(DummyLinearContract.State(linearId = stateAndRef.state.data.linearId, - participants = stateAndRef.state.data.participants), DUMMY_LINEAR_CONTRACT_PROGRAM_ID) - addCommand(dummyCommand(notary.owningKey)) - } - val producedTx = signInitialTransaction(builder, notary.owningKey) - - recordTransactions(producedTx) - - return producedTx.tx.outRef(0) -} - -fun ServiceHub.consumeAndProduce(states: List>, notary: Party) { - states.forEach { - consumeAndProduce(it, notary) - } -} - -fun ServiceHub.consumeDeals(dealStates: List>, notary: Party) = consume(dealStates, notary) -fun ServiceHub.consumeLinearStates(linearStates: List>, notary: Party) = consume(linearStates, notary) -fun ServiceHub.evolveLinearStates(linearStates: List>, notary: Party) = consumeAndProduce(linearStates, notary) -fun ServiceHub.evolveLinearState(linearState: StateAndRef, notary: Party): StateAndRef = consumeAndProduce(linearState, notary) - -/** - * 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 ServiceHub.consumeCash(amount: Amount, to: Party = CHARLIE, notary: Party): Vault.Update { - return consumeCash(amount, myInfo.chooseIdentityAndCert(), to, notary) -} - -/** - * Consume cash, sending any change to the specified identity. - */ -@JvmOverloads -fun ServiceHub.consumeCash(amount: Amount, ourIdentity: PartyAndCertificate, to: Party = CHARLIE, notary: Party): Vault.Update { - val update = vaultService.rawUpdates.toFuture() - val services = this - - // A tx that spends our money. - val builder = TransactionBuilder(notary).apply { - Cash.generateSpend(services, this, amount, ourIdentity, to) - } - val spendTx = signInitialTransaction(builder, notary.owningKey) - - recordTransactions(spendTx) - - return update.getOrThrow(Duration.ofSeconds(3)) -}