CORDA-654 Simplify TransactionDSL API (#2152)

This commit is contained in:
Andrzej Cichocki 2017-11-30 16:28:44 +00:00 committed by GitHub
parent 5a6f2a19b3
commit a314a6a125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 567 additions and 707 deletions

View File

@ -38,24 +38,20 @@ class PartialMerkleTreeTest {
testLedger = ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID)
output(Cash.PROGRAM_ID, "MEGA_CORP cash") {
output(Cash.PROGRAM_ID, "MEGA_CORP cash",
Cash.State(
amount = 1000.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MEGA_CORP
)
}
output(Cash.PROGRAM_ID, "dummy cash 1") {
owner = MEGA_CORP))
output(Cash.PROGRAM_ID, "dummy cash 1",
Cash.State(
amount = 900.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MINI_CORP
)
}
owner = MINI_CORP))
}
transaction {
attachments(Cash.PROGRAM_ID)
input("MEGA_CORP cash")
output(Cash.PROGRAM_ID, "MEGA_CORP cash".output<Cash.State>().copy(owner = MINI_CORP))
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
timeWindow(TEST_TX_TIME)
this.verifies()
}

View File

@ -55,10 +55,10 @@ class TransactionEncumbranceTests {
ledger {
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input(Cash.PROGRAM_ID) { state }
output(Cash.PROGRAM_ID, encumbrance = 1) { stateWithNewOwner }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, state)
output(Cash.PROGRAM_ID, encumbrance = 1, contractState = stateWithNewOwner)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
verifies()
}
}
@ -69,16 +69,16 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock") { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
// Un-encumber the output if the time of the transaction is later than the timelock.
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input("state encumbered by 5pm time-lock")
input("5pm time-lock")
output(Cash.PROGRAM_ID) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FIVE_PM)
verifies()
}
@ -90,16 +90,16 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock") { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
// The time of the transaction is earlier than the time specified in the encumbering timelock.
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input("state encumbered by 5pm time-lock")
input("5pm time-lock")
output(Cash.PROGRAM_ID) { state }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, state)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FOUR_PM)
this `fails with` "the time specified in the time-lock has passed"
}
@ -111,14 +111,14 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", encumbrance = 1) { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by 5pm time-lock", encumbrance = 1, contractState = state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
transaction {
attachments(Cash.PROGRAM_ID)
input("state encumbered by 5pm time-lock")
output(Cash.PROGRAM_ID) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FIVE_PM)
this `fails with` "Missing required encumbrance 1 in INPUT"
}
@ -130,9 +130,9 @@ class TransactionEncumbranceTests {
ledger {
transaction {
attachments(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { state }
output(Cash.PROGRAM_ID, encumbrance = 0) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, state)
output(Cash.PROGRAM_ID, encumbrance = 0, contractState = stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
this `fails with` "Missing required encumbrance 0 in OUTPUT"
}
}
@ -143,10 +143,10 @@ class TransactionEncumbranceTests {
ledger {
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input(Cash.PROGRAM_ID) { state }
output(TEST_TIMELOCK_ID, encumbrance = 2) { stateWithNewOwner }
output(TEST_TIMELOCK_ID) { timeLock }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, state)
output(TEST_TIMELOCK_ID, encumbrance = 2, contractState = stateWithNewOwner)
output(TEST_TIMELOCK_ID, timeLock)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
this `fails with` "Missing required encumbrance 2 in OUTPUT"
}
}
@ -157,16 +157,16 @@ class TransactionEncumbranceTests {
ledger {
unverifiedTransaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
output(Cash.PROGRAM_ID, "state encumbered by some other state", encumbrance = 1) { state }
output(Cash.PROGRAM_ID, "some other state") { state }
output(TEST_TIMELOCK_ID, "5pm time-lock") { timeLock }
output(Cash.PROGRAM_ID, "state encumbered by some other state", encumbrance = 1, contractState = state)
output(Cash.PROGRAM_ID, "some other state", state)
output(TEST_TIMELOCK_ID, "5pm time-lock", timeLock)
}
transaction {
attachments(Cash.PROGRAM_ID, TEST_TIMELOCK_ID)
input("state encumbered by some other state")
input("5pm time-lock")
output(Cash.PROGRAM_ID) { stateWithNewOwner }
command(MEGA_CORP.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, stateWithNewOwner)
command(MEGA_CORP.owningKey, Cash.Commands.Move())
timeWindow(FIVE_PM)
this `fails with` "Missing required encumbrance 1 in INPUT"
}

View File

@ -33,7 +33,7 @@ class CommercialPaperTest {
ledger {
transaction {
attachments(CP_PROGRAM_ID)
input(CP_PROGRAM_ID) { inState }
input(CP_PROGRAM_ID, inState)
verifies()
}
}
@ -46,8 +46,8 @@ class CommercialPaperTest {
val inState = getPaper()
ledger {
transaction {
input(CP_PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
input(CP_PROGRAM_ID, inState)
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
attachments(CP_PROGRAM_ID)
verifies()
}
@ -61,8 +61,8 @@ class CommercialPaperTest {
val inState = getPaper()
ledger {
transaction {
input(CP_PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
input(CP_PROGRAM_ID, inState)
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
attachments(CP_PROGRAM_ID)
`fails with`("the state is propagated")
}
@ -76,11 +76,11 @@ class CommercialPaperTest {
val inState = getPaper()
ledger {
transaction {
input(CP_PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
input(CP_PROGRAM_ID, inState)
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
attachments(CP_PROGRAM_ID)
`fails with`("the state is propagated")
output(CP_PROGRAM_ID, "alice's paper") { inState.withOwner(ALICE) }
output(CP_PROGRAM_ID, "alice's paper", inState.withOwner(ALICE))
verifies()
}
}
@ -92,15 +92,15 @@ class CommercialPaperTest {
fun `simple issuance with tweak`() {
ledger {
transaction {
output(CP_PROGRAM_ID, "paper") { getPaper() } // Some CP is issued onto the ledger by MegaCorp.
output(CP_PROGRAM_ID, "paper", getPaper()) // Some CP is issued onto the ledger by MegaCorp.
attachments(CP_PROGRAM_ID)
tweak {
// The wrong pubkey.
command(BIG_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
command(BIG_CORP_PUBKEY, CommercialPaper.Commands.Issue())
timeWindow(TEST_TX_TIME)
`fails with`("output states are issued by a command signer")
}
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
timeWindow(TEST_TX_TIME)
verifies()
}
@ -112,15 +112,15 @@ class CommercialPaperTest {
@Test
fun `simple issuance with tweak and top level transaction`() {
transaction {
output(CP_PROGRAM_ID, "paper") { getPaper() } // Some CP is issued onto the ledger by MegaCorp.
output(CP_PROGRAM_ID, "paper", getPaper()) // Some CP is issued onto the ledger by MegaCorp.
attachments(CP_PROGRAM_ID)
tweak {
// The wrong pubkey.
command(BIG_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
command(BIG_CORP_PUBKEY, CommercialPaper.Commands.Issue())
timeWindow(TEST_TX_TIME)
`fails with`("output states are issued by a command signer")
}
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
timeWindow(TEST_TX_TIME)
verifies()
}
@ -140,8 +140,8 @@ class CommercialPaperTest {
// Some CP is issued onto the ledger by MegaCorp.
transaction("Issuance") {
output(CP_PROGRAM_ID, "paper") { getPaper() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
output(CP_PROGRAM_ID, "paper", getPaper())
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
attachments(CP_PROGRAM_ID)
timeWindow(TEST_TX_TIME)
verifies()
@ -151,10 +151,10 @@ class CommercialPaperTest {
transaction("Trade") {
input("paper")
input("alice's $900")
output(Cash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP }
output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP)
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(ALICE))
command(ALICE_PUBKEY, Cash.Commands.Move())
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
verifies()
}
}
@ -173,8 +173,8 @@ class CommercialPaperTest {
// Some CP is issued onto the ledger by MegaCorp.
transaction("Issuance") {
output(CP_PROGRAM_ID, "paper") { getPaper() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
output(CP_PROGRAM_ID, "paper", getPaper())
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
attachments(CP_PROGRAM_ID)
timeWindow(TEST_TX_TIME)
verifies()
@ -183,18 +183,18 @@ class CommercialPaperTest {
transaction("Trade") {
input("paper")
input("alice's $900")
output(Cash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP }
output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP)
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(ALICE))
command(ALICE_PUBKEY, Cash.Commands.Move())
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
verifies()
}
transaction {
input("paper")
// We moved a paper to another pubkey.
output(CP_PROGRAM_ID, "bob's paper") { "paper".output<ICommercialPaperState>().withOwner(BOB) }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
output(CP_PROGRAM_ID, "bob's paper", "paper".output<ICommercialPaperState>().withOwner(BOB))
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
verifies()
}
@ -215,8 +215,8 @@ class CommercialPaperTest {
// Some CP is issued onto the ledger by MegaCorp.
transaction("Issuance") {
output(CP_PROGRAM_ID, "paper") { getPaper() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Issue() }
output(CP_PROGRAM_ID, "paper", getPaper())
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
attachments(CP_PROGRAM_ID)
timeWindow(TEST_TX_TIME)
verifies()
@ -225,10 +225,10 @@ class CommercialPaperTest {
transaction("Trade") {
input("paper")
input("alice's $900")
output(Cash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP }
output(CP_PROGRAM_ID, "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP)
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(ALICE))
command(ALICE_PUBKEY, Cash.Commands.Move())
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
verifies()
}
@ -236,8 +236,8 @@ class CommercialPaperTest {
transaction {
input("paper")
// We moved a paper to another pubkey.
output(CP_PROGRAM_ID, "bob's paper") { "paper".output<ICommercialPaperState>().withOwner(BOB) }
command(MEGA_CORP_PUBKEY) { CommercialPaper.Commands.Move() }
output(CP_PROGRAM_ID, "bob's paper", "paper".output<ICommercialPaperState>().withOwner(BOB))
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
verifies()
}
fails()

View File

@ -172,16 +172,14 @@ class Cap {
@Test
fun issue() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { stateInitial }
output(UNIVERSAL_PROGRAM_ID, stateInitial)
timeWindow(TEST_TX_TIME_1)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this.verifies()
}
}
@ -189,44 +187,38 @@ class Cap {
@Test
fun `first fixing`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateInitial }
output(UNIVERSAL_PROGRAM_ID) { stateAfterFixingFirst }
input(UNIVERSAL_PROGRAM_ID, stateInitial)
output(UNIVERSAL_PROGRAM_ID, stateAfterFixingFirst)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
tweak {
// wrong source
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", tradeDate, Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", tradeDate, Tenor("3M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong date
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate.plusYears(1), Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate.plusYears(1), Tenor("3M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong tenor
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("9M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("9M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.5.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.5.bd))))
this `fails with` "output state does not reflect fix command"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.0.bd))))
this.verifies()
}
}
@ -234,19 +226,16 @@ class Cap {
@Test
fun `first execute`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateAfterFixingFirst }
output(UNIVERSAL_PROGRAM_ID) { stateAfterExecutionFirst }
output(UNIVERSAL_PROGRAM_ID) { statePaymentFirst }
input(UNIVERSAL_PROGRAM_ID, stateAfterFixingFirst)
output(UNIVERSAL_PROGRAM_ID, stateAfterExecutionFirst)
output(UNIVERSAL_PROGRAM_ID, statePaymentFirst)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("exercise") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("exercise"))
this.verifies()
}
}
@ -254,18 +243,15 @@ class Cap {
@Test
fun `final execute`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateAfterFixingFinal }
output(UNIVERSAL_PROGRAM_ID) { statePaymentFinal }
input(UNIVERSAL_PROGRAM_ID, stateAfterFixingFinal)
output(UNIVERSAL_PROGRAM_ID, statePaymentFinal)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("exercise") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("exercise"))
this.verifies()
}
}
@ -273,44 +259,38 @@ class Cap {
@Test
fun `second fixing`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateAfterExecutionFirst }
output(UNIVERSAL_PROGRAM_ID) { stateAfterFixingFinal }
input(UNIVERSAL_PROGRAM_ID, stateAfterExecutionFirst)
output(UNIVERSAL_PROGRAM_ID, stateAfterFixingFinal)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
tweak {
// wrong source
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("3M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong date
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01").plusYears(1), Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01").plusYears(1), Tenor("3M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong tenor
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("9M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("9M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("3M")), 1.5.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("3M")), 1.5.bd))))
this `fails with` "output state does not reflect fix command"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", BusinessCalendar.parseDateFromString("2017-03-01"), Tenor("3M")), 1.0.bd))))
this.verifies()
}
}

View File

@ -55,16 +55,14 @@ class Caplet {
@Test
fun issue() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { stateStart }
output(UNIVERSAL_PROGRAM_ID, stateStart)
timeWindow(TEST_TX_TIME_1)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this.verifies()
}
}
@ -72,17 +70,15 @@ class Caplet {
@Test
fun `execute`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateFixed }
output(UNIVERSAL_PROGRAM_ID) { stateFinal }
input(UNIVERSAL_PROGRAM_ID, stateFixed)
output(UNIVERSAL_PROGRAM_ID, stateFinal)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("exercise") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("exercise"))
this.verifies()
}
}
@ -90,44 +86,38 @@ class Caplet {
@Test
fun `fixing`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateStart }
output(UNIVERSAL_PROGRAM_ID) { stateFixed }
input(UNIVERSAL_PROGRAM_ID, stateStart)
output(UNIVERSAL_PROGRAM_ID, stateFixed)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
tweak {
// wrong source
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", tradeDate, Tenor("6M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", tradeDate, Tenor("6M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong date
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate.plusYears(1), Tenor("6M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate.plusYears(1), Tenor("6M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong tenor
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("6M")), 1.5.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("6M")), 1.5.bd))))
this `fails with` "output state does not reflect fix command"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("6M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("6M")), 1.0.bd))))
this.verifies()
}
}

