Contracts: commercial paper issue command doesn't need a nonce, and fix a bug in the unit tests.

This commit is contained in:
Mike Hearn 2015-11-25 18:14:33 +01:00
parent ff05cb4a4c
commit 3172b0b86a
3 changed files with 13 additions and 13 deletions

View File

@ -2,7 +2,6 @@ package contracts
import core.*
import java.security.PublicKey
import java.security.SecureRandom
import java.time.Instant
/**
@ -43,12 +42,9 @@ class CommercialPaper : Contract {
interface Commands : Command {
object Move : Commands
object Redeem : Commands
/**
* Allows new cash states to be issued into existence: the nonce ("number used once") ensures the transaction
* has a unique ID even when there are no inputs.
*/
data class Issue(val nonce: Long = SecureRandom.getInstanceStrong().nextLong()) : Commands
// We don't need a nonce in the issue command, because the issuance.reference field should already be unique per CP.
// However, nothing in the platform enforces that uniqueness: it's up to the issuer.
object Issue : Commands
}
override fun verify(tx: TransactionForVerification) {

View File

@ -229,7 +229,7 @@ fun createKryo(): Kryo {
registerDataClass<CommercialPaper.State>()
register(CommercialPaper.Commands.Move.javaClass)
register(CommercialPaper.Commands.Redeem.javaClass)
registerDataClass<CommercialPaper.Commands.Issue>()
register(CommercialPaper.Commands.Issue.javaClass)
// And for unit testing ...
registerDataClass<DummyPublicKey>()

View File

@ -28,7 +28,7 @@ class CommercialPaperTests {
transactionGroup {
transaction {
output { PAPER_1 }
arg(DUMMY_PUBKEY_1) { CommercialPaper.Commands.Issue() }
arg(DUMMY_PUBKEY_1) { CommercialPaper.Commands.Issue }
}
expectFailureOfTx(1, "signed by the claimed issuer")
@ -40,7 +40,7 @@ class CommercialPaperTests {
transactionGroup {
transaction {
output { PAPER_1.copy(faceValue = 0.DOLLARS) }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue() }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue }
}
expectFailureOfTx(1, "face value is not zero")
@ -52,19 +52,23 @@ class CommercialPaperTests {
transactionGroup {
transaction {
output { PAPER_1.copy(maturityDate = TEST_TX_TIME - 10.days) }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue() }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue }
}
expectFailureOfTx(1, "maturity date is not in the past")
}
}
@Test
fun `issue cannot replace an existing state`() {
transactionGroup {
roots {
transaction(PAPER_1 label "paper")
}
transaction {
input("paper")
output { PAPER_1 }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue() }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue }
}
expectFailureOfTx(1, "there is no input state")
@ -95,7 +99,7 @@ class CommercialPaperTests {
// Some CP is issued onto the ledger by MegaCorp.
transaction {
output("paper") { PAPER_1 }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue() }
arg(MEGA_CORP_KEY) { CommercialPaper.Commands.Issue }
}
// The CP is sold to alice for her $900, $100 less than the face value. At 10% interest after only 7 days,