mirror of
https://github.com/corda/corda.git
synced 2024-12-25 23:51:10 +00:00
contracts: Port CashTests to new dsl
This commit is contained in:
parent
f4a6a43aa6
commit
7634331f68
@ -29,56 +29,59 @@ class CashTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun trivial() {
|
fun trivial() {
|
||||||
|
ledger {
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails with` "the amounts balance"
|
||||||
|
|
||||||
tweak {
|
tweak {
|
||||||
output { outState.copy(amount = 2000.DOLLARS `issued by` defaultIssuer) }
|
output { outState.copy(amount = 2000.DOLLARS `issued by` defaultIssuer) }
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails with` "the amounts balance"
|
||||||
}
|
}
|
||||||
tweak {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
// No command arguments
|
// No command commanduments
|
||||||
this `fails requirement` "required com.r3corda.contracts.asset.FungibleAsset.Commands.Move command"
|
this `fails with` "required com.r3corda.contracts.asset.FungibleAsset.Commands.Move command"
|
||||||
}
|
}
|
||||||
tweak {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(DUMMY_PUBKEY_2) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_2) { Cash.Commands.Move() }
|
||||||
this `fails requirement` "the owning keys are the same as the signing keys"
|
this `fails with` "the owning keys are the same as the signing keys"
|
||||||
}
|
}
|
||||||
tweak {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
output { outState `issued by` MINI_CORP }
|
output { outState `issued by` MINI_CORP }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
this `fails requirement` "at least one asset input"
|
this `fails with` "at least one asset input"
|
||||||
}
|
}
|
||||||
// Simple reallocation works.
|
// Simple reallocation works.
|
||||||
tweak {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun issueMoney() {
|
fun issueMoney() {
|
||||||
|
ledger {
|
||||||
// Check we can't "move" money into existence.
|
// Check we can't "move" money into existence.
|
||||||
transaction {
|
transaction {
|
||||||
input { DummyState() }
|
input { DummyState() }
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(MINI_CORP_PUBKEY) { Cash.Commands.Move() }
|
command(MINI_CORP_PUBKEY) { Cash.Commands.Move() }
|
||||||
|
|
||||||
this `fails requirement` "there is at least one asset input"
|
this `fails with` "there is at least one asset input"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check we can issue money only as long as the issuer institution is a command signer, i.e. any recognised
|
// Check we can issue money only as long as the issuer institution is a command signer, i.e. any recognised
|
||||||
// institution is allowed to issue as much cash as they want.
|
// institution is allowed to issue as much cash as they want.
|
||||||
transaction {
|
transaction {
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Issue() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Issue() }
|
||||||
this `fails requirement` "output deposits are owned by a command signer"
|
this `fails with` "output deposits are owned by a command signer"
|
||||||
}
|
}
|
||||||
transaction {
|
transaction {
|
||||||
output {
|
output {
|
||||||
@ -88,11 +91,11 @@ class CashTests {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
tweak {
|
tweak {
|
||||||
arg(MINI_CORP_PUBKEY) { Cash.Commands.Issue(0) }
|
command(MINI_CORP_PUBKEY) { Cash.Commands.Issue(0) }
|
||||||
this `fails requirement` "has a nonce"
|
this `fails with` "has a nonce"
|
||||||
}
|
}
|
||||||
arg(MINI_CORP_PUBKEY) { Cash.Commands.Issue() }
|
command(MINI_CORP_PUBKEY) { Cash.Commands.Issue() }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test generation works.
|
// Test generation works.
|
||||||
@ -120,14 +123,14 @@ class CashTests {
|
|||||||
|
|
||||||
// Move fails: not allowed to summon money.
|
// Move fails: not allowed to summon money.
|
||||||
tweak {
|
tweak {
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
this `fails requirement` "at issuer MegaCorp the amounts balance"
|
this `fails with` "at issuer MegaCorp the amounts balance"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue works.
|
// Issue works.
|
||||||
tweak {
|
tweak {
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,36 +138,37 @@ class CashTests {
|
|||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { inState.copy(amount = inState.amount / 2) }
|
output { inState.copy(amount = inState.amount / 2) }
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
||||||
this `fails requirement` "output values sum to more than the inputs"
|
this `fails with` "output values sum to more than the inputs"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't have an issue command that doesn't actually issue money.
|
// Can't have an issue command that doesn't actually issue money.
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { inState }
|
output { inState }
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
||||||
this `fails requirement` "output values sum to more than the inputs"
|
this `fails with` "output values sum to more than the inputs"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't have any other commands if we have an issue command (because the issue command overrules them)
|
// Can't have any other commands if we have an issue command (because the issue command overrules them)
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { inState.copy(amount = inState.amount * 2) }
|
output { inState.copy(amount = inState.amount * 2) }
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
||||||
tweak {
|
tweak {
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Issue() }
|
||||||
this `fails requirement` "there is only a single issue command"
|
this `fails with` "there is only a single issue command"
|
||||||
}
|
}
|
||||||
tweak {
|
tweak {
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Move() }
|
||||||
this `fails requirement` "there is only a single issue command"
|
this `fails with` "there is only a single issue command"
|
||||||
}
|
}
|
||||||
tweak {
|
tweak {
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(inState.amount / 2) }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(inState.amount / 2) }
|
||||||
this `fails requirement` "there is only a single issue command"
|
this `fails with` "there is only a single issue command"
|
||||||
|
}
|
||||||
|
this.verifies()
|
||||||
}
|
}
|
||||||
this.accepts()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,67 +193,72 @@ class CashTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMergeSplit() {
|
fun testMergeSplit() {
|
||||||
|
ledger {
|
||||||
// Splitting value works.
|
// Splitting value works.
|
||||||
transaction {
|
transaction {
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
tweak {
|
tweak {
|
||||||
input { inState }
|
input { inState }
|
||||||
for (i in 1..4) output { inState.copy(amount = inState.amount / 4) }
|
for (i in 1..4) output { inState.copy(amount = inState.amount / 4) }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
}
|
}
|
||||||
// Merging 4 inputs into 2 outputs works.
|
// Merging 4 inputs into 2 outputs works.
|
||||||
tweak {
|
tweak {
|
||||||
for (i in 1..4) input { inState.copy(amount = inState.amount / 4) }
|
for (i in 1..4) input { inState.copy(amount = inState.amount / 4) }
|
||||||
output { inState.copy(amount = inState.amount / 2) }
|
output { inState.copy(amount = inState.amount / 2) }
|
||||||
output { inState.copy(amount = inState.amount / 2) }
|
output { inState.copy(amount = inState.amount / 2) }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
}
|
}
|
||||||
// Merging 2 inputs into 1 works.
|
// Merging 2 inputs into 1 works.
|
||||||
tweak {
|
tweak {
|
||||||
input { inState.copy(amount = inState.amount / 2) }
|
input { inState.copy(amount = inState.amount / 2) }
|
||||||
input { inState.copy(amount = inState.amount / 2) }
|
input { inState.copy(amount = inState.amount / 2) }
|
||||||
output { inState }
|
output { inState }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun zeroSizedValues() {
|
fun zeroSizedValues() {
|
||||||
|
ledger {
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
input { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) }
|
input { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) }
|
||||||
this `fails requirement` "zero sized inputs"
|
this `fails with` "zero sized inputs"
|
||||||
}
|
}
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { inState }
|
output { inState }
|
||||||
output { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) }
|
output { inState.copy(amount = 0.DOLLARS `issued by` defaultIssuer) }
|
||||||
this `fails requirement` "zero sized outputs"
|
this `fails with` "zero sized outputs"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun trivialMismatches() {
|
fun trivialMismatches() {
|
||||||
|
ledger {
|
||||||
// Can't change issuer.
|
// Can't change issuer.
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { outState `issued by` MINI_CORP }
|
output { outState `issued by` MINI_CORP }
|
||||||
this `fails requirement` "at issuer MegaCorp the amounts balance"
|
this `fails with` "at issuer MegaCorp the amounts balance"
|
||||||
}
|
}
|
||||||
// Can't change deposit reference when splitting.
|
// Can't change deposit reference when splitting.
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { outState.copy(amount = inState.amount / 2).editDepositRef(0) }
|
output { outState.copy(amount = inState.amount / 2).editDepositRef(0) }
|
||||||
output { outState.copy(amount = inState.amount / 2).editDepositRef(1) }
|
output { outState.copy(amount = inState.amount / 2).editDepositRef(1) }
|
||||||
this `fails requirement` "for deposit [01] at issuer MegaCorp the amounts balance"
|
this `fails with` "for deposit [01] at issuer MegaCorp the amounts balance"
|
||||||
}
|
}
|
||||||
// Can't mix currencies.
|
// Can't mix currencies.
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { outState.copy(amount = 800.DOLLARS `issued by` defaultIssuer) }
|
output { outState.copy(amount = 800.DOLLARS `issued by` defaultIssuer) }
|
||||||
output { outState.copy(amount = 200.POUNDS `issued by` defaultIssuer) }
|
output { outState.copy(amount = 200.POUNDS `issued by` defaultIssuer) }
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails with` "the amounts balance"
|
||||||
}
|
}
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
@ -260,45 +269,47 @@ class CashTests {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
output { outState.copy(amount = 1150.DOLLARS `issued by` defaultIssuer) }
|
output { outState.copy(amount = 1150.DOLLARS `issued by` defaultIssuer) }
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails with` "the amounts balance"
|
||||||
}
|
}
|
||||||
// Can't have superfluous input states from different issuers.
|
// Can't have superfluous input states from different issuers.
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
input { inState `issued by` MINI_CORP }
|
input { inState `issued by` MINI_CORP }
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
this `fails requirement` "at issuer MiniCorp the amounts balance"
|
this `fails with` "at issuer MiniCorp the amounts balance"
|
||||||
}
|
}
|
||||||
// Can't combine two different deposits at the same issuer.
|
// Can't combine two different deposits at the same issuer.
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
input { inState.editDepositRef(3) }
|
input { inState.editDepositRef(3) }
|
||||||
output { outState.copy(amount = inState.amount * 2).editDepositRef(3) }
|
output { outState.copy(amount = inState.amount * 2).editDepositRef(3) }
|
||||||
this `fails requirement` "for deposit [01]"
|
this `fails with` "for deposit [01]"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun exitLedger() {
|
fun exitLedger() {
|
||||||
|
ledger {
|
||||||
// Single input/output straightforward case.
|
// Single input/output straightforward case.
|
||||||
transaction {
|
transaction {
|
||||||
input { inState }
|
input { inState }
|
||||||
output { outState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
|
output { outState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
|
||||||
|
|
||||||
tweak {
|
tweak {
|
||||||
arg(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(100.DOLLARS `issued by` defaultIssuer) }
|
command(MEGA_CORP_PUBKEY) { Cash.Commands.Exit(100.DOLLARS `issued by` defaultIssuer) }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails with` "the amounts balance"
|
||||||
}
|
}
|
||||||
|
|
||||||
tweak {
|
tweak {
|
||||||
arg(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 requirement` "required com.r3corda.contracts.asset.FungibleAsset.Commands.Move command"
|
this `fails with` "required com.r3corda.contracts.asset.FungibleAsset.Commands.Move command"
|
||||||
|
|
||||||
tweak {
|
tweak {
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,20 +321,22 @@ class CashTests {
|
|||||||
output { inState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) `issued by` MINI_CORP }
|
output { inState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) `issued by` MINI_CORP }
|
||||||
output { inState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
|
output { inState.copy(amount = inState.amount - (200.DOLLARS `issued by` defaultIssuer)) }
|
||||||
|
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
|
|
||||||
this `fails requirement` "at issuer MegaCorp the amounts balance"
|
this `fails with` "at issuer MegaCorp the amounts balance"
|
||||||
|
|
||||||
arg(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 requirement` "at issuer MiniCorp the amounts balance"
|
this `fails with` "at issuer MiniCorp the amounts balance"
|
||||||
|
|
||||||
arg(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.accepts()
|
this.verifies()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun multiIssuer() {
|
fun multiIssuer() {
|
||||||
|
ledger {
|
||||||
transaction {
|
transaction {
|
||||||
// Gather 2000 dollars from two different issuers.
|
// Gather 2000 dollars from two different issuers.
|
||||||
input { inState }
|
input { inState }
|
||||||
@ -332,25 +345,27 @@ class CashTests {
|
|||||||
// Can't merge them together.
|
// Can't merge them together.
|
||||||
tweak {
|
tweak {
|
||||||
output { inState.copy(owner = DUMMY_PUBKEY_2, amount = 2000.DOLLARS `issued by` defaultIssuer) }
|
output { inState.copy(owner = DUMMY_PUBKEY_2, amount = 2000.DOLLARS `issued by` defaultIssuer) }
|
||||||
this `fails requirement` "at issuer MegaCorp the amounts balance"
|
this `fails with` "at issuer MegaCorp the amounts balance"
|
||||||
}
|
}
|
||||||
// Missing MiniCorp deposit
|
// Missing MiniCorp deposit
|
||||||
tweak {
|
tweak {
|
||||||
output { inState.copy(owner = DUMMY_PUBKEY_2) }
|
output { inState.copy(owner = DUMMY_PUBKEY_2) }
|
||||||
output { inState.copy(owner = DUMMY_PUBKEY_2) }
|
output { inState.copy(owner = DUMMY_PUBKEY_2) }
|
||||||
this `fails requirement` "at issuer MegaCorp the amounts balance"
|
this `fails with` "at issuer MegaCorp the amounts balance"
|
||||||
}
|
}
|
||||||
|
|
||||||
// This works.
|
// This works.
|
||||||
output { inState.copy(owner = DUMMY_PUBKEY_2) }
|
output { inState.copy(owner = DUMMY_PUBKEY_2) }
|
||||||
output { inState.copy(owner = DUMMY_PUBKEY_2) `issued by` MINI_CORP }
|
output { inState.copy(owner = DUMMY_PUBKEY_2) `issued by` MINI_CORP }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1) { Cash.Commands.Move() }
|
||||||
this.accepts()
|
this.verifies()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun multiCurrency() {
|
fun multiCurrency() {
|
||||||
|
ledger {
|
||||||
// Check we can do an atomic currency trade tx.
|
// Check we can do an atomic currency trade tx.
|
||||||
transaction {
|
transaction {
|
||||||
val pounds = Cash.State(658.POUNDS `issued by` MINI_CORP.ref(3, 4, 5), DUMMY_PUBKEY_2)
|
val pounds = Cash.State(658.POUNDS `issued by` MINI_CORP.ref(3, 4, 5), DUMMY_PUBKEY_2)
|
||||||
@ -358,9 +373,10 @@ class CashTests {
|
|||||||
input { pounds }
|
input { pounds }
|
||||||
output { inState `owned by` DUMMY_PUBKEY_2 }
|
output { inState `owned by` DUMMY_PUBKEY_2 }
|
||||||
output { pounds `owned by` DUMMY_PUBKEY_1 }
|
output { pounds `owned by` DUMMY_PUBKEY_1 }
|
||||||
arg(DUMMY_PUBKEY_1, DUMMY_PUBKEY_2) { Cash.Commands.Move() }
|
command(DUMMY_PUBKEY_1, DUMMY_PUBKEY_2) { Cash.Commands.Move() }
|
||||||
|
|
||||||
this.accepts()
|
this.verifies()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user