ENT-10122: Updated tests to include consuming transaction id in the Vault.Update check.

This commit is contained in:
Adel El-Beik 2023-07-19 16:36:39 +01:00
parent 60bb4c58f2
commit aa9e41c7c2
2 changed files with 9 additions and 4 deletions

View File

@ -119,7 +119,7 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
val combinedProduced = produced.filter { it !in rhs.consumed }.toSet() + rhs.produced
return copy(consumed = combinedConsumed, produced = combinedProduced, references = references + rhs.references, consumingTxIds = consumingTxIds + rhs.consumingTxIds)
}
//val consumingTxIds: Map<StateRef, SecureHash> = emptyMap()
override fun toString(): String {
val sb = StringBuilder()
sb.appendln("${consumed.size} consumed, ${produced.size} produced")
@ -137,6 +137,10 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
references.forEach {
sb.appendln("${it.ref}: ${it.state}")
}
sb.appendln("Consuming TxIds:")
consumingTxIds.forEach {
sb.appendln("${it.key}: ${it.value}")
}
return sb.toString()
}

View File

@ -664,14 +664,15 @@ class NodeVaultServiceTest {
database.transaction { vaultService.notify(StatesToRecord.ONLY_RELEVANT, issueTx) }
val expectedIssueUpdate = Vault.Update(emptySet(), setOf(cashState), null)
database.transaction {
val moveTx = database.transaction {
val moveBuilder = TransactionBuilder(notary).apply {
CashUtils.generateSpend(services, this, Amount(1000, GBP), identity, thirdPartyIdentity)
}
val moveTx = moveBuilder.toWireTransaction(services)
vaultService.notify(StatesToRecord.ONLY_RELEVANT, moveTx)
moveTx
}
val expectedMoveUpdate = Vault.Update(setOf(cashState), emptySet(), null)
val expectedMoveUpdate = Vault.Update(setOf(cashState), emptySet(), null, consumingTxIds = mapOf(cashState.ref to moveTx.id))
// ensure transaction contract state is persisted in DBStorage
val signedMoveTx = services.signInitialTransaction(issueBuilder)
@ -740,7 +741,7 @@ class NodeVaultServiceTest {
val expectedIssueUpdate = Vault.Update(emptySet(), setOf(initialCashState), null)
val expectedNotaryChangeUpdate = Vault.Update(setOf(initialCashState), setOf(cashStateWithNewNotary), null, Vault.UpdateType.NOTARY_CHANGE)
val expectedMoveUpdate = Vault.Update(setOf(cashStateWithNewNotary), emptySet(), null)
val expectedMoveUpdate = Vault.Update(setOf(cashStateWithNewNotary), emptySet(), null, consumingTxIds = mapOf(cashStateWithNewNotary.ref to moveTx.id))
val observedUpdates = vaultSubscriber.onNextEvents
assertEquals(observedUpdates, listOf(expectedIssueUpdate, expectedNotaryChangeUpdate, expectedMoveUpdate))