View File

@ -52,20 +52,18 @@ class FXFwdTimeOption {
@Test
fun `issue - signature`() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID, inState)
timeWindow(TEST_TX_TIME_1)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey, acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(listOf(highStreetBank.owningKey, acmeCorp.owningKey), UniversalContract.Commands.Issue())
this.verifies()
}
}
@ -73,31 +71,28 @@ class FXFwdTimeOption {
@Test
fun `maturity, bank exercise`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
output(UNIVERSAL_PROGRAM_ID) { outState2 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
output(UNIVERSAL_PROGRAM_ID, outState2)
timeWindow(TEST_TX_TIME_AFTER_MATURITY)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("exercise") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("exercise"))
this `fails with` "condition must be met"
}
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("exercise") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("exercise"))
this `fails with` "condition must be met"
}
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("expire") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("expire"))
this `fails with` "condition must be met"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("expire") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("expire"))
this.verifies()
}
}
@ -105,31 +100,28 @@ class FXFwdTimeOption {
@Test
fun `maturity, corp exercise`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
output(UNIVERSAL_PROGRAM_ID) { outState2 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
output(UNIVERSAL_PROGRAM_ID, outState2)
timeWindow(TEST_TX_TIME_BEFORE_MATURITY)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("expire") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("expire"))
this `fails with` "condition must be met"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("expire") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("expire"))
this `fails with` "condition must be met"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("exercise") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("exercise"))
this `fails with` "condition must be met"
}
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("exercise") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("exercise"))
this.verifies()
}
}

View File

@ -44,20 +44,18 @@ class FXSwap {
fun `issue - signature`() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID, inState)
timeWindow(TEST_TX_TIME_1)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey, acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(listOf(highStreetBank.owningKey, acmeCorp.owningKey), UniversalContract.Commands.Issue())
this.verifies()
}
}
@ -65,18 +63,16 @@ class FXSwap {
@Test
fun `execute`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
output(UNIVERSAL_PROGRAM_ID) { outState2 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
output(UNIVERSAL_PROGRAM_ID, outState2)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("execute") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("execute"))
this.verifies()
}
}
@ -84,18 +80,16 @@ class FXSwap {
@Test
fun `execute - reversed order`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState2 }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState2)
output(UNIVERSAL_PROGRAM_ID, outState1)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("execute") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("execute"))
this.verifies()
}
}
@ -103,12 +97,11 @@ class FXSwap {
@Test
fun `execute - not authorized`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
output(UNIVERSAL_PROGRAM_ID) { outState2 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
output(UNIVERSAL_PROGRAM_ID, outState2)
timeWindow(TEST_TX_TIME_1)
command(momAndPop.owningKey) { UniversalContract.Commands.Action("execute") }
command(momAndPop.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "condition must be met"
}
}
@ -116,12 +109,11 @@ class FXSwap {
@Test
fun `execute - before maturity`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
output(UNIVERSAL_PROGRAM_ID) { outState2 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
output(UNIVERSAL_PROGRAM_ID, outState2)
timeWindow(TEST_TX_TIME_TOO_EARLY)
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("execute") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "condition must be met"
}
}
@ -129,11 +121,10 @@ class FXSwap {
@Test
fun `execute - outState mismatch 1`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
timeWindow(TEST_TX_TIME_1)
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("execute") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "output state must match action result state"
}
}
@ -141,12 +132,11 @@ class FXSwap {
@Test
fun `execute - outState mismatch 2`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
output(UNIVERSAL_PROGRAM_ID) { outStateBad2 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
output(UNIVERSAL_PROGRAM_ID, outStateBad2)
timeWindow(TEST_TX_TIME_1)
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("execute") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "output states must match action result state"
}
}
@ -154,12 +144,11 @@ class FXSwap {
@Test
fun `execute - outState mismatch 3`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outStateBad1 }
output(UNIVERSAL_PROGRAM_ID) { outState2 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outStateBad1)
output(UNIVERSAL_PROGRAM_ID, outState2)
timeWindow(TEST_TX_TIME_1)
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("execute") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "output states must match action result state"
}
}
@ -167,12 +156,11 @@ class FXSwap {
@Test
fun `execute - outState mismatch 4`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState1 }
output(UNIVERSAL_PROGRAM_ID) { outStateBad3 }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState1)
output(UNIVERSAL_PROGRAM_ID, outStateBad3)
timeWindow(TEST_TX_TIME_1)
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("execute") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "output states must match action result state"
}
}

View File

@ -134,16 +134,14 @@ class IRS {
@Test
fun issue() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { stateInitial }
output(UNIVERSAL_PROGRAM_ID, stateInitial)
timeWindow(TEST_TX_TIME_1)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this.verifies()
}
}
@ -151,44 +149,38 @@ class IRS {
@Test
fun `first fixing`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateInitial }
output(UNIVERSAL_PROGRAM_ID) { stateAfterFixingFirst }
input(UNIVERSAL_PROGRAM_ID, stateInitial)
output(UNIVERSAL_PROGRAM_ID, stateAfterFixingFirst)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
tweak {
// wrong source
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", tradeDate, Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBORx", tradeDate, Tenor("3M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong date
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate.plusYears(1), Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate.plusYears(1), Tenor("3M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
// wrong tenor
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("9M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("9M")), 1.0.bd))))
this `fails with` "relevant fixing must be included"
}
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.5.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.5.bd))))
this `fails with` "output state does not reflect fix command"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.0.bd))) }
command(highStreetBank.owningKey, UniversalContract.Commands.Fix(listOf(net.corda.finance.contracts.Fix(FixOf("LIBOR", tradeDate, Tenor("3M")), 1.0.bd))))
this.verifies()
}
}
@ -196,19 +188,16 @@ class IRS {
@Test
fun `first execute`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateAfterFixingFirst }
output(UNIVERSAL_PROGRAM_ID) { stateAfterExecutionFirst }
output(UNIVERSAL_PROGRAM_ID) { statePaymentFirst }
input(UNIVERSAL_PROGRAM_ID, stateAfterFixingFirst)
output(UNIVERSAL_PROGRAM_ID, stateAfterExecutionFirst)
output(UNIVERSAL_PROGRAM_ID, statePaymentFirst)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("pay floating") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("pay floating"))
this.verifies()
}
}

View File

@ -145,16 +145,14 @@ class RollOutTests {
@Test
fun issue() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { stateStart }
output(UNIVERSAL_PROGRAM_ID, stateStart)
timeWindow(TEST_TX_TIME_1)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this.verifies()
}
}
@ -162,18 +160,16 @@ class RollOutTests {
@Test
fun `execute`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { stateStart }
output(UNIVERSAL_PROGRAM_ID) { stateStep1a }
output(UNIVERSAL_PROGRAM_ID) { stateStep1b }
input(UNIVERSAL_PROGRAM_ID, stateStart)
output(UNIVERSAL_PROGRAM_ID, stateStep1a)
output(UNIVERSAL_PROGRAM_ID, stateStep1b)
timeWindow(TEST_TX_TIME_1)
/* tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
this `fails with` "action must be defined"
}*/
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("transfer") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("transfer"))
this.verifies()
}
}

View File

@ -61,16 +61,14 @@ class Swaption {
@Test
fun issue() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { stateInitial }
output(UNIVERSAL_PROGRAM_ID, stateInitial)
timeWindow(TEST_TX_TIME_1)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this.verifies()
}
}

View File

