ENT-10122: Added annotation for backwards compatibility and added test.

This commit is contained in:
Adel El-Beik 2023-08-01 15:11:21 +01:00
parent 117d319317
commit c614b21a2a
2 changed files with 43 additions and 1 deletions

View File

@ -37,6 +37,7 @@ import net.corda.core.node.services.vault.PageSpecification
import net.corda.core.node.services.vault.QueryCriteria import net.corda.core.node.services.vault.QueryCriteria
import net.corda.core.node.services.vault.Sort import net.corda.core.node.services.vault.Sort
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.DeprecatedConstructorForDeserialization
import net.corda.core.toFuture import net.corda.core.toFuture
import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.LedgerTransaction
import net.corda.core.utilities.NonEmptySet import net.corda.core.utilities.NonEmptySet
@ -81,6 +82,7 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
val references: Set<StateAndRef<U>> = emptySet(), val references: Set<StateAndRef<U>> = emptySet(),
val consumingTxIds: Map<StateRef, SecureHash> = emptyMap() val consumingTxIds: Map<StateRef, SecureHash> = emptyMap()
) { ) {
@DeprecatedConstructorForDeserialization(1)
@JvmOverloads constructor( consumed: Set<StateAndRef<U>>, @JvmOverloads constructor( consumed: Set<StateAndRef<U>>,
produced: Set<StateAndRef<U>>, produced: Set<StateAndRef<U>>,
flowId: UUID? = null, flowId: UUID? = null,
@ -151,7 +153,7 @@ class Vault<out T : ContractState>(val states: Iterable<StateAndRef<T>>) {
flowId: UUID? = null, flowId: UUID? = null,
type: UpdateType = UpdateType.GENERAL type: UpdateType = UpdateType.GENERAL
): Update<U> { ): Update<U> {
return Update(consumed, produced, flowId, type, references) return Update(consumed, produced, flowId, type, references, consumingTxIds)
} }
/** Additional copy method to maintain backwards compatibility. */ /** Additional copy method to maintain backwards compatibility. */

View File

@ -1,10 +1,16 @@
package net.corda.node package net.corda.node
import net.corda.core.messaging.startFlow import net.corda.core.messaging.startFlow
import net.corda.core.messaging.vaultTrackBy
import net.corda.core.node.services.Vault
import net.corda.core.node.services.vault.DEFAULT_PAGE_NUM
import net.corda.core.node.services.vault.PageSpecification
import net.corda.core.node.services.vault.QueryCriteria
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.core.utilities.loggerFor import net.corda.core.utilities.loggerFor
import net.corda.finance.DOLLARS import net.corda.finance.DOLLARS
import net.corda.finance.contracts.asset.Cash
import net.corda.finance.flows.CashIssueAndPaymentFlow import net.corda.finance.flows.CashIssueAndPaymentFlow
import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.NodeConfiguration
import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.ALICE_NAME
@ -17,6 +23,8 @@ import net.corda.testing.node.NotarySpec
import net.corda.testing.node.internal.findCordapp import net.corda.testing.node.internal.findCordapp
import org.junit.Test import org.junit.Test
import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertDoesNotThrow
import java.util.concurrent.CountDownLatch
import kotlin.test.assertEquals
/** /**
* Execute a flow with sub-flows, including the finality flow. * Execute a flow with sub-flows, including the finality flow.
@ -65,4 +73,36 @@ class CashIssueAndPaymentTest {
logger.info("TXN={}, recipient={}", result.stx, result.recipient) logger.info("TXN={}, recipient={}", result.stx, result.recipient)
} }
} }
@Test(timeout = 300_000)
fun `test can issue cash and see consumming transaction id in rpc client`() {
driver(parametersFor()) {
val alice = startNode(providedName = ALICE_NAME, customOverrides = configOverrides).getOrThrow()
val aliceParty = alice.nodeInfo.singleIdentity()
val notaryParty = notaryHandles.single().identity
val result = assertDoesNotThrow {
val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.CONSUMED)
val (vault, vaultUpdates) = alice.rpc.vaultTrackBy<Cash.State>(criteria = criteria, paging = PageSpecification(DEFAULT_PAGE_NUM))
val updateLatch = CountDownLatch(1)
vaultUpdates.subscribe { update ->
val consumedRef = update.consumed.single().ref
assertEquals( update.produced.single().ref.txhash, update.consumingTxIds[consumedRef] )
updateLatch.countDown()
}
val flowRet = alice.rpc.startFlow(::CashIssueAndPaymentFlow,
CASH_AMOUNT,
OpaqueBytes.of(0x01),
aliceParty,
false,
notaryParty
).use { flowHandle ->
flowHandle.returnValue.getOrThrow()
}
updateLatch.await()
flowRet
}
logger.info("TXN={}, recipient={}", result.stx, result.recipient)
}
}
} }