mirror of
https://github.com/corda/corda.git
synced 2024-12-30 09:48:59 +00:00
5b4969d366
This may not be really compatible with sandboxing, later on. But we can always change it back if not.
57 lines
1.8 KiB
Kotlin
57 lines
1.8 KiB
Kotlin
package contracts
|
|
|
|
import core.*
|
|
import org.junit.Test
|
|
|
|
// TODO: Finish this off.
|
|
|
|
class ComedyPaperTests {
|
|
val PAPER_1 = ComedyPaper.State(
|
|
issuance = InstitutionReference(MEGA_CORP, OpaqueBytes.of(123)),
|
|
owner = DUMMY_PUBKEY_1,
|
|
faceValue = 1000.DOLLARS,
|
|
maturityDate = TEST_TX_TIME + 7.days
|
|
)
|
|
val PAPER_2 = PAPER_1.copy(owner = DUMMY_PUBKEY_2)
|
|
|
|
val CASH_1 = Cash.State(InstitutionReference(MINI_CORP, OpaqueBytes.of(1)), 1000.DOLLARS, DUMMY_PUBKEY_1)
|
|
val CASH_2 = CASH_1.copy(owner = DUMMY_PUBKEY_2)
|
|
val CASH_3 = CASH_1.copy(owner = DUMMY_PUBKEY_1)
|
|
|
|
@Test
|
|
fun move() {
|
|
transaction {
|
|
// One entity sells the paper to another (e.g. the issuer sells it to a first time buyer)
|
|
input { PAPER_1 }
|
|
input { CASH_1 }
|
|
output("a") { PAPER_2 }
|
|
output { CASH_2 }
|
|
|
|
this.rejects()
|
|
|
|
transaction {
|
|
arg(DUMMY_PUBKEY_2) { ComedyPaper.Commands.Move }
|
|
this `fails requirement` "is signed by the owner"
|
|
}
|
|
|
|
arg(DUMMY_PUBKEY_1) { ComedyPaper.Commands.Move }
|
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
|
this.accepts()
|
|
}.chain("a") {
|
|
arg(DUMMY_PUBKEY_2, MINI_CORP_KEY) { ComedyPaper.Commands.Redeem }
|
|
|
|
// No cash output, can't redeem like that!
|
|
this.rejects("no cash being redeemed")
|
|
|
|
input { CASH_3 }
|
|
output { CASH_2 }
|
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
|
|
|
// Time passes, but not enough. An attempt to redeem is made.
|
|
this.rejects("must have matured")
|
|
|
|
// Try again at the right time.
|
|
this.accepts(TEST_TX_TIME + 10.days)
|
|
}
|
|
}
|
|
} |