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

View File

@ -15,8 +15,8 @@ import net.corda.core.schemas.PersistentState
import net.corda.core.schemas.QueryableState
import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.TransactionBuilder
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash
import com.r3.corda.enterprise.perftestcordapp.schemas.PtCommercialPaperSchemaV1
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.schemas.CommercialPaperSchemaV1
import com.r3.corda.enterprise.perftestcordapp.utils.sumCashBy
import java.time.Instant
import java.util.*
@ -43,12 +43,12 @@ import java.util.*
* 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.
class PtCommercialPaper : Contract {
class CommercialPaper : Contract {
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(
val issuance: PartyAndReference,
@ -69,13 +69,13 @@ class PtCommercialPaper : Contract {
fun withMaturityDate(newMaturityDate: Instant): State = copy(maturityDate = newMaturityDate)
/** 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, ...) */
/** Object Relational Mapping support. */
override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) {
is PtCommercialPaperSchemaV1 -> PtCommercialPaperSchemaV1.PersistentCommercialPaperState(
is CommercialPaperSchemaV1 -> CommercialPaperSchemaV1.PersistentCommercialPaperState(
issuanceParty = this.issuance.party.owningKey.toBase58String(),
issuanceRef = this.issuance.reference.bytes,
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
// 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
// Suppress compiler warning as 'key' is an unused variable when destructuring 'groups'.
@ -190,7 +190,7 @@ class PtCommercialPaper : Contract {
@Suspendable
fun generateRedeem(tx: TransactionBuilder, paper: StateAndRef<State>, services: ServiceHub, ourIdentity: PartyAndCertificate) {
// 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.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.utilities.OpaqueBytes
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.sumCashOrNull
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
* META-INF/services/net.corda.contracts.asset.CashSelection
*/
interface PtCashSelection {
interface CashSelection {
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() ?: {
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) }
cashSelectionAlgo?.let {
instance.set(cashSelectionAlgo)
cashSelectionAlgo
} ?: 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()
}
}
@ -86,7 +86,7 @@ interface PtCashSelection {
onlyFromIssuerParties: Set<AbstractParty> = emptySet(),
notary: Party? = null,
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
* 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>>
= commands.select<Commands>()
@ -134,7 +134,7 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
/** Object Relational Mapping support. */
override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) {
is PtCashSchemaV1 -> PtCashSchemaV1.PersistentCashState(
is CashSchemaV1 -> CashSchemaV1.PersistentCashState(
owner = this.owner,
pennies = this.amount.quantity,
currency = this.amount.token.product.currencyCode,
@ -147,7 +147,7 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
}
/** 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, ...) */
}
// DOCEND 1
@ -261,7 +261,7 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
}
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
@ -381,27 +381,27 @@ class PtCash : PtOnLedgerAsset<Currency, PtCash.Commands, PtCash.State>() {
// Retrieve unspent and unlocked cash states that meet our spending criteria.
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 revocationEnabled = false // Revocation is currently unsupported
// 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
// sent to
val changeIdentity = services.keyManagementService.freshKeyAndCert(ourIdentity, revocationEnabled)
return PtOnLedgerAsset.generateSpend(tx, payments, acceptableCoins,
return OnLedgerAsset.generateSpend(tx, payments, acceptableCoins,
changeIdentity.party.anonymise(),
{ state, quantity, owner -> deriveState(state, quantity, owner) },
{ PtCash().generateMoveCommand() })
{ Cash().generateMoveCommand() })
}
}
}
// Small DSL extensions.
/** @suppress */ infix fun PtCash.State.`owned by`(owner: AbstractParty) = ownedBy(owner)
/** @suppress */ infix fun PtCash.State.`issued by`(party: AbstractParty) = issuedBy(party)
/** @suppress */ infix fun PtCash.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.`owned by`(owner: AbstractParty) = ownedBy(owner)
/** @suppress */ infix fun Cash.State.`issued by`(party: AbstractParty) = issuedBy(party)
/** @suppress */ infix fun Cash.State.`issued by`(deposit: PartyAndReference) = issuedBy(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.
@ -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" */
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 */
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] */
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
* 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 {
val log = loggerFor<PtOnLedgerAsset<*, *, *>>()
val log = loggerFor<OnLedgerAsset<*, *, *>>()
/**
* 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.strands.Strand
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCashSelection
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.CashSelection
import net.corda.core.contracts.Amount
import net.corda.core.contracts.StateAndRef
import net.corda.core.contracts.StateRef
@ -23,11 +23,11 @@ import java.util.*
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock
class PtCashSelectionH2Impl : PtCashSelection {
class CashSelectionH2Impl : CashSelection {
companion object {
const val JDBC_DRIVER_NAME = "H2 JDBC Driver"
val log = loggerFor<PtCashSelectionH2Impl>()
val log = loggerFor<CashSelectionH2Impl>()
}
override fun isCompatible(metadata: DatabaseMetaData): Boolean {
@ -59,12 +59,12 @@ class PtCashSelectionH2Impl : PtCashSelection {
onlyFromIssuerParties: Set<AbstractParty>,
notary: Party?,
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 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:
// 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 index = rs.getInt(2)
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)
totalPennies = rs.getLong(5)
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.
*/
abstract class AbstractPtCashFlow<out T>(override val progressTracker: ProgressTracker) : FlowLogic<T>() {
abstract class AbstractCashFlow<out T>(override val progressTracker: ProgressTracker) : FlowLogic<T>() {
companion object {
object GENERATING_ID : ProgressTracker.Step("Generating anonymous identities")
object GENERATING_TX : ProgressTracker.Step("Generating transaction")

View File

@ -15,7 +15,7 @@ import java.util.*
* Flow to obtain cash cordapp app configuration.
*/
@StartableByRPC
class PtCashConfigDataFlow : FlowLogic<PtCashConfiguration>() {
class CashConfigDataFlow : FlowLogic<PtCashConfiguration>() {
companion object {
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.utilities.OpaqueBytes
import net.corda.core.utilities.ProgressTracker
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.PtCashSelection
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.Cash
import com.r3.corda.enterprise.perftestcordapp.contracts.asset.CashSelection
import com.r3.corda.enterprise.perftestcordapp.issuedBy
import java.util.*
@ -26,9 +26,9 @@ import java.util.*
* issuer.
*/
@StartableByRPC
class PtCashExitFlow(private val amount: Amount<Currency>,
class CashExitFlow(private val amount: Amount<Currency>,
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(request: ExitRequest) : this(request.amount, request.issueRef, tracker())
@ -42,15 +42,15 @@ class PtCashExitFlow(private val amount: Amount<Currency>,
*/
@Suspendable
@Throws(PtCashException::class)
override fun call(): AbstractPtCashFlow.Result {
override fun call(): AbstractCashFlow.Result {
progressTracker.currentStep = GENERATING_TX
val builder = TransactionBuilder(notary = null)
val issuer = ourIdentity.ref(issuerRef)
val exitStates = PtCashSelection
val exitStates = CashSelection
.getInstance { serviceHub.jdbcSession().metaData }
.unconsumedCashStatesForSpending(serviceHub, amount, setOf(issuer.party), builder.notary, builder.lockId, setOf(issuer.reference))
val signers = try {
PtCash().generateExit(
Cash().generateExit(
builder,
amount.issuedBy(issuer),
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)
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
// 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.
*/
@StartableByRPC
class PtCashIssueAndPaymentFlow(val amount: Amount<Currency>,
class CashIssueAndPaymentFlow(val amount: Amount<Currency>,
val issueRef: OpaqueBytes,
val recipient: Party,
val anonymous: Boolean,
val notary: Party,
progressTracker: ProgressTracker) : AbstractPtCashFlow<AbstractPtCashFlow.Result>(progressTracker) {
progressTracker: ProgressTracker) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
constructor(amount: Amount<Currency>,
issueRef: OpaqueBytes,
recipient: Party,
@ -36,8 +36,8 @@ class PtCashIssueAndPaymentFlow(val amount: Amount<Currency>,
@Suspendable
override fun call(): Result {
subFlow(PtCashIssueFlow(amount, issueRef, notary))
return subFlow(PtCashPaymentFlow(amount, recipient, anonymous))
subFlow(CashIssueFlow(amount, issueRef, notary))
return subFlow(CashPaymentFlow(amount, recipient, anonymous))
}
@CordaSerializable

View File

@ -8,7 +8,7 @@ import net.corda.core.serialization.CordaSerializable
import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.OpaqueBytes
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 java.util.*
@ -24,21 +24,21 @@ import java.util.*
* @param notary the notary to set on the output states.
*/
@StartableByRPC
class PtCashIssueFlow(private val amount: Amount<Currency>,
class CashIssueFlow(private val amount: Amount<Currency>,
private val issuerBankPartyRef: OpaqueBytes,
private val notary: Party,
progressTracker: ProgressTracker) : AbstractPtCashFlow<AbstractPtCashFlow.Result>(progressTracker) {
progressTracker: ProgressTracker) : AbstractCashFlow<AbstractCashFlow.Result>(progressTracker) {
constructor(amount: Amount<Currency>,
issuerBankPartyRef: OpaqueBytes,
notary: Party) : this(amount, issuerBankPartyRef, notary, tracker())
constructor(request: IssueRequest) : this(request.amount, request.issueRef, request.notary, tracker())
@Suspendable
override fun call(): AbstractPtCashFlow.Result {
override fun call(): AbstractCashFlow.Result {
progressTracker.currentStep = GENERATING_TX
val builder = TransactionBuilder(notary)
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
val tx = serviceHub.signInitialTransaction(builder, signers)
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.transactions.TransactionBuilder
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.*
/**
@ -23,12 +23,12 @@ import java.util.*
* for testing purposes.
*/
@StartableByRPC
open class PtCashPaymentFlow(
open class CashPaymentFlow(
val amount: Amount<Currency>,
val recipient: Party,
val anonymous: Boolean,
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. */
constructor(amount: Amount<Currency>, recipient: Party) : this(amount, recipient, true, tracker())
/** 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)
@Suspendable
override fun call(): AbstractPtCashFlow.Result {
override fun call(): AbstractCashFlow.Result {
progressTracker.currentStep = GENERATING_ID
val txIdentities = if (anonymous) {
subFlow(SwapIdentitiesFlow(recipient))
@ -48,7 +48,7 @@ open class PtCashPaymentFlow(
val builder = TransactionBuilder(notary = null)
// TODO: Have some way of restricting this to states the caller controls
val (spendTX, keysForSigning) = try {
PtCash.generateSpend(serviceHub,
Cash.generateSpend(serviceHub,
builder,
amount,
ourIdentityAndCert,

View File

@ -12,7 +12,7 @@ import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.ProgressTracker
import net.corda.core.utilities.seconds
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 java.security.PublicKey
import java.util.*
@ -219,7 +219,7 @@ object TwoPartyTradeFlow {
val ptx = TransactionBuilder(notary)
// 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.
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).
*/
object PtCashSchema
object CashSchema
/**
* 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.
*/
@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
@Table(name = "contract_cash_states",
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).
*/
object PtCommercialPaperSchema
object CommercialPaperSchema
/**
* 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.
*/
@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
@Table(name = "cp_states",
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),

View File

@ -1,6 +1,6 @@
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.Companion.sumOrNull
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
* 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
* 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. */
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. */
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. */

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.
interface PtCommercialPaperTestTemplate {
fun getPaper(): PtCommercialPaper.State
interface CommercialPaperTestTemplate {
fun getPaper(): CommercialPaper.State
fun getIssueCommand(notary: Party): CommandData
fun getRedeemCommand(notary: Party): CommandData
fun getMoveCommand(): CommandData
@ -35,32 +35,32 @@ interface PtCommercialPaperTestTemplate {
}
class KotlinCommercialPaperTest : PtCommercialPaperTestTemplate {
override fun getPaper(): PtCommercialPaper.State = PtCommercialPaper.State(
class KotlinCommercialPaperTest : CommercialPaperTestTemplate {
override fun getPaper(): CommercialPaper.State = CommercialPaper.State(
issuance = MEGA_CORP.ref(123),
owner = MEGA_CORP,
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
maturityDate = TEST_TX_TIME + 7.days
)
override fun getIssueCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Issue()
override fun getRedeemCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Redeem()
override fun getMoveCommand(): CommandData = PtCommercialPaper.Commands.Move()
override fun getContract() = PtCommercialPaper.CP_PROGRAM_ID
override fun getIssueCommand(notary: Party): CommandData = CommercialPaper.Commands.Issue()
override fun getRedeemCommand(notary: Party): CommandData = CommercialPaper.Commands.Redeem()
override fun getMoveCommand(): CommandData = CommercialPaper.Commands.Move()
override fun getContract() = CommercialPaper.CP_PROGRAM_ID
}
class KotlinCommercialPaperLegacyTest : PtCommercialPaperTestTemplate {
override fun getPaper(): PtCommercialPaper.State = PtCommercialPaper.State(
class KotlinCommercialPaperLegacyTest : CommercialPaperTestTemplate {
override fun getPaper(): CommercialPaper.State = CommercialPaper.State(
issuance = MEGA_CORP.ref(123),
owner = MEGA_CORP,
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
maturityDate = TEST_TX_TIME + 7.days
)
override fun getIssueCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Issue()
override fun getRedeemCommand(notary: Party): CommandData = PtCommercialPaper.Commands.Redeem()
override fun getMoveCommand(): CommandData = PtCommercialPaper.Commands.Move()
override fun getContract() = PtCommercialPaper.CP_PROGRAM_ID
override fun getIssueCommand(notary: Party): CommandData = CommercialPaper.Commands.Issue()
override fun getRedeemCommand(notary: Party): CommandData = CommercialPaper.Commands.Redeem()
override fun getMoveCommand(): CommandData = CommercialPaper.Commands.Move()
override fun getContract() = CommercialPaper.CP_PROGRAM_ID
}
@RunWith(Parameterized::class)
@ -71,7 +71,7 @@ class CommercialPaperTestsGeneric {
}
@Parameterized.Parameter
lateinit var thisTest: PtCommercialPaperTestTemplate
lateinit var thisTest: CommercialPaperTestTemplate
val issuer = MEGA_CORP.ref(123)
@ -80,14 +80,14 @@ class CommercialPaperTestsGeneric {
val someProfits = 1200.DOLLARS `issued by` issuer
ledger {
unverifiedTransaction {
attachment(PtCash.PROGRAM_ID)
output(PtCash.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)
attachment(Cash.PROGRAM_ID)
output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH `issued by` issuer `owned by` ALICE)
output(Cash.PROGRAM_ID, "some profits", someProfits.STATE `owned by` MEGA_CORP)
}
// Some CP is issued onto the ledger by MegaCorp.
transaction("Issuance") {
attachments(CP_PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID)
attachments(CP_PROGRAM_ID, CommercialPaper.CP_PROGRAM_ID)
output(thisTest.getContract(), "paper") { thisTest.getPaper() }
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
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,
// that sounds a bit too good to be true!
transaction("Trade") {
attachments(PtCash.PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID)
attachments(Cash.PROGRAM_ID, CommercialPaper.CP_PROGRAM_ID)
input("paper")
input("alice's $900")
output(PtCash.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) }
command(ALICE_PUBKEY) { PtCash.Commands.Move() }
output(Cash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP }
output(thisTest.getContract(), "alice's paper") { "paper".output<CommercialPaper.State>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { thisTest.getMoveCommand() }
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
// as a single payment from somewhere and uses it to pay Alice off, keeping the remaining $200 as change.
transaction("Redemption") {
attachments(CP_PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID)
attachments(CP_PROGRAM_ID, CommercialPaper.CP_PROGRAM_ID)
input("alice's paper")
input("some profits")
fun TransactionDSL<TransactionDSLInterpreter>.outputs(aliceGetsBack: Amount<Issued<Currency>>) {
output(PtCash.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, "Alice's profit") { aliceGetsBack.STATE `owned by` ALICE }
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) }
tweak {
@ -137,7 +137,7 @@ class CommercialPaperTestsGeneric {
timeWindow(TEST_TX_TIME + 8.days)
tweak {
output(thisTest.getContract()) { "paper".output<PtCommercialPaper.State>() }
output(thisTest.getContract()) { "paper".output<CommercialPaper.State>() }
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.
val faceValue = 10000.DOLLARS `issued by` DUMMY_CASH_ISSUER
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)
val issuePtx = bigCorpServices.signInitialTransaction(issueBuilder)
val issueTx = notaryServices.addSignature(issuePtx)
@ -254,8 +254,8 @@ class CommercialPaperTestsGeneric {
// Alice pays $9000 to BigCorp to own some of their debt.
moveTX = run {
val builder = TransactionBuilder(DUMMY_NOTARY)
PtCash.generateSpend(aliceServices, builder, 9000.DOLLARS, AnonymousParty(bigCorpServices.key.public))
PtCommercialPaper().generateMove(builder, issueTx.tx.outRef(0), AnonymousParty(aliceServices.key.public))
Cash.generateSpend(aliceServices, builder, 9000.DOLLARS, AnonymousParty(bigCorpServices.key.public))
CommercialPaper().generateMove(builder, issueTx.tx.outRef(0), AnonymousParty(aliceServices.key.public))
val ptx = aliceServices.signInitialTransaction(builder)
val ptx2 = bigCorpServices.addSignature(ptx)
val stx = notaryServices.addSignature(ptx2)
@ -276,7 +276,7 @@ class CommercialPaperTestsGeneric {
fun makeRedeemTX(time: Instant): Pair<SignedTransaction, UUID> {
val builder = TransactionBuilder(DUMMY_NOTARY)
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 ptx2 = bigCorpServices.addSignature(ptx)
val stx = notaryServices.addSignature(ptx2)

View File

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

View File

@ -5,9 +5,9 @@ import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.getOrThrow
import com.r3.corda.enterprise.perftestcordapp.DOLLARS
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 com.r3.corda.enterprise.perftestcordapp.flows.PtCashIssueFlow
import com.r3.corda.enterprise.perftestcordapp.flows.CashIssueFlow
import net.corda.testing.chooseIdentity
import net.corda.testing.getDefaultNotary
import net.corda.testing.node.InMemoryMessagingNetwork.ServicePeerAllocationStrategy.RoundRobin
@ -49,10 +49,10 @@ class CashIssueFlowTests {
fun `issue some cash`() {
val expected = 500.DOLLARS
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()
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)
}
@ -60,7 +60,7 @@ class CashIssueFlowTests {
fun `issue zero cash`() {
val expected = 0.DOLLARS
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()
assertFailsWith<IllegalArgumentException> {
future.getOrThrow()

View File

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

View File

@ -28,9 +28,9 @@ import net.corda.core.utilities.toNonEmptySet
import net.corda.core.utilities.unwrap
import com.r3.corda.enterprise.perftestcordapp.DOLLARS
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.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.`owned by`
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" }
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.
val eb1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
// Issued money to itself.
output(PtCash.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 1", notary = notary) { 800.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) {
command(issuer.party.owningKey) { PtCash.Commands.Issue() }
command(issuer.party.owningKey) { Cash.Commands.Issue() }
} else {
// 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)
if (withError) {
@ -699,16 +699,16 @@ class TwoPartyTradeFlowTests {
// Bob gets some cash onto the ledger from BoE
val bc1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
input("elbonian money 1")
output(PtCash.PROGRAM_ID, "bob cash 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` owner }
command(interimOwner.owningKey) { PtCash.Commands.Move() }
output(Cash.PROGRAM_ID, "bob cash 1", notary = notary) { 800.DOLLARS.CASH `issued by` issuer `owned by` owner }
command(interimOwner.owningKey) { Cash.Commands.Move() }
this.verifies()
}
val bc2 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
input("elbonian money 2")
output(PtCash.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.
command(interimOwner.owningKey) { PtCash.Commands.Move() }
output(Cash.PROGRAM_ID, "bob cash 2", notary = notary) { 300.DOLLARS.CASH `issued by` issuer `owned by` owner }
output(Cash.PROGRAM_ID, notary = notary) { 700.DOLLARS.CASH `issued by` issuer `owned by` interimOwner } // Change output.
command(interimOwner.owningKey) { Cash.Commands.Move() }
this.verifies()
}
@ -724,10 +724,10 @@ class TwoPartyTradeFlowTests {
attachmentID: SecureHash?,
notary: Party): Pair<Vault<ContractState>, List<WireTransaction>> {
val ap = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
output(PtCommercialPaper.CP_PROGRAM_ID, "alice's paper", notary = notary) {
PtCommercialPaper.State(issuer, owner, amount, TEST_TX_TIME + 7.days)
output(CommercialPaper.CP_PROGRAM_ID, "alice's paper", notary = notary) {
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)
timeWindow(time = TEST_TX_TIME)
if (attachmentID != null)