2015-11-06 16:55:20 +00:00
|
|
|
package contracts
|
|
|
|
|
|
|
|
import core.*
|
|
|
|
import org.junit.Test
|
|
|
|
|
|
|
|
// TODO: Finish this off.
|
|
|
|
|
2015-11-08 11:30:02 +00:00
|
|
|
class ComedyPaperTests {
|
|
|
|
val PAPER_1 = ComedyPaper.State(
|
2015-11-06 16:55:20 +00:00
|
|
|
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)
|
|
|
|
|
2015-11-12 21:58:47 +00:00
|
|
|
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)
|
|
|
|
|
2015-11-06 16:55:20 +00:00
|
|
|
@Test
|
|
|
|
fun move() {
|
|
|
|
transaction {
|
2015-11-12 21:58:47 +00:00
|
|
|
// One entity sells the paper to another (e.g. the issuer sells it to a first time buyer)
|
2015-11-06 16:55:20 +00:00
|
|
|
input { PAPER_1 }
|
2015-11-12 21:58:47 +00:00
|
|
|
input { CASH_1 }
|
|
|
|
output("a") { PAPER_2 }
|
|
|
|
output { CASH_2 }
|
2015-11-06 16:55:20 +00:00
|
|
|
|
2015-11-09 18:18:03 +00:00
|
|
|
this.rejects()
|
2015-11-06 16:55:20 +00:00
|
|
|
|
|
|
|
transaction {
|
2015-11-13 13:43:59 +00:00
|
|
|
arg(DUMMY_PUBKEY_2) { ComedyPaper.Commands.Move }
|
2015-11-09 18:18:03 +00:00
|
|
|
this `fails requirement` "is signed by the owner"
|
2015-11-06 16:55:20 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 13:43:59 +00:00
|
|
|
arg(DUMMY_PUBKEY_1) { ComedyPaper.Commands.Move }
|
|
|
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
2015-11-12 21:58:47 +00:00
|
|
|
this.accepts()
|
|
|
|
}.chain("a") {
|
2015-11-13 13:43:59 +00:00
|
|
|
arg(DUMMY_PUBKEY_2, MINI_CORP_KEY) { ComedyPaper.Commands.Redeem }
|
2015-11-12 21:58:47 +00:00
|
|
|
|
|
|
|
// No cash output, can't redeem like that!
|
2015-11-12 22:36:46 +00:00
|
|
|
this.rejects("no cash being redeemed")
|
2015-11-12 21:58:47 +00:00
|
|
|
|
|
|
|
input { CASH_3 }
|
|
|
|
output { CASH_2 }
|
2015-11-13 13:43:59 +00:00
|
|
|
arg(DUMMY_PUBKEY_1) { Cash.Commands.Move }
|
2015-11-12 21:58:47 +00:00
|
|
|
|
|
|
|
// 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)
|
2015-11-06 16:55:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|