mirror of
https://github.com/corda/corda.git
synced 2025-06-15 13:48:14 +00:00
[CORDA-1262]: Added integration test for Cash Selection. (#2874)
This commit is contained in:
committed by
GitHub
parent
7978910e0b
commit
36d403dd7d
@ -0,0 +1,43 @@
|
|||||||
|
package net.corda.finance.flows
|
||||||
|
|
||||||
|
import net.corda.core.internal.packageName
|
||||||
|
import net.corda.core.messaging.startFlow
|
||||||
|
import net.corda.core.utilities.OpaqueBytes
|
||||||
|
import net.corda.core.utilities.getOrThrow
|
||||||
|
import net.corda.finance.DOLLARS
|
||||||
|
import net.corda.finance.contracts.asset.Cash
|
||||||
|
import net.corda.finance.contracts.getCashBalance
|
||||||
|
import net.corda.finance.schemas.CashSchemaV1
|
||||||
|
import net.corda.testing.driver.DriverParameters
|
||||||
|
import net.corda.testing.driver.driver
|
||||||
|
import net.corda.testing.driver.internal.InProcessImpl
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class CashSelectionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun unconsumed_cash_states() {
|
||||||
|
|
||||||
|
driver(DriverParameters(startNodesInProcess = true, extraCordappPackagesToScan = listOf(Cash::class, CashSchemaV1::class).map { it.packageName })) {
|
||||||
|
|
||||||
|
defaultNotaryNode.getOrThrow()
|
||||||
|
val node = startNode().getOrThrow() as InProcessImpl
|
||||||
|
val issuerRef = OpaqueBytes.of(0)
|
||||||
|
val issuedAmount = 1000.DOLLARS
|
||||||
|
|
||||||
|
node.rpc.startFlow(::CashIssueFlow, issuedAmount, issuerRef, defaultNotaryIdentity).returnValue.getOrThrow()
|
||||||
|
|
||||||
|
val availableBalance = node.rpc.getCashBalance(issuedAmount.token)
|
||||||
|
|
||||||
|
assertThat(availableBalance).isEqualTo(issuedAmount)
|
||||||
|
|
||||||
|
val exitedAmount = 300.DOLLARS
|
||||||
|
node.rpc.startFlow(::CashExitFlow, exitedAmount, issuerRef).returnValue.getOrThrow()
|
||||||
|
|
||||||
|
val availableBalanceAfterExit = node.rpc.getCashBalance(issuedAmount.token)
|
||||||
|
|
||||||
|
assertThat(availableBalanceAfterExit).isEqualTo(issuedAmount - exitedAmount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -60,7 +60,7 @@ abstract class AbstractCashSelection {
|
|||||||
* loaded JDBC driver.
|
* loaded JDBC driver.
|
||||||
* Note: the first loaded implementation to pass this check will be used at run-time.
|
* Note: the first loaded implementation to pass this check will be used at run-time.
|
||||||
*/
|
*/
|
||||||
abstract fun isCompatible(metadata: DatabaseMetaData): Boolean
|
protected abstract fun isCompatible(metadata: DatabaseMetaData): Boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A vendor specific query(ies) to gather Cash states that are available.
|
* A vendor specific query(ies) to gather Cash states that are available.
|
||||||
@ -76,10 +76,10 @@ abstract class AbstractCashSelection {
|
|||||||
* otherwise what is available is returned unlocked for informational purposes.
|
* otherwise what is available is returned unlocked for informational purposes.
|
||||||
* @return The result of the withResultSet function
|
* @return The result of the withResultSet function
|
||||||
*/
|
*/
|
||||||
abstract fun executeQuery(connection: Connection, amount: Amount<Currency>, lockId: UUID, notary: Party?,
|
protected abstract fun executeQuery(connection: Connection, amount: Amount<Currency>, lockId: UUID, notary: Party?,
|
||||||
onlyFromIssuerParties: Set<AbstractParty>, withIssuerRefs: Set<OpaqueBytes>, withResultSet: (ResultSet) -> Boolean): Boolean
|
onlyFromIssuerParties: Set<AbstractParty>, withIssuerRefs: Set<OpaqueBytes>, withResultSet: (ResultSet) -> Boolean): Boolean
|
||||||
|
|
||||||
override abstract fun toString(): String
|
abstract override fun toString(): String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query to gather Cash states that are available and retry if they are temporarily unavailable.
|
* Query to gather Cash states that are available and retry if they are temporarily unavailable.
|
||||||
|
@ -34,6 +34,7 @@ class TraderDemoTest {
|
|||||||
startFlow<CommercialPaperIssueFlow>(),
|
startFlow<CommercialPaperIssueFlow>(),
|
||||||
all()))
|
all()))
|
||||||
driver(DriverParameters(startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.finance"))) {
|
driver(DriverParameters(startNodesInProcess = true, extraCordappPackagesToScan = listOf("net.corda.finance"))) {
|
||||||
|
defaultNotaryNode.getOrThrow()
|
||||||
val (nodeA, nodeB, bankNode) = listOf(
|
val (nodeA, nodeB, bankNode) = listOf(
|
||||||
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = listOf(demoUser)),
|
startNode(providedName = DUMMY_BANK_A_NAME, rpcUsers = listOf(demoUser)),
|
||||||
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = listOf(demoUser)),
|
startNode(providedName = DUMMY_BANK_B_NAME, rpcUsers = listOf(demoUser)),
|
||||||
|
Reference in New Issue
Block a user