DB test using transaction with rollback rather then recreating whole DB (#2994)

VaultQuery tests wrapped inside transaction which gets rolled back rather then recreating DB from scratch for each test
Moved Missing schema test to separate class, as it modifies global test class state
This commit is contained in:
Maksymilian Pawlak 2018-04-27 09:52:25 +01:00 committed by GitHub
parent 235df69efe
commit b210f7ab0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 280 additions and 179 deletions

View File

@ -284,6 +284,12 @@ tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
}
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
reportOn subprojects*.test
}
bintrayConfig {
user = System.getenv('CORDA_BINTRAY_USER')
key = System.getenv('CORDA_BINTRAY_KEY')

View File

@ -0,0 +1,116 @@
package net.corda.node.services.vault
import net.corda.core.identity.CordaX500Name
import net.corda.core.internal.packageName
import net.corda.core.node.services.*
import net.corda.core.node.services.vault.*
import net.corda.core.node.services.vault.QueryCriteria.*
import net.corda.finance.*
import net.corda.finance.contracts.asset.Cash
import net.corda.finance.schemas.CashSchemaV1
import net.corda.finance.schemas.SampleCashSchemaV3
import net.corda.nodeapi.internal.persistence.CordaPersistence
import net.corda.nodeapi.internal.persistence.DatabaseTransaction
import net.corda.testing.core.*
import net.corda.testing.internal.rigorousMock
import net.corda.testing.internal.vault.VaultFiller
import net.corda.testing.node.MockServices
import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServices
import net.corda.testing.node.makeTestIdentityService
import net.corda.testing.internal.vault.DummyLinearStateSchemaV1
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.*
import org.junit.rules.ExpectedException
class VaultQueryExceptionsTests {
private companion object {
val bankOfCorda = TestIdentity(BOC_NAME)
val cashNotary = TestIdentity(CordaX500Name("Cash Notary Service", "Zurich", "CH"), 21)
val dummyCashIssuer = TestIdentity(CordaX500Name("Snake Oil Issuer", "London", "GB"), 10)
val DUMMY_CASH_ISSUER = dummyCashIssuer.ref(1)
val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20)
val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB"))
val BOC_IDENTITY get() = bankOfCorda.identity
val BOC_KEY get() = bankOfCorda.keyPair
val CASH_NOTARY get() = cashNotary.party
val CASH_NOTARY_IDENTITY get() = cashNotary.identity
val DUMMY_NOTARY_KEY get() = dummyNotary.keyPair
val MEGA_CORP_IDENTITY get() = megaCorp.identity
val MEGA_CORP_KEY get() = megaCorp.keyPair
val MINI_CORP_IDENTITY get() = miniCorp.identity
private val cordappPackages = listOf(
"net.corda.testing.contracts",
"net.corda.finance.contracts",
CashSchemaV1::class.packageName,
DummyLinearStateSchemaV1::class.packageName) - SampleCashSchemaV3::class.packageName
private lateinit var services: MockServices
private lateinit var vaultFiller: VaultFiller
private lateinit var vaultFillerCashNotary: VaultFiller
private lateinit var notaryServices: MockServices
private val vaultService: VaultService get() = services.vaultService
private lateinit var identitySvc: IdentityService
private lateinit var database: CordaPersistence
@BeforeClass @JvmStatic
fun setUpClass() {
// register additional identities
val databaseAndServices = makeTestDatabaseAndMockServices(
cordappPackages,
makeTestIdentityService(Companion.MEGA_CORP_IDENTITY, Companion.MINI_CORP_IDENTITY, Companion.dummyCashIssuer.identity, Companion.dummyNotary.identity),
Companion.megaCorp,
moreKeys = Companion.DUMMY_NOTARY_KEY)
database = databaseAndServices.first
services = databaseAndServices.second
vaultFiller = VaultFiller(services, Companion.dummyNotary)
vaultFillerCashNotary = VaultFiller(services, Companion.dummyNotary, Companion.CASH_NOTARY)
notaryServices = MockServices(cordappPackages, Companion.dummyNotary, rigorousMock(), Companion.dummyCashIssuer.keyPair, Companion.BOC_KEY, Companion.MEGA_CORP_KEY)
identitySvc = services.identityService
// Register all of the identities we're going to use
(notaryServices.myInfo.legalIdentitiesAndCerts + Companion.BOC_IDENTITY + Companion.CASH_NOTARY_IDENTITY + Companion.MINI_CORP_IDENTITY + Companion.MEGA_CORP_IDENTITY).forEach { identity ->
services.identityService.verifyAndRegisterIdentity(identity)
}
}
}
private lateinit var transaction: DatabaseTransaction
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
@Rule
@JvmField
val expectedEx: ExpectedException = ExpectedException.none()
@Before
fun setUp() {
transaction = database.newTransaction()
}
@After
fun tearDown() {
transaction.rollback()
transaction.close()
}
@Test
fun `query attempting to use unregistered schema`() {
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, 1, DUMMY_CASH_ISSUER)
// CashSchemaV3 NOT registered with NodeSchemaService
val logicalExpression = builder { SampleCashSchemaV3.PersistentCashState::currency.equal(GBP.currencyCode) }
val criteria = VaultCustomQueryCriteria(logicalExpression)
assertThatThrownBy {
vaultService.queryBy<Cash.State>(criteria)
}.isInstanceOf(VaultQueryException::class.java).hasMessageContaining("Please register the entity")
}
}
}

