mirror of
https://github.com/corda/corda.git
synced 2025-01-29 15:43:55 +00:00
Minor: test dsl, rename recursive transaction method to 'tweak' to better describe what it does.
This commit is contained in:
parent
03ddf454c7
commit
636279ced9
@ -27,27 +27,27 @@ class CashTests {
|
|||||||
input { inState }
|
input { inState }
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails requirement` "the amounts balance"
|
||||||
|
|
||||||
transaction {
|
tweak {
|
||||||
output { outState.copy(amount = 2000.DOLLARS )}
|
output { outState.copy(amount = 2000.DOLLARS )}
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails requirement` "the amounts balance"
|
||||||
}
|
}
|
||||||
transaction {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
// No command arguments
|
// No command arguments
|
||||||
this `fails requirement` "required contracts.Cash.Commands.Move command"
|
this `fails requirement` "required contracts.Cash.Commands.Move command"
|
||||||
}
|
}
|
||||||
transaction {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(DUMMY_PUBKEY_2) { Cash.Commands.Move }
|
arg(DUMMY_PUBKEY_2) { Cash.Commands.Move }
|
||||||
this `fails requirement` "the owning keys are the same as the signing keys"
|
this `fails requirement` "the owning keys are the same as the signing keys"
|
||||||
}
|
}
|
||||||
transaction {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
output { outState.editInstitution(MINI_CORP) }
|
output { outState.editInstitution(MINI_CORP) }
|
||||||
this `fails requirement` "no output states are unaccounted for"
|
this `fails requirement` "no output states are unaccounted for"
|
||||||
}
|
}
|
||||||
// Simple reallocation works.
|
// Simple reallocation works.
|
||||||
transaction {
|
tweak {
|
||||||
output { outState }
|
output { outState }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
||||||
this.accepts()
|
this.accepts()
|
||||||
@ -81,7 +81,7 @@ class CashTests {
|
|||||||
deposit = InstitutionReference(MINI_CORP, OpaqueBytes.of(12, 34))
|
deposit = InstitutionReference(MINI_CORP, OpaqueBytes.of(12, 34))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
transaction {
|
tweak {
|
||||||
arg(MINI_CORP_KEY) { Cash.Commands.Issue(0) }
|
arg(MINI_CORP_KEY) { Cash.Commands.Issue(0) }
|
||||||
this `fails requirement` "has a nonce"
|
this `fails requirement` "has a nonce"
|
||||||
}
|
}
|
||||||
@ -105,20 +105,20 @@ class CashTests {
|
|||||||
// Splitting value works.
|
// Splitting value works.
|
||||||
transaction {
|
transaction {
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
||||||
transaction {
|
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.accepts()
|
||||||
}
|
}
|
||||||
// Merging 4 inputs into 2 outputs works.
|
// Merging 4 inputs into 2 outputs works.
|
||||||
transaction {
|
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.accepts()
|
||||||
}
|
}
|
||||||
// Merging 2 inputs into 1 works.
|
// Merging 2 inputs into 1 works.
|
||||||
transaction {
|
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 }
|
||||||
@ -193,17 +193,17 @@ class CashTests {
|
|||||||
input { inState }
|
input { inState }
|
||||||
output { outState.copy(amount = inState.amount - 200.DOLLARS) }
|
output { outState.copy(amount = inState.amount - 200.DOLLARS) }
|
||||||
|
|
||||||
transaction {
|
tweak {
|
||||||
arg(MEGA_CORP_KEY) { Cash.Commands.Exit(100.DOLLARS) }
|
arg(MEGA_CORP_KEY) { Cash.Commands.Exit(100.DOLLARS) }
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
||||||
this `fails requirement` "the amounts balance"
|
this `fails requirement` "the amounts balance"
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction {
|
tweak {
|
||||||
arg(MEGA_CORP_KEY) { Cash.Commands.Exit(200.DOLLARS) }
|
arg(MEGA_CORP_KEY) { Cash.Commands.Exit(200.DOLLARS) }
|
||||||
this `fails requirement` "required contracts.Cash.Commands.Move command"
|
this `fails requirement` "required contracts.Cash.Commands.Move command"
|
||||||
|
|
||||||
transaction {
|
tweak {
|
||||||
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
||||||
this.accepts()
|
this.accepts()
|
||||||
}
|
}
|
||||||
@ -237,12 +237,12 @@ class CashTests {
|
|||||||
input { inState.editInstitution(MINI_CORP) }
|
input { inState.editInstitution(MINI_CORP) }
|
||||||
|
|
||||||
// Can't merge them together.
|
// Can't merge them together.
|
||||||
transaction {
|
tweak {
|
||||||
output { inState.copy(owner = DUMMY_PUBKEY_2, amount = 2000.DOLLARS) }
|
output { inState.copy(owner = DUMMY_PUBKEY_2, amount = 2000.DOLLARS) }
|
||||||
this `fails requirement` "at issuer MegaCorp the amounts balance"
|
this `fails requirement` "at issuer MegaCorp the amounts balance"
|
||||||
}
|
}
|
||||||
// Missing MiniCorp deposit
|
// Missing MiniCorp deposit
|
||||||
transaction {
|
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 requirement` "at issuer MegaCorp the amounts balance"
|
||||||
|
@ -33,7 +33,7 @@ class CommercialPaperTests {
|
|||||||
|
|
||||||
this.rejects()
|
this.rejects()
|
||||||
|
|
||||||
transaction {
|
tweak {
|
||||||
arg(DUMMY_PUBKEY_2) { CommercialPaper.Commands.Move }
|
arg(DUMMY_PUBKEY_2) { CommercialPaper.Commands.Move }
|
||||||
this `fails requirement` "is signed by the owner"
|
this `fails requirement` "is signed by the owner"
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ val TEST_PROGRAM_MAP: Map<SecureHash, Contract> = mapOf(
|
|||||||
// output { someExpression }
|
// output { someExpression }
|
||||||
// arg { someExpression }
|
// arg { someExpression }
|
||||||
//
|
//
|
||||||
// transaction {
|
// tweak {
|
||||||
// ... same thing but works with a copy of the parent, can add inputs/outputs/args just within this scope.
|
// ... same thing but works with a copy of the parent, can add inputs/outputs/args just within this scope.
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
@ -106,7 +106,7 @@ class TransactionForTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allow customisation of partial transactions.
|
// Allow customisation of partial transactions.
|
||||||
fun transaction(body: TransactionForTest.() -> Unit): TransactionForTest {
|
fun tweak(body: TransactionForTest.() -> Unit): TransactionForTest {
|
||||||
val tx = TransactionForTest()
|
val tx = TransactionForTest()
|
||||||
tx.inStates.addAll(inStates)
|
tx.inStates.addAll(inStates)
|
||||||
tx.outStates.addAll(outStates)
|
tx.outStates.addAll(outStates)
|
||||||
@ -117,7 +117,7 @@ class TransactionForTest() {
|
|||||||
|
|
||||||
// Use this to create transactions where the output of this transaction is automatically used as an input of
|
// Use this to create transactions where the output of this transaction is automatically used as an input of
|
||||||
// the next.
|
// the next.
|
||||||
fun chain(vararg outputLabels: String, body: TransactionForTest.() -> Unit) {
|
fun chain(vararg outputLabels: String, body: TransactionForTest.() -> Unit): TransactionForTest {
|
||||||
val states = outStates.mapNotNull {
|
val states = outStates.mapNotNull {
|
||||||
val l = it.label
|
val l = it.label
|
||||||
if (l != null && outputLabels.contains(l))
|
if (l != null && outputLabels.contains(l))
|
||||||
@ -128,6 +128,7 @@ class TransactionForTest() {
|
|||||||
val tx = TransactionForTest()
|
val tx = TransactionForTest()
|
||||||
tx.inStates.addAll(states)
|
tx.inStates.addAll(states)
|
||||||
tx.body()
|
tx.body()
|
||||||
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user