Remove Pt prefix for classes in perftestcordapp

This commit is contained in:
Christian Sailer 2017-10-17 13:48:20 +01:00
parent f25c15b194
commit 9a145a710a
22 changed files with 325 additions and 325 deletions

View File

@ -1,4 +1,4 @@
@file:JvmName("PtCurrencies") @file:JvmName("Currencies")
package com.r3.corda.enterprise.perftestcordapp package com.r3.corda.enterprise.perftestcordapp

View File

@ -15,8 +15,8 @@ import net.corda.core.schemas.PersistentState
import net.corda.core.schemas.QueryableState import net.corda.core.schemas.QueryableState
import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.schemas.PtCommercialPaperSchemaV1 import com.r3.corda.enterprise.perftestcordapp.schemas.CommercialPaperSchemaV1
import com.r3.corda.enterprise.perftestcordapp.utils.sumCashBy import com.r3.corda.enterprise.perftestcordapp.utils.sumCashBy
import java.time.Instant import java.time.Instant
import java.util.* import java.util.*
@ -43,12 +43,12 @@ import java.util.*
* to do this in the Apache BVal project). * to do this in the Apache BVal project).
*/ */
val CP_PROGRAM_ID = "com.r3.corda.enterprise.perftestcordapp.contracts.PtCommercialPaper" val CP_PROGRAM_ID = "com.r3.corda.enterprise.perftestcordapp.contracts.CommercialPaper"
// TODO: Generalise the notion of an owned instrument into a superclass/supercontract. Consider composition vs inheritance. // TODO: Generalise the notion of an owned instrument into a superclass/supercontract. Consider composition vs inheritance.
class PtCommercialPaper : Contract { class CommercialPaper : Contract {
companion object { companion object {
const val CP_PROGRAM_ID: ContractClassName = "com.r3.corda.enterprise.perftestcordapp.contracts.PtCommercialPaper" const val CP_PROGRAM_ID: ContractClassName = "com.r3.corda.enterprise.perftestcordapp.contracts.CommercialPaper"
} }
data class State( data class State(
val issuance: PartyAndReference, val issuance: PartyAndReference,
@ -69,13 +69,13 @@ class PtCommercialPaper : Contract {
fun withMaturityDate(newMaturityDate: Instant): State = copy(maturityDate = newMaturityDate) fun withMaturityDate(newMaturityDate: Instant): State = copy(maturityDate = newMaturityDate)
/** Object Relational Mapping support. */ /** Object Relational Mapping support. */
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(PtCommercialPaperSchemaV1) override fun supportedSchemas(): Iterable<MappedSchema> = listOf(CommercialPaperSchemaV1)
/** Additional used schemas would be added here (eg. CommercialPaperV2, ...) */ /** Additional used schemas would be added here (eg. CommercialPaperV2, ...) */
/** Object Relational Mapping support. */ /** Object Relational Mapping support. */
override fun generateMappedObject(schema: MappedSchema): PersistentState { override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) { return when (schema) {
is PtCommercialPaperSchemaV1 -> PtCommercialPaperSchemaV1.PersistentCommercialPaperState( is CommercialPaperSchemaV1 -> CommercialPaperSchemaV1.PersistentCommercialPaperState(
issuanceParty = this.issuance.party.owningKey.toBase58String(), issuanceParty = this.issuance.party.owningKey.toBase58String(),
issuanceRef = this.issuance.reference.bytes, issuanceRef = this.issuance.reference.bytes,
owner = this.owner.owningKey.toBase58String(), owner = this.owner.owningKey.toBase58String(),
@ -108,7 +108,7 @@ class PtCommercialPaper : Contract {
// There are two possible things that can be done with this CP. The first is trading it. The second is redeeming // There are two possible things that can be done with this CP. The first is trading it. The second is redeeming
// it for cash on or after the maturity date. // it for cash on or after the maturity date.
val command = tx.commands.requireSingleCommand<PtCommercialPaper.Commands>() val command = tx.commands.requireSingleCommand<CommercialPaper.Commands>()
val timeWindow: TimeWindow? = tx.timeWindow val timeWindow: TimeWindow? = tx.timeWindow
// Suppress compiler warning as 'key' is an unused variable when destructuring 'groups'. // Suppress compiler warning as 'key' is an unused variable when destructuring 'groups'.
@ -190,7 +190,7 @@ class PtCommercialPaper : Contract {
@Suspendable @Suspendable
fun generateRedeem(tx: TransactionBuilder, paper: StateAndRef<State>, services: ServiceHub, ourIdentity: PartyAndCertificate) { fun generateRedeem(tx: TransactionBuilder, paper: StateAndRef<State>, services: ServiceHub, ourIdentity: PartyAndCertificate) {
// Add the cash movement using the states in our vault. // Add the cash movement using the states in our vault.
PtCash.generateSpend(services, tx, paper.state.data.faceValue.withoutIssuer(), ourIdentity, paper.state.data.owner) Cash.generateSpend(services, tx, paper.state.data.faceValue.withoutIssuer(), ourIdentity, paper.state.data.owner)
tx.addInputState(paper) tx.addInputState(paper)
tx.addCommand(Commands.Redeem(), paper.state.data.owner.owningKey) tx.addCommand(Commands.Redeem(), paper.state.data.owner.owningKey)
} }

View File

@ -19,7 +19,7 @@ import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.toBase58String import net.corda.core.utilities.toBase58String
import com.r3.corda.enterprise.perftestcordapp.schemas.PtCashSchemaV1 import com.r3.corda.enterprise.perftestcordapp.schemas.CashSchemaV1
import com.r3.corda.enterprise.perftestcordapp.utils.sumCash import com.r3.corda.enterprise.perftestcordapp.utils.sumCash
import com.r3.corda.enterprise.perftestcordapp.utils.sumCashOrNull import com.r3.corda.enterprise.perftestcordapp.utils.sumCashOrNull
import com.r3.corda.enterprise.perftestcordapp.utils.sumCashOrZero import com.r3.corda.enterprise.perftestcordapp.utils.sumCashOrZero
@ -40,20 +40,20 @@ import java.util.concurrent.atomic.AtomicReference
* Custom implementations must implement this interface and declare their implementation in * Custom implementations must implement this interface and declare their implementation in
* META-INF/services/net.corda.contracts.asset.CashSelection * META-INF/services/net.corda.contracts.asset.CashSelection
*/ */
interface PtCashSelection { interface CashSelection {
companion object { companion object {
val instance = AtomicReference<PtCashSelection>() val instance = AtomicReference<CashSelection>()
fun getInstance(metadata: () -> java.sql.DatabaseMetaData): PtCashSelection { fun getInstance(metadata: () -> java.sql.DatabaseMetaData): CashSelection {
return instance.get() ?: { return instance.get() ?: {
val _metadata = metadata() val _metadata = metadata()
val cashSelectionAlgos = ServiceLoader.load(PtCashSelection::class.java).toList() val cashSelectionAlgos = ServiceLoader.load(CashSelection::class.java).toList()
val cashSelectionAlgo = cashSelectionAlgos.firstOrNull { it.isCompatible(_metadata) } val cashSelectionAlgo = cashSelectionAlgos.firstOrNull { it.isCompatible(_metadata) }
cashSelectionAlgo?.let { cashSelectionAlgo?.let {
instance.set(cashSelectionAlgo) instance.set(cashSelectionAlgo)
cashSelectionAlgo cashSelectionAlgo
} ?: throw ClassNotFoundException("\nUnable to load compatible cash selection algorithm implementation for JDBC driver ($_metadata)." + } ?: throw ClassNotFoundException("\nUnable to load compatible cash selection algorithm implementation for JDBC driver ($_metadata)." +
"\nPlease specify an implementation in META-INF/services/com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCashSelection") "\nPlease specify an implementation in META-INF/services/com.r3.corda.enterprise.perftestcordapp.contracts.asset.CashSelection")
}.invoke() }.invoke()
} }
} }
@ -86,7 +86,7 @@ interface PtCashSelection {
onlyFromIssuerParties: Set<AbstractParty> = emptySet(), onlyFromIssuerParties: Set<AbstractParty> = emptySet(),
notary: Party? = null, notary: Party? = null,
lockId: UUID, lockId: UUID,
withIssuerRefs: Set<OpaqueBytes> = emptySet()): List<StateAndRef<PtCash.State>> withIssuerRefs: Set<OpaqueBytes> = emptySet()): List<StateAndRef<Cash.State>>
} }
/** /**
@ -102,7 +102,7 @@ interface PtCashSelection {
* At the same time, other contracts that just want money and don't care much who is currently holding it in their * At the same time, other contracts that just want money and don't care much who is currently holding it in their
* vaults can ignore the issuer/depositRefs and just examine the amount fields. * vaults can ignore the issuer/depositRefs and just examine the amount fields.
*/ */
class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() { class Cash : OnLedgerAsset<Currency, Cash.Commands, Cash.State>() {
override fun extractCommands(commands: Collection<CommandWithParties<CommandData>>): List<CommandWithParties<Commands>> override fun extractCommands(commands: Collection<CommandWithParties<CommandData>>): List<CommandWithParties<Commands>>
= commands.select<Commands>() = commands.select<Commands>()
@ -134,7 +134,7 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
/** Object Relational Mapping support. */ /** Object Relational Mapping support. */
override fun generateMappedObject(schema: MappedSchema): PersistentState { override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) { return when (schema) {
is PtCashSchemaV1 -> PtCashSchemaV1.PersistentCashState( is CashSchemaV1 -> CashSchemaV1.PersistentCashState(
owner = this.owner, owner = this.owner,
pennies = this.amount.quantity, pennies = this.amount.quantity,
currency = this.amount.token.product.currencyCode, currency = this.amount.token.product.currencyCode,
@ -147,7 +147,7 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
} }
/** Object Relational Mapping support. */ /** Object Relational Mapping support. */
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(PtCashSchemaV1) override fun supportedSchemas(): Iterable<MappedSchema> = listOf(CashSchemaV1)
/** Additional used schemas would be added here (eg. CashSchemaV2, CashSchemaV3, ...) */ /** Additional used schemas would be added here (eg. CashSchemaV2, CashSchemaV3, ...) */
} }
// DOCEND 1 // DOCEND 1
@ -261,7 +261,7 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
} }
companion object { companion object {
const val PROGRAM_ID: ContractClassName = "com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash" const val PROGRAM_ID: ContractClassName = "com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash"
/** /**
* Generate a transaction that moves an amount of currency to the given party, and sends any change back to * Generate a transaction that moves an amount of currency to the given party, and sends any change back to
@ -381,27 +381,27 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
// Retrieve unspent and unlocked cash states that meet our spending criteria. // Retrieve unspent and unlocked cash states that meet our spending criteria.
val totalAmount = payments.map { it.amount }.sumOrThrow() val totalAmount = payments.map { it.amount }.sumOrThrow()
val cashSelection = PtCashSelection.getInstance({ services.jdbcSession().metaData }) val cashSelection = CashSelection.getInstance({ services.jdbcSession().metaData })
val acceptableCoins = cashSelection.unconsumedCashStatesForSpending(services, totalAmount, onlyFromParties, tx.notary, tx.lockId) val acceptableCoins = cashSelection.unconsumedCashStatesForSpending(services, totalAmount, onlyFromParties, tx.notary, tx.lockId)
val revocationEnabled = false // Revocation is currently unsupported val revocationEnabled = false // Revocation is currently unsupported
// Generate a new identity that change will be sent to for confidentiality purposes. This means that a // Generate a new identity that change will be sent to for confidentiality purposes. This means that a
// third party with a copy of the transaction (such as the notary) cannot identify who the change was // third party with a copy of the transaction (such as the notary) cannot identify who the change was
// sent to // sent to
val changeIdentity = services.keyManagementService.freshKeyAndCert(ourIdentity, revocationEnabled) val changeIdentity = services.keyManagementService.freshKeyAndCert(ourIdentity, revocationEnabled)
return PtOnLedgerAsset.generateSpend(tx, payments, acceptableCoins, return OnLedgerAsset.generateSpend(tx, payments, acceptableCoins,
changeIdentity.party.anonymise(), changeIdentity.party.anonymise(),
{ state, quantity, owner -> deriveState(state, quantity, owner) }, { state, quantity, owner -> deriveState(state, quantity, owner) },
{ PtCash().generateMoveCommand() }) { Cash().generateMoveCommand() })
} }
} }
} }
// Small DSL extensions. // Small DSL extensions.
/** @suppress */ infix fun PtCash.State.`owned by`(owner: AbstractParty) = ownedBy(owner) /** @suppress */ infix fun Cash.State.`owned by`(owner: AbstractParty) = ownedBy(owner)
/** @suppress */ infix fun PtCash.State.`issued by`(party: AbstractParty) = issuedBy(party) /** @suppress */ infix fun Cash.State.`issued by`(party: AbstractParty) = issuedBy(party)
/** @suppress */ infix fun PtCash.State.`issued by`(deposit: PartyAndReference) = issuedBy(deposit) /** @suppress */ infix fun Cash.State.`issued by`(deposit: PartyAndReference) = issuedBy(deposit)
/** @suppress */ infix fun PtCash.State.`with deposit`(deposit: PartyAndReference): PtCash.State = withDeposit(deposit) /** @suppress */ infix fun Cash.State.`with deposit`(deposit: PartyAndReference): Cash.State = withDeposit(deposit)
// Unit testing helpers. These could go in a separate file but it's hardly worth it for just a few functions. // Unit testing helpers. These could go in a separate file but it's hardly worth it for just a few functions.
@ -410,6 +410,6 @@ val DUMMY_CASH_ISSUER_KEY by lazy { entropyToKeyPair(BigInteger.valueOf(10)) }
/** A dummy, randomly generated issuer party by the name of "Snake Oil Issuer" */ /** A dummy, randomly generated issuer party by the name of "Snake Oil Issuer" */
val DUMMY_CASH_ISSUER by lazy { Party(CordaX500Name(organisation = "Snake Oil Issuer", locality = "London", country = "GB"), DUMMY_CASH_ISSUER_KEY.public).ref(1) } val DUMMY_CASH_ISSUER by lazy { Party(CordaX500Name(organisation = "Snake Oil Issuer", locality = "London", country = "GB"), DUMMY_CASH_ISSUER_KEY.public).ref(1) }
/** An extension property that lets you write 100.DOLLARS.CASH */ /** An extension property that lets you write 100.DOLLARS.CASH */
val Amount<Currency>.CASH: PtCash.State get() = PtCash.State(Amount(quantity, Issued(DUMMY_CASH_ISSUER, token)), NULL_PARTY) val Amount<Currency>.CASH: Cash.State get() = Cash.State(Amount(quantity, Issued(DUMMY_CASH_ISSUER, token)), NULL_PARTY)
/** An extension property that lets you get a cash state from an issued token, under the [NULL_PARTY] */ /** An extension property that lets you get a cash state from an issued token, under the [NULL_PARTY] */
val Amount<Issued<Currency>>.STATE: PtCash.State get() = PtCash.State(this, NULL_PARTY) val Amount<Issued<Currency>>.STATE: Cash.State get() = Cash.State(this, NULL_PARTY)

View File

@ -31,9 +31,9 @@ data class PartyAndAmount<T : Any>(val party: AbstractParty, val amount: Amount<
* At the same time, other contracts that just want assets and don't care much who is currently holding it can ignore * At the same time, other contracts that just want assets and don't care much who is currently holding it can ignore
* the issuer/depositRefs and just examine the amount fields. * the issuer/depositRefs and just examine the amount fields.
*/ */
abstract class PtOnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : Contract { abstract class OnLedgerAsset<T : Any, C : CommandData, S : FungibleAsset<T>> : Contract {
companion object { companion object {
val log = loggerFor<PtOnLedgerAsset<*, *, *>>() val log = loggerFor<OnLedgerAsset<*, *, *>>()
/** /**
* Generate a transaction that moves an amount of currency to the given pubkey. * Generate a transaction that moves an amount of currency to the given pubkey.

View File

@ -3,8 +3,8 @@ package com.r3.corda.enterprise.perftestcordapp.contracts.asset.cash.selection
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.strands.Strand import co.paralleluniverse.strands.Strand
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCashSelection import com.r3.corda.enterprise.perftestcordapp.contracts.asset.CashSelection
import net.corda.core.contracts.Amount 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
@ -23,11 +23,11 @@ import java.util.*
import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock import kotlin.concurrent.withLock
class PtCashSelectionH2Impl : PtCashSelection { class CashSelectionH2Impl : CashSelection {
companion object { companion object {
const val JDBC_DRIVER_NAME = "H2 JDBC Driver" const val JDBC_DRIVER_NAME = "H2 JDBC Driver"
val log = loggerFor<PtCashSelectionH2Impl>() val log = loggerFor<CashSelectionH2Impl>()
} }
override fun isCompatible(metadata: DatabaseMetaData): Boolean { override fun isCompatible(metadata: DatabaseMetaData): Boolean {
@ -59,12 +59,12 @@ class PtCashSelectionH2Impl : PtCashSelection {
onlyFromIssuerParties: Set<AbstractParty>, onlyFromIssuerParties: Set<AbstractParty>,
notary: Party?, notary: Party?,
lockId: UUID, lockId: UUID,
withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<PtCash.State>> { withIssuerRefs: Set<OpaqueBytes>): List<StateAndRef<Cash.State>> {
val issuerKeysStr = onlyFromIssuerParties.fold("") { left, right -> left + "('${right.owningKey.toBase58String()}')," }.dropLast(1) val issuerKeysStr = onlyFromIssuerParties.fold("") { left, right -> left + "('${right.owningKey.toBase58String()}')," }.dropLast(1)
val issuerRefsStr = withIssuerRefs.fold("") { left, right -> left + "('${right.bytes.toHexString()}')," }.dropLast(1) val issuerRefsStr = withIssuerRefs.fold("") { left, right -> left + "('${right.bytes.toHexString()}')," }.dropLast(1)
val stateAndRefs = mutableListOf<StateAndRef<PtCash.State>>() val stateAndRefs = mutableListOf<StateAndRef<Cash.State>>()
// We are using an H2 specific means of selecting a minimum set of rows that match a request amount of coins: // We are using an H2 specific means of selecting a minimum set of rows that match a request amount of coins:
// 1) There is no standard SQL mechanism of calculating a cumulative total on a field and restricting row selection on the // 1) There is no standard SQL mechanism of calculating a cumulative total on a field and restricting row selection on the
@ -106,7 +106,7 @@ class PtCashSelectionH2Impl : PtCashSelection {
val txHash = SecureHash.parse(rs.getString(1)) val txHash = SecureHash.parse(rs.getString(1))
val index = rs.getInt(2) val index = rs.getInt(2)
val stateRef = StateRef(txHash, index) val stateRef = StateRef(txHash, index)
val state = rs.getBytes(3).deserialize<TransactionState<PtCash.State>>(context = SerializationDefaults.STORAGE_CONTEXT) val state = rs.getBytes(3).deserialize<TransactionState<Cash.State>>(context = SerializationDefaults.STORAGE_CONTEXT)
val pennies = rs.getLong(4) val pennies = rs.getLong(4)
totalPennies = rs.getLong(5) totalPennies = rs.getLong(5)
val rowLockId = rs.getString(6) val rowLockId = rs.getString(6)

View File

@ -16,7 +16,7 @@ import java.util.*
/** /**
* Initiates a flow that produces an Issue/Move or Exit Cash transaction. * Initiates a flow that produces an Issue/Move or Exit Cash transaction.
*/ */
abstract class AbstractPtCashFlow<out T>(override val progressTracker: ProgressTracker) : FlowLogic<T>() { abstract class AbstractCashFlow<out T>(override val progressTracker: ProgressTracker) : FlowLogic<T>() {
companion object { companion object {
object GENERATING_ID : ProgressTracker.Step("Generating anonymous identities") object GENERATING_ID : ProgressTracker.Step("Generating anonymous identities")
object GENERATING_TX : ProgressTracker.Step("Generating transaction") object GENERATING_TX : ProgressTracker.Step("Generating transaction")

View File

@ -15,7 +15,7 @@ import java.util.*
* Flow to obtain cash cordapp app configuration. * Flow to obtain cash cordapp app configuration.
*/ */
@StartableByRPC @StartableByRPC
class PtCashConfigDataFlow : FlowLogic<PtCashConfiguration>() { class CashConfigDataFlow : FlowLogic<PtCashConfiguration>() {
companion object { companion object {
private val supportedCurrencies = listOf(USD, GBP, CHF, EUR) private val supportedCurrencies = listOf(USD, GBP, CHF, EUR)
} }

View File

@ -13,8 +13,8 @@ import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCashSelection import com.r3.corda.enterprise.perftestcordapp.contracts.asset.CashSelection
import com.r3.corda.enterprise.perftestcordapp.issuedBy import com.r3.corda.enterprise.perftestcordapp.issuedBy
import java.util.* import java.util.*
@ -26,9 +26,9 @@ import java.util.*
* issuer. * issuer.
*/ */
@StartableByRPC @StartableByRPC
class PtCashExitFlow(private val amount: Amount<Currency>, class CashExitFlow(private val amount: Amount<Currency>,
private val issuerRef: OpaqueBytes, private val issuerRef: OpaqueBytes,
progressTracker: ProgressTracker) : AbstractPtCashFlow<AbstractPtCashFlow.Result>(progressTracker) { progressTracker: ProgressTracker) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
constructor(amount: Amount<Currency>, issueRef: OpaqueBytes) : this(amount, issueRef, tracker()) constructor(amount: Amount<Currency>, issueRef: OpaqueBytes) : this(amount, issueRef, tracker())
constructor(request: ExitRequest) : this(request.amount, request.issueRef, tracker()) constructor(request: ExitRequest) : this(request.amount, request.issueRef, tracker())
@ -42,15 +42,15 @@ class PtCashExitFlow(private val amount: Amount<Currency>,
*/ */
@Suspendable @Suspendable
@Throws(PtCashException::class) @Throws(PtCashException::class)
override fun call(): AbstractPtCashFlow.Result { override fun call(): AbstractCashFlow.Result {
progressTracker.currentStep = GENERATING_TX progressTracker.currentStep = GENERATING_TX
val builder = TransactionBuilder(notary = null) val builder = TransactionBuilder(notary = null)
val issuer = ourIdentity.ref(issuerRef) val issuer = ourIdentity.ref(issuerRef)
val exitStates = PtCashSelection val exitStates = CashSelection
.getInstance { serviceHub.jdbcSession().metaData } .getInstance { serviceHub.jdbcSession().metaData }
.unconsumedCashStatesForSpending(serviceHub, amount, setOf(issuer.party), builder.notary, builder.lockId, setOf(issuer.reference)) .unconsumedCashStatesForSpending(serviceHub, amount, setOf(issuer.party), builder.notary, builder.lockId, setOf(issuer.reference))
val signers = try { val signers = try {
PtCash().generateExit( Cash().generateExit(
builder, builder,
amount.issuedBy(issuer), amount.issuedBy(issuer),
exitStates) exitStates)
@ -59,7 +59,7 @@ class PtCashExitFlow(private val amount: Amount<Currency>,
} }
// Work out who the owners of the burnt states were (specify page size so we don't silently drop any if > DEFAULT_PAGE_SIZE) // Work out who the owners of the burnt states were (specify page size so we don't silently drop any if > DEFAULT_PAGE_SIZE)
val inputStates = serviceHub.vaultQueryService.queryBy<PtCash.State>(VaultQueryCriteria(stateRefs = builder.inputStates()), val inputStates = serviceHub.vaultQueryService.queryBy<Cash.State>(VaultQueryCriteria(stateRefs = builder.inputStates()),
PageSpecification(pageNumber = DEFAULT_PAGE_NUM, pageSize = builder.inputStates().size)).states PageSpecification(pageNumber = DEFAULT_PAGE_NUM, pageSize = builder.inputStates().size)).states
// TODO: Is it safe to drop participants we don't know how to contact? Does not knowing how to contact them // TODO: Is it safe to drop participants we don't know how to contact? Does not knowing how to contact them

View File

@ -21,12 +21,12 @@ import java.util.*
* @param notary the notary to set on the output states. * @param notary the notary to set on the output states.
*/ */
@StartableByRPC @StartableByRPC
class PtCashIssueAndPaymentFlow(val amount: Amount<Currency>, class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
val issueRef: OpaqueBytes, val issueRef: OpaqueBytes,
val recipient: Party, val recipient: Party,
val anonymous: Boolean, val anonymous: Boolean,
val notary: Party, val notary: Party,
progressTracker: ProgressTracker) : AbstractPtCashFlow<AbstractPtCashFlow.Result>(progressTracker) { progressTracker: ProgressTracker) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
constructor(amount: Amount<Currency>, constructor(amount: Amount<Currency>,
issueRef: OpaqueBytes, issueRef: OpaqueBytes,
recipient: Party, recipient: Party,
@ -36,8 +36,8 @@ class PtCashIssueAndPaymentFlow(val amount: Amount<Currency>,
@Suspendable @Suspendable
override fun call(): Result { override fun call(): Result {
subFlow(PtCashIssueFlow(amount, issueRef, notary)) subFlow(CashIssueFlow(amount, issueRef, notary))
return subFlow(PtCashPaymentFlow(amount, recipient, anonymous)) return subFlow(CashPaymentFlow(amount, recipient, anonymous))
} }
@CordaSerializable @CordaSerializable

View File

@ -8,7 +8,7 @@ import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.issuedBy import com.r3.corda.enterprise.perftestcordapp.issuedBy
import java.util.* import java.util.*
@ -24,21 +24,21 @@ import java.util.*
* @param notary the notary to set on the output states. * @param notary the notary to set on the output states.
*/ */
@StartableByRPC @StartableByRPC
class PtCashIssueFlow(private val amount: Amount<Currency>, class CashIssueFlow(private val amount: Amount<Currency>,
private val issuerBankPartyRef: OpaqueBytes, private val issuerBankPartyRef: OpaqueBytes,
private val notary: Party, private val notary: Party,
progressTracker: ProgressTracker) : AbstractPtCashFlow<AbstractPtCashFlow.Result>(progressTracker) { progressTracker: ProgressTracker) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
constructor(amount: Amount<Currency>, constructor(amount: Amount<Currency>,
issuerBankPartyRef: OpaqueBytes, issuerBankPartyRef: OpaqueBytes,
notary: Party) : this(amount, issuerBankPartyRef, notary, tracker()) notary: Party) : this(amount, issuerBankPartyRef, notary, tracker())
constructor(request: IssueRequest) : this(request.amount, request.issueRef, request.notary, tracker()) constructor(request: IssueRequest) : this(request.amount, request.issueRef, request.notary, tracker())
@Suspendable @Suspendable
override fun call(): AbstractPtCashFlow.Result { override fun call(): AbstractCashFlow.Result {
progressTracker.currentStep = GENERATING_TX progressTracker.currentStep = GENERATING_TX
val builder = TransactionBuilder(notary) val builder = TransactionBuilder(notary)
val issuer = ourIdentity.ref(issuerBankPartyRef) val issuer = ourIdentity.ref(issuerBankPartyRef)
val signers = PtCash().generateIssue(builder, amount.issuedBy(issuer), ourIdentity, notary) val signers = Cash().generateIssue(builder, amount.issuedBy(issuer), ourIdentity, notary)
progressTracker.currentStep = SIGNING_TX progressTracker.currentStep = SIGNING_TX
val tx = serviceHub.signInitialTransaction(builder, signers) val tx = serviceHub.signInitialTransaction(builder, signers)
progressTracker.currentStep = FINALISING_TX progressTracker.currentStep = FINALISING_TX

View File

@ -10,7 +10,7 @@ import net.corda.core.identity.Party
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import java.util.* import java.util.*
/** /**
@ -23,12 +23,12 @@ import java.util.*
* for testing purposes. * for testing purposes.
*/ */
@StartableByRPC @StartableByRPC
open class PtCashPaymentFlow( open class CashPaymentFlow(
val amount: Amount<Currency>, val amount: Amount<Currency>,
val recipient: Party, val recipient: Party,
val anonymous: Boolean, val anonymous: Boolean,
progressTracker: ProgressTracker, progressTracker: ProgressTracker,
val issuerConstraint: Set<Party> = emptySet()) : AbstractPtCashFlow<AbstractPtCashFlow.Result>(progressTracker) { val issuerConstraint: Set<Party> = emptySet()) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
/** A straightforward constructor that constructs spends using cash states of any issuer. */ /** A straightforward constructor that constructs spends using cash states of any issuer. */
constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker()) constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker())
/** A straightforward constructor that constructs spends using cash states of any issuer. */ /** A straightforward constructor that constructs spends using cash states of any issuer. */
@ -36,7 +36,7 @@ open class PtCashPaymentFlow(
constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint) constructor(request: PaymentRequest) : this(request.amount, request.recipient, request.anonymous, tracker(), request.issuerConstraint)
@Suspendable @Suspendable
override fun call(): AbstractPtCashFlow.Result { override fun call(): AbstractCashFlow.Result {
progressTracker.currentStep = GENERATING_ID progressTracker.currentStep = GENERATING_ID
val txIdentities = if (anonymous) { val txIdentities = if (anonymous) {
subFlow(SwapIdentitiesFlow(recipient)) subFlow(SwapIdentitiesFlow(recipient))
@ -48,7 +48,7 @@ open class PtCashPaymentFlow(
val builder = TransactionBuilder(notary = null) val builder = TransactionBuilder(notary = null)
// TODO: Have some way of restricting this to states the caller controls // TODO: Have some way of restricting this to states the caller controls
val (spendTX, keysForSigning) = try { val (spendTX, keysForSigning) = try {
PtCash.generateSpend(serviceHub, Cash.generateSpend(serviceHub,
builder, builder,
amount, amount,
ourIdentityAndCert, ourIdentityAndCert,

View File

@ -12,7 +12,7 @@ import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.ProgressTracker import net.corda.core.utilities.ProgressTracker
import net.corda.core.utilities.seconds import net.corda.core.utilities.seconds
import net.corda.core.utilities.unwrap import net.corda.core.utilities.unwrap
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.utils.sumCashBy import com.r3.corda.enterprise.perftestcordapp.utils.sumCashBy
import java.security.PublicKey import java.security.PublicKey
import java.util.* import java.util.*
@ -219,7 +219,7 @@ object TwoPartyTradeFlow {
val ptx = TransactionBuilder(notary) val ptx = TransactionBuilder(notary)
// Add input and output states for the movement of cash, by using the Cash contract to generate the states // Add input and output states for the movement of cash, by using the Cash contract to generate the states
val (tx, cashSigningPubKeys) = PtCash.generateSpend(serviceHub, ptx, tradeRequest.price, ourIdentityAndCert, tradeRequest.payToIdentity.party) val (tx, cashSigningPubKeys) = Cash.generateSpend(serviceHub, ptx, tradeRequest.price, ourIdentityAndCert, tradeRequest.payToIdentity.party)
// Add inputs/outputs/a command for the movement of the asset. // Add inputs/outputs/a command for the movement of the asset.
tx.addInputState(assetForSale) tx.addInputState(assetForSale)

View File

@ -13,14 +13,14 @@ import javax.persistence.Table
/** /**
* An object used to fully qualify the [CashSchema] family name (i.e. independent of version). * An object used to fully qualify the [CashSchema] family name (i.e. independent of version).
*/ */
object PtCashSchema object CashSchema
/** /**
* First version of a cash contract ORM schema that maps all fields of the [Cash] contract state as it stood * First version of a cash contract ORM schema that maps all fields of the [Cash] contract state as it stood
* at the time of writing. * at the time of writing.
*/ */
@CordaSerializable @CordaSerializable
object PtCashSchemaV1 : MappedSchema(schemaFamily = PtCashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) { object CashSchemaV1 : MappedSchema(schemaFamily = CashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) {
@Entity @Entity
@Table(name = "contract_cash_states", @Table(name = "contract_cash_states",
indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"), indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"),

View File

@ -11,14 +11,14 @@ import javax.persistence.Table
/** /**
* An object used to fully qualify the [CommercialPaperSchema] family name (i.e. independent of version). * An object used to fully qualify the [CommercialPaperSchema] family name (i.e. independent of version).
*/ */
object PtCommercialPaperSchema object CommercialPaperSchema
/** /**
* First version of a commercial paper contract ORM schema that maps all fields of the [CommercialPaper] contract state * First version of a commercial paper contract ORM schema that maps all fields of the [CommercialPaper] contract state
* as it stood at the time of writing. * as it stood at the time of writing.
*/ */
@CordaSerializable @CordaSerializable
object PtCommercialPaperSchemaV1 : MappedSchema(schemaFamily = PtCommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) { object CommercialPaperSchemaV1 : MappedSchema(schemaFamily = CommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
@Entity @Entity
@Table(name = "cp_states", @Table(name = "cp_states",
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"), indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),

View File

@ -1,6 +1,6 @@
package com.r3.corda.enterprise.perftestcordapp.utils package com.r3.corda.enterprise.perftestcordapp.utils
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import net.corda.core.contracts.Amount import net.corda.core.contracts.Amount
import net.corda.core.contracts.Amount.Companion.sumOrNull import net.corda.core.contracts.Amount.Companion.sumOrNull
import net.corda.core.contracts.Amount.Companion.sumOrThrow import net.corda.core.contracts.Amount.Companion.sumOrThrow
@ -16,20 +16,20 @@ import java.util.*
* if there are none, or if any of the cash states cannot be added together (i.e. are * if there are none, or if any of the cash states cannot be added together (i.e. are
* different currencies or issuers). * different currencies or issuers).
*/ */
fun Iterable<ContractState>.sumCashBy(owner: AbstractParty): Amount<Issued<Currency>> = filterIsInstance<PtCash.State>().filter { it.owner == owner }.map { it.amount }.sumOrThrow() fun Iterable<ContractState>.sumCashBy(owner: AbstractParty): Amount<Issued<Currency>> = filterIsInstance<Cash.State>().filter { it.owner == owner }.map { it.amount }.sumOrThrow()
/** /**
* Sums the cash states in the list, throwing an exception if there are none, or if any of the cash * Sums the cash states in the list, throwing an exception if there are none, or if any of the cash
* states cannot be added together (i.e. are different currencies or issuers). * states cannot be added together (i.e. are different currencies or issuers).
*/ */
fun Iterable<ContractState>.sumCash(): Amount<Issued<Currency>> = filterIsInstance<PtCash.State>().map { it.amount }.sumOrThrow() fun Iterable<ContractState>.sumCash(): Amount<Issued<Currency>> = filterIsInstance<Cash.State>().map { it.amount }.sumOrThrow()
/** Sums the cash states in the list, returning null if there are none. */ /** Sums the cash states in the list, returning null if there are none. */
fun Iterable<ContractState>.sumCashOrNull(): Amount<Issued<Currency>>? = filterIsInstance<PtCash.State>().map { it.amount }.sumOrNull() fun Iterable<ContractState>.sumCashOrNull(): Amount<Issued<Currency>>? = filterIsInstance<Cash.State>().map { it.amount }.sumOrNull()
/** Sums the cash states in the list, returning zero of the given currency+issuer if there are none. */ /** Sums the cash states in the list, returning zero of the given currency+issuer if there are none. */
fun Iterable<ContractState>.sumCashOrZero(currency: Issued<Currency>): Amount<Issued<Currency>> { fun Iterable<ContractState>.sumCashOrZero(currency: Issued<Currency>): Amount<Issued<Currency>> {
return filterIsInstance<PtCash.State>().map { it.amount }.sumOrZero(currency) return filterIsInstance<Cash.State>().map { it.amount }.sumOrZero(currency)
} }
/** Sums the asset states in the list, returning null if there are none. */ /** Sums the asset states in the list, returning null if there are none. */

View File

@ -1,2 +1,2 @@
com.r3.corda.enterprise.perftestcordapp.contracts.asset.cash.selection.PtCashSelectionH2Impl com.r3.corda.enterprise.perftestcordapp.contracts.asset.cash.selection.CashSelectionH2Impl

View File

@ -26,8 +26,8 @@ import kotlin.test.assertTrue
// TODO: The generate functions aren't tested by these tests: add them. // TODO: The generate functions aren't tested by these tests: add them.
interface PtCommercialPaperTestTemplate { interface CommercialPaperTestTemplate {
fun getPaper(): PtCommercialPaper.State fun getPaper(): CommercialPaper.State
fun getIssueCommand(notary: Party): CommandData fun getIssueCommand(notary: Party): CommandData
fun getRedeemCommand(notary: Party): CommandData fun getRedeemCommand(notary: Party): CommandData
fun getMoveCommand(): CommandData fun getMoveCommand(): CommandData
@ -35,32 +35,32 @@ interface PtCommercialPaperTestTemplate {
} }
class KotlinCommercialPaperTest : PtCommercialPaperTestTemplate { class KotlinCommercialPaperTest : CommercialPaperTestTemplate {
override fun getPaper(): PtCommercialPaper.State = PtCommercialPaper.State( override fun getPaper(): CommercialPaper.State = CommercialPaper.State(
issuance = MEGA_CORP.ref(123), issuance = MEGA_CORP.ref(123),
owner = MEGA_CORP, owner = MEGA_CORP,
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123), faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
maturityDate = TEST_TX_TIME + 7.days maturityDate = TEST_TX_TIME + 7.days
) )
override fun getIssueCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Issue() override fun getIssueCommand(notary: Party): CommandData = CommercialPaper.Commands.Issue()
override fun getRedeemCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Redeem() override fun getRedeemCommand(notary: Party): CommandData = CommercialPaper.Commands.Redeem()
override fun getMoveCommand(): CommandData = PtCommercialPaper.Commands.Move() override fun getMoveCommand(): CommandData = CommercialPaper.Commands.Move()
override fun getContract() = PtCommercialPaper.CP_PROGRAM_ID override fun getContract() = CommercialPaper.CP_PROGRAM_ID
} }
class KotlinCommercialPaperLegacyTest : PtCommercialPaperTestTemplate { class KotlinCommercialPaperLegacyTest : CommercialPaperTestTemplate {
override fun getPaper(): PtCommercialPaper.State = PtCommercialPaper.State( override fun getPaper(): CommercialPaper.State = CommercialPaper.State(
issuance = MEGA_CORP.ref(123), issuance = MEGA_CORP.ref(123),
owner = MEGA_CORP, owner = MEGA_CORP,
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123), faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
maturityDate = TEST_TX_TIME + 7.days maturityDate = TEST_TX_TIME + 7.days
) )
override fun getIssueCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Issue() override fun getIssueCommand(notary: Party): CommandData = CommercialPaper.Commands.Issue()
override fun getRedeemCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Redeem() override fun getRedeemCommand(notary: Party): CommandData = CommercialPaper.Commands.Redeem()
override fun getMoveCommand(): CommandData = PtCommercialPaper.Commands.Move() override fun getMoveCommand(): CommandData = CommercialPaper.Commands.Move()
override fun getContract() = PtCommercialPaper.CP_PROGRAM_ID override fun getContract() = CommercialPaper.CP_PROGRAM_ID
} }
@RunWith(Parameterized::class) @RunWith(Parameterized::class)
@ -71,7 +71,7 @@ class CommercialPaperTestsGeneric {
} }
@Parameterized.Parameter @Parameterized.Parameter
lateinit var thisTest: PtCommercialPaperTestTemplate lateinit var thisTest: CommercialPaperTestTemplate
val issuer = MEGA_CORP.ref(123) val issuer = MEGA_CORP.ref(123)
@ -80,14 +80,14 @@ class CommercialPaperTestsGeneric {
val someProfits = 1200.DOLLARS `issued by` issuer val someProfits = 1200.DOLLARS `issued by` issuer
ledger { ledger {
unverifiedTransaction { unverifiedTransaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
output(PtCash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH `issued by` issuer `owned by` ALICE) output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH `issued by` issuer `owned by` ALICE)
output(PtCash.PROGRAM_ID, "some profits", someProfits.STATE `owned by` MEGA_CORP) output(Cash.PROGRAM_ID, "some profits", someProfits.STATE `owned by` MEGA_CORP)
} }
// Some CP is issued onto the ledger by MegaCorp. // Some CP is issued onto the ledger by MegaCorp.
transaction("Issuance") { transaction("Issuance") {
attachments(CP_PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID) attachments(CP_PROGRAM_ID, CommercialPaper.CP_PROGRAM_ID)
output(thisTest.getContract(), "paper") { thisTest.getPaper() } output(thisTest.getContract(), "paper") { thisTest.getPaper() }
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) } command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
@ -97,12 +97,12 @@ class CommercialPaperTestsGeneric {
// The CP is sold to alice for her $900, $100 less than the face value. At 10% interest after only 7 days, // The CP is sold to alice for her $900, $100 less than the face value. At 10% interest after only 7 days,
// that sounds a bit too good to be true! // that sounds a bit too good to be true!
transaction("Trade") { transaction("Trade") {
attachments(PtCash.PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID) attachments(Cash.PROGRAM_ID, CommercialPaper.CP_PROGRAM_ID)
input("paper") input("paper")
input("alice's $900") input("alice's $900")
output(PtCash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP } output(Cash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP }
output(thisTest.getContract(), "alice's paper") { "paper".output<PtCommercialPaper.State>().withOwner(ALICE) } output(thisTest.getContract(), "alice's paper") { "paper".output<CommercialPaper.State>().withOwner(ALICE) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { thisTest.getMoveCommand() } command(MEGA_CORP_PUBKEY) { thisTest.getMoveCommand() }
this.verifies() this.verifies()
} }
@ -110,16 +110,16 @@ class CommercialPaperTestsGeneric {
// Time passes, and Alice redeem's her CP for $1000, netting a $100 profit. MegaCorp has received $1200 // Time passes, and Alice redeem's her CP for $1000, netting a $100 profit. MegaCorp has received $1200
// as a single payment from somewhere and uses it to pay Alice off, keeping the remaining $200 as change. // as a single payment from somewhere and uses it to pay Alice off, keeping the remaining $200 as change.
transaction("Redemption") { transaction("Redemption") {
attachments(CP_PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID) attachments(CP_PROGRAM_ID, CommercialPaper.CP_PROGRAM_ID)
input("alice's paper") input("alice's paper")
input("some profits") input("some profits")
fun TransactionDSL<TransactionDSLInterpreter>.outputs(aliceGetsBack: Amount<Issued<Currency>>) { fun TransactionDSL<TransactionDSLInterpreter>.outputs(aliceGetsBack: Amount<Issued<Currency>>) {
output(PtCash.PROGRAM_ID, "Alice's profit") { aliceGetsBack.STATE `owned by` ALICE } output(Cash.PROGRAM_ID, "Alice's profit") { aliceGetsBack.STATE `owned by` ALICE }
output(PtCash.PROGRAM_ID, "Change") { (someProfits - aliceGetsBack).STATE `owned by` MEGA_CORP } output(Cash.PROGRAM_ID, "Change") { (someProfits - aliceGetsBack).STATE `owned by` MEGA_CORP }
} }
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Move() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { thisTest.getRedeemCommand(DUMMY_NOTARY) } command(ALICE_PUBKEY) { thisTest.getRedeemCommand(DUMMY_NOTARY) }
tweak { tweak {
@ -137,7 +137,7 @@ class CommercialPaperTestsGeneric {
timeWindow(TEST_TX_TIME + 8.days) timeWindow(TEST_TX_TIME + 8.days)
tweak { tweak {
output(thisTest.getContract()) { "paper".output<PtCommercialPaper.State>() } output(thisTest.getContract()) { "paper".output<CommercialPaper.State>() }
this `fails with` "must be destroyed" this `fails with` "must be destroyed"
} }
@ -245,7 +245,7 @@ class CommercialPaperTestsGeneric {
// BigCorp™ issues $10,000 of commercial paper, to mature in 30 days, owned initially by itself. // BigCorp™ issues $10,000 of commercial paper, to mature in 30 days, owned initially by itself.
val faceValue = 10000.DOLLARS `issued by` DUMMY_CASH_ISSUER val faceValue = 10000.DOLLARS `issued by` DUMMY_CASH_ISSUER
val issuance = bigCorpServices.myInfo.chooseIdentity().ref(1) val issuance = bigCorpServices.myInfo.chooseIdentity().ref(1)
val issueBuilder = PtCommercialPaper().generateIssue(issuance, faceValue, TEST_TX_TIME + 30.days, DUMMY_NOTARY) val issueBuilder = CommercialPaper().generateIssue(issuance, faceValue, TEST_TX_TIME + 30.days, DUMMY_NOTARY)
issueBuilder.setTimeWindow(TEST_TX_TIME, 30.seconds) issueBuilder.setTimeWindow(TEST_TX_TIME, 30.seconds)
val issuePtx = bigCorpServices.signInitialTransaction(issueBuilder) val issuePtx = bigCorpServices.signInitialTransaction(issueBuilder)
val issueTx = notaryServices.addSignature(issuePtx) val issueTx = notaryServices.addSignature(issuePtx)
@ -254,8 +254,8 @@ class CommercialPaperTestsGeneric {
// Alice pays $9000 to BigCorp to own some of their debt. // Alice pays $9000 to BigCorp to own some of their debt.
moveTX = run { moveTX = run {
val builder = TransactionBuilder(DUMMY_NOTARY) val builder = TransactionBuilder(DUMMY_NOTARY)
PtCash.generateSpend(aliceServices, builder, 9000.DOLLARS, AnonymousParty(bigCorpServices.key.public)) Cash.generateSpend(aliceServices, builder, 9000.DOLLARS, AnonymousParty(bigCorpServices.key.public))
PtCommercialPaper().generateMove(builder, issueTx.tx.outRef(0), AnonymousParty(aliceServices.key.public)) CommercialPaper().generateMove(builder, issueTx.tx.outRef(0), AnonymousParty(aliceServices.key.public))
val ptx = aliceServices.signInitialTransaction(builder) val ptx = aliceServices.signInitialTransaction(builder)
val ptx2 = bigCorpServices.addSignature(ptx) val ptx2 = bigCorpServices.addSignature(ptx)
val stx = notaryServices.addSignature(ptx2) val stx = notaryServices.addSignature(ptx2)
@ -276,7 +276,7 @@ class CommercialPaperTestsGeneric {
fun makeRedeemTX(time: Instant): Pair<SignedTransaction, UUID> { fun makeRedeemTX(time: Instant): Pair<SignedTransaction, UUID> {
val builder = TransactionBuilder(DUMMY_NOTARY) val builder = TransactionBuilder(DUMMY_NOTARY)
builder.setTimeWindow(time, 30.seconds) builder.setTimeWindow(time, 30.seconds)
PtCommercialPaper().generateRedeem(builder, moveTX.tx.outRef(1), bigCorpServices, bigCorpServices.myInfo.chooseIdentityAndCert()) CommercialPaper().generateRedeem(builder, moveTX.tx.outRef(1), bigCorpServices, bigCorpServices.myInfo.chooseIdentityAndCert())
val ptx = aliceServices.signInitialTransaction(builder) val ptx = aliceServices.signInitialTransaction(builder)
val ptx2 = bigCorpServices.addSignature(ptx) val ptx2 = bigCorpServices.addSignature(ptx)
val stx = notaryServices.addSignature(ptx2) val stx = notaryServices.addSignature(ptx2)

View File

@ -53,14 +53,14 @@ fun ServiceHub.fillWithSomeTestCash(howMuch: Amount<Currency>,
rng: Random = Random(), rng: Random = Random(),
ref: OpaqueBytes = OpaqueBytes(ByteArray(1, { 1 })), ref: OpaqueBytes = OpaqueBytes(ByteArray(1, { 1 })),
ownedBy: AbstractParty? = null, ownedBy: AbstractParty? = null,
issuedBy: PartyAndReference = DUMMY_CASH_ISSUER): Vault<PtCash.State> { issuedBy: PartyAndReference = DUMMY_CASH_ISSUER): Vault<Cash.State> {
val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng) val amounts = calculateRandomlySizedAmounts(howMuch, atLeastThisManyStates, atMostThisManyStates, rng)
val myKey = ownedBy?.owningKey ?: myInfo.chooseIdentity().owningKey val myKey = ownedBy?.owningKey ?: myInfo.chooseIdentity().owningKey
val anonParty = AnonymousParty(myKey) val anonParty = AnonymousParty(myKey)
// We will allocate one state to one transaction, for simplicities sake. // We will allocate one state to one transaction, for simplicities sake.
val cash = PtCash() 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.copy(reference = ref), howMuch.token)), anonParty, outputNotary) cash.generateIssue(issuance, Amount(pennies, Issued(issuedBy.copy(reference = ref), howMuch.token)), anonParty, outputNotary)
@ -72,17 +72,17 @@ fun ServiceHub.fillWithSomeTestCash(howMuch: Amount<Currency>,
// Get all the StateRefs of all the generated transactions. // Get all the StateRefs of all the generated transactions.
val states = transactions.flatMap { stx -> val states = transactions.flatMap { stx ->
stx.tx.outputs.indices.map { i -> stx.tx.outRef<PtCash.State>(i) } stx.tx.outputs.indices.map { i -> stx.tx.outRef<Cash.State>(i) }
} }
return Vault(states) return Vault(states)
} }
class PtCashTests : TestDependencyInjectionBase() { class CashTests : TestDependencyInjectionBase() {
val defaultRef = OpaqueBytes(ByteArray(1, { 1 })) val defaultRef = OpaqueBytes(ByteArray(1, { 1 }))
val defaultIssuer = MEGA_CORP.ref(defaultRef) val defaultIssuer = MEGA_CORP.ref(defaultRef)
val inState = PtCash.State( val inState = Cash.State(
amount = 1000.DOLLARS `issued by` defaultIssuer, amount = 1000.DOLLARS `issued by` defaultIssuer,
owner = AnonymousParty(ALICE_PUBKEY) owner = AnonymousParty(ALICE_PUBKEY)
) )
@ -90,7 +90,7 @@ class PtCashTests : TestDependencyInjectionBase() {
val issuerInState = inState.copy(owner = defaultIssuer.party) val issuerInState = inState.copy(owner = defaultIssuer.party)
val outState = issuerInState.copy(owner = AnonymousParty(BOB_PUBKEY)) val outState = issuerInState.copy(owner = AnonymousParty(BOB_PUBKEY))
fun PtCash.State.editDepositRef(ref: Byte) = copy( fun Cash.State.editDepositRef(ref: Byte) = copy(
amount = Amount(amount.quantity, token = amount.token.copy(amount.token.issuer.copy(reference = OpaqueBytes.of(ref)))) amount = Amount(amount.quantity, token = amount.token.copy(amount.token.issuer.copy(reference = OpaqueBytes.of(ref))))
) )
@ -98,7 +98,7 @@ class PtCashTests : TestDependencyInjectionBase() {
lateinit var megaCorpServices: MockServices lateinit var megaCorpServices: MockServices
val vault: VaultService get() = miniCorpServices.vaultService val vault: VaultService get() = miniCorpServices.vaultService
lateinit var database: CordaPersistence lateinit var database: CordaPersistence
lateinit var vaultStatesUnconsumed: List<StateAndRef<PtCash.State>> lateinit var vaultStatesUnconsumed: List<StateAndRef<Cash.State>>
@Before @Before
fun setUp() { fun setUp() {
@ -120,7 +120,7 @@ class PtCashTests : TestDependencyInjectionBase() {
ownedBy = OUR_IDENTITY_1, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices) ownedBy = OUR_IDENTITY_1, issuedBy = MINI_CORP.ref(1), issuerServices = miniCorpServices)
} }
database.transaction { database.transaction {
vaultStatesUnconsumed = miniCorpServices.vaultQueryService.queryBy<PtCash.State>().states vaultStatesUnconsumed = miniCorpServices.vaultQueryService.queryBy<Cash.State>().states
} }
resetTestSerialization() resetTestSerialization()
} }
@ -133,35 +133,35 @@ class PtCashTests : TestDependencyInjectionBase() {
@Test @Test
fun trivial() { fun trivial() {
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
tweak { tweak {
output(PtCash.PROGRAM_ID) { outState.copy(amount = 2000.DOLLARS `issued by` defaultIssuer) } output(Cash.PROGRAM_ID) { outState.copy(amount = 2000.DOLLARS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
tweak { tweak {
output(PtCash.PROGRAM_ID) { outState } output(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { DummyCommandData } command(ALICE_PUBKEY) { DummyCommandData }
// Invalid command // Invalid command
this `fails with` "required com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash.Commands.Move command" this `fails with` "required com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash.Commands.Move command"
} }
tweak { tweak {
output(PtCash.PROGRAM_ID) { outState } output(Cash.PROGRAM_ID) { outState }
command(BOB_PUBKEY) { PtCash.Commands.Move() } command(BOB_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the owning keys are a subset of the signing keys" this `fails with` "the owning keys are a subset of the signing keys"
} }
tweak { tweak {
output(PtCash.PROGRAM_ID) { outState } output(Cash.PROGRAM_ID) { outState }
output(PtCash.PROGRAM_ID) { outState `issued by` MINI_CORP } output(Cash.PROGRAM_ID) { outState `issued by` MINI_CORP }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "at least one cash input" this `fails with` "at least one cash input"
} }
// Simple reallocation works. // Simple reallocation works.
tweak { tweak {
output(PtCash.PROGRAM_ID) { outState } output(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }
} }
@ -171,10 +171,10 @@ class PtCashTests : TestDependencyInjectionBase() {
fun `issue by move`() { fun `issue by move`() {
// Check we can't "move" money into existence. // Check we can't "move" money into existence.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { DummyState() } input(Cash.PROGRAM_ID) { DummyState() }
output(PtCash.PROGRAM_ID) { outState } output(Cash.PROGRAM_ID) { outState }
command(MINI_CORP_PUBKEY) { PtCash.Commands.Move() } command(MINI_CORP_PUBKEY) { Cash.Commands.Move() }
this `fails with` "there is at least one cash input for this group" this `fails with` "there is at least one cash input for this group"
} }
@ -185,20 +185,20 @@ class PtCashTests : TestDependencyInjectionBase() {
// Check we can issue money only as long as the issuer institution is a command signer, i.e. any recognised // Check we can issue money only as long as the issuer institution is a command signer, i.e. any recognised
// institution is allowed to issue as much cash as they want. // institution is allowed to issue as much cash as they want.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
output(PtCash.PROGRAM_ID) { outState } output(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { PtCash.Commands.Issue() } command(ALICE_PUBKEY) { Cash.Commands.Issue() }
this `fails with` "output states are issued by a command signer" this `fails with` "output states are issued by a command signer"
} }
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
output(PtCash.PROGRAM_ID) { output(Cash.PROGRAM_ID) {
PtCash.State( Cash.State(
amount = 1000.DOLLARS `issued by` MINI_CORP.ref(12, 34), amount = 1000.DOLLARS `issued by` MINI_CORP.ref(12, 34),
owner = AnonymousParty(ALICE_PUBKEY) owner = AnonymousParty(ALICE_PUBKEY)
) )
} }
command(MINI_CORP_PUBKEY) { PtCash.Commands.Issue() } command(MINI_CORP_PUBKEY) { Cash.Commands.Issue() }
this.verifies() this.verifies()
} }
} }
@ -208,14 +208,14 @@ class PtCashTests : TestDependencyInjectionBase() {
initialiseTestSerialization() initialiseTestSerialization()
// Test generation works. // Test generation works.
val tx: WireTransaction = TransactionBuilder(notary = null).apply { val tx: WireTransaction = TransactionBuilder(notary = null).apply {
PtCash().generateIssue(this, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY) Cash().generateIssue(this, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY)
}.toWireTransaction(miniCorpServices) }.toWireTransaction(miniCorpServices)
assertTrue(tx.inputs.isEmpty()) assertTrue(tx.inputs.isEmpty())
val s = tx.outputsOfType<PtCash.State>().single() val s = tx.outputsOfType<Cash.State>().single()
assertEquals(100.DOLLARS `issued by` MINI_CORP.ref(12, 34), s.amount) assertEquals(100.DOLLARS `issued by` MINI_CORP.ref(12, 34), s.amount)
assertEquals(MINI_CORP as AbstractParty, s.amount.token.issuer.party) assertEquals(MINI_CORP as AbstractParty, s.amount.token.issuer.party)
assertEquals(AnonymousParty(ALICE_PUBKEY), s.owner) assertEquals(AnonymousParty(ALICE_PUBKEY), s.owner)
assertTrue(tx.commands[0].value is PtCash.Commands.Issue) assertTrue(tx.commands[0].value is Cash.Commands.Issue)
assertEquals(MINI_CORP_PUBKEY, tx.commands[0].signers[0]) assertEquals(MINI_CORP_PUBKEY, tx.commands[0].signers[0])
} }
@ -225,7 +225,7 @@ class PtCashTests : TestDependencyInjectionBase() {
// Test issuance from an issued amount // Test issuance from an issued amount
val amount = 100.DOLLARS `issued by` MINI_CORP.ref(12, 34) val amount = 100.DOLLARS `issued by` MINI_CORP.ref(12, 34)
val tx: WireTransaction = TransactionBuilder(notary = null).apply { val tx: WireTransaction = TransactionBuilder(notary = null).apply {
PtCash().generateIssue(this, amount, owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY) Cash().generateIssue(this, amount, owner = AnonymousParty(ALICE_PUBKEY), notary = DUMMY_NOTARY)
}.toWireTransaction(miniCorpServices) }.toWireTransaction(miniCorpServices)
assertTrue(tx.inputs.isEmpty()) assertTrue(tx.inputs.isEmpty())
assertEquals(tx.outputs[0], tx.outputs[0]) assertEquals(tx.outputs[0], tx.outputs[0])
@ -235,49 +235,49 @@ class PtCashTests : TestDependencyInjectionBase() {
fun `extended issue examples`() { fun `extended issue examples`() {
// We can consume $1000 in a transaction and output $2000 as long as it's signed by an issuer. // We can consume $1000 in a transaction and output $2000 as long as it's signed by an issuer.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { issuerInState } input(Cash.PROGRAM_ID) { issuerInState }
output(PtCash.PROGRAM_ID) { inState.copy(amount = inState.amount * 2) } output(Cash.PROGRAM_ID) { inState.copy(amount = inState.amount * 2) }
// Move fails: not allowed to summon money. // Move fails: not allowed to summon money.
tweak { tweak {
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
// Issue works. // Issue works.
tweak { tweak {
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Issue() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
this.verifies() this.verifies()
} }
} }
// Can't use an issue command to lower the amount. // Can't use an issue command to lower the amount.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { inState.copy(amount = inState.amount.splitEvenly(2).first()) } output(Cash.PROGRAM_ID) { inState.copy(amount = inState.amount.splitEvenly(2).first()) }
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Issue() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
this `fails with` "output values sum to more than the inputs" this `fails with` "output values sum to more than the inputs"
} }
// Can't have an issue command that doesn't actually issue money. // Can't have an issue command that doesn't actually issue money.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { inState } output(Cash.PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Issue() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
this `fails with` "output values sum to more than the inputs" this `fails with` "output values sum to more than the inputs"
} }
// Can't have any other commands if we have an issue command (because the issue command overrules them) // Can't have any other commands if we have an issue command (because the issue command overrules them)
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { inState.copy(amount = inState.amount * 2) } output(Cash.PROGRAM_ID) { inState.copy(amount = inState.amount * 2) }
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Issue() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
tweak { tweak {
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Issue() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
this `fails with` "there is only a single issue command" this `fails with` "there is only a single issue command"
} }
this.verifies() this.verifies()
@ -294,40 +294,40 @@ class PtCashTests : TestDependencyInjectionBase() {
// Issue some cash // Issue some cash
var ptx = TransactionBuilder(DUMMY_NOTARY) var ptx = TransactionBuilder(DUMMY_NOTARY)
PtCash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP, notary = DUMMY_NOTARY) Cash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP, notary = DUMMY_NOTARY)
val tx = miniCorpServices.signInitialTransaction(ptx) val tx = miniCorpServices.signInitialTransaction(ptx)
// Include the previously issued cash in a new issuance command // Include the previously issued cash in a new issuance command
ptx = TransactionBuilder(DUMMY_NOTARY) ptx = TransactionBuilder(DUMMY_NOTARY)
ptx.addInputState(tx.tx.outRef<PtCash.State>(0)) ptx.addInputState(tx.tx.outRef<Cash.State>(0))
PtCash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP, notary = DUMMY_NOTARY) Cash().generateIssue(ptx, 100.DOLLARS `issued by` MINI_CORP.ref(12, 34), owner = MINI_CORP, notary = DUMMY_NOTARY)
} }
@Test @Test
fun testMergeSplit() { fun testMergeSplit() {
// Splitting value works. // Splitting value works.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
tweak { tweak {
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
val splits4 = inState.amount.splitEvenly(4) val splits4 = inState.amount.splitEvenly(4)
for (i in 0..3) output(PtCash.PROGRAM_ID) { inState.copy(amount = splits4[i]) } for (i in 0..3) output(Cash.PROGRAM_ID) { inState.copy(amount = splits4[i]) }
this.verifies() this.verifies()
} }
// Merging 4 inputs into 2 outputs works. // Merging 4 inputs into 2 outputs works.
tweak { tweak {
val splits2 = inState.amount.splitEvenly(2) val splits2 = inState.amount.splitEvenly(2)
val splits4 = inState.amount.splitEvenly(4) val splits4 = inState.amount.splitEvenly(4)
for (i in 0..3) input(PtCash.PROGRAM_ID) { inState.copy(amount = splits4[i]) } for (i in 0..3) input(Cash.PROGRAM_ID) { inState.copy(amount = splits4[i]) }
for (i in 0..1) output(PtCash.PROGRAM_ID) { inState.copy(amount = splits2[i]) } for (i in 0..1) output(Cash.PROGRAM_ID) { inState.copy(amount = splits2[i]) }
this.verifies() this.verifies()
} }
// Merging 2 inputs into 1 works. // Merging 2 inputs into 1 works.
tweak { tweak {
val splits2 = inState.amount.splitEvenly(2) val splits2 = inState.amount.splitEvenly(2)
for (i in 0..1) input(PtCash.PROGRAM_ID) { inState.copy(amount = splits2[i]) } for (i in 0..1) input(Cash.PROGRAM_ID) { inState.copy(amount = splits2[i]) }
output(PtCash.PROGRAM_ID) { inState } output(Cash.PROGRAM_ID) { inState }
this.verifies() this.verifies()
} }
} }
@ -336,18 +336,18 @@ class PtCashTests : TestDependencyInjectionBase() {
@Test @Test
fun zeroSizedValues() { fun zeroSizedValues() {
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
input(PtCash.PROGRAM_ID) { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) } input(Cash.PROGRAM_ID) { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "zero sized inputs" this `fails with` "zero sized inputs"
} }
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { inState } output(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) } output(Cash.PROGRAM_ID) { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "zero sized outputs" this `fails with` "zero sized outputs"
} }
} }
@ -356,59 +356,59 @@ class PtCashTests : TestDependencyInjectionBase() {
fun trivialMismatches() { fun trivialMismatches() {
// Can't change issuer. // Can't change issuer.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { outState `issued by` MINI_CORP } output(Cash.PROGRAM_ID) { outState `issued by` MINI_CORP }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
// Can't change deposit reference when splitting. // Can't change deposit reference when splitting.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
val splits2 = inState.amount.splitEvenly(2) val splits2 = inState.amount.splitEvenly(2)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
for (i in 0..1) output(PtCash.PROGRAM_ID) { outState.copy(amount = splits2[i]).editDepositRef(i.toByte()) } for (i in 0..1) output(Cash.PROGRAM_ID) { outState.copy(amount = splits2[i]).editDepositRef(i.toByte()) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
// Can't mix currencies. // Can't mix currencies.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { outState.copy(amount = 800.DOLLARS `issued by` defaultIssuer) } output(Cash.PROGRAM_ID) { outState.copy(amount = 800.DOLLARS `issued by` defaultIssuer) }
output(PtCash.PROGRAM_ID) { outState.copy(amount = 200.POUNDS `issued by` defaultIssuer) } output(Cash.PROGRAM_ID) { outState.copy(amount = 200.POUNDS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
input(PtCash.PROGRAM_ID) { input(Cash.PROGRAM_ID) {
inState.copy( inState.copy(
amount = 150.POUNDS `issued by` defaultIssuer, amount = 150.POUNDS `issued by` defaultIssuer,
owner = AnonymousParty(BOB_PUBKEY) owner = AnonymousParty(BOB_PUBKEY)
) )
} }
output(PtCash.PROGRAM_ID) { outState.copy(amount = 1150.DOLLARS `issued by` defaultIssuer) } output(Cash.PROGRAM_ID) { outState.copy(amount = 1150.DOLLARS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
// Can't have superfluous input states from different issuers. // Can't have superfluous input states from different issuers.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
input(PtCash.PROGRAM_ID) { inState `issued by` MINI_CORP } input(Cash.PROGRAM_ID) { inState `issued by` MINI_CORP }
output(PtCash.PROGRAM_ID) { outState } output(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
// Can't combine two different deposits at the same issuer. // Can't combine two different deposits at the same issuer.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
input(PtCash.PROGRAM_ID) { inState.editDepositRef(3) } input(Cash.PROGRAM_ID) { inState.editDepositRef(3) }
output(PtCash.PROGRAM_ID) { outState.copy(amount = inState.amount * 2).editDepositRef(3) } output(Cash.PROGRAM_ID) { outState.copy(amount = inState.amount * 2).editDepositRef(3) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "for reference [01]" this `fails with` "for reference [01]"
} }
} }
@ -417,22 +417,22 @@ class PtCashTests : TestDependencyInjectionBase() {
fun exitLedger() { fun exitLedger() {
// Single input/output straightforward case. // Single input/output straightforward case.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { issuerInState } input(Cash.PROGRAM_ID) { issuerInState }
output(PtCash.PROGRAM_ID) { issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) } output(Cash.PROGRAM_ID) { issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
tweak { tweak {
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Exit(100.DOLLARS `issued by` defaultIssuer) } command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(100.DOLLARS `issued by` defaultIssuer) }
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Move() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
tweak { tweak {
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) } command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) }
this `fails with` "required com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash.Commands.Move command" this `fails with` "required com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash.Commands.Move command"
tweak { tweak {
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Move() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }
} }
@ -443,21 +443,21 @@ class PtCashTests : TestDependencyInjectionBase() {
fun `exit ledger with multiple issuers`() { fun `exit ledger with multiple issuers`() {
// Multi-issuer case. // Multi-issuer case.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { issuerInState } input(Cash.PROGRAM_ID) { issuerInState }
input(PtCash.PROGRAM_ID) { issuerInState.copy(owner = MINI_CORP) `issued by` MINI_CORP } input(Cash.PROGRAM_ID) { issuerInState.copy(owner = MINI_CORP) `issued by` MINI_CORP }
output(PtCash.PROGRAM_ID) { issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) `issued by` MINI_CORP } output(Cash.PROGRAM_ID) { issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) `issued by` MINI_CORP }
output(PtCash.PROGRAM_ID) { issuerInState.copy(owner = MINI_CORP, amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) } output(Cash.PROGRAM_ID) { issuerInState.copy(owner = MINI_CORP, amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
command(MEGA_CORP_PUBKEY, MINI_CORP_PUBKEY) { PtCash.Commands.Move() } command(MEGA_CORP_PUBKEY, MINI_CORP_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) } command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
command(MINI_CORP_PUBKEY) { PtCash.Commands.Exit(200.DOLLARS `issued by` MINI_CORP.ref(defaultRef)) } command(MINI_CORP_PUBKEY) { Cash.Commands.Exit(200.DOLLARS `issued by` MINI_CORP.ref(defaultRef)) }
this.verifies() this.verifies()
} }
} }
@ -466,11 +466,11 @@ class PtCashTests : TestDependencyInjectionBase() {
fun `exit cash not held by its issuer`() { fun `exit cash not held by its issuer`() {
// Single input/output straightforward case. // Single input/output straightforward case.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
output(PtCash.PROGRAM_ID) { outState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) } output(Cash.PROGRAM_ID) { outState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) } command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
} }
@ -478,27 +478,27 @@ class PtCashTests : TestDependencyInjectionBase() {
@Test @Test
fun multiIssuer() { fun multiIssuer() {
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
// Gather 2000 dollars from two different issuers. // Gather 2000 dollars from two different issuers.
input(PtCash.PROGRAM_ID) { inState } input(Cash.PROGRAM_ID) { inState }
input(PtCash.PROGRAM_ID) { inState `issued by` MINI_CORP } input(Cash.PROGRAM_ID) { inState `issued by` MINI_CORP }
command(ALICE_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY) { Cash.Commands.Move() }
// Can't merge them together. // Can't merge them together.
tweak { tweak {
output(PtCash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY), amount = 2000.DOLLARS `issued by` defaultIssuer) } output(Cash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY), amount = 2000.DOLLARS `issued by` defaultIssuer) }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
// Missing MiniCorp deposit // Missing MiniCorp deposit
tweak { tweak {
output(PtCash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) } output(Cash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) }
output(PtCash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) } output(Cash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) }
this `fails with` "the amounts balance" this `fails with` "the amounts balance"
} }
// This works. // This works.
output(PtCash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) } output(Cash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) }
output(PtCash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) `issued by` MINI_CORP } output(Cash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) `issued by` MINI_CORP }
this.verifies() this.verifies()
} }
} }
@ -507,13 +507,13 @@ class PtCashTests : TestDependencyInjectionBase() {
fun multiCurrency() { fun multiCurrency() {
// Check we can do an atomic currency trade tx. // Check we can do an atomic currency trade tx.
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
val pounds = PtCash.State(658.POUNDS `issued by` MINI_CORP.ref(3, 4, 5), AnonymousParty(BOB_PUBKEY)) val pounds = Cash.State(658.POUNDS `issued by` MINI_CORP.ref(3, 4, 5), AnonymousParty(BOB_PUBKEY))
input(PtCash.PROGRAM_ID) { inState `owned by` AnonymousParty(ALICE_PUBKEY) } input(Cash.PROGRAM_ID) { inState `owned by` AnonymousParty(ALICE_PUBKEY) }
input(PtCash.PROGRAM_ID) { pounds } input(Cash.PROGRAM_ID) { pounds }
output(PtCash.PROGRAM_ID) { inState `owned by` AnonymousParty(BOB_PUBKEY) } output(Cash.PROGRAM_ID) { inState `owned by` AnonymousParty(BOB_PUBKEY) }
output(PtCash.PROGRAM_ID) { pounds `owned by` AnonymousParty(ALICE_PUBKEY) } output(Cash.PROGRAM_ID) { pounds `owned by` AnonymousParty(ALICE_PUBKEY) }
command(ALICE_PUBKEY, BOB_PUBKEY) { PtCash.Commands.Move() } command(ALICE_PUBKEY, BOB_PUBKEY) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }
@ -531,7 +531,7 @@ class PtCashTests : TestDependencyInjectionBase() {
fun makeCash(amount: Amount<Currency>, corp: Party, depositRef: Byte = 1) = fun makeCash(amount: Amount<Currency>, corp: Party, depositRef: Byte = 1) =
StateAndRef( StateAndRef(
TransactionState<PtCash.State>(PtCash.State(amount `issued by` corp.ref(depositRef), OUR_IDENTITY_1), PtCash.PROGRAM_ID, DUMMY_NOTARY), TransactionState<Cash.State>(Cash.State(amount `issued by` corp.ref(depositRef), OUR_IDENTITY_1), Cash.PROGRAM_ID, DUMMY_NOTARY),
StateRef(SecureHash.randomSHA256(), Random().nextInt(32)) StateRef(SecureHash.randomSHA256(), Random().nextInt(32))
) )
@ -547,14 +547,14 @@ class PtCashTests : TestDependencyInjectionBase() {
*/ */
private fun makeExit(amount: Amount<Currency>, corp: Party, depositRef: Byte = 1): WireTransaction { private fun makeExit(amount: Amount<Currency>, corp: Party, depositRef: Byte = 1): WireTransaction {
val tx = TransactionBuilder(DUMMY_NOTARY) val tx = TransactionBuilder(DUMMY_NOTARY)
PtCash().generateExit(tx, Amount(amount.quantity, Issued(corp.ref(depositRef), amount.token)), WALLET) Cash().generateExit(tx, Amount(amount.quantity, Issued(corp.ref(depositRef), amount.token)), WALLET)
return tx.toWireTransaction(miniCorpServices) return tx.toWireTransaction(miniCorpServices)
} }
private fun makeSpend(amount: Amount<Currency>, dest: AbstractParty): WireTransaction { private fun makeSpend(amount: Amount<Currency>, dest: AbstractParty): WireTransaction {
val tx = TransactionBuilder(DUMMY_NOTARY) val tx = TransactionBuilder(DUMMY_NOTARY)
database.transaction { database.transaction {
PtCash.generateSpend(miniCorpServices, tx, amount, dest) Cash.generateSpend(miniCorpServices, tx, amount, dest)
} }
return tx.toWireTransaction(miniCorpServices) return tx.toWireTransaction(miniCorpServices)
} }
@ -569,8 +569,8 @@ class PtCashTests : TestDependencyInjectionBase() {
assertEquals(WALLET[0].ref, wtx.inputs[0]) assertEquals(WALLET[0].ref, wtx.inputs[0])
assertEquals(0, wtx.outputs.size) assertEquals(0, wtx.outputs.size)
val expectedMove = PtCash.Commands.Move() val expectedMove = Cash.Commands.Move()
val expectedExit = PtCash.Commands.Exit(Amount(10000, Issued(MEGA_CORP.ref(1), USD))) val expectedExit = Cash.Commands.Exit(Amount(10000, Issued(MEGA_CORP.ref(1), USD)))
assertEquals(listOf(expectedMove, expectedExit), wtx.commands.map { it.value }) assertEquals(listOf(expectedMove, expectedExit), wtx.commands.map { it.value })
} }
@ -631,7 +631,7 @@ class PtCashTests : TestDependencyInjectionBase() {
initialiseTestSerialization() initialiseTestSerialization()
assertFailsWith<InsufficientBalanceException> { assertFailsWith<InsufficientBalanceException> {
val tx = TransactionBuilder(DUMMY_NOTARY) val tx = TransactionBuilder(DUMMY_NOTARY)
PtCash().generateExit(tx, Amount(100, Issued(CHARLIE.ref(1), GBP)), emptyList()) Cash().generateExit(tx, Amount(100, Issued(CHARLIE.ref(1), GBP)), emptyList())
} }
} }
@ -647,7 +647,7 @@ class PtCashTests : TestDependencyInjectionBase() {
val vaultState = vaultStatesUnconsumed.elementAt(0) val vaultState = vaultStatesUnconsumed.elementAt(0)
assertEquals(vaultState.ref, wtx.inputs[0]) assertEquals(vaultState.ref, wtx.inputs[0])
assertEquals(vaultState.state.data.copy(owner = THEIR_IDENTITY_1), wtx.getOutput(0)) assertEquals(vaultState.state.data.copy(owner = THEIR_IDENTITY_1), wtx.getOutput(0))
assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is PtCash.Commands.Move }.signers[0]) assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is Cash.Commands.Move }.signers[0])
} }
} }
@ -657,7 +657,7 @@ class PtCashTests : TestDependencyInjectionBase() {
database.transaction { database.transaction {
val tx = TransactionBuilder(DUMMY_NOTARY) val tx = TransactionBuilder(DUMMY_NOTARY)
PtCash.generateSpend(miniCorpServices, tx, 80.DOLLARS, ALICE, setOf(MINI_CORP)) Cash.generateSpend(miniCorpServices, tx, 80.DOLLARS, ALICE, setOf(MINI_CORP))
assertEquals(vaultStatesUnconsumed.elementAt(2).ref, tx.inputStates()[0]) assertEquals(vaultStatesUnconsumed.elementAt(2).ref, tx.inputStates()[0])
} }
@ -675,18 +675,18 @@ class PtCashTests : TestDependencyInjectionBase() {
val vaultState = vaultStatesUnconsumed.elementAt(0) val vaultState = vaultStatesUnconsumed.elementAt(0)
val changeAmount = 90.DOLLARS `issued by` defaultIssuer val changeAmount = 90.DOLLARS `issued by` defaultIssuer
val likelyChangeState = wtx.outputs.map(TransactionState<*>::data).filter { state -> val likelyChangeState = wtx.outputs.map(TransactionState<*>::data).filter { state ->
if (state is PtCash.State) { if (state is Cash.State) {
state.amount == changeAmount state.amount == changeAmount
} else { } else {
false false
} }
}.single() }.single()
val changeOwner = (likelyChangeState as PtCash.State).owner val changeOwner = (likelyChangeState as Cash.State).owner
assertEquals(1, miniCorpServices.keyManagementService.filterMyKeys(setOf(changeOwner.owningKey)).toList().size) assertEquals(1, miniCorpServices.keyManagementService.filterMyKeys(setOf(changeOwner.owningKey)).toList().size)
assertEquals(vaultState.ref, wtx.inputs[0]) assertEquals(vaultState.ref, wtx.inputs[0])
assertEquals(vaultState.state.data.copy(owner = THEIR_IDENTITY_1, amount = 10.DOLLARS `issued by` defaultIssuer), wtx.outputs[0].data) assertEquals(vaultState.state.data.copy(owner = THEIR_IDENTITY_1, amount = 10.DOLLARS `issued by` defaultIssuer), wtx.outputs[0].data)
assertEquals(vaultState.state.data.copy(amount = changeAmount, owner = changeOwner), wtx.outputs[1].data) assertEquals(vaultState.state.data.copy(amount = changeAmount, owner = changeOwner), wtx.outputs[1].data)
assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is PtCash.Commands.Move }.signers[0]) assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is Cash.Commands.Move }.signers[0])
} }
} }
@ -704,7 +704,7 @@ class PtCashTests : TestDependencyInjectionBase() {
assertEquals(vaultState0.ref, wtx.inputs[0]) assertEquals(vaultState0.ref, wtx.inputs[0])
assertEquals(vaultState1.ref, wtx.inputs[1]) assertEquals(vaultState1.ref, wtx.inputs[1])
assertEquals(vaultState0.state.data.copy(owner = THEIR_IDENTITY_1, amount = 500.DOLLARS `issued by` defaultIssuer), wtx.getOutput(0)) assertEquals(vaultState0.state.data.copy(owner = THEIR_IDENTITY_1, amount = 500.DOLLARS `issued by` defaultIssuer), wtx.getOutput(0))
assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is PtCash.Commands.Move }.signers[0]) assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is Cash.Commands.Move }.signers[0])
} }
} }
@ -718,15 +718,15 @@ class PtCashTests : TestDependencyInjectionBase() {
wtx wtx
} }
database.transaction { database.transaction {
val vaultState0: StateAndRef<PtCash.State> = vaultStatesUnconsumed.elementAt(0) val vaultState0: StateAndRef<Cash.State> = vaultStatesUnconsumed.elementAt(0)
val vaultState1: StateAndRef<PtCash.State> = vaultStatesUnconsumed.elementAt(1) val vaultState1: StateAndRef<Cash.State> = vaultStatesUnconsumed.elementAt(1)
val vaultState2: StateAndRef<PtCash.State> = vaultStatesUnconsumed.elementAt(2) val vaultState2: StateAndRef<Cash.State> = vaultStatesUnconsumed.elementAt(2)
assertEquals(vaultState0.ref, wtx.inputs[0]) assertEquals(vaultState0.ref, wtx.inputs[0])
assertEquals(vaultState1.ref, wtx.inputs[1]) assertEquals(vaultState1.ref, wtx.inputs[1])
assertEquals(vaultState2.ref, wtx.inputs[2]) assertEquals(vaultState2.ref, wtx.inputs[2])
assertEquals(vaultState0.state.data.copy(owner = THEIR_IDENTITY_1, amount = 500.DOLLARS `issued by` defaultIssuer), wtx.outputs[1].data) assertEquals(vaultState0.state.data.copy(owner = THEIR_IDENTITY_1, amount = 500.DOLLARS `issued by` defaultIssuer), wtx.outputs[1].data)
assertEquals(vaultState2.state.data.copy(owner = THEIR_IDENTITY_1), wtx.outputs[0].data) assertEquals(vaultState2.state.data.copy(owner = THEIR_IDENTITY_1), wtx.outputs[0].data)
assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is PtCash.Commands.Move }.signers[0]) assertEquals(OUR_IDENTITY_1.owningKey, wtx.commands.single { it.value is Cash.Commands.Move }.signers[0])
} }
} }
@ -751,9 +751,9 @@ class PtCashTests : TestDependencyInjectionBase() {
*/ */
@Test @Test
fun aggregation() { fun aggregation() {
val fiveThousandDollarsFromMega = PtCash.State(5000.DOLLARS `issued by` MEGA_CORP.ref(2), MEGA_CORP) val fiveThousandDollarsFromMega = Cash.State(5000.DOLLARS `issued by` MEGA_CORP.ref(2), MEGA_CORP)
val twoThousandDollarsFromMega = PtCash.State(2000.DOLLARS `issued by` MEGA_CORP.ref(2), MINI_CORP) val twoThousandDollarsFromMega = Cash.State(2000.DOLLARS `issued by` MEGA_CORP.ref(2), MINI_CORP)
val oneThousandDollarsFromMini = PtCash.State(1000.DOLLARS `issued by` MINI_CORP.ref(3), MEGA_CORP) val oneThousandDollarsFromMini = Cash.State(1000.DOLLARS `issued by` MINI_CORP.ref(3), MEGA_CORP)
// Obviously it must be possible to aggregate states with themselves // Obviously it must be possible to aggregate states with themselves
assertEquals(fiveThousandDollarsFromMega.amount.token, fiveThousandDollarsFromMega.amount.token) assertEquals(fiveThousandDollarsFromMega.amount.token, fiveThousandDollarsFromMega.amount.token)
@ -767,7 +767,7 @@ class PtCashTests : TestDependencyInjectionBase() {
// States cannot be aggregated if the currency differs // States cannot be aggregated if the currency differs
assertNotEquals(oneThousandDollarsFromMini.amount.token, assertNotEquals(oneThousandDollarsFromMini.amount.token,
PtCash.State(1000.POUNDS `issued by` MINI_CORP.ref(3), MEGA_CORP).amount.token) Cash.State(1000.POUNDS `issued by` MINI_CORP.ref(3), MEGA_CORP).amount.token)
// States cannot be aggregated if the reference differs // States cannot be aggregated if the reference differs
assertNotEquals(fiveThousandDollarsFromMega.amount.token, (fiveThousandDollarsFromMega `with deposit` defaultIssuer).amount.token) assertNotEquals(fiveThousandDollarsFromMega.amount.token, (fiveThousandDollarsFromMega `with deposit` defaultIssuer).amount.token)
@ -777,9 +777,9 @@ class PtCashTests : TestDependencyInjectionBase() {
@Test @Test
fun `summing by owner`() { fun `summing by owner`() {
val states = listOf( val states = listOf(
PtCash.State(1000.DOLLARS `issued by` defaultIssuer, MINI_CORP), Cash.State(1000.DOLLARS `issued by` defaultIssuer, MINI_CORP),
PtCash.State(2000.DOLLARS `issued by` defaultIssuer, MEGA_CORP), Cash.State(2000.DOLLARS `issued by` defaultIssuer, MEGA_CORP),
PtCash.State(4000.DOLLARS `issued by` defaultIssuer, MEGA_CORP) Cash.State(4000.DOLLARS `issued by` defaultIssuer, MEGA_CORP)
) )
assertEquals(6000.DOLLARS `issued by` defaultIssuer, states.sumCashBy(MEGA_CORP)) assertEquals(6000.DOLLARS `issued by` defaultIssuer, states.sumCashBy(MEGA_CORP))
} }
@ -787,31 +787,31 @@ class PtCashTests : TestDependencyInjectionBase() {
@Test(expected = UnsupportedOperationException::class) @Test(expected = UnsupportedOperationException::class)
fun `summing by owner throws`() { fun `summing by owner throws`() {
val states = listOf( val states = listOf(
PtCash.State(2000.DOLLARS `issued by` defaultIssuer, MEGA_CORP), Cash.State(2000.DOLLARS `issued by` defaultIssuer, MEGA_CORP),
PtCash.State(4000.DOLLARS `issued by` defaultIssuer, MEGA_CORP) Cash.State(4000.DOLLARS `issued by` defaultIssuer, MEGA_CORP)
) )
states.sumCashBy(MINI_CORP) states.sumCashBy(MINI_CORP)
} }
@Test @Test
fun `summing no currencies`() { fun `summing no currencies`() {
val states = emptyList<PtCash.State>() val states = emptyList<Cash.State>()
assertEquals(0.POUNDS `issued by` defaultIssuer, states.sumCashOrZero(GBP `issued by` defaultIssuer)) assertEquals(0.POUNDS `issued by` defaultIssuer, states.sumCashOrZero(GBP `issued by` defaultIssuer))
assertNull(states.sumCashOrNull()) assertNull(states.sumCashOrNull())
} }
@Test(expected = UnsupportedOperationException::class) @Test(expected = UnsupportedOperationException::class)
fun `summing no currencies throws`() { fun `summing no currencies throws`() {
val states = emptyList<PtCash.State>() val states = emptyList<Cash.State>()
states.sumCash() states.sumCash()
} }
@Test @Test
fun `summing a single currency`() { fun `summing a single currency`() {
val states = listOf( val states = listOf(
PtCash.State(1000.DOLLARS `issued by` defaultIssuer, MEGA_CORP), Cash.State(1000.DOLLARS `issued by` defaultIssuer, MEGA_CORP),
PtCash.State(2000.DOLLARS `issued by` defaultIssuer, MEGA_CORP), Cash.State(2000.DOLLARS `issued by` defaultIssuer, MEGA_CORP),
PtCash.State(4000.DOLLARS `issued by` defaultIssuer, MEGA_CORP) Cash.State(4000.DOLLARS `issued by` defaultIssuer, MEGA_CORP)
) )
// Test that summing everything produces the total number of dollars // Test that summing everything produces the total number of dollars
val expected = 7000.DOLLARS `issued by` defaultIssuer val expected = 7000.DOLLARS `issued by` defaultIssuer
@ -822,8 +822,8 @@ class PtCashTests : TestDependencyInjectionBase() {
@Test(expected = IllegalArgumentException::class) @Test(expected = IllegalArgumentException::class)
fun `summing multiple currencies`() { fun `summing multiple currencies`() {
val states = listOf( val states = listOf(
PtCash.State(1000.DOLLARS `issued by` defaultIssuer, MEGA_CORP), Cash.State(1000.DOLLARS `issued by` defaultIssuer, MEGA_CORP),
PtCash.State(4000.POUNDS `issued by` defaultIssuer, MEGA_CORP) Cash.State(4000.POUNDS `issued by` defaultIssuer, MEGA_CORP)
) )
// Test that summing everything fails because we're mixing units // Test that summing everything fails because we're mixing units
states.sumCash() states.sumCash()
@ -836,9 +836,9 @@ class PtCashTests : TestDependencyInjectionBase() {
ledger(mockService) { ledger(mockService) {
unverifiedTransaction { unverifiedTransaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
output(PtCash.PROGRAM_ID, "MEGA_CORP cash") { output(Cash.PROGRAM_ID, "MEGA_CORP cash") {
PtCash.State( Cash.State(
amount = 1000.DOLLARS `issued by` MEGA_CORP.ref(1, 1), amount = 1000.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MEGA_CORP owner = MEGA_CORP
) )
@ -846,20 +846,20 @@ class PtCashTests : TestDependencyInjectionBase() {
} }
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input("MEGA_CORP cash") input("MEGA_CORP cash")
output(PtCash.PROGRAM_ID, "MEGA_CORP cash 2", "MEGA_CORP cash".output<PtCash.State>().copy(owner = AnonymousParty(ALICE_PUBKEY)) ) output(Cash.PROGRAM_ID, "MEGA_CORP cash 2", "MEGA_CORP cash".output<Cash.State>().copy(owner = AnonymousParty(ALICE_PUBKEY)) )
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Move() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }
tweak { tweak {
transaction { transaction {
attachment(PtCash.PROGRAM_ID) attachment(Cash.PROGRAM_ID)
input("MEGA_CORP cash") input("MEGA_CORP cash")
// We send it to another pubkey so that the transaction is not identical to the previous one // We send it to another pubkey so that the transaction is not identical to the previous one
output(PtCash.PROGRAM_ID, "MEGA_CORP cash 3", "MEGA_CORP cash".output<PtCash.State>().copy(owner = ALICE)) output(Cash.PROGRAM_ID, "MEGA_CORP cash 3", "MEGA_CORP cash".output<Cash.State>().copy(owner = ALICE))
command(MEGA_CORP_PUBKEY) { PtCash.Commands.Move() } command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }
this.fails() this.fails()
@ -878,10 +878,10 @@ class PtCashTests : TestDependencyInjectionBase() {
PartyAndAmount(THEIR_IDENTITY_1, 400.DOLLARS), PartyAndAmount(THEIR_IDENTITY_1, 400.DOLLARS),
PartyAndAmount(THEIR_IDENTITY_2, 150.DOLLARS) PartyAndAmount(THEIR_IDENTITY_2, 150.DOLLARS)
) )
PtCash.generateSpend(miniCorpServices, tx, payments) Cash.generateSpend(miniCorpServices, tx, payments)
} }
val wtx = tx.toWireTransaction(miniCorpServices) val wtx = tx.toWireTransaction(miniCorpServices)
fun out(i: Int) = wtx.getOutput(i) as PtCash.State fun out(i: Int) = wtx.getOutput(i) as Cash.State
assertEquals(4, wtx.outputs.size) assertEquals(4, wtx.outputs.size)
assertEquals(80.DOLLARS, out(0).amount.withoutIssuer()) assertEquals(80.DOLLARS, out(0).amount.withoutIssuer())
assertEquals(320.DOLLARS, out(1).amount.withoutIssuer()) assertEquals(320.DOLLARS, out(1).amount.withoutIssuer())

View File

@ -4,11 +4,11 @@ import net.corda.core.identity.Party
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 com.r3.corda.enterprise.perftestcordapp.flows.PtCashException import com.r3.corda.enterprise.perftestcordapp.flows.PtCashException
import com.r3.corda.enterprise.perftestcordapp.flows.PtCashExitFlow import com.r3.corda.enterprise.perftestcordapp.flows.CashExitFlow
import com.r3.corda.enterprise.perftestcordapp.flows.PtCashIssueFlow import com.r3.corda.enterprise.perftestcordapp.flows.CashIssueFlow
import com.r3.corda.enterprise.perftestcordapp.DOLLARS import com.r3.corda.enterprise.perftestcordapp.DOLLARS
import com.r3.corda.enterprise.perftestcordapp.`issued by` import com.r3.corda.enterprise.perftestcordapp.`issued by`
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import net.corda.node.internal.StartedNode import net.corda.node.internal.StartedNode
import net.corda.testing.chooseIdentity import net.corda.testing.chooseIdentity
import net.corda.testing.getDefaultNotary import net.corda.testing.getDefaultNotary
@ -43,7 +43,7 @@ class CashExitFlowTests {
mockNet.runNetwork() mockNet.runNetwork()
notary = bankOfCordaNode.services.getDefaultNotary() notary = bankOfCordaNode.services.getDefaultNotary()
val future = bankOfCordaNode.services.startFlow(PtCashIssueFlow(initialBalance, ref, notary)).resultFuture val future = bankOfCordaNode.services.startFlow(CashIssueFlow(initialBalance, ref, notary)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
future.getOrThrow() future.getOrThrow()
} }
@ -57,20 +57,20 @@ class CashExitFlowTests {
@Test @Test
fun `exit some cash`() { fun `exit some cash`() {
val exitAmount = 500.DOLLARS val exitAmount = 500.DOLLARS
val future = bankOfCordaNode.services.startFlow(PtCashExitFlow(exitAmount, ref)).resultFuture val future = bankOfCordaNode.services.startFlow(CashExitFlow(exitAmount, ref)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
val exitTx = future.getOrThrow().stx.tx val exitTx = future.getOrThrow().stx.tx
val expected = (initialBalance - exitAmount).`issued by`(bankOfCorda.ref(ref)) val expected = (initialBalance - exitAmount).`issued by`(bankOfCorda.ref(ref))
assertEquals(1, exitTx.inputs.size) assertEquals(1, exitTx.inputs.size)
assertEquals(1, exitTx.outputs.size) assertEquals(1, exitTx.outputs.size)
val output = exitTx.outputsOfType<PtCash.State>().single() val output = exitTx.outputsOfType<Cash.State>().single()
assertEquals(expected, output.amount) assertEquals(expected, output.amount)
} }
@Test @Test
fun `exit zero cash`() { fun `exit zero cash`() {
val expected = 0.DOLLARS val expected = 0.DOLLARS
val future = bankOfCordaNode.services.startFlow(PtCashExitFlow(expected, ref)).resultFuture val future = bankOfCordaNode.services.startFlow(CashExitFlow(expected, ref)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
assertFailsWith<PtCashException> { assertFailsWith<PtCashException> {
future.getOrThrow() future.getOrThrow()

View File

@ -5,9 +5,9 @@ import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import com.r3.corda.enterprise.perftestcordapp.DOLLARS import com.r3.corda.enterprise.perftestcordapp.DOLLARS
import com.r3.corda.enterprise.perftestcordapp.`issued by` import com.r3.corda.enterprise.perftestcordapp.`issued by`
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import net.corda.node.internal.StartedNode import net.corda.node.internal.StartedNode
import com.r3.corda.enterprise.perftestcordapp.flows.PtCashIssueFlow import com.r3.corda.enterprise.perftestcordapp.flows.CashIssueFlow
import net.corda.testing.chooseIdentity import net.corda.testing.chooseIdentity
import net.corda.testing.getDefaultNotary import net.corda.testing.getDefaultNotary
import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin
@ -49,10 +49,10 @@ class CashIssueFlowTests {
fun `issue some cash`() { fun `issue some cash`() {
val expected = 500.DOLLARS val expected = 500.DOLLARS
val ref = OpaqueBytes.of(0x01) val ref = OpaqueBytes.of(0x01)
val future = bankOfCordaNode.services.startFlow(PtCashIssueFlow(expected, ref, notary)).resultFuture val future = bankOfCordaNode.services.startFlow(CashIssueFlow(expected, ref, notary)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
val issueTx = future.getOrThrow().stx val issueTx = future.getOrThrow().stx
val output = issueTx.tx.outputsOfType<PtCash.State>().single() val output = issueTx.tx.outputsOfType<Cash.State>().single()
assertEquals(expected.`issued by`(bankOfCorda.ref(ref)), output.amount) assertEquals(expected.`issued by`(bankOfCorda.ref(ref)), output.amount)
} }
@ -60,7 +60,7 @@ class CashIssueFlowTests {
fun `issue zero cash`() { fun `issue zero cash`() {
val expected = 0.DOLLARS val expected = 0.DOLLARS
val ref = OpaqueBytes.of(0x01) val ref = OpaqueBytes.of(0x01)
val future = bankOfCordaNode.services.startFlow(PtCashIssueFlow(expected, ref, notary)).resultFuture val future = bankOfCordaNode.services.startFlow(CashIssueFlow(expected, ref, notary)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
assertFailsWith<IllegalArgumentException> { assertFailsWith<IllegalArgumentException> {
future.getOrThrow() future.getOrThrow()

View File

@ -8,10 +8,10 @@ import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import com.r3.corda.enterprise.perftestcordapp.DOLLARS import com.r3.corda.enterprise.perftestcordapp.DOLLARS
import com.r3.corda.enterprise.perftestcordapp.`issued by` import com.r3.corda.enterprise.perftestcordapp.`issued by`
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.flows.PtCashException import com.r3.corda.enterprise.perftestcordapp.flows.PtCashException
import com.r3.corda.enterprise.perftestcordapp.flows.PtCashIssueFlow import com.r3.corda.enterprise.perftestcordapp.flows.CashIssueFlow
import com.r3.corda.enterprise.perftestcordapp.flows.PtCashPaymentFlow import com.r3.corda.enterprise.perftestcordapp.flows.CashPaymentFlow
import net.corda.node.internal.StartedNode import net.corda.node.internal.StartedNode
import net.corda.testing.chooseIdentity import net.corda.testing.chooseIdentity
import net.corda.testing.expect import net.corda.testing.expect
@ -45,7 +45,7 @@ class CashPaymentFlowTests {
bankOfCordaNode = nodes.partyNodes[0] bankOfCordaNode = nodes.partyNodes[0]
bankOfCorda = bankOfCordaNode.info.chooseIdentity() bankOfCorda = bankOfCordaNode.info.chooseIdentity()
notary = notaryNode.services.getDefaultNotary() notary = notaryNode.services.getDefaultNotary()
val future = bankOfCordaNode.services.startFlow(PtCashIssueFlow(initialBalance, ref, notary)).resultFuture val future = bankOfCordaNode.services.startFlow(CashIssueFlow(initialBalance, ref, notary)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
future.getOrThrow() future.getOrThrow()
} }
@ -64,10 +64,10 @@ class CashPaymentFlowTests {
bankOfCordaNode.database.transaction { bankOfCordaNode.database.transaction {
// Register for vault updates // Register for vault updates
val criteria = QueryCriteria.VaultQueryCriteria(status = Vault.StateStatus.ALL) val criteria = QueryCriteria.VaultQueryCriteria(status = Vault.StateStatus.ALL)
val (_, vaultUpdatesBoc) = bankOfCordaNode.services.vaultQueryService.trackBy<PtCash.State>(criteria) val (_, vaultUpdatesBoc) = bankOfCordaNode.services.vaultQueryService.trackBy<Cash.State>(criteria)
val (_, vaultUpdatesBankClient) = notaryNode.services.vaultQueryService.trackBy<PtCash.State>(criteria) val (_, vaultUpdatesBankClient) = notaryNode.services.vaultQueryService.trackBy<Cash.State>(criteria)
val future = bankOfCordaNode.services.startFlow(PtCashPaymentFlow(expectedPayment, val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expectedPayment,
payTo)).resultFuture payTo)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
future.getOrThrow() future.getOrThrow()
@ -99,7 +99,7 @@ class CashPaymentFlowTests {
fun `pay more than we have`() { fun `pay more than we have`() {
val payTo = notaryNode.info.chooseIdentity() val payTo = notaryNode.info.chooseIdentity()
val expected = 4000.DOLLARS val expected = 4000.DOLLARS
val future = bankOfCordaNode.services.startFlow(PtCashPaymentFlow(expected, val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
payTo)).resultFuture payTo)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
assertFailsWith<PtCashException> { assertFailsWith<PtCashException> {
@ -111,7 +111,7 @@ class CashPaymentFlowTests {
fun `pay zero cash`() { fun `pay zero cash`() {
val payTo = notaryNode.info.chooseIdentity() val payTo = notaryNode.info.chooseIdentity()
val expected = 0.DOLLARS val expected = 0.DOLLARS
val future = bankOfCordaNode.services.startFlow(PtCashPaymentFlow(expected, val future = bankOfCordaNode.services.startFlow(CashPaymentFlow(expected,
payTo)).resultFuture payTo)).resultFuture
mockNet.runNetwork() mockNet.runNetwork()
assertFailsWith<IllegalArgumentException> { assertFailsWith<IllegalArgumentException> {

View File

@ -28,9 +28,9 @@ import net.corda.core.utilities.toNonEmptySet
import net.corda.core.utilities.unwrap import net.corda.core.utilities.unwrap
import com.r3.corda.enterprise.perftestcordapp.DOLLARS import com.r3.corda.enterprise.perftestcordapp.DOLLARS
import com.r3.corda.enterprise.perftestcordapp.`issued by` import com.r3.corda.enterprise.perftestcordapp.`issued by`
import com.r3.corda.enterprise.perftestcordapp.contracts.PtCommercialPaper import com.r3.corda.enterprise.perftestcordapp.contracts.CommercialPaper
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.CASH import com.r3.corda.enterprise.perftestcordapp.contracts.asset.CASH
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.`issued by` import com.r3.corda.enterprise.perftestcordapp.contracts.asset.`issued by`
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.`owned by` import com.r3.corda.enterprise.perftestcordapp.contracts.asset.`owned by`
import com.r3.corda.enterprise.perftestcordapp.flows.TwoPartyTradeFlow.Buyer import com.r3.corda.enterprise.perftestcordapp.flows.TwoPartyTradeFlow.Buyer
@ -583,7 +583,7 @@ class TwoPartyTradeFlowTests {
require(serviceHub.networkMapCache.isNotary(it.notaryIdentity)) { "${it.notaryIdentity} is not a notary" } require(serviceHub.networkMapCache.isNotary(it.notaryIdentity)) { "${it.notaryIdentity} is not a notary" }
it it
} }
return subFlow(Buyer(sellerSession, notary, price, PtCommercialPaper.State::class.java, anonymous)) return subFlow(Buyer(sellerSession, notary, price, CommercialPaper.State::class.java, anonymous))
} }
} }
@ -680,13 +680,13 @@ class TwoPartyTradeFlowTests {
// wants to sell to Bob. // wants to sell to Bob.
val eb1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) { val eb1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
// Issued money to itself. // Issued money to itself.
output(PtCash.PROGRAM_ID, "elbonian money 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` interimOwner } output(Cash.PROGRAM_ID, "elbonian money 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` interimOwner }
output(PtCash.PROGRAM_ID, "elbonian money 2", notary = notary) { 1000.DOLLARS.CASH `issued by` issuer `owned by` interimOwner } output(Cash.PROGRAM_ID, "elbonian money 2", notary = notary) { 1000.DOLLARS.CASH `issued by` issuer `owned by` interimOwner }
if (!withError) { if (!withError) {
command(issuer.party.owningKey) { PtCash.Commands.Issue() } command(issuer.party.owningKey) { Cash.Commands.Issue() }
} else { } else {
// Put a broken command on so at least a signature is created // Put a broken command on so at least a signature is created
command(issuer.party.owningKey) { PtCash.Commands.Move() } command(issuer.party.owningKey) { Cash.Commands.Move() }
} }
timeWindow(TEST_TX_TIME) timeWindow(TEST_TX_TIME)
if (withError) { if (withError) {
@ -699,16 +699,16 @@ class TwoPartyTradeFlowTests {
// Bob gets some cash onto the ledger from BoE // Bob gets some cash onto the ledger from BoE
val bc1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) { val bc1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
input("elbonian money 1") input("elbonian money 1")
output(PtCash.PROGRAM_ID, "bob cash 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` owner } output(Cash.PROGRAM_ID, "bob cash 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` owner }
command(interimOwner.owningKey) { PtCash.Commands.Move() } command(interimOwner.owningKey) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }
val bc2 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) { val bc2 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
input("elbonian money 2") input("elbonian money 2")
output(PtCash.PROGRAM_ID, "bob cash 2", notary = notary) { 300.DOLLARS.CASH `issued by` issuer `owned by` owner } output(Cash.PROGRAM_ID, "bob cash 2", notary = notary) { 300.DOLLARS.CASH `issued by` issuer `owned by` owner }
output(PtCash.PROGRAM_ID, notary = notary) { 700.DOLLARS.CASH `issued by` issuer `owned by` interimOwner } // Change output. output(Cash.PROGRAM_ID, notary = notary) { 700.DOLLARS.CASH `issued by` issuer `owned by` interimOwner } // Change output.
command(interimOwner.owningKey) { PtCash.Commands.Move() } command(interimOwner.owningKey) { Cash.Commands.Move() }
this.verifies() this.verifies()
} }
@ -724,10 +724,10 @@ class TwoPartyTradeFlowTests {
attachmentID: SecureHash?, attachmentID: SecureHash?,
notary: Party): Pair<Vault<ContractState>, List<WireTransaction>> { notary: Party): Pair<Vault<ContractState>, List<WireTransaction>> {
val ap = transaction(transactionBuilder = TransactionBuilder(notary = notary)) { val ap = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
output(PtCommercialPaper.CP_PROGRAM_ID, "alice's paper", notary = notary) { output(CommercialPaper.CP_PROGRAM_ID, "alice's paper", notary = notary) {
PtCommercialPaper.State(issuer, owner, amount, TEST_TX_TIME + 7.days) CommercialPaper.State(issuer, owner, amount, TEST_TX_TIME + 7.days)
} }
command(issuer.party.owningKey) { PtCommercialPaper.Commands.Issue() } command(issuer.party.owningKey) { CommercialPaper.Commands.Issue() }
if (!withError) if (!withError)
timeWindow(time = TEST_TX_TIME) timeWindow(time = TEST_TX_TIME)
if (attachmentID != null) if (attachmentID != null)