corda/tests/contracts/ComedyPaperTests.kt
Mike Hearn 12b7c7c184 Platform: fix the ability to summon cash in uncontrolled ways.
Introduce three ways to represent transactions: wire, ledger and for-verification.

TransactionForVerification contains the arguments formally passed to verify(). Making Contract.verify() take only a single object as the argument makes it easier to evolve the Contract binary interface without breaking backwards compatibility with existing contracts that are uploaded to the ledger. The Kotlin "with" construct can be used to bring the members into scope, thus acting syntactically like function arguments.

Make the contracts to be run depend on both input AND output states: this approach seems simpler than trying to have some notion of marking outputs that are checked. The TransactionForVerification class implements this simple logic (it's all moved into Transactions.kt).
2015-11-09 18:18:03 +00:00

37 lines
975 B
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)
@Test
fun move() {
// One entity sells the paper to another (e.g. the issuer sells it to a first time buyer)
transaction {
input { PAPER_1 }
output { PAPER_2 }
this.rejects()
transaction {
arg(DUMMY_PUBKEY_2) { ComedyPaper.Commands.Move() }
this `fails requirement` "is signed by the owner"
}
transaction {
arg(DUMMY_PUBKEY_1) { ComedyPaper.Commands.Move() }
this.accepts()
}
}
}
}