CORDA-654 Pass key constants into VaultFiller (#2118)

This commit is contained in:
Andrzej Cichocki 2017-11-29 12:51:01 +00:00 committed by GitHub
parent a81352acbb
commit b45d9e957b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 350 additions and 399 deletions

View File

@ -240,7 +240,7 @@ class CommercialPaperTestsGeneric {
aliceVaultService = aliceServices.vaultService aliceVaultService = aliceServices.vaultService
databaseAlice.transaction { databaseAlice.transaction {
alicesVault = VaultFiller(aliceServices).fillWithSomeTestCash(9000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) alicesVault = VaultFiller(aliceServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random).fillWithSomeTestCash(9000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER)
aliceVaultService = aliceServices.vaultService aliceVaultService = aliceServices.vaultService
} }
@ -250,7 +250,7 @@ class CommercialPaperTestsGeneric {
bigCorpVaultService = bigCorpServices.vaultService bigCorpVaultService = bigCorpServices.vaultService
databaseBigCorp.transaction { databaseBigCorp.transaction {
bigCorpVault = VaultFiller(bigCorpServices).fillWithSomeTestCash(13000.DOLLARS, issuerServices, atLeastThisManyStates = 1, atMostThisManyStates = 1, issuedBy = DUMMY_CASH_ISSUER) bigCorpVault = VaultFiller(bigCorpServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random).fillWithSomeTestCash(13000.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER)
bigCorpVaultService = bigCorpServices.vaultService bigCorpVaultService = bigCorpServices.vaultService
} }

View File

@ -82,15 +82,11 @@ class CashTests {
// Create some cash. Any attempt to spend >$500 will require multiple issuers to be involved. // Create some cash. Any attempt to spend >$500 will require multiple issuers to be involved.
database.transaction { database.transaction {
val vaultFiller = VaultFiller(ourServices) val vaultFiller = VaultFiller(ourServices, DUMMY_NOTARY, DUMMY_NOTARY_KEY, rngFactory = ::Random)
vaultFiller.fillWithSomeTestCash(howMuch = 100.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, vaultFiller.fillWithSomeTestCash(100.DOLLARS, megaCorpServices, 1, MEGA_CORP.ref(1), ourIdentity)
owner = ourIdentity, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) vaultFiller.fillWithSomeTestCash(400.DOLLARS, megaCorpServices, 1, MEGA_CORP.ref(1), ourIdentity)
vaultFiller.fillWithSomeTestCash(howMuch = 400.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1, vaultFiller.fillWithSomeTestCash(80.DOLLARS, miniCorpServices, 1, MINI_CORP.ref(1), ourIdentity)
owner = ourIdentity, issuedBy = MEGA_CORP.ref(1), issuerServices = megaCorpServices) vaultFiller.fillWithSomeTestCash(80.SWISS_FRANCS, miniCorpServices, 1, MINI_CORP.ref(1), ourIdentity)
vaultFiller.fillWithSomeTestCash(howMuch = 80.DOLLARS, atLeastThisManyStates = 1, atMostThisManyStates = 1,
owner = ourIdentity, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices)
vaultFiller.fillWithSomeTestCash(howMuch = 80.SWISS_FRANCS, atLeastThisManyStates = 1, atMostThisManyStates = 1,
owner = ourIdentity, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices)
} }
database.transaction { database.transaction {
vaultStatesUnconsumed = ourServices.vaultService.queryBy<Cash.State>().states vaultStatesUnconsumed = ourServices.vaultService.queryBy<Cash.State>().states

View File

@ -18,13 +18,11 @@ import net.corda.core.utilities.EncodingUtils;
import net.corda.core.utilities.OpaqueBytes; import net.corda.core.utilities.OpaqueBytes;
import net.corda.finance.contracts.DealState; import net.corda.finance.contracts.DealState;
import net.corda.finance.contracts.asset.Cash; import net.corda.finance.contracts.asset.Cash;
import net.corda.finance.contracts.asset.CashUtilities;
import net.corda.finance.schemas.CashSchemaV1; import net.corda.finance.schemas.CashSchemaV1;
import net.corda.node.services.identity.InMemoryIdentityService; import net.corda.node.services.identity.InMemoryIdentityService;
import net.corda.node.utilities.CordaPersistence; import net.corda.node.utilities.CordaPersistence;
import net.corda.node.utilities.DatabaseTransaction; import net.corda.node.utilities.DatabaseTransaction;
import net.corda.testing.SerializationEnvironmentRule; import net.corda.testing.SerializationEnvironmentRule;
import net.corda.testing.TestConstants;
import net.corda.testing.contracts.DummyLinearContract; import net.corda.testing.contracts.DummyLinearContract;
import net.corda.testing.contracts.VaultFiller; import net.corda.testing.contracts.VaultFiller;
import net.corda.testing.node.MockServices; import net.corda.testing.node.MockServices;
@ -74,7 +72,7 @@ public class VaultQueryJavaTests {
issuerServices = new MockServices(cordappPackages, getDUMMY_CASH_ISSUER_NAME(), getDUMMY_CASH_ISSUER_KEY(), getBOC_KEY()); issuerServices = new MockServices(cordappPackages, getDUMMY_CASH_ISSUER_NAME(), getDUMMY_CASH_ISSUER_KEY(), getBOC_KEY());
database = databaseAndServices.getFirst(); database = databaseAndServices.getFirst();
MockServices services = databaseAndServices.getSecond(); MockServices services = databaseAndServices.getSecond();
vaultFiller = new VaultFiller(services); vaultFiller = new VaultFiller(services, getDUMMY_NOTARY(), getDUMMY_NOTARY_KEY());
vaultService = services.getVaultService(); vaultService = services.getVaultService();
} }
@ -139,18 +137,16 @@ public class VaultQueryJavaTests {
Amount<Currency> amount = new Amount<>(100, Currency.getInstance("USD")); Amount<Currency> amount = new Amount<>(100, Currency.getInstance("USD"));
database.transaction(tx -> { database.transaction(tx -> {
vaultFiller.fillWithSomeTestCash( vaultFiller.fillWithSomeTestCash(
new Amount<Currency>(100, Currency.getInstance("USD")), new Amount<>(100, Currency.getInstance("USD")),
issuerServices, issuerServices,
TestConstants.getDUMMY_NOTARY(),
3, 3,
3, getDUMMY_CASH_ISSUER(),
new Random(),
null, null,
CashUtilities.getDUMMY_CASH_ISSUER()); new Random());
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {
vaultFiller.consumeCash(amount, getDUMMY_NOTARY()); vaultFiller.consumeCash(amount, getCHARLIE());
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {
@ -179,8 +175,8 @@ public class VaultQueryJavaTests {
}); });
database.transaction(tx -> { database.transaction(tx -> {
// consume states // consume states
vaultFiller.consumeDeals((List<? extends StateAndRef<? extends DealState>>) ids.getThird().getStates(), getDUMMY_NOTARY()); vaultFiller.consumeDeals((List<? extends StateAndRef<? extends DealState>>) ids.getThird().getStates());
vaultFiller.consumeLinearStates(Collections.singletonList(ids.getFirst()), getDUMMY_NOTARY()); vaultFiller.consumeLinearStates(Collections.singletonList(ids.getFirst()));
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {
@ -219,10 +215,10 @@ public class VaultQueryJavaTests {
Amount<Currency> dollars100 = new Amount<>(100, Currency.getInstance("USD")); Amount<Currency> dollars100 = new Amount<>(100, Currency.getInstance("USD"));
Amount<Currency> dollars10 = new Amount<>(10, Currency.getInstance("USD")); Amount<Currency> dollars10 = new Amount<>(10, Currency.getInstance("USD"));
Amount<Currency> dollars1 = new Amount<>(1, Currency.getInstance("USD")); Amount<Currency> dollars1 = new Amount<>(1, Currency.getInstance("USD"));
vaultFiller.fillWithSomeTestCash(pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(pounds, issuerServices, 1, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars10, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars10, issuerServices, 1, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars1, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars1, issuerServices, 1, getDUMMY_CASH_ISSUER());
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {
@ -262,12 +258,10 @@ public class VaultQueryJavaTests {
vaultFiller.fillWithSomeTestCash( vaultFiller.fillWithSomeTestCash(
new Amount<>(100, Currency.getInstance("USD")), new Amount<>(100, Currency.getInstance("USD")),
issuerServices, issuerServices,
TestConstants.getDUMMY_NOTARY(),
3, 3,
3, getDUMMY_CASH_ISSUER(),
new Random(),
null, null,
getDUMMY_CASH_ISSUER()); new Random());
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {
@ -339,11 +333,11 @@ public class VaultQueryJavaTests {
Amount<Currency> dollars300 = new Amount<>(300, Currency.getInstance("USD")); Amount<Currency> dollars300 = new Amount<>(300, Currency.getInstance("USD"));
Amount<Currency> pounds = new Amount<>(400, Currency.getInstance("GBP")); Amount<Currency> pounds = new Amount<>(400, Currency.getInstance("GBP"));
Amount<Currency> swissfrancs = new Amount<>(500, Currency.getInstance("CHF")); Amount<Currency> swissfrancs = new Amount<>(500, Currency.getInstance("CHF"));
vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, 3, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(pounds, issuerServices, 4, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, 5, getDUMMY_CASH_ISSUER());
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {
@ -385,11 +379,11 @@ public class VaultQueryJavaTests {
Amount<Currency> dollars300 = new Amount<>(300, Currency.getInstance("USD")); Amount<Currency> dollars300 = new Amount<>(300, Currency.getInstance("USD"));
Amount<Currency> pounds = new Amount<>(400, Currency.getInstance("GBP")); Amount<Currency> pounds = new Amount<>(400, Currency.getInstance("GBP"));
Amount<Currency> swissfrancs = new Amount<>(500, Currency.getInstance("CHF")); Amount<Currency> swissfrancs = new Amount<>(500, Currency.getInstance("CHF"));
vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars300, issuerServices, 3, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(pounds, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(pounds, issuerServices, 4, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, TestConstants.getDUMMY_NOTARY(), 5, 5, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(swissfrancs, issuerServices, 5, getDUMMY_CASH_ISSUER());
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {
@ -409,21 +403,21 @@ public class VaultQueryJavaTests {
// DOCEND VaultJavaQueryExample22 // DOCEND VaultJavaQueryExample22
assertThat(results.getOtherResults()).hasSize(18); assertThat(results.getOtherResults()).hasSize(18);
/** CHF */ /* CHF */
assertThat(results.getOtherResults().get(0)).isEqualTo(500L); assertThat(results.getOtherResults().get(0)).isEqualTo(500L);
assertThat(results.getOtherResults().get(1)).isEqualTo(5L); assertThat(results.getOtherResults().get(1)).isEqualTo(5L);
assertThat(results.getOtherResults().get(2)).isEqualTo(102L); assertThat(results.getOtherResults().get(2)).isEqualTo(102L);
assertThat(results.getOtherResults().get(3)).isEqualTo(94L); assertThat(results.getOtherResults().get(3)).isEqualTo(94L);
assertThat(results.getOtherResults().get(4)).isEqualTo(100.00); assertThat(results.getOtherResults().get(4)).isEqualTo(100.00);
assertThat(results.getOtherResults().get(5)).isEqualTo("CHF"); assertThat(results.getOtherResults().get(5)).isEqualTo("CHF");
/** GBP */ /* GBP */
assertThat(results.getOtherResults().get(6)).isEqualTo(400L); assertThat(results.getOtherResults().get(6)).isEqualTo(400L);
assertThat(results.getOtherResults().get(7)).isEqualTo(4L); assertThat(results.getOtherResults().get(7)).isEqualTo(4L);
assertThat(results.getOtherResults().get(8)).isEqualTo(103L); assertThat(results.getOtherResults().get(8)).isEqualTo(103L);
assertThat(results.getOtherResults().get(9)).isEqualTo(93L); assertThat(results.getOtherResults().get(9)).isEqualTo(93L);
assertThat(results.getOtherResults().get(10)).isEqualTo(100.0); assertThat(results.getOtherResults().get(10)).isEqualTo(100.0);
assertThat(results.getOtherResults().get(11)).isEqualTo("GBP"); assertThat(results.getOtherResults().get(11)).isEqualTo("GBP");
/** USD */ /* USD */
assertThat(results.getOtherResults().get(12)).isEqualTo(600L); assertThat(results.getOtherResults().get(12)).isEqualTo(600L);
assertThat(results.getOtherResults().get(13)).isEqualTo(6L); assertThat(results.getOtherResults().get(13)).isEqualTo(6L);
assertThat(results.getOtherResults().get(14)).isEqualTo(113L); assertThat(results.getOtherResults().get(14)).isEqualTo(113L);
@ -446,10 +440,10 @@ public class VaultQueryJavaTests {
Amount<Currency> dollars200 = new Amount<>(200, Currency.getInstance("USD")); Amount<Currency> dollars200 = new Amount<>(200, Currency.getInstance("USD"));
Amount<Currency> pounds300 = new Amount<>(300, Currency.getInstance("GBP")); Amount<Currency> pounds300 = new Amount<>(300, Currency.getInstance("GBP"));
Amount<Currency> pounds400 = new Amount<>(400, Currency.getInstance("GBP")); Amount<Currency> pounds400 = new Amount<>(400, Currency.getInstance("GBP"));
vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, TestConstants.getDUMMY_NOTARY(), 1, 1, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(dollars100, issuerServices, 1, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, TestConstants.getDUMMY_NOTARY(), 2, 2, new Random(0L), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); vaultFiller.fillWithSomeTestCash(dollars200, issuerServices, 2, getBOC().ref(new OpaqueBytes("1".getBytes())));
vaultFiller.fillWithSomeTestCash(pounds300, issuerServices, TestConstants.getDUMMY_NOTARY(), 3, 3, new Random(0L), null, getDUMMY_CASH_ISSUER()); vaultFiller.fillWithSomeTestCash(pounds300, issuerServices, 3, getDUMMY_CASH_ISSUER());
vaultFiller.fillWithSomeTestCash(pounds400, issuerServices, TestConstants.getDUMMY_NOTARY(), 4, 4, new Random(0L), null, getBOC().ref(new OpaqueBytes("1".getBytes()))); vaultFiller.fillWithSomeTestCash(pounds400, issuerServices, 4, getBOC().ref(new OpaqueBytes("1".getBytes())));
return tx; return tx;
}); });
database.transaction(tx -> { database.transaction(tx -> {

View File

@ -106,8 +106,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
bobNode.internals.disableDBCloseOnStop() bobNode.internals.disableDBCloseOnStop()
bobNode.database.transaction { bobNode.database.transaction {
VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, cashIssuer)
issuedBy = cashIssuer)
} }
val alicesFakePaper = aliceNode.database.transaction { val alicesFakePaper = aliceNode.database.transaction {
@ -156,8 +155,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
bobNode.internals.disableDBCloseOnStop() bobNode.internals.disableDBCloseOnStop()
val cashStates = bobNode.database.transaction { val cashStates = bobNode.database.transaction {
VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, notary, 3, 3, VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, issuer)
issuedBy = issuer)
} }
val alicesFakePaper = aliceNode.database.transaction { val alicesFakePaper = aliceNode.database.transaction {
@ -216,8 +214,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
val issuer = bank.ref(1, 2, 3) val issuer = bank.ref(1, 2, 3)
bobNode.database.transaction { bobNode.database.transaction {
VaultFiller(bobNode.services).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, outputNotary = notary, VaultFiller(bobNode.services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random).fillWithSomeTestCash(2000.DOLLARS, bankNode.services, 3, 10, issuer)
issuedBy = issuer)
} }
val alicesFakePaper = aliceNode.database.transaction { val alicesFakePaper = aliceNode.database.transaction {
fillUpForSeller(false, issuer, alice, fillUpForSeller(false, issuer, alice,

View File

@ -3,6 +3,7 @@ package net.corda.node.services.persistence
import com.nhaarman.mockito_kotlin.any import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.whenever import com.nhaarman.mockito_kotlin.whenever
import net.corda.core.contracts.Amount
import net.corda.core.contracts.StateAndRef import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionState import net.corda.core.contracts.TransactionState
@ -82,6 +83,7 @@ class HibernateConfigurationTest {
bankServices = MockServices(cordappPackages, BOC.name, BOC_KEY) bankServices = MockServices(cordappPackages, BOC.name, BOC_KEY)
issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY) issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY)
notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY) notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
notary = notaryServices.myInfo.singleIdentity()
val dataSourceProps = makeTestDataSourceProperties() val dataSourceProps = makeTestDataSourceProperties()
val identityService = rigorousMock<IdentityService>().also { mock -> val identityService = rigorousMock<IdentityService>().also { mock ->
doReturn(null).whenever(mock).wellKnownPartyFromAnonymous(any<AbstractParty>()) doReturn(null).whenever(mock).wellKnownPartyFromAnonymous(any<AbstractParty>())
@ -106,18 +108,15 @@ class HibernateConfigurationTest {
override fun jdbcSession() = database.createSession() override fun jdbcSession() = database.createSession()
} }
vaultFiller = VaultFiller(services) vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, notary, ::Random)
hibernatePersister = services.hibernatePersister hibernatePersister = services.hibernatePersister
} }
identity = services.myInfo.singleIdentity() identity = services.myInfo.singleIdentity()
issuer = issuerServices.myInfo.singleIdentity() issuer = issuerServices.myInfo.singleIdentity()
notary = notaryServices.myInfo.singleIdentity()
database.transaction { database.transaction {
val numStates = 10 val numStates = 10
cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, numStates, numStates, Random(0L), issuedBy = issuer.ref(1)) cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, numStates, issuer.ref(1), rng = Random(0L)).states.toList()
.states.toList()
} }
sessionFactory = sessionFactoryForSchemas(VaultSchemaV1, CashSchemaV1, SampleCashSchemaV2, SampleCashSchemaV3) sessionFactory = sessionFactoryForSchemas(VaultSchemaV1, CashSchemaV1, SampleCashSchemaV2, SampleCashSchemaV3)
@ -126,7 +125,7 @@ class HibernateConfigurationTest {
} }
private fun sessionFactoryForSchemas(vararg schemas: MappedSchema) = hibernateConfig.sessionFactoryForSchemas(schemas.toSet()) private fun sessionFactoryForSchemas(vararg schemas: MappedSchema) = hibernateConfig.sessionFactoryForSchemas(schemas.toSet())
private fun consumeCash(amount: Amount<Currency>) = vaultFiller.consumeCash(amount, CHARLIE)
@After @After
fun cleanUp() { fun cleanUp() {
database.close() database.close()
@ -147,7 +146,7 @@ class HibernateConfigurationTest {
@Test @Test
fun `consumed states`() { fun `consumed states`() {
database.transaction { database.transaction {
vaultFiller.consumeCash(50.DOLLARS, notary = notary) consumeCash(50.DOLLARS)
} }
// structure query // structure query
@ -228,11 +227,7 @@ class HibernateConfigurationTest {
fun `with sorting by state ref desc and asc`() { fun `with sorting by state ref desc and asc`() {
// generate additional state ref indexes // generate additional state ref indexes
database.transaction { database.transaction {
vaultFiller.consumeCash(1.DOLLARS, notary = notary) (1..5).forEach { consumeCash(it.DOLLARS) }
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 // structure query
@ -258,11 +253,7 @@ class HibernateConfigurationTest {
fun `with sorting by state ref index and txId desc and asc`() { fun `with sorting by state ref index and txId desc and asc`() {
// generate additional state ref indexes // generate additional state ref indexes
database.transaction { database.transaction {
vaultFiller.consumeCash(1.DOLLARS, notary = notary) (1..5).forEach { consumeCash(it.DOLLARS) }
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 // structure query
@ -289,7 +280,7 @@ class HibernateConfigurationTest {
fun `with pagination`() { fun `with pagination`() {
// add 100 additional cash entries // add 100 additional cash entries
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(1000.POUNDS, issuerServices, notary, 100, 100, Random(0L), issuedBy = issuer.ref(1)) vaultFiller.fillWithSomeTestCash(1000.POUNDS, issuerServices, 100, issuer.ref(1), rng = Random(0L))
} }
// structure query // structure query
@ -389,11 +380,11 @@ class HibernateConfigurationTest {
@Test @Test
fun `calculate cash balances`() { fun `calculate cash balances`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 10, issuer.ref(1)) // +$100 = $200 vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 10, issuer.ref(1)) // +$100 = $200
vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // £50 = £50 vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, 5, issuer.ref(1)) // £50 = £50
vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // +£25 = £175 vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, 5, issuer.ref(1)) // +£25 = £175
vaultFiller.fillWithSomeTestCash(500.SWISS_FRANCS, issuerServices, notary, 10, issuer.ref(1)) // CHF500 = CHF500 vaultFiller.fillWithSomeTestCash(500.SWISS_FRANCS, issuerServices, 10, issuer.ref(1)) // CHF500 = CHF500
vaultFiller.fillWithSomeTestCash(250.SWISS_FRANCS, issuerServices, notary, 5, issuer.ref(1)) // +CHF250 = CHF750 vaultFiller.fillWithSomeTestCash(250.SWISS_FRANCS, issuerServices, 5, issuer.ref(1)) // +CHF250 = CHF750
} }
// structure query // structure query
@ -422,8 +413,8 @@ class HibernateConfigurationTest {
@Test @Test
fun `calculate cash balance for single currency`() { fun `calculate cash balance for single currency`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // £50 = £50 vaultFiller.fillWithSomeTestCash(50.POUNDS, issuerServices, 5, issuer.ref(1)) // £50 = £50
vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, notary, 5, issuer.ref(1)) // +£25 = £175 vaultFiller.fillWithSomeTestCash(25.POUNDS, issuerServices, 5, issuer.ref(1)) // +£25 = £175
} }
// structure query // structure query
@ -453,9 +444,9 @@ class HibernateConfigurationTest {
fun `calculate and order by cash balance for owner and currency`() { fun `calculate and order by cash balance for owner and currency`() {
database.transaction { database.transaction {
val bank = bankServices.myInfo.legalIdentities.single() val bank = bankServices.myInfo.legalIdentities.single()
vaultFiller.fillWithSomeTestCash(200.DOLLARS, bankServices, notary, 2, bank.ref(1)) vaultFiller.fillWithSomeTestCash(200.DOLLARS, bankServices, 2, bank.ref(1))
vaultFiller.fillWithSomeTestCash(300.POUNDS, issuerServices, notary, 3, issuer.ref(1)) vaultFiller.fillWithSomeTestCash(300.POUNDS, issuerServices, 3, issuer.ref(1))
vaultFiller.fillWithSomeTestCash(400.POUNDS, bankServices, notary, 4, bank.ref(2)) vaultFiller.fillWithSomeTestCash(400.POUNDS, bankServices, 4, bank.ref(2))
} }
// structure query // structure query
@ -640,9 +631,8 @@ class HibernateConfigurationTest {
val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner)
hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3)
} }
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 2, issuer.ref(1), ALICE, Random(0L))
issuedBy = issuer.ref(1), owner = ALICE) val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, 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 // persist additional cash states explicitly with V3 schema
cashStates.forEach { cashStates.forEach {
val cashState = it.state.data val cashState = it.state.data
@ -718,15 +708,14 @@ class HibernateConfigurationTest {
val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner)
hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3)
} }
val moreCash = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, notary, 2, 2, Random(0L), val moreCash = vaultFiller.fillWithSomeTestCash(100.DOLLARS, services, 2, identity.ref(0), identity, Random(0L)).states
issuedBy = identity.ref(0), owner = identity).states
// persist additional cash states explicitly with V3 schema // persist additional cash states explicitly with V3 schema
moreCash.forEach { moreCash.forEach {
val cashState = it.state.data val cashState = it.state.data
val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner) val dummyFungibleState = DummyFungibleContract.State(cashState.amount, cashState.owner)
hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3) hibernatePersister.persistStateWithSchema(dummyFungibleState, it.ref, SampleCashSchemaV3)
} }
val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, notary, 2, 2, Random(0L), owner = ALICE, issuedBy = issuer.ref(1)).states val cashStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 2, issuer.ref(1), ALICE, Random(0L)).states
// persist additional cash states explicitly with V3 schema // persist additional cash states explicitly with V3 schema
cashStates.forEach { cashStates.forEach {
val cashState = it.state.data val cashState = it.state.data

View File

@ -75,7 +75,7 @@ class NodeVaultServiceTest {
val databaseAndServices = MockServices.makeTestDatabaseAndMockServices(cordappPackages = cordappPackages) val databaseAndServices = MockServices.makeTestDatabaseAndMockServices(cordappPackages = cordappPackages)
database = databaseAndServices.first database = databaseAndServices.first
services = databaseAndServices.second services = databaseAndServices.second
vaultFiller = VaultFiller(services) vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY)
// This is safe because MockServices only ever have a single identity // This is safe because MockServices only ever have a single identity
identity = services.myInfo.singleIdentityAndCert() identity = services.myInfo.singleIdentityAndCert()
issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY) issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY)
@ -113,7 +113,7 @@ class NodeVaultServiceTest {
@Test @Test
fun `states not local to instance`() { fun `states not local to instance`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
val w1 = vaultService.queryBy<Cash.State>().states val w1 = vaultService.queryBy<Cash.State>().states
@ -138,7 +138,7 @@ class NodeVaultServiceTest {
@Test @Test
fun `states for refs`() { fun `states for refs`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
val w1 = vaultService.queryBy<Cash.State>().states val w1 = vaultService.queryBy<Cash.State>().states
@ -152,7 +152,7 @@ class NodeVaultServiceTest {
@Test @Test
fun `states soft locking reserve and release`() { fun `states soft locking reserve and release`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
@ -205,7 +205,7 @@ class NodeVaultServiceTest {
val vaultStates = val vaultStates =
database.transaction { database.transaction {
assertEquals(0.DOLLARS, services.getCashBalance(USD)) assertEquals(0.DOLLARS, services.getCashBalance(USD))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet()
println("State Refs:: $stateRefsToSoftLock") println("State Refs:: $stateRefsToSoftLock")
@ -260,7 +260,7 @@ class NodeVaultServiceTest {
val vaultStates = val vaultStates =
database.transaction { database.transaction {
assertEquals(0.DOLLARS, services.getCashBalance(USD)) assertEquals(0.DOLLARS, services.getCashBalance(USD))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
val stateRefsToSoftLock = vaultStates.states.map { it.ref } val stateRefsToSoftLock = vaultStates.states.map { it.ref }
println("State Refs:: $stateRefsToSoftLock") println("State Refs:: $stateRefsToSoftLock")
@ -288,7 +288,7 @@ class NodeVaultServiceTest {
val vaultStates = val vaultStates =
database.transaction { database.transaction {
assertEquals(0.DOLLARS, services.getCashBalance(USD)) assertEquals(0.DOLLARS, services.getCashBalance(USD))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet() val stateRefsToSoftLock = (vaultStates.states.map { it.ref }).toNonEmptySet()
println("State Refs:: $stateRefsToSoftLock") println("State Refs:: $stateRefsToSoftLock")
@ -315,7 +315,7 @@ class NodeVaultServiceTest {
val vaultStates = val vaultStates =
database.transaction { database.transaction {
assertEquals(0.DOLLARS, services.getCashBalance(USD)) assertEquals(0.DOLLARS, services.getCashBalance(USD))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
val stateRefsToSoftLock = vaultStates.states.map { it.ref } val stateRefsToSoftLock = vaultStates.states.map { it.ref }
println("State Refs:: $stateRefsToSoftLock") println("State Refs:: $stateRefsToSoftLock")
@ -336,7 +336,7 @@ class NodeVaultServiceTest {
@Test @Test
fun `unconsumedStatesForSpending exact amount`() { fun `unconsumedStatesForSpending exact amount`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
@ -355,8 +355,8 @@ class NodeVaultServiceTest {
@Test @Test
fun `unconsumedStatesForSpending from two issuer parties`() { fun `unconsumedStatesForSpending from two issuer parties`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(1))
} }
database.transaction { database.transaction {
val spendableStatesUSD = vaultService.unconsumedCashStatesForSpending(200.DOLLARS, val spendableStatesUSD = vaultService.unconsumedCashStatesForSpending(200.DOLLARS,
@ -372,10 +372,10 @@ class NodeVaultServiceTest {
@Test @Test
fun `unconsumedStatesForSpending from specific issuer party and refs`() { fun `unconsumedStatesForSpending from specific issuer party and refs`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(1))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(2)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(2))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(3)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, bocServices, 1, BOC.ref(3))
} }
database.transaction { database.transaction {
val unconsumedStates = vaultService.queryBy<Cash.State>().states val unconsumedStates = vaultService.queryBy<Cash.State>().states
@ -394,7 +394,7 @@ class NodeVaultServiceTest {
@Test @Test
fun `unconsumedStatesForSpending insufficient amount`() { fun `unconsumedStatesForSpending insufficient amount`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 1, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
val unconsumedStates = vaultService.queryBy<Cash.State>().states val unconsumedStates = vaultService.queryBy<Cash.State>().states
@ -411,7 +411,7 @@ class NodeVaultServiceTest {
@Test @Test
fun `unconsumedStatesForSpending small amount`() { fun `unconsumedStatesForSpending small amount`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 2, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
val unconsumedStates = vaultService.queryBy<Cash.State>().states val unconsumedStates = vaultService.queryBy<Cash.State>().states
@ -429,9 +429,9 @@ class NodeVaultServiceTest {
@Test @Test
fun `states soft locking query granularity`() { fun `states soft locking query granularity`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), issuerServices, 10, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L)) }
} }
database.transaction { database.transaction {
var unlockedStates = 30 var unlockedStates = 30

View File

@ -23,6 +23,7 @@ import net.corda.finance.contracts.DealState
import net.corda.finance.contracts.asset.Cash import net.corda.finance.contracts.asset.Cash
import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER
import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER_KEY import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER_KEY
import net.corda.finance.contracts.asset.DUMMY_OBLIGATION_ISSUER
import net.corda.finance.schemas.CashSchemaV1 import net.corda.finance.schemas.CashSchemaV1
import net.corda.finance.schemas.CashSchemaV1.PersistentCashState import net.corda.finance.schemas.CashSchemaV1.PersistentCashState
import net.corda.finance.schemas.CommercialPaperSchemaV1 import net.corda.finance.schemas.CommercialPaperSchemaV1
@ -64,6 +65,7 @@ class VaultQueryTests {
DummyLinearStateSchemaV1::class.packageName) DummyLinearStateSchemaV1::class.packageName)
private lateinit var services: MockServices private lateinit var services: MockServices
private lateinit var vaultFiller: VaultFiller private lateinit var vaultFiller: VaultFiller
private lateinit var vaultFillerCashNotary: VaultFiller
private lateinit var notaryServices: MockServices private lateinit var notaryServices: MockServices
private val vaultService: VaultService get() = services.vaultService private val vaultService: VaultService get() = services.vaultService
private lateinit var identitySvc: IdentityService private lateinit var identitySvc: IdentityService
@ -81,7 +83,8 @@ class VaultQueryTests {
cordappPackages = cordappPackages) cordappPackages = cordappPackages)
database = databaseAndServices.first database = databaseAndServices.first
services = databaseAndServices.second services = databaseAndServices.second
vaultFiller = VaultFiller(services) vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY)
vaultFillerCashNotary = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY, CASH_NOTARY)
notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY, DUMMY_CASH_ISSUER_KEY, BOC_KEY, MEGA_CORP_KEY) notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY, DUMMY_CASH_ISSUER_KEY, BOC_KEY, MEGA_CORP_KEY)
identitySvc = services.identityService identitySvc = services.identityService
// Register all of the identities we're going to use // Register all of the identities we're going to use
@ -107,10 +110,11 @@ class VaultQueryTests {
database.close() database.close()
} }
private fun consumeCash(amount: Amount<Currency>) = vaultFiller.consumeCash(amount, CHARLIE)
private fun setUpDb(_database: CordaPersistence, delay: Long = 0) { private fun setUpDb(_database: CordaPersistence, delay: Long = 0) {
_database.transaction { _database.transaction {
// create new states // create new states
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER)
val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ")
val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL") val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL")
vaultFiller.fillWithSomeTestLinearStates(3, "ABC") vaultFiller.fillWithSomeTestLinearStates(3, "ABC")
@ -119,10 +123,10 @@ class VaultQueryTests {
sleep(delay) sleep(delay)
// consume some states // consume some states
vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList())
vaultFiller.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStatesJKL.states.toList())
vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" })
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) consumeCash(50.DOLLARS)
// Total unconsumed states = 4 + 3 + 2 + 1 (new cash change) = 10 // Total unconsumed states = 4 + 3 + 2 + 1 (new cash change) = 10
// Total consumed states = 6 + 1 + 2 + 1 = 10 // Total consumed states = 6 + 1 + 2 + 1 = 10
} }
@ -147,7 +151,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed states simple`() { fun `unconsumed states simple`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
// DOCSTART VaultQueryExample1 // DOCSTART VaultQueryExample1
@ -172,7 +176,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed states verbose`() { fun `unconsumed states verbose`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
val criteria = VaultQueryCriteria() // default is UNCONSUMED val criteria = VaultQueryCriteria() // default is UNCONSUMED
@ -186,16 +190,15 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed states with count`() { fun `unconsumed states with count`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) repeat(4) {
vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
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 paging = PageSpecification(DEFAULT_PAGE_NUM, 10)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val resultsBeforeConsume = vaultService.queryBy<ContractState>(criteria, paging) val resultsBeforeConsume = vaultService.queryBy<ContractState>(criteria, paging)
assertThat(resultsBeforeConsume.states).hasSize(4) assertThat(resultsBeforeConsume.states).hasSize(4)
assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4)
vaultFiller.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) consumeCash(75.DOLLARS)
val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.UNCONSUMED) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.UNCONSUMED)
val resultsAfterConsume = vaultService.queryBy<ContractState>(consumedCriteria, paging) val resultsAfterConsume = vaultService.queryBy<ContractState>(consumedCriteria, paging)
assertThat(resultsAfterConsume.states).hasSize(1) assertThat(resultsAfterConsume.states).hasSize(1)
@ -206,7 +209,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed cash states simple`() { fun `unconsumed cash states simple`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
val result = vaultService.queryBy<Cash.State>() val result = vaultService.queryBy<Cash.State>()
@ -219,7 +222,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed cash states verbose`() { fun `unconsumed cash states verbose`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
val criteria = VaultQueryCriteria() // default is UNCONSUMED val criteria = VaultQueryCriteria() // default is UNCONSUMED
@ -234,12 +237,12 @@ class VaultQueryTests {
fun `unconsumed cash states sorted by state ref`() { fun `unconsumed cash states sorted by state ref`() {
val stateRefs: MutableList<StateRef> = mutableListOf() val stateRefs: MutableList<StateRef> = mutableListOf()
database.transaction { database.transaction {
val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER)
val issuedStateRefs = issuedStates.states.map { it.ref }.toList() val issuedStateRefs = issuedStates.states.map { it.ref }.toList()
stateRefs.addAll(issuedStateRefs) stateRefs.addAll(issuedStateRefs)
} }
database.transaction { database.transaction {
val spentStates = vaultFiller.consumeCash(25.DOLLARS, notary = DUMMY_NOTARY) val spentStates = consumeCash(25.DOLLARS)
val consumedStateRefs = spentStates.consumed.map { it.ref }.toList() val consumedStateRefs = spentStates.consumed.map { it.ref }.toList()
val producedStateRefs = spentStates.produced.map { it.ref }.toList() val producedStateRefs = spentStates.produced.map { it.ref }.toList()
stateRefs.addAll(consumedStateRefs.plus(producedStateRefs)) stateRefs.addAll(consumedStateRefs.plus(producedStateRefs))
@ -265,11 +268,11 @@ class VaultQueryTests {
fun `unconsumed cash states sorted by state ref txnId and index`() { fun `unconsumed cash states sorted by state ref txnId and index`() {
val consumed = mutableSetOf<SecureHash>() val consumed = mutableSetOf<SecureHash>()
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
vaultFiller.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).consumed.forEach { consumed += it.ref.txhash } consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash }
vaultFiller.consumeCash(10.DOLLARS, notary = DUMMY_NOTARY).consumed.forEach { consumed += it.ref.txhash } consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash }
val sortAttributeTxnId = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_TXN_ID) val sortAttributeTxnId = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_TXN_ID)
val sortAttributeIndex = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_INDEX) val sortAttributeIndex = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_INDEX)
val sortBy = Sort(setOf(Sort.SortColumn(sortAttributeTxnId, Sort.Direction.ASC), val sortBy = Sort(setOf(Sort.SortColumn(sortAttributeTxnId, Sort.Direction.ASC),
@ -311,7 +314,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed states for contract state types`() { fun `unconsumed states for contract state types`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
// default State.Status is UNCONSUMED // default State.Status is UNCONSUMED
@ -326,13 +329,13 @@ class VaultQueryTests {
@Test @Test
fun `consumed states`() { fun `consumed states`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId
vaultFiller.fillWithSomeTestLinearStates(8) vaultFiller.fillWithSomeTestLinearStates(8)
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.states.toList())
vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" })
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) consumeCash(50.DOLLARS)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
val results = vaultService.queryBy<ContractState>(criteria) val results = vaultService.queryBy<ContractState>(criteria)
assertThat(results.states).hasSize(5) assertThat(results.states).hasSize(5)
@ -342,16 +345,15 @@ class VaultQueryTests {
@Test @Test
fun `consumed states with count`() { fun `consumed states with count`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) repeat(4) {
vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(25.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
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 paging = PageSpecification(DEFAULT_PAGE_NUM, 10)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val resultsBeforeConsume = vaultService.queryBy<ContractState>(criteria, paging) val resultsBeforeConsume = vaultService.queryBy<ContractState>(criteria, paging)
assertThat(resultsBeforeConsume.states).hasSize(4) assertThat(resultsBeforeConsume.states).hasSize(4)
assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(4)
vaultFiller.consumeCash(75.DOLLARS, notary = DUMMY_NOTARY) consumeCash(75.DOLLARS)
val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val consumedCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
val resultsAfterConsume = vaultService.queryBy<ContractState>(consumedCriteria, paging) val resultsAfterConsume = vaultService.queryBy<ContractState>(consumedCriteria, paging)
assertThat(resultsAfterConsume.states).hasSize(3) assertThat(resultsAfterConsume.states).hasSize(3)
@ -362,13 +364,13 @@ class VaultQueryTests {
@Test @Test
fun `all states`() { fun `all states`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 results with same UID val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 results with same UID
vaultFiller.fillWithSomeTestLinearStates(8) vaultFiller.fillWithSomeTestLinearStates(8)
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.states.toList())
vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" })
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // generates a new change state! consumeCash(50.DOLLARS) // generates a new change state!
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val results = vaultService.queryBy<ContractState>(criteria) val results = vaultService.queryBy<ContractState>(criteria)
assertThat(results.states).hasSize(17) assertThat(results.states).hasSize(17)
@ -378,14 +380,14 @@ class VaultQueryTests {
@Test @Test
fun `all states with count`() { fun `all states with count`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val paging = PageSpecification(DEFAULT_PAGE_NUM, 10) val paging = PageSpecification(DEFAULT_PAGE_NUM, 10)
val resultsBeforeConsume = vaultService.queryBy<ContractState>(criteria, paging) val resultsBeforeConsume = vaultService.queryBy<ContractState>(criteria, paging)
assertThat(resultsBeforeConsume.states).hasSize(1) assertThat(resultsBeforeConsume.states).hasSize(1)
assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(1) assertThat(resultsBeforeConsume.totalStatesAvailable).isEqualTo(1)
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) // consumed 100 (spent), produced 50 (change) consumeCash(50.DOLLARS) // consumed 100 (spent), produced 50 (change)
val resultsAfterConsume = vaultService.queryBy<ContractState>(criteria, paging) val resultsAfterConsume = vaultService.queryBy<ContractState>(criteria, paging)
assertThat(resultsAfterConsume.states).hasSize(2) assertThat(resultsAfterConsume.states).hasSize(2)
assertThat(resultsAfterConsume.totalStatesAvailable).isEqualTo(2) assertThat(resultsAfterConsume.totalStatesAvailable).isEqualTo(2)
@ -395,7 +397,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed states by notary`() { fun `unconsumed states by notary`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
// DOCSTART VaultQueryExample4 // DOCSTART VaultQueryExample4
@ -438,7 +440,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed states with soft locking`() { fun `unconsumed states with soft locking`() {
database.transaction { database.transaction {
val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)).states.toList() val issuedStates = vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER).states.toList()
vaultService.softLockReserve(UUID.randomUUID(), NonEmptySet.of(issuedStates[1].ref, issuedStates[2].ref, issuedStates[3].ref)) vaultService.softLockReserve(UUID.randomUUID(), NonEmptySet.of(issuedStates[1].ref, issuedStates[2].ref, issuedStates[3].ref))
val lockId1 = UUID.randomUUID() val lockId1 = UUID.randomUUID()
vaultService.softLockReserve(lockId1, NonEmptySet.of(issuedStates[4].ref, issuedStates[5].ref)) vaultService.softLockReserve(lockId1, NonEmptySet.of(issuedStates[4].ref, issuedStates[5].ref))
@ -481,9 +483,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator EQUAL`() { fun `logical operator EQUAL`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -494,9 +496,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator NOT EQUAL`() { fun `logical operator NOT EQUAL`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notEqual(GBP.currencyCode) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notEqual(GBP.currencyCode) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -507,9 +509,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator GREATER_THAN`() { fun `logical operator GREATER_THAN`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach {
vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThan(1000L) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThan(1000L) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -520,9 +522,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator GREATER_THAN_OR_EQUAL`() { fun `logical operator GREATER_THAN_OR_EQUAL`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach {
vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThanOrEqual(1000L) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.greaterThanOrEqual(1000L) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -533,9 +535,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator LESS_THAN`() { fun `logical operator LESS_THAN`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach {
vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThan(1000L) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThan(1000L) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -546,9 +548,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator LESS_THAN_OR_EQUAL`() { fun `logical operator LESS_THAN_OR_EQUAL`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach {
vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThanOrEqual(1000L) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.lessThanOrEqual(1000L) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -559,9 +561,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator BETWEEN`() { fun `logical operator BETWEEN`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(1.DOLLARS, 10.POUNDS, 100.SWISS_FRANCS).forEach {
vaultFiller.fillWithSomeTestCash(10.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.between(500L, 1500L) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::pennies.between(500L, 1500L) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -572,9 +574,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator IN`() { fun `logical operator IN`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val currencies = listOf(CHF.currencyCode, GBP.currencyCode)
val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.`in`(currencies) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.`in`(currencies) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
@ -586,9 +588,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator NOT IN`() { fun `logical operator NOT IN`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val currencies = listOf(CHF.currencyCode, GBP.currencyCode) val currencies = listOf(CHF.currencyCode, GBP.currencyCode)
val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notIn(currencies) } val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notIn(currencies) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
@ -600,9 +602,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator LIKE`() { fun `logical operator LIKE`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.like("%BP") } // GPB val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.like("%BP") } // GPB
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -613,9 +615,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator NOT LIKE`() { fun `logical operator NOT LIKE`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notLike("%BP") } // GPB val logicalExpression = builder { CashSchemaV1.PersistentCashState::currency.notLike("%BP") } // GPB
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -626,9 +628,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator IS_NULL`() { fun `logical operator IS_NULL`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.isNull() } val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.isNull() }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -639,9 +641,9 @@ class VaultQueryTests {
@Test @Test
fun `logical operator NOT_NULL`() { fun `logical operator NOT_NULL`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) }
val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.notNull() } val logicalExpression = builder { CashSchemaV1.PersistentCashState::issuerPartyHash.notNull() }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
@ -652,11 +654,9 @@ class VaultQueryTests {
@Test @Test
fun `aggregate functions without group clause`() { fun `aggregate functions without group clause`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(100.DOLLARS, 200.DOLLARS, 300.DOLLARS, 400.POUNDS, 500.SWISS_FRANCS).zip(1..5).forEach { (howMuch, states) ->
vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER)
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 // DOCSTART VaultQueryExample21
val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum() } val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum() }
val sumCriteria = VaultCustomQueryCriteria(sum) val sumCriteria = VaultCustomQueryCriteria(sum)
@ -692,11 +692,9 @@ class VaultQueryTests {
@Test @Test
fun `aggregate functions with single group clause`() { fun `aggregate functions with single group clause`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(100.DOLLARS, 200.DOLLARS, 300.DOLLARS, 400.POUNDS, 500.SWISS_FRANCS).zip(1..5).forEach { (howMuch, states) ->
vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER)
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 // DOCSTART VaultQueryExample22
val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) }
val sumCriteria = VaultCustomQueryCriteria(sum) val sumCriteria = VaultCustomQueryCriteria(sum)
@ -742,10 +740,10 @@ class VaultQueryTests {
fun `aggregate functions sum by issuer and currency and sort by aggregate sum`() { fun `aggregate functions sum by issuer and currency and sort by aggregate sum`() {
database.transaction { database.transaction {
identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L), issuedBy = BOC.ref(1)) vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, 2, BOC.ref(1))
vaultFiller.fillWithSomeTestCash(300.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestCash(300.POUNDS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(400.POUNDS, notaryServices, DUMMY_NOTARY, 4, 4, Random(0L), issuedBy = BOC.ref(2)) vaultFiller.fillWithSomeTestCash(400.POUNDS, notaryServices, 4, BOC.ref(2))
// DOCSTART VaultQueryExample23 // DOCSTART VaultQueryExample23
val sum = builder { val sum = builder {
CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::issuerPartyHash, CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::issuerPartyHash,
@ -777,7 +775,7 @@ class VaultQueryTests {
fun `aggregate functions count by contract type`() { fun `aggregate functions count by contract type`() {
database.transaction { database.transaction {
// create new states // create new states
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 10, 10, Random(0L)) vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") vaultFiller.fillWithSomeTestLinearStates(1, "XYZ")
vaultFiller.fillWithSomeTestLinearStates(2, "JKL") vaultFiller.fillWithSomeTestLinearStates(2, "JKL")
vaultFiller.fillWithSomeTestLinearStates(3, "ABC") vaultFiller.fillWithSomeTestLinearStates(3, "ABC")
@ -802,7 +800,7 @@ class VaultQueryTests {
fun `aggregate functions count by contract type and state status`() { fun `aggregate functions count by contract type and state status`() {
database.transaction { database.transaction {
// create new states // create new states
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 10, 10, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER)
val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ") val linearStatesXYZ = vaultFiller.fillWithSomeTestLinearStates(1, "XYZ")
val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL") val linearStatesJKL = vaultFiller.fillWithSomeTestLinearStates(2, "JKL")
vaultFiller.fillWithSomeTestLinearStates(3, "ABC") vaultFiller.fillWithSomeTestLinearStates(3, "ABC")
@ -823,10 +821,10 @@ class VaultQueryTests {
assertThat(dealStateCount).isEqualTo(3L) assertThat(dealStateCount).isEqualTo(3L)
// consume some states // consume some states
vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStatesXYZ.states.toList())
vaultFiller.consumeLinearStates(linearStatesJKL.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStatesJKL.states.toList())
vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" })
val cashUpdates = vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) val cashUpdates = consumeCash(50.DOLLARS)
// UNCONSUMED states (default) // UNCONSUMED states (default)
// count fungible assets // count fungible assets
@ -864,7 +862,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed states recorded between two time intervals`() { fun `unconsumed states recorded between two time intervals`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 3, 3, Random(0L)) vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
// DOCSTART VaultQueryExample6 // DOCSTART VaultQueryExample6
val start = TODAY val start = TODAY
val end = TODAY.plus(30, ChronoUnit.DAYS) val end = TODAY.plus(30, ChronoUnit.DAYS)
@ -888,12 +886,12 @@ class VaultQueryTests {
@Test @Test
fun `states consumed after time`() { fun `states consumed after time`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
} }
database.transaction { database.transaction {
vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) consumeCash(100.DOLLARS)
val asOfDateTime = TODAY val asOfDateTime = TODAY
val consumedAfterExpression = TimeCondition( val consumedAfterExpression = TimeCondition(
QueryCriteria.TimeInstantType.CONSUMED, ColumnPredicate.BinaryComparison(BinaryComparisonOperator.GREATER_THAN_OR_EQUAL, asOfDateTime)) QueryCriteria.TimeInstantType.CONSUMED, ColumnPredicate.BinaryComparison(BinaryComparisonOperator.GREATER_THAN_OR_EQUAL, asOfDateTime))
@ -909,7 +907,7 @@ class VaultQueryTests {
@Test @Test
fun `all states with paging specification - first page`() { fun `all states with paging specification - first page`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER)
// DOCSTART VaultQueryExample7 // DOCSTART VaultQueryExample7
val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, 10) val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, 10)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
@ -924,7 +922,7 @@ class VaultQueryTests {
@Test @Test
fun `all states with paging specification - last`() { fun `all states with paging specification - last`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(95.DOLLARS, notaryServices, DUMMY_NOTARY, 95, 95, Random(0L)) vaultFiller.fillWithSomeTestCash(95.DOLLARS, notaryServices, 95, DUMMY_CASH_ISSUER)
// Last page implies we need to perform a row count for the Query first, // 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) // and then re-query for a given offset defined by (count - pageSize)
val pagingSpec = PageSpecification(10, 10) val pagingSpec = PageSpecification(10, 10)
@ -943,7 +941,7 @@ class VaultQueryTests {
expectedEx.expectMessage("Page specification: invalid page number") expectedEx.expectMessage("Page specification: invalid page number")
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER)
val pagingSpec = PageSpecification(0, 10) val pagingSpec = PageSpecification(0, 10)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
@ -958,7 +956,7 @@ class VaultQueryTests {
expectedEx.expectMessage("Page specification: invalid page size") expectedEx.expectMessage("Page specification: invalid page size")
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 100, 100, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER)
@Suppress("EXPECTED_CONDITION") @Suppress("EXPECTED_CONDITION")
val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, @Suppress("INTEGER_OVERFLOW") MAX_PAGE_SIZE + 1) // overflow = -2147483648 val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, @Suppress("INTEGER_OVERFLOW") MAX_PAGE_SIZE + 1) // overflow = -2147483648
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
@ -973,7 +971,7 @@ class VaultQueryTests {
expectedEx.expectMessage("Please specify a `PageSpecification`") expectedEx.expectMessage("Please specify a `PageSpecification`")
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, DUMMY_NOTARY, 201, 201, Random(0L)) vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, 201, DUMMY_CASH_ISSUER)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
vaultService.queryBy<ContractState>(criteria) vaultService.queryBy<ContractState>(criteria)
} }
@ -1011,8 +1009,8 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed fungible assets`() { fun `unconsumed fungible assets`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1))
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
val results = vaultService.queryBy<FungibleAsset<*>>() val results = vaultService.queryBy<FungibleAsset<*>>()
assertThat(results.states).hasSize(4) assertThat(results.states).hasSize(4)
@ -1022,11 +1020,11 @@ class VaultQueryTests {
@Test @Test
fun `consumed fungible assets`() { fun `consumed fungible assets`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) consumeCash(50.DOLLARS)
vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1))
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
val results = vaultService.queryBy<FungibleAsset<*>>(criteria) val results = vaultService.queryBy<FungibleAsset<*>>(criteria)
@ -1037,7 +1035,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed cash fungible assets`() { fun `unconsumed cash fungible assets`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
val results = vaultService.queryBy<Cash.State>() val results = vaultService.queryBy<Cash.State>()
assertThat(results.states).hasSize(3) assertThat(results.states).hasSize(3)
@ -1047,10 +1045,10 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed cash fungible assets after spending`() { fun `unconsumed cash fungible assets after spending`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) consumeCash(50.DOLLARS)
// should now have x2 CONSUMED + x2 UNCONSUMED (one spent + one change) // should now have x2 CONSUMED + x2 UNCONSUMED (one spent + one change)
val results = vaultService.queryBy<Cash.State>(FungibleAssetQueryCriteria()) val results = vaultService.queryBy<Cash.State>(FungibleAssetQueryCriteria())
assertThat(results.statesMetadata).hasSize(2) assertThat(results.statesMetadata).hasSize(2)
@ -1061,12 +1059,12 @@ class VaultQueryTests {
@Test @Test
fun `consumed cash fungible assets`() { fun `consumed cash fungible assets`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) consumeCash(50.DOLLARS)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10) val linearStates = vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.states.toList())
val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
val results = vaultService.queryBy<Cash.State>(criteria) val results = vaultService.queryBy<Cash.State>(criteria)
assertThat(results.states).hasSize(2) assertThat(results.states).hasSize(2)
@ -1076,7 +1074,7 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed linear heads`() { fun `unconsumed linear heads`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
val results = vaultService.queryBy<LinearState>() val results = vaultService.queryBy<LinearState>()
@ -1087,13 +1085,13 @@ class VaultQueryTests {
@Test @Test
fun `consumed linear heads`() { fun `consumed linear heads`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 states with same externalId
vaultFiller.fillWithSomeTestLinearStates(8) vaultFiller.fillWithSomeTestLinearStates(8)
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")) val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
vaultFiller.consumeLinearStates(linearStates.states.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.states.toList())
vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" }, DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" })
vaultFiller.consumeCash(50.DOLLARS, notary = DUMMY_NOTARY) consumeCash(50.DOLLARS)
val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
val results = vaultService.queryBy<LinearState>(criteria) val results = vaultService.queryBy<LinearState>(criteria)
assertThat(results.states).hasSize(3) assertThat(results.states).hasSize(3)
@ -1146,9 +1144,9 @@ class VaultQueryTests {
database.transaction { database.transaction {
val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST") val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST")
val linearState = txns.states.first() val linearState = txns.states.first()
vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference repeat(3) {
vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference vaultFiller.evolveLinearState(linearState) // 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 val linearId = linearState.state.data.linearId
// should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" // should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST"
@ -1166,9 +1164,9 @@ class VaultQueryTests {
database.transaction { database.transaction {
val txns = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") val txns = vaultFiller.fillWithSomeTestLinearStates(2, "TEST")
val linearStates = txns.states.toList() val linearStates = txns.states.toList()
vaultFiller.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference repeat(3) {
vaultFiller.evolveLinearStates(linearStates, DUMMY_NOTARY) // consume current and produce new state reference vaultFiller.evolveLinearStates(linearStates) // 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" // 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 linearStateCriteria = LinearStateQueryCriteria(uuid = linearStates.map { it.state.data.linearId.id }, status = Vault.StateStatus.ALL)
val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
@ -1234,9 +1232,9 @@ class VaultQueryTests {
database.transaction { database.transaction {
val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST") val txns = vaultFiller.fillWithSomeTestLinearStates(1, "TEST")
val linearState = txns.states.first() val linearState = txns.states.first()
val linearState2 = vaultFiller.evolveLinearState(linearState, DUMMY_NOTARY) // consume current and produce new state reference val linearState2 = vaultFiller.evolveLinearState(linearState) // consume current and produce new state reference
val linearState3 = vaultFiller.evolveLinearState(linearState2, DUMMY_NOTARY) // consume current and produce new state reference val linearState3 = vaultFiller.evolveLinearState(linearState2) // consume current and produce new state reference
vaultFiller.evolveLinearState(linearState3, DUMMY_NOTARY) // consume current and produce new state reference vaultFiller.evolveLinearState(linearState3) // consume current and produce new state reference
// should now have 1 UNCONSUMED & 3 CONSUMED state refs for Linear State with "TEST" // 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 linearStateCriteria = LinearStateQueryCriteria(linearId = txns.states.map { it.state.data.linearId }, status = Vault.StateStatus.CONSUMED)
val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED) val vaultCriteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
@ -1308,10 +1306,9 @@ class VaultQueryTests {
fun `unconsumed fungible assets for specific issuer party and refs`() { fun `unconsumed fungible assets for specific issuer party and refs`() {
database.transaction { database.transaction {
identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = DUMMY_CASH_ISSUER) listOf(DUMMY_CASH_ISSUER, BOC.ref(1), BOC.ref(2), BOC.ref(3)).forEach {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, it)
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), val criteria = FungibleAssetQueryCriteria(issuer = listOf(BOC),
issuerRef = listOf(BOC.ref(1).reference, BOC.ref(2).reference)) issuerRef = listOf(BOC.ref(1).reference, BOC.ref(2).reference))
val results = vaultService.queryBy<FungibleAsset<*>>(criteria) val results = vaultService.queryBy<FungibleAsset<*>>(criteria)
@ -1337,9 +1334,9 @@ class VaultQueryTests {
services.identityService.verifyAndRegisterIdentity(identity) services.identityService.verifyAndRegisterIdentity(identity)
} }
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = gbpCashIssuer.party.ref(1)) vaultFiller.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, 1, gbpCashIssuer.party.ref(1))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = usdCashIssuer.party.ref(1)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, 1, usdCashIssuer.party.ref(1))
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = chfCashIssuer.party.ref(1)) vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, 1, chfCashIssuer.party.ref(1))
} }
database.transaction { database.transaction {
val criteria = FungibleAssetQueryCriteria(issuer = listOf(gbpCashIssuer.party, usdCashIssuer.party)) val criteria = FungibleAssetQueryCriteria(issuer = listOf(gbpCashIssuer.party, usdCashIssuer.party))
@ -1351,9 +1348,8 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed fungible assets by owner`() { fun `unconsumed fungible assets by owner`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = BOC.ref(1)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, BOC.ref(1))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, MEGA_CORP.ref(0), MINI_CORP)
issuedBy = MEGA_CORP.ref(0), owner = (MINI_CORP))
} }
database.transaction { database.transaction {
val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP)) val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP))
@ -1365,11 +1361,9 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed fungible states for owners`() { fun `unconsumed fungible states for owners`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, CASH_NOTARY, 1, 1, Random(0L)) vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, MEGA_CORP.ref(0), MEGA_CORP)
issuedBy = MEGA_CORP.ref(0), owner = (MEGA_CORP)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, BOC.ref(0), MINI_CORP) // irrelevant to this vault
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L),
issuedBy = BOC.ref(0), owner = MINI_CORP) // irrelevant to this vault
} }
database.transaction { database.transaction {
// DOCSTART VaultQueryExample5.2 // DOCSTART VaultQueryExample5.2
@ -1386,9 +1380,9 @@ class VaultQueryTests {
fun `unconsumed fungible assets for single currency`() { fun `unconsumed fungible assets for single currency`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestLinearStates(10) vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) listOf(USD, GBP, CHF).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(AMOUNT(100, it), notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) }
// DOCSTART VaultQueryExample12 // DOCSTART VaultQueryExample12
val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(USD.currencyCode) } val ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(USD.currencyCode) }
val criteria = VaultCustomQueryCriteria(ccyIndex) val criteria = VaultCustomQueryCriteria(ccyIndex)
@ -1402,8 +1396,9 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed cash balance for single currency`() { fun `unconsumed cash balance for single currency`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(100, 200).zip(1..2).forEach { (howMuch, states) ->
vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) vaultFiller.fillWithSomeTestCash(howMuch.DOLLARS, notaryServices, states, DUMMY_CASH_ISSUER)
}
val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) } val sum = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) }
val sumCriteria = VaultCustomQueryCriteria(sum) val sumCriteria = VaultCustomQueryCriteria(sum)
@ -1421,12 +1416,9 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed cash balances for all currencies`() { fun `unconsumed cash balances for all currencies`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(100.DOLLARS, 200.DOLLARS, 300.POUNDS, 400.POUNDS, 500.SWISS_FRANCS, 600.SWISS_FRANCS).zip(1..6).forEach { (howMuch, states) ->
vaultFiller.fillWithSomeTestCash(200.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER)
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 ccyIndex = builder { CashSchemaV1.PersistentCashState::pennies.sum(groupByColumns = listOf(CashSchemaV1.PersistentCashState::currency)) }
val criteria = VaultCustomQueryCriteria(ccyIndex) val criteria = VaultCustomQueryCriteria(ccyIndex)
val results = vaultService.queryBy<FungibleAsset<*>>(criteria) val results = vaultService.queryBy<FungibleAsset<*>>(criteria)
@ -1444,10 +1436,9 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed fungible assets for quantity greater than`() { fun `unconsumed fungible assets for quantity greater than`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) listOf(10.DOLLARS, 25.POUNDS, 50.POUNDS, 100.SWISS_FRANCS).zip(listOf(3, 1, 1, 3)).forEach { (howMuch, states) ->
vaultFiller.fillWithSomeTestCash(25.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(howMuch, notaryServices, states, DUMMY_CASH_ISSUER)
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 // DOCSTART VaultQueryExample13
val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(2500L) }) val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(2500L) })
val results = vaultService.queryBy<Cash.State>(fungibleAssetCriteria) val results = vaultService.queryBy<Cash.State>(fungibleAssetCriteria)
@ -1461,8 +1452,9 @@ class VaultQueryTests {
fun `unconsumed fungible assets for issuer party`() { fun `unconsumed fungible assets for issuer party`() {
database.transaction { database.transaction {
identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY) identitySvc.verifyAndRegisterIdentity(BOC_IDENTITY)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (DUMMY_CASH_ISSUER)) listOf(DUMMY_CASH_ISSUER, BOC.ref(1)).forEach {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L), issuedBy = (BOC.ref(1))) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, it)
}
// DOCSTART VaultQueryExample14 // DOCSTART VaultQueryExample14
val criteria = FungibleAssetQueryCriteria(issuer = listOf(BOC)) val criteria = FungibleAssetQueryCriteria(issuer = listOf(BOC))
val results = vaultService.queryBy<FungibleAsset<*>>(criteria) val results = vaultService.queryBy<FungibleAsset<*>>(criteria)
@ -1475,10 +1467,9 @@ class VaultQueryTests {
@Test @Test
fun `unconsumed fungible assets for single currency and quantity greater than`() { fun `unconsumed fungible assets for single currency and quantity greater than`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) listOf(100.DOLLARS, 100.POUNDS, 50.POUNDS, 100.SWISS_FRANCS).forEach {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(it, notaryServices, 1, DUMMY_CASH_ISSUER)
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 ccyIndex = builder { CashSchemaV1.PersistentCashState::currency.equal(GBP.currencyCode) }
val customCriteria = VaultCustomQueryCriteria(ccyIndex) val customCriteria = VaultCustomQueryCriteria(ccyIndex)
val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(5000L) }) val fungibleAssetCriteria = FungibleAssetQueryCriteria(quantity = builder { greaterThan(5000L) })
@ -1578,9 +1569,9 @@ class VaultQueryTests {
cordappPackages -= SampleCashSchemaV3::class.packageName cordappPackages -= SampleCashSchemaV3::class.packageName
setUp() setUp()
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, 1, DUMMY_CASH_ISSUER)
// CashSchemaV3 NOT registered with NodeSchemaService // CashSchemaV3 NOT registered with NodeSchemaService
val logicalExpression = builder { SampleCashSchemaV3.PersistentCashState::currency.equal(GBP.currencyCode) } val logicalExpression = builder { SampleCashSchemaV3.PersistentCashState::currency.equal(GBP.currencyCode) }
val criteria = VaultCustomQueryCriteria(logicalExpression) val criteria = VaultCustomQueryCriteria(logicalExpression)
@ -1597,10 +1588,10 @@ class VaultQueryTests {
@Test @Test
fun `custom - all cash states with amount of currency greater or equal than`() { fun `custom - all cash states with amount of currency greater or equal than`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(10.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(10.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(1.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
// DOCSTART VaultQueryExample20 // DOCSTART VaultQueryExample20
val generalCriteria = VaultQueryCriteria(Vault.StateStatus.ALL) val generalCriteria = VaultQueryCriteria(Vault.StateStatus.ALL)
@ -1690,7 +1681,7 @@ class VaultQueryTests {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestLinearStates(1, "TEST1") vaultFiller.fillWithSomeTestLinearStates(1, "TEST1")
val aState = vaultFiller.fillWithSomeTestLinearStates(1, "TEST2").states val aState = vaultFiller.fillWithSomeTestLinearStates(1, "TEST2").states
vaultFiller.consumeLinearStates(aState.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(aState.toList())
val uuid = vaultFiller.fillWithSomeTestLinearStates(1, "TEST1").states.first().state.data.linearId.id 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 // 2 unconsumed states with same external ID, 1 consumed with different external ID
val results = builder { val results = builder {
@ -1777,8 +1768,8 @@ class VaultQueryTests {
@Test @Test
fun `enriched and overridden composite query handles defaults correctly`() { fun `enriched and overridden composite query handles defaults correctly`() {
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 2, 2, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 2, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices) vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1))
vaultFiller.fillWithSomeTestLinearStates(1, "ABC") vaultFiller.fillWithSomeTestLinearStates(1, "ABC")
vaultFiller.fillWithSomeTestDeals(listOf("123")) vaultFiller.fillWithSomeTestDeals(listOf("123"))
// Base criteria // Base criteria
@ -1813,20 +1804,20 @@ class VaultQueryTests {
} }
val (linearStates, dealStates) = val (linearStates, dealStates) =
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
// add more cash // add more cash
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal // add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates) Pair(linearStates, dealStates)
} }
database.transaction { database.transaction {
// consume stuff // consume stuff
vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.toList())
} }
updates.expectEvents { updates.expectEvents {
@ -1854,24 +1845,24 @@ class VaultQueryTests {
} }
val (linearStates, dealStates) = val (linearStates, dealStates) =
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
// add more cash // add more cash
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal // add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates) Pair(linearStates, dealStates)
} }
database.transaction { database.transaction {
// consume stuff // consume stuff
vaultFiller.consumeCash(100.POUNDS, notary = DUMMY_NOTARY) consumeCash(100.POUNDS)
} }
database.transaction { database.transaction {
// consume more stuff // consume more stuff
vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.toList())
} }
updates.expectEvents { updates.expectEvents {
@ -1899,24 +1890,24 @@ class VaultQueryTests {
} }
val (linearStates, dealStates) = val (linearStates, dealStates) =
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 5, 5, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
// add more cash // add more cash
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal // add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates) Pair(linearStates, dealStates)
} }
database.transaction { database.transaction {
// consume stuff // consume stuff
vaultFiller.consumeCash(99.POUNDS, notary = DUMMY_NOTARY) consumeCash(99.POUNDS)
} }
database.transaction { database.transaction {
// consume more stuff // consume more stuff
vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.toList())
} }
updates.expectEvents { updates.expectEvents {
@ -1957,20 +1948,20 @@ class VaultQueryTests {
} }
val (linearStates, dealStates) = val (linearStates, dealStates) =
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
// add more cash // add more cash
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal // add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates) Pair(linearStates, dealStates)
} }
database.transaction { database.transaction {
// consume stuff // consume stuff
vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.toList())
} }
updates.expectEvents { updates.expectEvents {
@ -2006,20 +1997,20 @@ class VaultQueryTests {
} }
val (linearStates, dealStates) = val (linearStates, dealStates) =
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, DUMMY_NOTARY, 3, 3, Random(0L)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
// add more cash // add more cash
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal // add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL")) vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates) Pair(linearStates, dealStates)
} }
database.transaction { database.transaction {
// consume stuff // consume stuff
vaultFiller.consumeCash(100.DOLLARS, notary = DUMMY_NOTARY) consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList(), DUMMY_NOTARY) vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList(), DUMMY_NOTARY) vaultFiller.consumeLinearStates(linearStates.toList())
} }
updates.expectEvents { updates.expectEvents {

View File

@ -35,7 +35,6 @@ import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import java.util.*
import java.util.concurrent.Executors import java.util.concurrent.Executors
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.fail import kotlin.test.fail
@ -64,7 +63,7 @@ class VaultWithCashTest {
val databaseAndServices = makeTestDatabaseAndMockServices(cordappPackages = cordappPackages, keys = listOf(generateKeyPair(), DUMMY_NOTARY_KEY)) val databaseAndServices = makeTestDatabaseAndMockServices(cordappPackages = cordappPackages, keys = listOf(generateKeyPair(), DUMMY_NOTARY_KEY))
database = databaseAndServices.first database = databaseAndServices.first
services = databaseAndServices.second services = databaseAndServices.second
vaultFiller = VaultFiller(services) vaultFiller = VaultFiller(services, DUMMY_NOTARY, DUMMY_NOTARY_KEY)
issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY) issuerServices = MockServices(cordappPackages, DUMMY_CASH_ISSUER_NAME, DUMMY_CASH_ISSUER_KEY, MEGA_CORP_KEY)
notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY) notaryServices = MockServices(cordappPackages, DUMMY_NOTARY.name, DUMMY_NOTARY_KEY)
notary = notaryServices.myInfo.legalIdentitiesAndCerts.single().party notary = notaryServices.myInfo.legalIdentitiesAndCerts.single().party
@ -80,7 +79,7 @@ class VaultWithCashTest {
fun splits() { fun splits() {
database.transaction { database.transaction {
// Fix the PRNG so that we get the same splits every time. // Fix the PRNG so that we get the same splits every time.
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), issuedBy = DUMMY_CASH_ISSUER) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
val w = vaultService.queryBy<Cash.State>().states val w = vaultService.queryBy<Cash.State>().states
@ -150,8 +149,7 @@ class VaultWithCashTest {
database.transaction { database.transaction {
// A tx that sends us money. // A tx that sends us money.
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 10, 10, Random(0L), owner = AnonymousParty(freshKey), vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 10, MEGA_CORP.ref(1), AnonymousParty(freshKey))
issuedBy = MEGA_CORP.ref(1))
println("Cash balance: ${services.getCashBalance(USD)}") println("Cash balance: ${services.getCashBalance(USD)}")
} }
database.transaction { database.transaction {
@ -300,9 +298,9 @@ class VaultWithCashTest {
val freshKey = services.keyManagementService.freshKey() val freshKey = services.keyManagementService.freshKey()
database.transaction { database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, DUMMY_NOTARY, 3, 3, Random(0L), owner = AnonymousParty(freshKey)) vaultFiller.fillWithSomeTestCash(100.DOLLARS, issuerServices, 3, DUMMY_CASH_ISSUER, AnonymousParty(freshKey))
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, DUMMY_NOTARY, 2, 2, Random(0L)) vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, issuerServices, 2, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.POUNDS, issuerServices, DUMMY_NOTARY, 1, 1, Random(0L)) vaultFiller.fillWithSomeTestCash(100.POUNDS, issuerServices, 1, DUMMY_CASH_ISSUER)
} }
database.transaction { database.transaction {
val cash = vaultService.queryBy<Cash.State>().states val cash = vaultService.queryBy<Cash.State>().states

View File

@ -8,28 +8,39 @@ import net.corda.core.crypto.SignatureMetadata
import net.corda.core.identity.AbstractParty import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.identity.PartyAndCertificate
import net.corda.core.node.ServiceHub import net.corda.core.node.ServiceHub
import net.corda.core.node.services.Vault import net.corda.core.node.services.Vault
import net.corda.core.toFuture import net.corda.core.toFuture
import net.corda.core.transactions.SignedTransaction import net.corda.core.transactions.SignedTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.finance.contracts.Commodity import net.corda.finance.contracts.Commodity
import net.corda.finance.contracts.DealState import net.corda.finance.contracts.DealState
import net.corda.finance.contracts.asset.Cash import net.corda.finance.contracts.asset.Cash
import net.corda.finance.contracts.asset.CommodityContract import net.corda.finance.contracts.asset.CommodityContract
import net.corda.finance.contracts.asset.DUMMY_CASH_ISSUER import net.corda.testing.chooseIdentity
import net.corda.finance.contracts.asset.DUMMY_OBLIGATION_ISSUER import net.corda.testing.chooseIdentityAndCert
import net.corda.testing.* import net.corda.testing.dummyCommand
import net.corda.testing.singleIdentity
import java.security.KeyPair
import java.security.PublicKey import java.security.PublicKey
import java.time.Duration import java.time.Duration
import java.time.Instant import java.time.Instant
import java.time.Instant.now import java.time.Instant.now
import java.util.* import java.util.*
class VaultFiller(private val services: ServiceHub) { /**
* The service hub should provide at least a key management service and a storage service.
* @param defaultNotary used in [fillWithSomeTestDeals] and [fillWithSomeTestLinearStates].
* @param altNotary used in [fillWithSomeTestCash], [fillWithSomeTestCommodity] and consume/evolve methods. If not specified, same as [defaultNotary].
* @param rngFactory used by [fillWithSomeTestCash] if no custom [Random] provided.
*/
class VaultFiller @JvmOverloads constructor(
private val services: ServiceHub,
private val defaultNotary: Party,
private val defaultNotaryKeyPair: KeyPair,
private val altNotary: Party = defaultNotary,
private val rngFactory: () -> Random = { Random(0L) }) {
companion object { companion object {
fun calculateRandomlySizedAmounts(howMuch: Amount<Currency>, min: Int, max: Int, rng: Random): LongArray { fun calculateRandomlySizedAmounts(howMuch: Amount<Currency>, min: Int, max: Int, rng: Random): LongArray {
val numSlots = min + Math.floor(rng.nextDouble() * (max - min)).toInt() val numSlots = min + Math.floor(rng.nextDouble() * (max - min)).toInt()
@ -60,22 +71,25 @@ class VaultFiller(private val services: ServiceHub) {
} }
} }
init {
require(defaultNotary.owningKey == defaultNotaryKeyPair.public) { "Default notary public keys must match." }
}
@JvmOverloads @JvmOverloads
fun fillWithSomeTestDeals(dealIds: List<String>, fun fillWithSomeTestDeals(dealIds: List<String>,
issuerServices: ServiceHub = services, issuerServices: ServiceHub = services,
participants: List<AbstractParty> = emptyList(), participants: List<AbstractParty> = emptyList()): Vault<DealState> {
notary: Party = DUMMY_NOTARY): Vault<DealState> {
val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey
val me = AnonymousParty(myKey) val me = AnonymousParty(myKey)
val transactions: List<SignedTransaction> = dealIds.map { val transactions: List<SignedTransaction> = dealIds.map {
// Issue a deal state // Issue a deal state
val dummyIssue = TransactionBuilder(notary = notary).apply { val dummyIssue = TransactionBuilder(notary = defaultNotary).apply {
addOutputState(DummyDealContract.State(ref = it, participants = participants.plus(me)), DUMMY_DEAL_PROGRAM_ID) addOutputState(DummyDealContract.State(ref = it, participants = participants.plus(me)), DUMMY_DEAL_PROGRAM_ID)
addCommand(dummyCommand()) addCommand(dummyCommand())
} }
val stx = issuerServices.signInitialTransaction(dummyIssue) val stx = issuerServices.signInitialTransaction(dummyIssue)
return@map services.addSignature(stx, notary.owningKey) return@map services.addSignature(stx, defaultNotaryKeyPair.public)
} }
services.recordTransactions(transactions) services.recordTransactions(transactions)
// Get all the StateAndRefs of all the generated transactions. // Get all the StateAndRefs of all the generated transactions.
@ -96,11 +110,11 @@ class VaultFiller(private val services: ServiceHub) {
linearTimestamp: Instant = now()): Vault<LinearState> { linearTimestamp: Instant = now()): Vault<LinearState> {
val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey
val me = AnonymousParty(myKey) val me = AnonymousParty(myKey)
val issuerKey = DUMMY_NOTARY_KEY val issuerKey = defaultNotaryKeyPair
val signatureMetadata = SignatureMetadata(services.myInfo.platformVersion, Crypto.findSignatureScheme(issuerKey.public).schemeNumberID) val signatureMetadata = SignatureMetadata(services.myInfo.platformVersion, Crypto.findSignatureScheme(issuerKey.public).schemeNumberID)
val transactions: List<SignedTransaction> = (1..numberToCreate).map { val transactions: List<SignedTransaction> = (1..numberToCreate).map {
// Issue a Linear state // Issue a Linear state
val dummyIssue = TransactionBuilder(notary = DUMMY_NOTARY).apply { val dummyIssue = TransactionBuilder(notary = defaultNotary).apply {
addOutputState(DummyLinearContract.State( addOutputState(DummyLinearContract.State(
linearId = UniqueIdentifier(externalId), linearId = UniqueIdentifier(externalId),
participants = participants.plus(me), participants = participants.plus(me),
@ -121,49 +135,35 @@ class VaultFiller(private val services: ServiceHub) {
return Vault(states) return Vault(states)
} }
@JvmOverloads
fun fillWithSomeTestCash(howMuch: Amount<Currency>,
issuerServices: ServiceHub,
thisManyStates: Int,
issuedBy: PartyAndReference,
owner: AbstractParty? = null,
rng: Random? = null) = fillWithSomeTestCash(howMuch, issuerServices, thisManyStates, thisManyStates, issuedBy, owner, rng)
/** /**
* Creates a random set of cash states that add up to the given amount and adds them to the vault. This is intended for * Creates a random set of between (by default) 3 and 10 cash states that add up to the given amount and adds them
* unit tests. The cash is owned by the legal identity key from the storage service. * to the vault. This is intended for unit tests. By default 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 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!). * @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!).
*/ */
fun fillWithSomeTestCash(howMuch: Amount<Currency>, fun fillWithSomeTestCash(howMuch: Amount<Currency>,
issuerServices: ServiceHub, issuerServices: ServiceHub,
outputNotary: Party, atLeastThisManyStates: Int,
states: Int, atMostThisManyStates: Int,
issuedBy: PartyAndReference): Vault<Cash.State> issuedBy: PartyAndReference,
= fillWithSomeTestCash(howMuch, issuerServices, outputNotary, states, states, issuedBy = issuedBy)
/**
* Creates a random set of between (by default) 3 and 10 cash states that add up to the given amount and adds them
* to the vault. This is intended for unit tests. By default the cash is issued by [DUMMY_CASH_ISSUER] and owned by the legal
* identity key from the storage service.
*
* The service hub needs to provide at least a key management service and a storage service.
*
* @param issuerServices service hub of the issuer node, which will be used to sign the transaction.
* @param outputNotary the notary to use for output states. The transaction is NOT signed by this notary.
* @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!).
*/
fun fillWithSomeTestCash(howMuch: Amount<Currency>,
issuerServices: ServiceHub = services,
outputNotary: Party = DUMMY_NOTARY,
atLeastThisManyStates: Int = 3,
atMostThisManyStates: Int = 10,
rng: Random = Random(),
owner: AbstractParty? = null, owner: AbstractParty? = null,
issuedBy: PartyAndReference = DUMMY_CASH_ISSUER): Vault<Cash.State> { rng: Random? = null): Vault<Cash.State> {
val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng) val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng ?: rngFactory())
// We will allocate one state to one transaction, for simplicities sake. // We will allocate one state to one transaction, for simplicities sake.
val cash = Cash() val cash = Cash()
val transactions: List<SignedTransaction> = amounts.map { pennies -> val transactions: List<SignedTransaction> = amounts.map { pennies ->
val issuance = TransactionBuilder(null as Party?) val issuance = TransactionBuilder(null as Party?)
cash.generateIssue(issuance, Amount(pennies, Issued(issuedBy, howMuch.token)), owner ?: services.myInfo.singleIdentity(), outputNotary) cash.generateIssue(issuance, Amount(pennies, Issued(issuedBy, howMuch.token)), owner ?: services.myInfo.singleIdentity(), altNotary)
return@map issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) return@map issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey)
} }
services.recordTransactions(transactions) services.recordTransactions(transactions)
@ -178,88 +178,74 @@ class VaultFiller(private val services: ServiceHub) {
/** /**
* *
* @param issuerServices service hub of the issuer node, which will be used to sign the transaction. * @param 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!). * @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 // TODO: need to make all FungibleAsset commands (issue, move, exit) generic
fun fillWithSomeTestCommodity(amount: Amount<Commodity>, fun fillWithSomeTestCommodity(amount: Amount<Commodity>, issuerServices: ServiceHub, issuedBy: PartyAndReference): Vault<CommodityContract.State> {
issuerServices: ServiceHub = services, val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey
outputNotary: Party = DUMMY_NOTARY,
ref: OpaqueBytes = OpaqueBytes(ByteArray(1, { 1 })),
ownedBy: AbstractParty? = null,
issuedBy: PartyAndReference = DUMMY_OBLIGATION_ISSUER.ref(1)): Vault<CommodityContract.State> {
val myKey: PublicKey = ownedBy?.owningKey ?: services.myInfo.chooseIdentity().owningKey
val me = AnonymousParty(myKey) val me = AnonymousParty(myKey)
val commodity = CommodityContract() val commodity = CommodityContract()
val issuance = TransactionBuilder(null as Party?) val issuance = TransactionBuilder(null as Party?)
commodity.generateIssue(issuance, Amount(amount.quantity, Issued(issuedBy.copy(reference = ref), amount.token)), me, outputNotary) commodity.generateIssue(issuance, Amount(amount.quantity, Issued(issuedBy, amount.token)), me, altNotary)
val transaction = issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey) val transaction = issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey)
services.recordTransactions(transaction) services.recordTransactions(transaction)
return Vault(setOf(transaction.tx.outRef(0))) return Vault(setOf(transaction.tx.outRef(0)))
} }
fun <T : LinearState> consume(states: List<StateAndRef<T>>, notary: Party) { private fun <T : LinearState> consume(states: List<StateAndRef<T>>) {
// Create a txn consuming different contract types // Create a txn consuming different contract types
states.forEach { states.forEach {
val builder = TransactionBuilder(notary = notary).apply { val builder = TransactionBuilder(notary = altNotary).apply {
addInputState(it) addInputState(it)
addCommand(dummyCommand(notary.owningKey)) addCommand(dummyCommand(altNotary.owningKey))
} }
val consumedTx = services.signInitialTransaction(builder, notary.owningKey) val consumedTx = services.signInitialTransaction(builder, altNotary.owningKey)
services.recordTransactions(consumedTx) services.recordTransactions(consumedTx)
} }
} }
private fun <T : LinearState> consumeAndProduce(stateAndRef: StateAndRef<T>, notary: Party): StateAndRef<T> { private fun <T : LinearState> consumeAndProduce(stateAndRef: StateAndRef<T>): StateAndRef<T> {
// Create a txn consuming different contract types // Create a txn consuming different contract types
var builder = TransactionBuilder(notary = notary).apply { var builder = TransactionBuilder(notary = altNotary).apply {
addInputState(stateAndRef) addInputState(stateAndRef)
addCommand(dummyCommand(notary.owningKey)) addCommand(dummyCommand(altNotary.owningKey))
} }
val consumedTx = services.signInitialTransaction(builder, notary.owningKey) val consumedTx = services.signInitialTransaction(builder, altNotary.owningKey)
services.recordTransactions(consumedTx) services.recordTransactions(consumedTx)
// Create a txn consuming different contract types // Create a txn consuming different contract types
builder = TransactionBuilder(notary = notary).apply { builder = TransactionBuilder(notary = altNotary).apply {
addOutputState(DummyLinearContract.State(linearId = stateAndRef.state.data.linearId, addOutputState(DummyLinearContract.State(linearId = stateAndRef.state.data.linearId,
participants = stateAndRef.state.data.participants), DUMMY_LINEAR_CONTRACT_PROGRAM_ID) participants = stateAndRef.state.data.participants), DUMMY_LINEAR_CONTRACT_PROGRAM_ID)
addCommand(dummyCommand(notary.owningKey)) addCommand(dummyCommand(altNotary.owningKey))
} }
val producedTx = services.signInitialTransaction(builder, notary.owningKey) val producedTx = services.signInitialTransaction(builder, altNotary.owningKey)
services.recordTransactions(producedTx) services.recordTransactions(producedTx)
return producedTx.tx.outRef(0) return producedTx.tx.outRef(0)
} }
private fun <T : LinearState> consumeAndProduce(states: List<StateAndRef<T>>, notary: Party) { private fun <T : LinearState> consumeAndProduce(states: List<StateAndRef<T>>) {
states.forEach { states.forEach {
consumeAndProduce(it, notary) consumeAndProduce(it)
} }
} }
fun consumeDeals(dealStates: List<StateAndRef<DealState>>, notary: Party) = consume(dealStates, notary) fun consumeDeals(dealStates: List<StateAndRef<DealState>>) = consume(dealStates)
fun consumeLinearStates(linearStates: List<StateAndRef<LinearState>>, notary: Party) = consume(linearStates, notary) fun consumeLinearStates(linearStates: List<StateAndRef<LinearState>>) = consume(linearStates)
fun evolveLinearStates(linearStates: List<StateAndRef<LinearState>>, notary: Party) = consumeAndProduce(linearStates, notary) fun evolveLinearStates(linearStates: List<StateAndRef<LinearState>>) = consumeAndProduce(linearStates)
fun evolveLinearState(linearState: StateAndRef<LinearState>, notary: Party): StateAndRef<LinearState> = consumeAndProduce(linearState, notary) fun evolveLinearState(linearState: StateAndRef<LinearState>): StateAndRef<LinearState> = consumeAndProduce(linearState)
/** /**
* Consume cash, sending any change to the default identity for this node. Only suitable for use in test scenarios, * 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. * where nodes have a default identity.
*/ */
@JvmOverloads fun consumeCash(amount: Amount<Currency>, to: AbstractParty): Vault.Update<ContractState> {
fun consumeCash(amount: Amount<Currency>, to: Party = CHARLIE, notary: Party): Vault.Update<ContractState> { val ourIdentity = services.myInfo.chooseIdentityAndCert()
return consumeCash(amount, services.myInfo.chooseIdentityAndCert(), to, notary)
}
/**
* Consume cash, sending any change to the specified identity.
*/
private fun consumeCash(amount: Amount<Currency>, ourIdentity: PartyAndCertificate, to: Party = CHARLIE, notary: Party): Vault.Update<ContractState> {
val update = services.vaultService.rawUpdates.toFuture() val update = services.vaultService.rawUpdates.toFuture()
// A tx that spends our money. // A tx that spends our money.
val builder = TransactionBuilder(notary).apply { val builder = TransactionBuilder(altNotary).apply {
Cash.generateSpend(services, this, amount, ourIdentity, to) Cash.generateSpend(services, this, amount, ourIdentity, to)
} }
val spendTx = services.signInitialTransaction(builder, notary.owningKey) val spendTx = services.signInitialTransaction(builder, altNotary.owningKey)
services.recordTransactions(spendTx) services.recordTransactions(spendTx)
return update.getOrThrow(Duration.ofSeconds(3)) return update.getOrThrow(Duration.ofSeconds(3))
} }