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
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"
}