@ -51,15 +51,12 @@ class ZeroCouponBond {
@Test
fun `issue - signature`() {
transaction {
output(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID, inState)
tweak {
command(acmeCorp.owningKey) { UniversalContract.Commands.Issue() }
command(acmeCorp.owningKey, UniversalContract.Commands.Issue())
this `fails with` "the transaction is signed by all liable parties"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Issue() }
command(highStreetBank.owningKey, UniversalContract.Commands.Issue())
this.verifies()
}
}
@ -67,17 +64,15 @@ class ZeroCouponBond {
@Test
fun `execute`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState)
timeWindow(TEST_TX_TIME_1)
tweak {
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("some undefined name") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("some undefined name"))
this `fails with` "action must be defined"
}
command(highStreetBank.owningKey) { UniversalContract.Commands.Action("execute") }
command(highStreetBank.owningKey, UniversalContract.Commands.Action("execute"))
this.verifies()
}
}
@ -85,11 +80,10 @@ class ZeroCouponBond {
@Test
fun `execute - not authorized`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outState }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outState)
timeWindow(TEST_TX_TIME_1)
command(momAndPop.owningKey) { UniversalContract.Commands.Action("execute") }
command(momAndPop.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "condition must be met"
}
}
@ -97,11 +91,10 @@ class ZeroCouponBond {
@Test
fun `execute - outState mismatch`() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
output(UNIVERSAL_PROGRAM_ID) { outStateWrong }
input(UNIVERSAL_PROGRAM_ID, inState)
output(UNIVERSAL_PROGRAM_ID, outStateWrong)
timeWindow(TEST_TX_TIME_1)
command(acmeCorp.owningKey) { UniversalContract.Commands.Action("execute") }
command(acmeCorp.owningKey, UniversalContract.Commands.Action("execute"))
this `fails with` "output state must match action result state"
}
}
@ -109,29 +102,23 @@ class ZeroCouponBond {
@Test
fun move() {
transaction {
input(UNIVERSAL_PROGRAM_ID) { inState }
input(UNIVERSAL_PROGRAM_ID, inState)
tweak {
output(UNIVERSAL_PROGRAM_ID) { outStateMove }
command(acmeCorp.owningKey) {
UniversalContract.Commands.Move(acmeCorp, momAndPop)
}
output(UNIVERSAL_PROGRAM_ID, outStateMove)
command(acmeCorp.owningKey,
UniversalContract.Commands.Move(acmeCorp, momAndPop))
this `fails with` "the transaction is signed by all liable parties"
}
tweak {
output(UNIVERSAL_PROGRAM_ID) { inState }
command(acmeCorp.owningKey, momAndPop.owningKey, highStreetBank.owningKey) {
UniversalContract.Commands.Move(acmeCorp, momAndPop)
}
output(UNIVERSAL_PROGRAM_ID, inState)
command(listOf(acmeCorp.owningKey, momAndPop.owningKey, highStreetBank.owningKey),
UniversalContract.Commands.Move(acmeCorp, momAndPop))
this `fails with` "output state does not reflect move command"
}
output(UNIVERSAL_PROGRAM_ID) { outStateMove }
command(acmeCorp.owningKey, momAndPop.owningKey, highStreetBank.owningKey) {
UniversalContract.Commands.Move(acmeCorp, momAndPop)
}
output(UNIVERSAL_PROGRAM_ID, outStateMove)
command(listOf(acmeCorp.owningKey, momAndPop.owningKey, highStreetBank.owningKey),
UniversalContract.Commands.Move(acmeCorp, momAndPop))
this.verifies()
}
}

View File

@ -32,34 +32,34 @@ public class CashTestsJava {
tx.input(Cash.PROGRAM_ID, inState);
tx.tweak(tw -> {
tw.output(Cash.PROGRAM_ID, () -> new Cash.State(issuedBy(DOLLARS(2000), defaultIssuer), new AnonymousParty(getMINI_CORP_PUBKEY())));
tw.output(Cash.PROGRAM_ID, new Cash.State(issuedBy(DOLLARS(2000), defaultIssuer), new AnonymousParty(getMINI_CORP_PUBKEY())));
tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move());
return tw.failsWith("the amounts balance");
});
tx.tweak(tw -> {
tw.output(Cash.PROGRAM_ID, () -> outState);
tw.output(Cash.PROGRAM_ID, outState);
tw.command(getMEGA_CORP_PUBKEY(), DummyCommandData.INSTANCE);
// Invalid command
return tw.failsWith("required net.corda.finance.contracts.asset.Cash.Commands.Move command");
});
tx.tweak(tw -> {
tw.output(Cash.PROGRAM_ID, () -> outState);
tw.output(Cash.PROGRAM_ID, outState);
tw.command(getMINI_CORP_PUBKEY(), new Cash.Commands.Move());
return tw.failsWith("the owning keys are a subset of the signing keys");
});
tx.tweak(tw -> {
tw.output(Cash.PROGRAM_ID, () -> outState);
tw.output(Cash.PROGRAM_ID, outState);
// issuedBy() can't be directly imported because it conflicts with other identically named functions
// with different overloads (for some reason).
tw.output(Cash.PROGRAM_ID, () -> outState.issuedBy(getMINI_CORP()));
tw.output(Cash.PROGRAM_ID, outState.issuedBy(getMINI_CORP()));
tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move());
return tw.failsWith("at least one cash input");
});
// Simple reallocation works.
return tx.tweak(tw -> {
tw.output(Cash.PROGRAM_ID, () -> outState);
tw.output(Cash.PROGRAM_ID, outState);
tw.command(getMEGA_CORP_PUBKEY(), new Cash.Commands.Move());
return tw.verifies();
});

View File

