在Corda中,如何按照教程“编写合同测试”来创建用于编写合同测试的样本商业票据状态?

时间:2019-07-07 19:44:54

标签: corda

我正在遵循以下Corda教程:https://docs.corda.r3.com/tutorial-contract.html

有人可以提供getPaper()函数的示例实现,而该函数在那里没有实现

1 个答案:

答案 0 :(得分:0)

我不确定这是否行得通。请有人确认这是否是构建商业票据合同测试时正确的方法

private companion object {
    val testIssuance = bigCorp.ref(111)
    val testPounds: Cash.State = 1999.POUNDS.CASH issuedBy testIssuance

}

fun getPaper(): CommercialPaperState {
    return CommercialPaperState(testIssuance, testIssuance.party, testPounds.amount , Instant.now()+10.days)
    }

或者以下是另一种更复杂的处理方法,而无需使用随Corda 4一起提供的Finance CorDapp提供的现金。

import net.corda.finance.`issued by`

private companion object {
     val bigCorp = TestIdentity((CordaX500Name("BigCorp", "New York", "GB")))
     val testIssuance = bigCorp.ref((("JoinKey").toByte()))
     val testAmount = Amount<Currency>(1000,Currency.getInstance(Locale.GERMANY))

}

fun getPaper(): CommercialPaperState {
    return CommercialPaperState(testIssuance, testIssuance.party, testAmount `issued by` testIssuance, Instant.now()+10.days)
}