View File

@ -20,10 +20,10 @@ import net.corda.finance.contracts.asset.cash.selection.AbstractCashSelection
import net.corda.finance.schemas.CashSchemaV1
import net.corda.finance.schemas.CashSchemaV1.PersistentCashState
import net.corda.finance.schemas.CommercialPaperSchemaV1
import net.corda.finance.schemas.SampleCashSchemaV3
import net.corda.node.internal.configureDatabase
import net.corda.nodeapi.internal.persistence.CordaPersistence
import net.corda.nodeapi.internal.persistence.DatabaseConfig
import net.corda.nodeapi.internal.persistence.DatabaseTransaction
import net.corda.testing.core.*
import net.corda.testing.internal.TEST_TX_TIME
import net.corda.testing.internal.rigorousMock
@ -35,7 +35,6 @@ import net.corda.testing.node.MockServices.Companion.makeTestDatabaseAndMockServ
import net.corda.testing.node.makeTestIdentityService
import net.corda.testing.internal.vault.DummyLinearStateSchemaV1
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.*
import org.junit.rules.ExpectedException
import java.lang.Thread.sleep
@ -81,17 +80,8 @@ class VaultQueryTests {
val MEGA_CORP get() = megaCorp.party
val MINI_CORP_IDENTITY get() = miniCorp.identity
val MINI_CORP get() = miniCorp.party
}
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
@Rule
@JvmField
val expectedEx: ExpectedException = ExpectedException.none()
private val cordappPackages = mutableListOf(
private val cordappPackages = listOf(
"net.corda.testing.contracts",
"net.corda.finance.contracts",
CashSchemaV1::class.packageName,
@ -103,29 +93,48 @@ class VaultQueryTests {
private val vaultService: VaultService get() = services.vaultService
private lateinit var identitySvc: IdentityService
private lateinit var database: CordaPersistence
@Before
fun setUp() {
@BeforeClass @JvmStatic
fun setUpClass() {
// register additional identities
val databaseAndServices = makeTestDatabaseAndMockServices(
cordappPackages,
makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity),
megaCorp,
moreKeys = DUMMY_NOTARY_KEY)
makeTestIdentityService(Companion.MEGA_CORP_IDENTITY, Companion.MINI_CORP_IDENTITY, Companion.dummyCashIssuer.identity, Companion.dummyNotary.identity),
Companion.megaCorp,
moreKeys = Companion.DUMMY_NOTARY_KEY)
database = databaseAndServices.first
services = databaseAndServices.second
vaultFiller = VaultFiller(services, dummyNotary)
vaultFillerCashNotary = VaultFiller(services, dummyNotary, CASH_NOTARY)
notaryServices = MockServices(cordappPackages, dummyNotary, rigorousMock(), dummyCashIssuer.keyPair, BOC_KEY, MEGA_CORP_KEY)
vaultFiller = VaultFiller(services, Companion.dummyNotary)
vaultFillerCashNotary = VaultFiller(services, Companion.dummyNotary, Companion.CASH_NOTARY)
notaryServices = MockServices(cordappPackages, Companion.dummyNotary, rigorousMock(), Companion.dummyCashIssuer.keyPair, Companion.BOC_KEY, Companion.MEGA_CORP_KEY)
identitySvc = services.identityService
// Register all of the identities we're going to use
(notaryServices.myInfo.legalIdentitiesAndCerts + BOC_IDENTITY + CASH_NOTARY_IDENTITY + MINI_CORP_IDENTITY + MEGA_CORP_IDENTITY).forEach { identity ->
(notaryServices.myInfo.legalIdentitiesAndCerts + Companion.BOC_IDENTITY + Companion.CASH_NOTARY_IDENTITY + Companion.MINI_CORP_IDENTITY + Companion.MEGA_CORP_IDENTITY).forEach { identity ->
services.identityService.verifyAndRegisterIdentity(identity)
}
}
}
private lateinit var transaction: DatabaseTransaction
@Rule
@JvmField
val testSerialization = SerializationEnvironmentRule()
@Rule
@JvmField
val expectedEx: ExpectedException = ExpectedException.none()
@Before
fun setUp() {
transaction = database.newTransaction()
}
@After
fun tearDown() {
database.close()
transaction.rollback()
transaction.close()
}
/**
@ -270,8 +279,8 @@ class VaultQueryTests {
val issuedStates = vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER)
val issuedStateRefs = issuedStates.states.map { it.ref }.toList()
stateRefs.addAll(issuedStateRefs)
}
database.transaction {
this.session.flush()
val spentStates = consumeCash(25.DOLLARS)
val consumedStateRefs = spentStates.consumed.map { it.ref }.toList()
val producedStateRefs = spentStates.produced.map { it.ref }.toList()
@ -299,8 +308,8 @@ class VaultQueryTests {
val consumed = mutableSetOf<SecureHash>()
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 10, DUMMY_CASH_ISSUER)
}
database.transaction {
this.session.flush()
consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash }
consumeCash(10.DOLLARS).consumed.forEach { consumed += it.ref.txhash }
val sortAttributeTxnId = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF_TXN_ID)
@ -398,9 +407,12 @@ class VaultQueryTests {
val linearStates = vaultFiller.fillWithSomeTestLinearStates(2, "TEST") // create 2 results with same UID
vaultFiller.fillWithSomeTestLinearStates(8)
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
vaultFiller.consumeLinearStates(linearStates.states.toList())
vaultFiller.consumeDeals(dealStates.states.filter { it.state.data.linearId.externalId == "456" })
consumeCash(50.DOLLARS) // generates a new change state!
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
val results = vaultService.queryBy<ContractState>(criteria)
assertThat(results.states).hasSize(17)
@ -913,8 +925,7 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789"))
}
database.transaction {
this.session.flush()
consumeCash(100.DOLLARS)
val asOfDateTime = TODAY
val consumedAfterExpression = TimeCondition(
@ -1032,8 +1043,8 @@ class VaultQueryTests {
// sorting
@Test
fun `sorting - all states sorted by contract type, state status, consumed time`() {
setUpDb(database)
database.transaction {
setUpDb(database)
val sortCol1 = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.CONTRACT_STATE_TYPE), Sort.Direction.DESC)
val sortCol2 = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.STATE_STATUS), Sort.Direction.ASC)
val sortCol3 = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.CONSUMED_TIME), Sort.Direction.DESC)
@ -1043,10 +1054,6 @@ class VaultQueryTests {
val states = result.states
val metadata = result.statesMetadata
for (i in 0 until states.size) {
println("${states[i].ref} : ${metadata[i].contractStateClassName}, ${metadata[i].status}, ${metadata[i].consumedTime}")
}
assertThat(states).hasSize(20)
assertThat(metadata.first().contractStateClassName).isEqualTo("$DUMMY_LINEAR_CONTRACT_PROGRAM_ID\$State")
assertThat(metadata.first().status).isEqualTo(Vault.StateStatus.UNCONSUMED) // 0 = UNCONSUMED
@ -1061,6 +1068,7 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1))
vaultFiller.fillWithSomeTestLinearStates(10)
val results = vaultService.queryBy<FungibleAsset<*>>()
assertThat(results.states).hasSize(4)
}
@ -1070,8 +1078,8 @@ class VaultQueryTests {
fun `consumed fungible assets`() {
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
}
database.transaction {
this.session.flush()
consumeCash(50.DOLLARS)
vaultFiller.fillWithSomeTestCommodity(Amount(100, Commodity.getInstance("FCOJ")!!), notaryServices, DUMMY_OBLIGATION_ISSUER.ref(1))
vaultFiller.fillWithSomeTestLinearStates(10)
@ -1095,8 +1103,8 @@ class VaultQueryTests {
fun `unconsumed cash fungible assets after spending`() {
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
}
database.transaction {
this.session.flush()
consumeCash(50.DOLLARS)
// should now have x2 CONSUMED + x2 UNCONSUMED (one spent + one change)
val results = vaultService.queryBy<Cash.State>(FungibleAssetQueryCriteria())
@ -1109,8 +1117,8 @@ class VaultQueryTests {
fun `consumed cash fungible assets`() {
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
}
database.transaction {
this.session.flush()
consumeCash(50.DOLLARS)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10)
vaultFiller.consumeLinearStates(linearStates.states.toList())
@ -1237,7 +1245,6 @@ class VaultQueryTests {
val sorting = Sort(setOf(Sort.SortColumn(SortAttribute.Standard(Sort.LinearStateAttribute.EXTERNAL_ID), Sort.Direction.DESC)))
val results = vaultService.queryBy<DummyLinearContract.State>((vaultCriteria), sorting = sorting)
results.states.forEach { println(it.state.data.linearString) }
assertThat(results.states).hasSize(6)
}
}
@ -1324,8 +1331,6 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestLinearStates(2, "TEST")
vaultFiller.fillWithSomeTestDeals(listOf("456"))
vaultFiller.fillWithSomeTestDeals(listOf("123", "789"))
val all = vaultService.queryBy<DealState>()
all.states.forEach { println(it.state) }
val criteria = LinearStateQueryCriteria(externalId = listOf("456"))
val results = vaultService.queryBy<DealState>(criteria)
@ -1386,8 +1391,8 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.POUNDS, gbpCashIssuerServices, 1, gbpCashIssuer.party.ref(1))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, usdCashIssuerServices, 1, usdCashIssuer.party.ref(1))
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, chfCashIssuerServices, 1, chfCashIssuer.party.ref(1))
}
database.transaction {
this.session.flush()
val criteria = FungibleAssetQueryCriteria(issuer = listOf(gbpCashIssuer.party, usdCashIssuer.party))
val results = vaultService.queryBy<FungibleAsset<*>>(criteria)
assertThat(results.states).hasSize(2)
@ -1399,8 +1404,7 @@ class VaultQueryTests {
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, BOC.ref(1))
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, MEGA_CORP.ref(0), MINI_CORP)
}
database.transaction {
val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP))
val results = vaultService.queryBy<FungibleAsset<*>>(criteria)
assertThat(results.states).hasSize(1) // can only be 1 owner of a node (MEGA_CORP in this MockServices setup)
@ -1413,8 +1417,7 @@ class VaultQueryTests {
vaultFillerCashNotary.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, MEGA_CORP.ref(0), MEGA_CORP)
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, BOC.ref(0), MINI_CORP) // irrelevant to this vault
}
database.transaction {
// DOCSTART VaultQueryExample5.2
val criteria = FungibleAssetQueryCriteria(owner = listOf(MEGA_CORP, BOC))
val results = vaultService.queryBy<ContractState>(criteria)
@ -1614,25 +1617,6 @@ class VaultQueryTests {
}
}
@Test
fun `query attempting to use unregistered schema`() {
tearDown()
cordappPackages -= SampleCashSchemaV3::class.packageName
setUp()
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
vaultFiller.fillWithSomeTestCash(100.SWISS_FRANCS, notaryServices, 1, DUMMY_CASH_ISSUER)
// CashSchemaV3 NOT registered with NodeSchemaService
val logicalExpression = builder { SampleCashSchemaV3.PersistentCashState::currency.equal(GBP.currencyCode) }
val criteria = VaultCustomQueryCriteria(logicalExpression)
assertThatThrownBy {
vaultService.queryBy<Cash.State>(criteria)
}.isInstanceOf(VaultQueryException::class.java).hasMessageContaining("Please register the entity")
}
}
/** Chaining together different Query Criteria tests**/
// specifying Query on Cash contract state attributes
@ -1847,14 +1831,12 @@ class VaultQueryTests {
@Test
fun trackCashStates_unconsumed() {
val updates = database.transaction {
val updates =
database.transaction {
// DOCSTART VaultQueryExample15
vaultService.trackBy<Cash.State>().updates // UNCONSUMED default
// DOCEND VaultQueryExample15
}
val (linearStates, dealStates) =
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
@ -1862,13 +1844,15 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates)
}
database.transaction {
this.session.flush()
// consume stuff
consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList())
close() // transaction needs to be closed to trigger events
updates
}
updates.expectEvents {
@ -1889,13 +1873,11 @@ class VaultQueryTests {
@Test
fun trackCashStates_consumed() {
val updates =
database.transaction {
val updates = database.transaction {
val criteria = VaultQueryCriteria(status = Vault.StateStatus.CONSUMED)
vaultService.trackBy<Cash.State>(criteria).updates
}
val (linearStates, dealStates) =
database.transaction {
val updates = vaultService.trackBy<Cash.State>(criteria).updates
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
@ -1903,17 +1885,17 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates)
}
database.transaction {
// consume stuff
this.session.flush()
consumeCash(100.POUNDS)
}
database.transaction {
// consume more stuff
consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList())
close() // transaction needs to be closed to trigger events
updates
}
updates.expectEvents {
@ -1934,13 +1916,12 @@ class VaultQueryTests {
@Test
fun trackCashStates_all() {
val updates = database.transaction {
val updates =
database.transaction {
val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL)
vaultService.trackBy<Cash.State>(criteria).updates
}
val (linearStates, dealStates) =
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 5, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
@ -1948,17 +1929,17 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates)
}
database.transaction {
this.session.flush()
// consume stuff
consumeCash(99.POUNDS)
}
database.transaction {
// consume more stuff
consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList())
close() // transaction needs to be closed to trigger events
updates
}
updates.expectEvents {
@ -1989,16 +1970,13 @@ class VaultQueryTests {
@Test
fun trackLinearStates() {
val updates =
database.transaction {
val updates = database.transaction {
// DOCSTART VaultQueryExample16
val (snapshot, updates) = vaultService.trackBy<LinearState>()
// DOCEND VaultQueryExample16
assertThat(snapshot.states).hasSize(0)
updates
}
val (linearStates, dealStates) =
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
@ -2006,13 +1984,15 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates)
}
database.transaction {
this.session.flush()
// consume stuff
consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList())
close() // transaction needs to be closed to trigger events
updates
}
updates.expectEvents {
@ -2038,16 +2018,14 @@ class VaultQueryTests {
@Test
fun trackDealStates() {
val updates =
database.transaction {
val updates = database.transaction {
// DOCSTART VaultQueryExample17
val (snapshot, updates) = vaultService.trackBy<DealState>()
// DOCEND VaultQueryExample17
assertThat(snapshot.states).hasSize(0)
updates
}
val (linearStates, dealStates) =
database.transaction {
vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 3, DUMMY_CASH_ISSUER)
val linearStates = vaultFiller.fillWithSomeTestLinearStates(10).states
val dealStates = vaultFiller.fillWithSomeTestDeals(listOf("123", "456", "789")).states
@ -2055,13 +2033,15 @@ class VaultQueryTests {
vaultFiller.fillWithSomeTestCash(100.POUNDS, notaryServices, 1, DUMMY_CASH_ISSUER)
// add another deal
vaultFiller.fillWithSomeTestDeals(listOf("SAMPLE DEAL"))
Pair(linearStates, dealStates)
}
database.transaction {
this.session.flush()
// consume stuff
consumeCash(100.DOLLARS)
vaultFiller.consumeDeals(dealStates.toList())
vaultFiller.consumeLinearStates(linearStates.toList())
close()
updates
}
updates.expectEvents {
@ -2084,8 +2064,8 @@ class VaultQueryTests {
fun `unconsumedCashStatesForSpending_single_issuer_reference`() {
database.transaction {
vaultFiller.fillWithSomeTestCash(1000.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
}
database.transaction {
this.session.flush()
val builder = TransactionBuilder()
val issuer = DUMMY_CASH_ISSUER
val exitStates = AbstractCashSelection
@ -2102,8 +2082,7 @@ class VaultQueryTests {
fun `unconsumedCashStatesForSpending_single_issuer_reference_not_matching`() {
database.transaction {
vaultFiller.fillWithSomeTestCash(1000.DOLLARS, notaryServices, 1, DUMMY_CASH_ISSUER)
}
database.transaction {
val builder = TransactionBuilder()
val issuer = DUMMY_CASH_ISSUER
val exitStates = AbstractCashSelection