@ -106,8 +106,8 @@ class CommercialPaperTestsGeneric {
// Some CP is issued onto the ledger by MegaCorp.
transaction("Issuance") {
attachments(CP_PROGRAM_ID, JavaCommercialPaper.JCP_PROGRAM_ID)
output(thisTest.getContract(), "paper") { thisTest.getPaper() }
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
output(thisTest.getContract(), "paper", thisTest.getPaper())
command(MEGA_CORP_PUBKEY, thisTest.getIssueCommand(DUMMY_NOTARY))
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -118,10 +118,10 @@ class CommercialPaperTestsGeneric {
attachments(Cash.PROGRAM_ID, JavaCommercialPaper.JCP_PROGRAM_ID)
input("paper")
input("alice's $900")
output(Cash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP }
output(thisTest.getContract(), "alice's paper") { "paper".output<ICommercialPaperState>().withOwner(ALICE) }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY) { thisTest.getMoveCommand() }
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP)
output(thisTest.getContract(), "alice's paper", "paper".output<ICommercialPaperState>().withOwner(ALICE))
command(ALICE_PUBKEY, Cash.Commands.Move())
command(MEGA_CORP_PUBKEY, thisTest.getMoveCommand())
this.verifies()
}
@ -133,13 +133,11 @@ class CommercialPaperTestsGeneric {
input("some profits")
fun TransactionDSL<TransactionDSLInterpreter>.outputs(aliceGetsBack: Amount<Issued<Currency>>) {
output(Cash.PROGRAM_ID, "Alice's profit") { aliceGetsBack.STATE ownedBy ALICE }
output(Cash.PROGRAM_ID, "Change") { (someProfits - aliceGetsBack).STATE ownedBy MEGA_CORP }
output(Cash.PROGRAM_ID, "Alice's profit", aliceGetsBack.STATE ownedBy ALICE)
output(Cash.PROGRAM_ID, "Change", (someProfits - aliceGetsBack).STATE ownedBy MEGA_CORP)
}
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
command(ALICE_PUBKEY) { thisTest.getRedeemCommand(DUMMY_NOTARY) }
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
command(ALICE_PUBKEY, thisTest.getRedeemCommand(DUMMY_NOTARY))
tweak {
outputs(700.DOLLARS `issued by` issuer)
timeWindow(TEST_TX_TIME + 8.days)
@ -155,7 +153,7 @@ class CommercialPaperTestsGeneric {
timeWindow(TEST_TX_TIME + 8.days)
tweak {
output(thisTest.getContract()) { "paper".output<ICommercialPaperState>() }
output(thisTest.getContract(), "paper".output<ICommercialPaperState>())
this `fails with` "must be destroyed"
}
@ -169,8 +167,8 @@ class CommercialPaperTestsGeneric {
transaction {
attachment(CP_PROGRAM_ID)
attachment(JavaCommercialPaper.JCP_PROGRAM_ID)
output(thisTest.getContract()) { thisTest.getPaper() }
command(MINI_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
output(thisTest.getContract(), thisTest.getPaper())
command(MINI_CORP_PUBKEY, thisTest.getIssueCommand(DUMMY_NOTARY))
timeWindow(TEST_TX_TIME)
this `fails with` "output states are issued by a command signer"
}
@ -181,8 +179,8 @@ class CommercialPaperTestsGeneric {
transaction {
attachment(CP_PROGRAM_ID)
attachment(JavaCommercialPaper.JCP_PROGRAM_ID)
output(thisTest.getContract()) { thisTest.getPaper().withFaceValue(0.DOLLARS `issued by` issuer) }
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
output(thisTest.getContract(), thisTest.getPaper().withFaceValue(0.DOLLARS `issued by` issuer))
command(MEGA_CORP_PUBKEY, thisTest.getIssueCommand(DUMMY_NOTARY))
timeWindow(TEST_TX_TIME)
this `fails with` "output values sum to more than the inputs"
}
@ -193,8 +191,8 @@ class CommercialPaperTestsGeneric {
transaction {
attachment(CP_PROGRAM_ID)
attachment(JavaCommercialPaper.JCP_PROGRAM_ID)
output(thisTest.getContract()) { thisTest.getPaper().withMaturityDate(TEST_TX_TIME - 10.days) }
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
output(thisTest.getContract(), thisTest.getPaper().withMaturityDate(TEST_TX_TIME - 10.days))
command(MEGA_CORP_PUBKEY, thisTest.getIssueCommand(DUMMY_NOTARY))
timeWindow(TEST_TX_TIME)
this `fails with` "maturity date is not in the past"
}
@ -206,8 +204,8 @@ class CommercialPaperTestsGeneric {
attachment(CP_PROGRAM_ID)
attachment(JavaCommercialPaper.JCP_PROGRAM_ID)
input(thisTest.getContract(), thisTest.getPaper())
output(thisTest.getContract()) { thisTest.getPaper() }
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
output(thisTest.getContract(), thisTest.getPaper())
command(MEGA_CORP_PUBKEY, thisTest.getIssueCommand(DUMMY_NOTARY))
timeWindow(TEST_TX_TIME)
this `fails with` "output values sum to more than the inputs"
}

View File

@ -111,34 +111,33 @@ class CashTests {
fun trivial() {
transaction {
attachment(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { inState }
input(Cash.PROGRAM_ID, inState)
tweak {
output(Cash.PROGRAM_ID) { outState.copy(amount = 2000.DOLLARS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { Cash.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(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { DummyCommandData }
output(Cash.PROGRAM_ID, outState)
command(ALICE_PUBKEY, DummyCommandData)
// Invalid command
this `fails with` "required net.corda.finance.contracts.asset.Cash.Commands.Move command"
}
tweak {
output(Cash.PROGRAM_ID) { outState }
command(BOB_PUBKEY) { Cash.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(Cash.PROGRAM_ID) { outState }
output(Cash.PROGRAM_ID) { outState issuedBy MINI_CORP }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, outState)
output(Cash.PROGRAM_ID, outState issuedBy MINI_CORP)
command(ALICE_PUBKEY, Cash.Commands.Move())
this `fails with` "at least one cash input"
}
// Simple reallocation works.
tweak {
output(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, outState)
command(ALICE_PUBKEY, Cash.Commands.Move())
this.verifies()
}
}
@ -149,10 +148,9 @@ class CashTests {
// Check we can't "move" money into existence.
transaction {
attachment(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { DummyState() }
output(Cash.PROGRAM_ID) { outState }
command(MINI_CORP_PUBKEY) { Cash.Commands.Move() }
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"
}
}
@ -163,19 +161,17 @@ class CashTests {
// institution is allowed to issue as much cash as they want.
transaction {
attachment(Cash.PROGRAM_ID)
output(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { Cash.Commands.Issue() }
output(Cash.PROGRAM_ID, outState)
command(ALICE_PUBKEY, Cash.Commands.Issue())
this `fails with` "output states are issued by a command signer"
}
transaction {
attachment(Cash.PROGRAM_ID)
output(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) { Cash.Commands.Issue() }
owner = AnonymousParty(ALICE_PUBKEY)))
command(MINI_CORP_PUBKEY, Cash.Commands.Issue())
this.verifies()
}
}
@ -211,18 +207,17 @@ class CashTests {
// We can consume $1000 in a transaction and output $2000 as long as it's signed by an issuer.
transaction {
attachment(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { issuerInState }
output(Cash.PROGRAM_ID) { inState.copy(amount = inState.amount * 2) }
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) { Cash.Commands.Move() }
command(ALICE_PUBKEY, Cash.Commands.Move())
this `fails with` "the amounts balance"
}
// Issue works.
tweak {
command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
command(MEGA_CORP_PUBKEY, Cash.Commands.Issue())
this.verifies()
}
}
@ -230,29 +225,29 @@ class CashTests {
// Can't use an issue command to lower the amount.
transaction {
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() }
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(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { inState }
output(Cash.PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
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(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() }
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) { Cash.Commands.Issue() }
command(MEGA_CORP_PUBKEY, Cash.Commands.Issue())
this `fails with` "there is only a single issue command"
}
this.verifies()
@ -282,26 +277,26 @@ class CashTests {
// Splitting value works.
transaction {
attachment(Cash.PROGRAM_ID)
command(ALICE_PUBKEY) { Cash.Commands.Move() }
command(ALICE_PUBKEY, Cash.Commands.Move())
tweak {
input(Cash.PROGRAM_ID) { inState }
input(Cash.PROGRAM_ID, inState)
val splits4 = inState.amount.splitEvenly(4)
for (i in 0..3) output(Cash.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(Cash.PROGRAM_ID) { inState.copy(amount = splits4[i]) }
for (i in 0..1) output(Cash.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(Cash.PROGRAM_ID) { inState.copy(amount = splits2[i]) }
output(Cash.PROGRAM_ID) { inState }
for (i in 0..1) input(Cash.PROGRAM_ID, inState.copy(amount = splits2[i]))
output(Cash.PROGRAM_ID, inState)
this.verifies()
}
}
@ -311,17 +306,17 @@ class CashTests {
fun zeroSizedValues() {
transaction {
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() }
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(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() }
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"
}
}
@ -331,58 +326,56 @@ class CashTests {
// Can't change issuer.
transaction {
attachment(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { inState }
output(Cash.PROGRAM_ID) { outState issuedBy MINI_CORP }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, inState)
output(Cash.PROGRAM_ID, outState issuedBy MINI_CORP)
command(ALICE_PUBKEY, Cash.Commands.Move())
this `fails with` "the amounts balance"
}
// Can't change deposit reference when splitting.
transaction {
attachment(Cash.PROGRAM_ID)
val splits2 = inState.amount.splitEvenly(2)
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() }
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(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() }
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(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { inState }
input(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(Cash.PROGRAM_ID) { outState.copy(amount = 1150.DOLLARS `issued by` defaultIssuer) }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
owner = AnonymousParty(BOB_PUBKEY)))
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(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { inState }
input(Cash.PROGRAM_ID) { inState issuedBy MINI_CORP }
output(Cash.PROGRAM_ID) { outState }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, inState)
input(Cash.PROGRAM_ID, inState issuedBy 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(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() }
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]"
}
}
@ -392,21 +385,20 @@ class CashTests {
// Single input/output straightforward case.
transaction {
attachment(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { issuerInState }
output(Cash.PROGRAM_ID) { issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
input(Cash.PROGRAM_ID, issuerInState)
output(Cash.PROGRAM_ID, issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)))
tweak {
command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(100.DOLLARS `issued by` defaultIssuer) }
command(MEGA_CORP_PUBKEY) { Cash.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) { Cash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer) }
command(MEGA_CORP_PUBKEY, Cash.Commands.Exit(200.DOLLARS `issued by` defaultIssuer))
this `fails with` "required net.corda.finance.contracts.asset.Cash.Commands.Move command"
tweak {
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
this.verifies()
}
}
@ -418,20 +410,15 @@ class CashTests {
// Multi-issuer case.
transaction {
attachment(Cash.PROGRAM_ID)
input(Cash.PROGRAM_ID) { issuerInState }
input(Cash.PROGRAM_ID) { issuerInState.copy(owner = MINI_CORP) issuedBy MINI_CORP }
output(Cash.PROGRAM_ID) { issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) issuedBy 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) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, issuerInState)
input(Cash.PROGRAM_ID, issuerInState.copy(owner = MINI_CORP) issuedBy MINI_CORP)
output(Cash.PROGRAM_ID, issuerInState.copy(amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)) issuedBy MINI_CORP)
output(Cash.PROGRAM_ID, issuerInState.copy(owner = MINI_CORP, amount = issuerInState.amount - (200.DOLLARS `issued by` defaultIssuer)))
command(listOf(MEGA_CORP_PUBKEY, MINI_CORP_PUBKEY), Cash.Commands.Move())
this `fails with` "the amounts balance"
command(MEGA_CORP_PUBKEY) { Cash.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) { Cash.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()
}
}
@ -441,10 +428,10 @@ class CashTests {
// Single input/output straightforward case.
transaction {
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() }
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"
}
}
@ -454,25 +441,24 @@ class CashTests {
transaction {
attachment(Cash.PROGRAM_ID)
// Gather 2000 dollars from two different issuers.
input(Cash.PROGRAM_ID) { inState }
input(Cash.PROGRAM_ID) { inState issuedBy MINI_CORP }
command(ALICE_PUBKEY) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, inState)
input(Cash.PROGRAM_ID, inState issuedBy MINI_CORP)
command(ALICE_PUBKEY, Cash.Commands.Move())
// Can't merge them together.
tweak {
output(Cash.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(Cash.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)))
output(Cash.PROGRAM_ID, inState.copy(owner = AnonymousParty(BOB_PUBKEY)))
this `fails with` "the amounts balance"
}
// This works.
output(Cash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) }
output(Cash.PROGRAM_ID) { inState.copy(owner = AnonymousParty(BOB_PUBKEY)) issuedBy MINI_CORP }
output(Cash.PROGRAM_ID, inState.copy(owner = AnonymousParty(BOB_PUBKEY)))
output(Cash.PROGRAM_ID, inState.copy(owner = AnonymousParty(BOB_PUBKEY)) issuedBy MINI_CORP)
this.verifies()
}
}
@ -483,12 +469,11 @@ class CashTests {
transaction {
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 ownedBy AnonymousParty(ALICE_PUBKEY) }
input(Cash.PROGRAM_ID) { pounds }
output(Cash.PROGRAM_ID) { inState ownedBy AnonymousParty(BOB_PUBKEY) }
output(Cash.PROGRAM_ID) { pounds ownedBy AnonymousParty(ALICE_PUBKEY) }
command(ALICE_PUBKEY, BOB_PUBKEY) { Cash.Commands.Move() }
input(Cash.PROGRAM_ID, inState ownedBy AnonymousParty(ALICE_PUBKEY))
input(Cash.PROGRAM_ID, pounds)
output(Cash.PROGRAM_ID, inState ownedBy AnonymousParty(BOB_PUBKEY))
output(Cash.PROGRAM_ID, pounds ownedBy AnonymousParty(ALICE_PUBKEY))
command(listOf(ALICE_PUBKEY, BOB_PUBKEY), Cash.Commands.Move())
this.verifies()
}
}
@ -792,19 +777,17 @@ class CashTests {
ledger(mockService) {
unverifiedTransaction {
attachment(Cash.PROGRAM_ID)
output(Cash.PROGRAM_ID, "MEGA_CORP cash") {
output(Cash.PROGRAM_ID, "MEGA_CORP cash",
Cash.State(
amount = 1000.DOLLARS `issued by` MEGA_CORP.ref(1, 1),
owner = MEGA_CORP
)
}
owner = MEGA_CORP))
}
transaction {
attachment(Cash.PROGRAM_ID)
input("MEGA_CORP cash")
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() }
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
this.verifies()
}
@ -814,7 +797,7 @@ class CashTests {
input("MEGA_CORP cash")
// We send it to another pubkey so that the transaction is not identical to the previous one
output(Cash.PROGRAM_ID, "MEGA_CORP cash 3", "MEGA_CORP cash".output<Cash.State>().copy(owner = ALICE))
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
this.verifies()
}
this.fails()

View File

@ -71,34 +71,33 @@ class ObligationTests {
fun trivial() {
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
input(Obligation.PROGRAM_ID, inState)
tweak {
output(Obligation.PROGRAM_ID) { outState.copy(quantity = 2000.DOLLARS.quantity) }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
output(Obligation.PROGRAM_ID, outState.copy(quantity = 2000.DOLLARS.quantity))
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
tweak {
output(Obligation.PROGRAM_ID) { outState }
command(CHARLIE.owningKey) { DummyCommandData }
output(Obligation.PROGRAM_ID, outState)
command(CHARLIE.owningKey, DummyCommandData)
// Invalid command
this `fails with` "required net.corda.finance.contracts.asset.Obligation.Commands.Move command"
}
tweak {
output(Obligation.PROGRAM_ID) { outState }
command(BOB_PUBKEY) { Obligation.Commands.Move() }
output(Obligation.PROGRAM_ID, outState)
command(BOB_PUBKEY, Obligation.Commands.Move())
this `fails with` "the owning keys are a subset of the signing keys"
}
tweak {
output(Obligation.PROGRAM_ID) { outState }
output(Obligation.PROGRAM_ID) { outState `issued by` MINI_CORP }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
output(Obligation.PROGRAM_ID, outState)
output(Obligation.PROGRAM_ID, outState `issued by` MINI_CORP)
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "at least one obligation input"
}
// Simple reallocation works.
tweak {
output(Obligation.PROGRAM_ID) { outState }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
output(Obligation.PROGRAM_ID, outState)
command(CHARLIE.owningKey, Obligation.Commands.Move())
this.verifies()
}
}
@ -109,10 +108,9 @@ class ObligationTests {
// Check we can't "move" debt into existence.
transaction {
attachments(DummyContract.PROGRAM_ID, Obligation.PROGRAM_ID)
input(DummyContract.PROGRAM_ID) { DummyState() }
output(Obligation.PROGRAM_ID) { outState }
command(MINI_CORP_PUBKEY) { Obligation.Commands.Move() }
input(DummyContract.PROGRAM_ID, DummyState())
output(Obligation.PROGRAM_ID, outState)
command(MINI_CORP_PUBKEY, Obligation.Commands.Move())
this `fails with` "at least one obligation input"
}
@ -120,21 +118,19 @@ class ObligationTests {
// institution is allowed to issue as much cash as they want.
transaction {
attachments(Obligation.PROGRAM_ID)
output(Obligation.PROGRAM_ID) { outState }
command(CHARLIE.owningKey) { Obligation.Commands.Issue() }
output(Obligation.PROGRAM_ID, outState)
command(CHARLIE.owningKey, Obligation.Commands.Issue())
this `fails with` "output states are issued by a command signer"
}
transaction {
attachments(Obligation.PROGRAM_ID)
output(Obligation.PROGRAM_ID) {
output(Obligation.PROGRAM_ID,
Obligation.State(
obligor = MINI_CORP,
quantity = 1000.DOLLARS.quantity,
beneficiary = CHARLIE,
template = megaCorpDollarSettlement
)
}
command(MINI_CORP_PUBKEY) { Obligation.Commands.Issue() }
template = megaCorpDollarSettlement))
command(MINI_CORP_PUBKEY, Obligation.Commands.Issue())
this.verifies()
}
run {
@ -157,18 +153,17 @@ class ObligationTests {
// We can consume $1000 in a transaction and output $2000 as long as it's signed by an issuer.
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.amount.quantity * 2) }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, inState.copy(quantity = inState.amount.quantity * 2))
// Move fails: not allowed to summon money.
tweak {
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
// Issue works.
tweak {
command(MEGA_CORP_PUBKEY) { Obligation.Commands.Issue() }
command(MEGA_CORP_PUBKEY, Obligation.Commands.Issue())
this.verifies()
}
}
@ -176,29 +171,29 @@ class ObligationTests {
// Can't use an issue command to lower the amount.
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.amount.quantity / 2) }
command(MEGA_CORP_PUBKEY) { Obligation.Commands.Issue() }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, inState.copy(quantity = inState.amount.quantity / 2))
command(MEGA_CORP_PUBKEY, Obligation.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 {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { inState }
command(MEGA_CORP_PUBKEY) { Obligation.Commands.Issue() }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, inState)
command(MEGA_CORP_PUBKEY, Obligation.Commands.Issue())
this `fails with` ""
}
// Can't have any other commands if we have an issue command (because the issue command overrules them).
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.amount.quantity * 2) }
command(MEGA_CORP_PUBKEY) { Obligation.Commands.Issue() }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, inState.copy(quantity = inState.amount.quantity * 2))
command(MEGA_CORP_PUBKEY, Obligation.Commands.Issue())
tweak {
command(MEGA_CORP_PUBKEY) { Obligation.Commands.Issue() }
command(MEGA_CORP_PUBKEY, Obligation.Commands.Issue())
this `fails with` "there is only a single issue command"
}
this.verifies()
@ -352,7 +347,7 @@ class ObligationTests {
input("Alice's $1,000,000 obligation to Bob")
input("Bob's $1,000,000 obligation to Alice")
// Note we can sign with either key here
command(ALICE_PUBKEY) { Obligation.Commands.Net(NetType.CLOSE_OUT) }
command(ALICE_PUBKEY, Obligation.Commands.Net(NetType.CLOSE_OUT))
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -368,8 +363,8 @@ class ObligationTests {
input("Alice's $1,000,000 obligation to Bob")
input("Bob's $1,000,000 obligation to Alice")
input("MegaCorp's $1,000,000 obligation to Bob")
output(Obligation.PROGRAM_ID, "change") { oneMillionDollars.OBLIGATION between Pair(MEGA_CORP, BOB) }
command(BOB_PUBKEY, MEGA_CORP_PUBKEY) { Obligation.Commands.Net(NetType.CLOSE_OUT) }
output(Obligation.PROGRAM_ID, "change", oneMillionDollars.OBLIGATION between Pair(MEGA_CORP, BOB))
command(listOf(BOB_PUBKEY, MEGA_CORP_PUBKEY), Obligation.Commands.Net(NetType.CLOSE_OUT))
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -383,8 +378,8 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Alice's $1,000,000 obligation to Bob")
input("Bob's $1,000,000 obligation to Alice")
output(Obligation.PROGRAM_ID, "change") { (oneMillionDollars.splitEvenly(2).first()).OBLIGATION between Pair(ALICE, BOB) }
command(BOB_PUBKEY) { Obligation.Commands.Net(NetType.CLOSE_OUT) }
output(Obligation.PROGRAM_ID, "change", oneMillionDollars.splitEvenly(2).first().OBLIGATION between Pair(ALICE, BOB))
command(BOB_PUBKEY, Obligation.Commands.Net(NetType.CLOSE_OUT))
timeWindow(TEST_TX_TIME)
this `fails with` "amounts owed on input and output must match"
}
@ -397,7 +392,7 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Alice's $1,000,000 obligation to Bob")
input("Bob's $1,000,000 obligation to Alice")
command(MEGA_CORP_PUBKEY) { Obligation.Commands.Net(NetType.CLOSE_OUT) }
command(MEGA_CORP_PUBKEY, Obligation.Commands.Net(NetType.CLOSE_OUT))
timeWindow(TEST_TX_TIME)
this `fails with` "any involved party has signed"
}
@ -413,7 +408,7 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Alice's $1,000,000 obligation to Bob")
input("Bob's $1,000,000 obligation to Alice")
command(ALICE_PUBKEY, BOB_PUBKEY) { Obligation.Commands.Net(NetType.PAYMENT) }
command(listOf(ALICE_PUBKEY, BOB_PUBKEY), Obligation.Commands.Net(NetType.PAYMENT))
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -428,7 +423,7 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Alice's $1,000,000 obligation to Bob")
input("Bob's $1,000,000 obligation to Alice")
command(BOB_PUBKEY) { Obligation.Commands.Net(NetType.PAYMENT) }
command(BOB_PUBKEY, Obligation.Commands.Net(NetType.PAYMENT))
timeWindow(TEST_TX_TIME)
this `fails with` "all involved parties have signed"
}
@ -441,8 +436,8 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Bob's $1,000,000 obligation to Alice")
input("MegaCorp's $1,000,000 obligation to Bob")
output(Obligation.PROGRAM_ID, "MegaCorp's $1,000,000 obligation to Alice") { oneMillionDollars.OBLIGATION between Pair(MEGA_CORP, ALICE) }
command(ALICE_PUBKEY, BOB_PUBKEY, MEGA_CORP_PUBKEY) { Obligation.Commands.Net(NetType.PAYMENT) }
output(Obligation.PROGRAM_ID, "MegaCorp's $1,000,000 obligation to Alice", oneMillionDollars.OBLIGATION between Pair(MEGA_CORP, ALICE))
command(listOf(ALICE_PUBKEY, BOB_PUBKEY, MEGA_CORP_PUBKEY), Obligation.Commands.Net(NetType.PAYMENT))
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -456,8 +451,8 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Bob's $1,000,000 obligation to Alice")
input("MegaCorp's $1,000,000 obligation to Bob")
output(Obligation.PROGRAM_ID, "MegaCorp's $1,000,000 obligation to Alice") { oneMillionDollars.OBLIGATION between Pair(MEGA_CORP, ALICE) }
command(ALICE_PUBKEY, BOB_PUBKEY) { Obligation.Commands.Net(NetType.PAYMENT) }
output(Obligation.PROGRAM_ID, "MegaCorp's $1,000,000 obligation to Alice", oneMillionDollars.OBLIGATION between Pair(MEGA_CORP, ALICE))
command(listOf(ALICE_PUBKEY, BOB_PUBKEY), Obligation.Commands.Net(NetType.PAYMENT))
timeWindow(TEST_TX_TIME)
this `fails with` "all involved parties have signed"
}
@ -473,9 +468,9 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Alice's $1,000,000 obligation to Bob")
input("Alice's $1,000,000")
output(Obligation.PROGRAM_ID, "Bob's $1,000,000") { 1000000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB }
command(ALICE_PUBKEY) { Obligation.Commands.Settle(Amount(oneMillionDollars.quantity, inState.amount.token)) }
command(ALICE_PUBKEY) { Cash.Commands.Move(Obligation::class.java) }
output(Obligation.PROGRAM_ID, "Bob's $1,000,000", 1000000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB)
command(ALICE_PUBKEY, Obligation.Commands.Settle(Amount(oneMillionDollars.quantity, inState.amount.token)))
command(ALICE_PUBKEY, Cash.Commands.Move(Obligation::class.java))
attachment(attachment(cashContractBytes.inputStream()))
this.verifies()
}
@ -488,10 +483,10 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID, Cash.PROGRAM_ID)
input(Obligation.PROGRAM_ID, oneMillionDollars.OBLIGATION between Pair(ALICE, BOB))
input(Cash.PROGRAM_ID, 500000.DOLLARS.CASH issuedBy defaultIssuer ownedBy ALICE)
output(Obligation.PROGRAM_ID, "Alice's $500,000 obligation to Bob") { halfAMillionDollars.OBLIGATION between Pair(ALICE, BOB) }
output(Obligation.PROGRAM_ID, "Bob's $500,000") { 500000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB }
command(ALICE_PUBKEY) { Obligation.Commands.Settle(Amount(oneMillionDollars.quantity / 2, inState.amount.token)) }
command(ALICE_PUBKEY) { Cash.Commands.Move(Obligation::class.java) }
output(Obligation.PROGRAM_ID, "Alice's $500,000 obligation to Bob", halfAMillionDollars.OBLIGATION between Pair(ALICE, BOB))
output(Obligation.PROGRAM_ID, "Bob's $500,000", 500000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB)
command(ALICE_PUBKEY, Obligation.Commands.Settle(Amount(oneMillionDollars.quantity / 2, inState.amount.token)))
command(ALICE_PUBKEY, Cash.Commands.Move(Obligation::class.java))
attachment(attachment(cashContractBytes.inputStream()))
this.verifies()
}
@ -504,9 +499,9 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID, Cash.PROGRAM_ID)
input(Obligation.PROGRAM_ID, defaultedObligation) // Alice's defaulted $1,000,000 obligation to Bob
input(Cash.PROGRAM_ID, 1000000.DOLLARS.CASH issuedBy defaultIssuer ownedBy ALICE)
output(Obligation.PROGRAM_ID, "Bob's $1,000,000") { 1000000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB }
command(ALICE_PUBKEY) { Obligation.Commands.Settle(Amount(oneMillionDollars.quantity, inState.amount.token)) }
command(ALICE_PUBKEY) { Cash.Commands.Move(Obligation::class.java) }
output(Obligation.PROGRAM_ID, "Bob's $1,000,000", 1000000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB)
command(ALICE_PUBKEY, Obligation.Commands.Settle(Amount(oneMillionDollars.quantity, inState.amount.token)))
command(ALICE_PUBKEY, Cash.Commands.Move(Obligation::class.java))
this `fails with` "all inputs are in the normal state"
}
}
@ -518,9 +513,9 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Alice's $1,000,000 obligation to Bob")
input("Alice's $1,000,000")
output(Obligation.PROGRAM_ID, "Bob's $1,000,000") { 1000000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB }
command(ALICE_PUBKEY) { Obligation.Commands.Settle(Amount(oneMillionDollars.quantity / 2, inState.amount.token)) }
command(ALICE_PUBKEY) { Cash.Commands.Move(Obligation::class.java) }
output(Obligation.PROGRAM_ID, "Bob's $1,000,000", 1000000.DOLLARS.CASH issuedBy defaultIssuer ownedBy BOB)
command(ALICE_PUBKEY, Obligation.Commands.Settle(Amount(oneMillionDollars.quantity / 2, inState.amount.token)))
command(ALICE_PUBKEY, Cash.Commands.Move(Obligation::class.java))
attachment(attachment(cashContractBytes.inputStream()))
this `fails with` "amount in settle command"
}
@ -546,9 +541,9 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
input("Alice's 1 FCOJ obligation to Bob")
input("Alice's 1 FCOJ")
output(Obligation.PROGRAM_ID, "Bob's 1 FCOJ") { CommodityContract.State(oneUnitFcoj, BOB) }
command(ALICE_PUBKEY) { Obligation.Commands.Settle(Amount(oneUnitFcoj.quantity, oneUnitFcojObligation.amount.token)) }
command(ALICE_PUBKEY) { CommodityContract.Commands.Move(Obligation::class.java) }
output(Obligation.PROGRAM_ID, "Bob's 1 FCOJ", CommodityContract.State(oneUnitFcoj, BOB))
command(ALICE_PUBKEY, Obligation.Commands.Settle(Amount(oneUnitFcoj.quantity, oneUnitFcojObligation.amount.token)))
command(ALICE_PUBKEY, CommodityContract.Commands.Move(Obligation::class.java))
attachment(attachment(commodityContractBytes.inputStream()))
verifies()
}
@ -563,8 +558,8 @@ class ObligationTests {
transaction("Settlement") {
attachments(Obligation.PROGRAM_ID)
input("Alice's $1,000,000 obligation to Bob")
output(Obligation.PROGRAM_ID, "Alice's defaulted $1,000,000 obligation to Bob") { (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB)).copy(lifecycle = Lifecycle.DEFAULTED) }
command(BOB_PUBKEY) { Obligation.Commands.SetLifecycle(Lifecycle.DEFAULTED) }
output(Obligation.PROGRAM_ID, "Alice's defaulted $1,000,000 obligation to Bob", (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB)).copy(lifecycle = Lifecycle.DEFAULTED))
command(BOB_PUBKEY, Obligation.Commands.SetLifecycle(Lifecycle.DEFAULTED))
this `fails with` "there is a time-window from the authority"
}
}
@ -575,8 +570,8 @@ class ObligationTests {
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID, oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` futureTestTime)
output(Obligation.PROGRAM_ID, "Alice's defaulted $1,000,000 obligation to Bob") { (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` futureTestTime).copy(lifecycle = Lifecycle.DEFAULTED) }
command(BOB_PUBKEY) { Obligation.Commands.SetLifecycle(Lifecycle.DEFAULTED) }
output(Obligation.PROGRAM_ID, "Alice's defaulted $1,000,000 obligation to Bob", (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` futureTestTime).copy(lifecycle = Lifecycle.DEFAULTED))
command(BOB_PUBKEY, Obligation.Commands.SetLifecycle(Lifecycle.DEFAULTED))
timeWindow(TEST_TX_TIME)
this `fails with` "the due date has passed"
}
@ -586,8 +581,8 @@ class ObligationTests {
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID, oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` pastTestTime)
output(Obligation.PROGRAM_ID, "Alice's defaulted $1,000,000 obligation to Bob") { (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` pastTestTime).copy(lifecycle = Lifecycle.DEFAULTED) }
command(BOB_PUBKEY) { Obligation.Commands.SetLifecycle(Lifecycle.DEFAULTED) }
output(Obligation.PROGRAM_ID, "Alice's defaulted $1,000,000 obligation to Bob", (oneMillionDollars.OBLIGATION between Pair(ALICE, BOB) `at` pastTestTime).copy(lifecycle = Lifecycle.DEFAULTED))
command(BOB_PUBKEY, Obligation.Commands.SetLifecycle(Lifecycle.DEFAULTED))
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -600,24 +595,24 @@ class ObligationTests {
// Splitting value works.
transaction {
attachments(Obligation.PROGRAM_ID)
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
command(CHARLIE.owningKey, Obligation.Commands.Move())
tweak {
input(Obligation.PROGRAM_ID) { inState }
repeat(4) { output(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.quantity / 4) } }
input(Obligation.PROGRAM_ID, inState)
repeat(4) { output(Obligation.PROGRAM_ID, inState.copy(quantity = inState.quantity / 4)) }
this.verifies()
}
// Merging 4 inputs into 2 outputs works.
tweak {
repeat(4) { input(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.quantity / 4) } }
output(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.quantity / 2) }
output(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.quantity / 2) }
repeat(4) { input(Obligation.PROGRAM_ID, inState.copy(quantity = inState.quantity / 4)) }
output(Obligation.PROGRAM_ID, inState.copy(quantity = inState.quantity / 2))
output(Obligation.PROGRAM_ID, inState.copy(quantity = inState.quantity / 2))
this.verifies()
}
// Merging 2 inputs into 1 works.
tweak {
input(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.quantity / 2) }
input(Obligation.PROGRAM_ID) { inState.copy(quantity = inState.quantity / 2) }
output(Obligation.PROGRAM_ID) { inState }
input(Obligation.PROGRAM_ID, inState.copy(quantity = inState.quantity / 2))
input(Obligation.PROGRAM_ID, inState.copy(quantity = inState.quantity / 2))
output(Obligation.PROGRAM_ID, inState)
this.verifies()
}
}
@ -627,18 +622,16 @@ class ObligationTests {
fun zeroSizedValues() {
transaction {
attachments(Obligation.PROGRAM_ID)
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
command(CHARLIE.owningKey, Obligation.Commands.Move())
tweak {
input(Obligation.PROGRAM_ID) { inState }
input(Obligation.PROGRAM_ID) { inState.copy(quantity = 0L) }
input(Obligation.PROGRAM_ID, inState)
input(Obligation.PROGRAM_ID, inState.copy(quantity = 0L))
this `fails with` "zero sized inputs"
}
tweak {
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { inState.copy(quantity = 0L) }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, inState.copy(quantity = 0L))
this `fails with` "zero sized outputs"
}
}
@ -649,41 +642,39 @@ class ObligationTests {
// Can't change issuer.
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { outState `issued by` MINI_CORP }
command(MINI_CORP_PUBKEY) { Obligation.Commands.Move() }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, outState `issued by` MINI_CORP)
command(MINI_CORP_PUBKEY, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
// Can't mix currencies.
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { outState.copy(quantity = 80000, template = megaCorpDollarSettlement) }
output(Obligation.PROGRAM_ID) { outState.copy(quantity = 20000, template = megaCorpPoundSettlement) }
command(MINI_CORP_PUBKEY) { Obligation.Commands.Move() }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, outState.copy(quantity = 80000, template = megaCorpDollarSettlement))
output(Obligation.PROGRAM_ID, outState.copy(quantity = 20000, template = megaCorpPoundSettlement))
command(MINI_CORP_PUBKEY, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
input(Obligation.PROGRAM_ID) {
input(Obligation.PROGRAM_ID, inState)
input(Obligation.PROGRAM_ID,
inState.copy(
quantity = 15000,
template = megaCorpPoundSettlement,
beneficiary = AnonymousParty(BOB_PUBKEY)
)
}
output(Obligation.PROGRAM_ID) { outState.copy(quantity = 115000) }
command(MINI_CORP_PUBKEY) { Obligation.Commands.Move() }
beneficiary = AnonymousParty(BOB_PUBKEY)))
output(Obligation.PROGRAM_ID, outState.copy(quantity = 115000))
command(MINI_CORP_PUBKEY, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
// Can't have superfluous input states from different issuers.
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
input(Obligation.PROGRAM_ID) { inState `issued by` MINI_CORP }
output(Obligation.PROGRAM_ID) { outState }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
input(Obligation.PROGRAM_ID, inState)
input(Obligation.PROGRAM_ID, inState `issued by` MINI_CORP)
output(Obligation.PROGRAM_ID, outState)
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
}
@ -693,21 +684,20 @@ class ObligationTests {
// Single input/output straightforward case.
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState }
output(Obligation.PROGRAM_ID) { outState.copy(quantity = inState.quantity - 200.DOLLARS.quantity) }
input(Obligation.PROGRAM_ID, inState)
output(Obligation.PROGRAM_ID, outState.copy(quantity = inState.quantity - 200.DOLLARS.quantity))
tweak {
command(CHARLIE.owningKey) { Obligation.Commands.Exit(Amount(100.DOLLARS.quantity, inState.amount.token)) }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
command(CHARLIE.owningKey, Obligation.Commands.Exit(Amount(100.DOLLARS.quantity, inState.amount.token)))
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
tweak {
command(CHARLIE.owningKey) { Obligation.Commands.Exit(Amount(200.DOLLARS.quantity, inState.amount.token)) }
command(CHARLIE.owningKey, Obligation.Commands.Exit(Amount(200.DOLLARS.quantity, inState.amount.token)))
this `fails with` "required net.corda.finance.contracts.asset.Obligation.Commands.Move command"
tweak {
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
command(CHARLIE.owningKey, Obligation.Commands.Move())
this.verifies()
}
}
@ -720,21 +710,15 @@ class ObligationTests {
// Multi-product case.
transaction {
attachments(Obligation.PROGRAM_ID)
input(Obligation.PROGRAM_ID) { inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedPounds)) }
input(Obligation.PROGRAM_ID) { inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedDollars)) }
output(Obligation.PROGRAM_ID) { inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedPounds), quantity = inState.quantity - 200.POUNDS.quantity) }
output(Obligation.PROGRAM_ID) { inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedDollars), quantity = inState.quantity - 200.DOLLARS.quantity) }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
input(Obligation.PROGRAM_ID, inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedPounds)))
input(Obligation.PROGRAM_ID, inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedDollars)))
output(Obligation.PROGRAM_ID, inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedPounds), quantity = inState.quantity - 200.POUNDS.quantity))
output(Obligation.PROGRAM_ID, inState.copy(template = inState.template.copy(acceptableIssuedProducts = megaIssuedDollars), quantity = inState.quantity - 200.DOLLARS.quantity))
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "the amounts balance"
command(CHARLIE.owningKey) { Obligation.Commands.Exit(Amount(200.DOLLARS.quantity, inState.amount.token.copy(product = megaCorpDollarSettlement))) }
command(CHARLIE.owningKey, Obligation.Commands.Exit(Amount(200.DOLLARS.quantity, inState.amount.token.copy(product = megaCorpDollarSettlement))))
this `fails with` "the amounts balance"
command(CHARLIE.owningKey) { Obligation.Commands.Exit(Amount(200.POUNDS.quantity, inState.amount.token.copy(product = megaCorpPoundSettlement))) }
command(CHARLIE.owningKey, Obligation.Commands.Exit(Amount(200.POUNDS.quantity, inState.amount.token.copy(product = megaCorpPoundSettlement))))
this.verifies()
}
}
@ -745,27 +729,26 @@ class ObligationTests {
attachments(Obligation.PROGRAM_ID)
// Gather 2000 dollars from two different issuers.
input(Obligation.PROGRAM_ID) { inState }
input(Obligation.PROGRAM_ID) { inState `issued by` MINI_CORP }
input(Obligation.PROGRAM_ID, inState)
input(Obligation.PROGRAM_ID, inState `issued by` MINI_CORP)
// Can't merge them together.
tweak {
output(Obligation.PROGRAM_ID) { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY), quantity = 200000L) }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
output(Obligation.PROGRAM_ID, inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY), quantity = 200000L))
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
// Missing MiniCorp deposit
tweak {
output(Obligation.PROGRAM_ID) { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
output(Obligation.PROGRAM_ID) { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
output(Obligation.PROGRAM_ID, inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)))
output(Obligation.PROGRAM_ID, inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)))
command(CHARLIE.owningKey, Obligation.Commands.Move())
this `fails with` "the amounts balance"
}
// This works.
output(Obligation.PROGRAM_ID) { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) }
output(Obligation.PROGRAM_ID) { inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) `issued by` MINI_CORP }
command(CHARLIE.owningKey) { Obligation.Commands.Move() }
output(Obligation.PROGRAM_ID, inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)))
output(Obligation.PROGRAM_ID, inState.copy(beneficiary = AnonymousParty(BOB_PUBKEY)) `issued by` MINI_CORP)
command(CHARLIE.owningKey, Obligation.Commands.Move())
this.verifies()
}
}
@ -776,12 +759,11 @@ class ObligationTests {
transaction {
attachments(Obligation.PROGRAM_ID)
val pounds = Obligation.State(Lifecycle.NORMAL, MINI_CORP, megaCorpPoundSettlement, 658.POUNDS.quantity, AnonymousParty(BOB_PUBKEY))
input(Obligation.PROGRAM_ID) { inState `owned by` CHARLIE }
input(Obligation.PROGRAM_ID) { pounds }
output(Obligation.PROGRAM_ID) { inState `owned by` AnonymousParty(BOB_PUBKEY) }
output(Obligation.PROGRAM_ID) { pounds `owned by` CHARLIE }
command(CHARLIE.owningKey, BOB_PUBKEY) { Obligation.Commands.Move() }
input(Obligation.PROGRAM_ID, inState `owned by` CHARLIE)
input(Obligation.PROGRAM_ID, pounds)
output(Obligation.PROGRAM_ID, inState `owned by` AnonymousParty(BOB_PUBKEY))
output(Obligation.PROGRAM_ID, pounds `owned by` CHARLIE)
command(listOf(CHARLIE.owningKey, BOB_PUBKEY), Obligation.Commands.Move())
this.verifies()
}
}

View File

@ -653,13 +653,13 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
// wants to sell to Bob.
val eb1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
// Issued money to itself.
output(Cash.PROGRAM_ID, "elbonian money 1", notary = notary) { 800.DOLLARS.CASH issuedBy issuer ownedBy interimOwner }
output(Cash.PROGRAM_ID, "elbonian money 2", notary = notary) { 1000.DOLLARS.CASH issuedBy issuer ownedBy interimOwner }
output(Cash.PROGRAM_ID, "elbonian money 1", notary = notary, contractState = 800.DOLLARS.CASH issuedBy issuer ownedBy interimOwner)
output(Cash.PROGRAM_ID, "elbonian money 2", notary = notary, contractState = 1000.DOLLARS.CASH issuedBy issuer ownedBy interimOwner)
if (!withError) {
command(issuer.party.owningKey) { Cash.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) { Cash.Commands.Move() }
command(issuer.party.owningKey, Cash.Commands.Move())
}
timeWindow(TEST_TX_TIME)
if (withError) {
@ -672,16 +672,16 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
// Bob gets some cash onto the ledger from BoE
val bc1 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
input("elbonian money 1")
output(Cash.PROGRAM_ID, "bob cash 1", notary = notary) { 800.DOLLARS.CASH issuedBy issuer ownedBy owner }
command(interimOwner.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, "bob cash 1", notary = notary, contractState = 800.DOLLARS.CASH issuedBy issuer ownedBy owner)
command(interimOwner.owningKey, Cash.Commands.Move())
this.verifies()
}
val bc2 = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
input("elbonian money 2")
output(Cash.PROGRAM_ID, "bob cash 2", notary = notary) { 300.DOLLARS.CASH issuedBy issuer ownedBy owner }
output(Cash.PROGRAM_ID, notary = notary) { 700.DOLLARS.CASH issuedBy issuer ownedBy interimOwner } // Change output.
command(interimOwner.owningKey) { Cash.Commands.Move() }
output(Cash.PROGRAM_ID, "bob cash 2", notary = notary, contractState = 300.DOLLARS.CASH issuedBy issuer ownedBy owner)
output(Cash.PROGRAM_ID, notary = notary, contractState = 700.DOLLARS.CASH issuedBy issuer ownedBy interimOwner) // Change output.
command(interimOwner.owningKey, Cash.Commands.Move())
this.verifies()
}
@ -697,10 +697,9 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) {
attachmentID: SecureHash?,
notary: Party): Pair<Vault<ContractState>, List<WireTransaction>> {
val ap = transaction(transactionBuilder = TransactionBuilder(notary = notary)) {
output(CommercialPaper.CP_PROGRAM_ID, "alice's paper", notary = notary) {
CommercialPaper.State(issuer, owner, amount, TEST_TX_TIME + 7.days)
}
command(issuer.party.owningKey) { CommercialPaper.Commands.Issue() }
output(CommercialPaper.CP_PROGRAM_ID, "alice's paper", notary = notary,
contractState = CommercialPaper.State(issuer, owner, amount, TEST_TX_TIME + 7.days))
command(issuer.party.owningKey, CommercialPaper.Commands.Issue())
if (!withError)
timeWindow(time = TEST_TX_TIME)
if (attachmentID != null)

View File

@ -385,8 +385,8 @@ class IRSTests {
return ledger {
transaction("Agreement") {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, "irs post agreement") { singleIRS() }
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
output(IRS_PROGRAM_ID, "irs post agreement", singleIRS())
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -395,17 +395,14 @@ class IRSTests {
attachments(IRS_PROGRAM_ID)
input("irs post agreement")
val postAgreement = "irs post agreement".output<InterestRateSwap.State>()
output(IRS_PROGRAM_ID, "irs post first fixing") {
output(IRS_PROGRAM_ID, "irs post first fixing",
postAgreement.copy(
postAgreement.fixedLeg,
postAgreement.floatingLeg,
postAgreement.calculation.applyFixing(ld, FixedRate(RatioUnit(bd))),
postAgreement.common
)
}
command(ORACLE_PUBKEY) {
InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd))
}
postAgreement.common))
command(ORACLE_PUBKEY,
InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)))
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -419,7 +416,7 @@ class IRSTests {
attachments(IRS_PROGRAM_ID)
input(IRS_PROGRAM_ID, irs)
output(IRS_PROGRAM_ID, "irs post agreement", irs)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "There are no in states for an agreement"
}
@ -432,7 +429,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(calculation = irs.calculation.copy(fixedLegPaymentSchedule = emptySchedule)))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "There are events in the fix schedule"
}
@ -445,7 +442,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(calculation = irs.calculation.copy(floatingLegPaymentSchedule = emptySchedule)))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "There are events in the float schedule"
}
@ -457,7 +454,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(irs.fixedLeg.copy(notional = irs.fixedLeg.notional.copy(quantity = 0))))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "All notionals must be non zero"
}
@ -465,7 +462,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, irs.copy(irs.fixedLeg.copy(notional = irs.floatingLeg.notional.copy(quantity = 0))))
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "All notionals must be non zero"
}
@ -478,7 +475,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "The fixed leg rate must be positive"
}
@ -494,7 +491,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "The currency of the notionals must be the same"
}
@ -507,7 +504,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "All leg notionals must be the same"
}
@ -520,7 +517,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS1)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "The effective date is before the termination date for the fixed leg"
}
@ -529,7 +526,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS2)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "The effective date is before the termination date for the floating leg"
}
@ -543,7 +540,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS3)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "The termination dates are aligned"
}
@ -553,7 +550,7 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, modifiedIRS4)
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this `fails with` "The effective dates are aligned"
}
@ -567,8 +564,8 @@ class IRSTests {
transaction {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, "irs post agreement") { singleIRS() }
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
output(IRS_PROGRAM_ID, "irs post agreement", singleIRS())
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -585,9 +582,8 @@ class IRSTests {
// Templated tweak for reference. A corrent fixing applied should be ok
tweak {
command(ORACLE_PUBKEY) {
InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd))
}
command(ORACLE_PUBKEY,
InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)))
timeWindow(TEST_TX_TIME)
output(IRS_PROGRAM_ID, newIRS)
this.verifies()
@ -595,7 +591,7 @@ class IRSTests {
// This test makes sure that verify confirms the fixing was applied and there is a difference in the old and new
tweak {
command(ORACLE_PUBKEY) { InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)) }
command(ORACLE_PUBKEY, InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)))
timeWindow(TEST_TX_TIME)
output(IRS_PROGRAM_ID, oldIRS)
this `fails with` "There is at least one difference in the IRS floating leg payment schedules"
@ -603,42 +599,36 @@ class IRSTests {
// This tests tries to sneak in a change to another fixing (which may or may not be the latest one)
tweak {
command(ORACLE_PUBKEY) { InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)) }
command(ORACLE_PUBKEY, InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)))
timeWindow(TEST_TX_TIME)
val firstResetKey = newIRS.calculation.floatingLegPaymentSchedule.keys.toList()[1]
val firstResetValue = newIRS.calculation.floatingLegPaymentSchedule[firstResetKey]
val modifiedFirstResetValue = firstResetValue!!.copy(notional = Amount(firstResetValue.notional.quantity, Currency.getInstance("JPY")))
output(IRS_PROGRAM_ID) {
output(IRS_PROGRAM_ID,
newIRS.copy(
newIRS.fixedLeg,
newIRS.floatingLeg,
newIRS.calculation.copy(floatingLegPaymentSchedule = newIRS.calculation.floatingLegPaymentSchedule.plus(
Pair(firstResetKey, modifiedFirstResetValue))),
newIRS.common
)
}
newIRS.common))
this `fails with` "There is only one change in the IRS floating leg payment schedule"
}
// This tests modifies the payment currency for the fixing
tweak {
command(ORACLE_PUBKEY) { InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)) }
command(ORACLE_PUBKEY, InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld, Tenor("3M")), bd)))
timeWindow(TEST_TX_TIME)
val latestReset = newIRS.calculation.floatingLegPaymentSchedule.filter { it.value.rate is FixedRate }.maxBy { it.key }
val modifiedLatestResetValue = latestReset!!.value.copy(notional = Amount(latestReset.value.notional.quantity, Currency.getInstance("JPY")))
output(IRS_PROGRAM_ID) {
output(IRS_PROGRAM_ID,
newIRS.copy(
newIRS.fixedLeg,
newIRS.floatingLeg,
newIRS.calculation.copy(floatingLegPaymentSchedule = newIRS.calculation.floatingLegPaymentSchedule.plus(
Pair(latestReset.key, modifiedLatestResetValue))),
newIRS.common
)
}
newIRS.common))
this `fails with` "The fix payment has the same currency as the notional"
}
}
@ -660,31 +650,27 @@ class IRSTests {
return ledger {
transaction("Agreement") {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, "irs post agreement1") {
output(IRS_PROGRAM_ID, "irs post agreement1",
irs.copy(
irs.fixedLeg,
irs.floatingLeg,
irs.calculation,
irs.common.copy(tradeID = "t1")
)
}
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
irs.common.copy(tradeID = "t1")))
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this.verifies()
}
transaction("Agreement") {
attachments(IRS_PROGRAM_ID)
output(IRS_PROGRAM_ID, "irs post agreement2") {
output(IRS_PROGRAM_ID, "irs post agreement2",
irs.copy(
linearId = UniqueIdentifier("t2"),
fixedLeg = irs.fixedLeg,
floatingLeg = irs.floatingLeg,
calculation = irs.calculation,
common = irs.common.copy(tradeID = "t2")
)
}
command(MEGA_CORP_PUBKEY) { InterestRateSwap.Commands.Agree() }
common = irs.common.copy(tradeID = "t2")))
command(MEGA_CORP_PUBKEY, InterestRateSwap.Commands.Agree())
timeWindow(TEST_TX_TIME)
this.verifies()
}
@ -694,27 +680,21 @@ class IRSTests {
input("irs post agreement1")
input("irs post agreement2")
val postAgreement1 = "irs post agreement1".output<InterestRateSwap.State>()
output(IRS_PROGRAM_ID, "irs post first fixing1") {
output(IRS_PROGRAM_ID, "irs post first fixing1",
postAgreement1.copy(
postAgreement1.fixedLeg,
postAgreement1.floatingLeg,
postAgreement1.calculation.applyFixing(ld1, FixedRate(RatioUnit(bd1))),
postAgreement1.common.copy(tradeID = "t1")
)
}
postAgreement1.common.copy(tradeID = "t1")))
val postAgreement2 = "irs post agreement2".output<InterestRateSwap.State>()
output(IRS_PROGRAM_ID, "irs post first fixing2") {
output(IRS_PROGRAM_ID, "irs post first fixing2",
postAgreement2.copy(
postAgreement2.fixedLeg,
postAgreement2.floatingLeg,
postAgreement2.calculation.applyFixing(ld1, FixedRate(RatioUnit(bd1))),
postAgreement2.common.copy(tradeID = "t2")
)
}
command(ORACLE_PUBKEY) {
InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld1, Tenor("3M")), bd1))
}
postAgreement2.common.copy(tradeID = "t2")))
command(ORACLE_PUBKEY,
InterestRateSwap.Commands.Refix(Fix(FixOf("ICE LIBOR", ld1, Tenor("3M")), bd1)))
timeWindow(TEST_TX_TIME)
this.verifies()
}

View File

@ -93,7 +93,7 @@ data class TestTransactionDSLInterpreter private constructor(
transactionBuilder.addInputState(StateAndRef(state, stateRef))
}
override fun _output(contractClassName: ContractClassName,
override fun output(contractClassName: ContractClassName,
label: String?,
notary: Party,
encumbrance: Int?,
@ -115,7 +115,7 @@ data class TestTransactionDSLInterpreter private constructor(
transactionBuilder.addAttachment(attachmentId)
}
override fun _command(signers: List<PublicKey>, commandData: CommandData) {
override fun command(signers: List<PublicKey>, commandData: CommandData) {
val command = Command(commandData, signers)
transactionBuilder.addCommand(command)
}

View File

@ -35,12 +35,12 @@ interface TransactionDSLInterpreter : Verifies, OutputStateLookup {
* @param contractState The state itself.
* @param contractClassName The class name of the contract that verifies this state.
*/
fun _output(contractClassName: ContractClassName,
label: String?,
notary: Party,
encumbrance: Int?,
attachmentConstraint: AttachmentConstraint,
contractState: ContractState)
fun output(contractClassName: ContractClassName,
label: String?,
notary: Party,
encumbrance: Int?,
attachmentConstraint: AttachmentConstraint,
contractState: ContractState)
/**
* Adds an [Attachment] reference to the transaction.
@ -53,7 +53,7 @@ interface TransactionDSLInterpreter : Verifies, OutputStateLookup {
* @param signers The signer public keys.
* @param commandData The contents of the command.
*/
fun _command(signers: List<PublicKey>, commandData: CommandData)
fun command(signers: List<PublicKey>, commandData: CommandData)
/**
* Sets the time-window of the transaction.
@ -74,10 +74,10 @@ interface TransactionDSLInterpreter : Verifies, OutputStateLookup {
fun _attachment(contractClassName: ContractClassName)
}
class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : TransactionDSLInterpreter by interpreter {
class TransactionDSL<out T : TransactionDSLInterpreter>(interpreter: T) : TransactionDSLInterpreter by interpreter {
/**
* Looks up the output label and adds the found state as an input.
* @param stateLabel The label of the output state specified when calling [TransactionDSLInterpreter._output] and friends.
* @param stateLabel The label of the output state specified when calling [TransactionDSLInterpreter.output] and friends.
*/
fun input(stateLabel: String) = input(retrieveOutputStateAndRef(ContractState::class.java, stateLabel).ref)
@ -88,49 +88,51 @@ class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : Tr
*/
fun input(contractClassName: ContractClassName, state: ContractState) {
val transaction = ledgerInterpreter._unverifiedTransaction(null, TransactionBuilder(notary = DUMMY_NOTARY)) {
output(contractClassName, attachmentConstraint = AlwaysAcceptAttachmentConstraint) { state }
output(contractClassName, null, DUMMY_NOTARY, null, AlwaysAcceptAttachmentConstraint, state)
}
input(transaction.outRef<ContractState>(0).ref)
}
fun input(contractClassName: ContractClassName, stateClosure: () -> ContractState) = input(contractClassName, stateClosure())
/**
* Adds an output to the transaction.
* Adds a labelled output to the transaction.
*/
@JvmOverloads
fun output(contractClassName: ContractClassName,
label: String? = null,
notary: Party = DUMMY_NOTARY,
encumbrance: Int? = null,
attachmentConstraint: AttachmentConstraint = AutomaticHashConstraint,
contractStateClosure: () -> ContractState) =
_output(contractClassName, label, notary, encumbrance, attachmentConstraint, contractStateClosure())
fun output(contractClassName: ContractClassName, label: String, notary: Party, contractState: ContractState) =
output(contractClassName, label, notary, null, AutomaticHashConstraint, contractState)
/**
* Adds a labelled output to the transaction.
*/
@JvmOverloads
fun output(contractClassName: ContractClassName, label: String, contractState: ContractState, attachmentConstraint: AttachmentConstraint = AutomaticHashConstraint) =
_output(contractClassName, label, DUMMY_NOTARY, null, attachmentConstraint, contractState)
fun output(contractClassName: ContractClassName, label: String, encumbrance: Int, contractState: ContractState) =
output(contractClassName, label, DUMMY_NOTARY, encumbrance, AutomaticHashConstraint, contractState)
/**
* Adds a labelled output to the transaction.
*/
fun output(contractClassName: ContractClassName, label: String, contractState: ContractState) =
output(contractClassName, label, DUMMY_NOTARY, null, AutomaticHashConstraint, contractState)
/**
* Adds an output to the transaction.
*/
@JvmOverloads
fun output(contractClassName: ContractClassName, contractState: ContractState, attachmentConstraint: AttachmentConstraint = AutomaticHashConstraint) =
_output(contractClassName, null, DUMMY_NOTARY, null, attachmentConstraint, contractState)
fun output(contractClassName: ContractClassName, notary: Party, contractState: ContractState) =
output(contractClassName, null, notary, null, AutomaticHashConstraint, contractState)
/**
* Adds an output to the transaction.
*/
fun output(contractClassName: ContractClassName, encumbrance: Int, contractState: ContractState) =
output(contractClassName, null, DUMMY_NOTARY, encumbrance, AutomaticHashConstraint, contractState)
/**
* Adds an output to the transaction.
*/
fun output(contractClassName: ContractClassName, contractState: ContractState) =
output(contractClassName, null, DUMMY_NOTARY, null, AutomaticHashConstraint, contractState)
/**
* Adds a command to the transaction.
*/
fun command(vararg signers: PublicKey, commandDataClosure: () -> CommandData) =
_command(listOf(*signers), commandDataClosure())
/**
* Adds a command to the transaction.
*/
fun command(signer: PublicKey, commandData: CommandData) = _command(listOf(signer), commandData)
fun command(signer: PublicKey, commandData: CommandData) = command(listOf(signer), commandData)
/**
* Sets the [TimeWindow] of the transaction.
@ -142,7 +144,7 @@ class TransactionDSL<out T : TransactionDSLInterpreter>(val interpreter: T) : Tr
timeWindow(TimeWindow.withTolerance(time, tolerance))
/**
* @see TransactionDSLInterpreter._contractAttachment
* @see TransactionDSLInterpreter._attachment
*/
fun attachment(contractClassName: ContractClassName) = _attachment(contractClassName)