Fix bugs in the trade finance contracts and tests, where txns weren't being properly verified and thus the lack of timestamping wasn't detected.

This commit is contained in:
Mike Hearn 2016-07-29 15:43:24 +02:00
parent 1c3379f508
commit 301d787e45
4 changed files with 16 additions and 4 deletions

View File

@ -3,7 +3,10 @@ package com.r3corda.contracts
import com.r3corda.core.contracts.*
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.days
import com.r3corda.core.testing.DUMMY_NOTARY
import java.security.PublicKey
import java.time.Instant
import java.time.LocalDate
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -109,9 +112,11 @@ class BillOfLadingAgreement : Contract {
/**
* Returns a transaction that issues a Bill of Lading Agreement
*/
fun generateIssue(owner: PublicKey, beneficiary: Party, props: BillOfLadingProperties, notary: Party? = null): TransactionBuilder {
fun generateIssue(owner: PublicKey, beneficiary: Party, props: BillOfLadingProperties, notary: Party = DUMMY_NOTARY): TransactionBuilder {
val state = State(owner, beneficiary, props)
return TransactionType.General.Builder(notary = notary).withItems(state, Command(Commands.IssueBL(), props.carrierOwner.owningKey))
val builder = TransactionType.General.Builder(notary = notary)
builder.setTime(Instant.now(), notary, 1.days)
return builder.withItems(state, Command(Commands.IssueBL(), props.carrierOwner.owningKey))
}
/**

View File

@ -4,7 +4,10 @@ import com.r3corda.contracts.asset.sumCashBy
import com.r3corda.core.contracts.*
import com.r3corda.core.crypto.Party
import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.days
import com.r3corda.core.testing.DUMMY_NOTARY
import java.security.PublicKey
import java.time.Instant
import java.time.LocalDate
import java.time.Period
import java.time.ZoneOffset
@ -142,7 +145,9 @@ class LOC : Contract {
fun generateIssue(beneficiaryPaid: Boolean, issued: Boolean, terminated: Boolean, props: LOCProperties, notary: Party): TransactionBuilder {
val state = State(beneficiaryPaid, issued, terminated, props)
return TransactionType.General.Builder(notary = notary).withItems(state, Command(Commands.Issuance(), props.issuingbank.owningKey))
val builder = TransactionType.General.Builder(notary = notary)
builder.setTime(Instant.now(), notary, 1.days)
return builder.withItems(state, Command(Commands.Issuance(), props.issuingbank.owningKey))
}

View File

@ -48,8 +48,9 @@ class BillOfLadingAgreementTests {
@Test
fun issueGenerationMethod() {
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary,Bill.props, notary = DUMMY_NOTARY).apply {
val ptx = BillOfLadingAgreement().generateIssue(Bill.owner, Bill.beneficiary,Bill.props).apply {
signWith(ALICE_KEY)
signWith(DUMMY_NOTARY_KEY)
}
val stx = ptx.toSignedTransaction()
stx.verifyToLedgerTransaction(MOCK_IDENTITY_SERVICE,attachments)

View File

@ -120,6 +120,7 @@ class LOCTests {
fun issueSignedByBank() {
val ptx = LOC().generateIssue(LOCstate.beneficiaryPaid, LOCstate.issued, LOCstate.terminated, LOCstate.props, DUMMY_NOTARY).apply {
signWith(MEGA_CORP_KEY)
signWith(DUMMY_NOTARY_KEY)
}
val stx = ptx.toSignedTransaction()
stx.verify()