在 Corda 中,“getPaper()” 在教程“撰写合约测试”中是什么意思?

3
3个回答

2

1
我发现
    override fun getPaper(): ICommercialPaperState = JavaCommercialPaper.State(
            megaCorp.ref(123),
            megaCorp.party,
            1000.DOLLARS `issued by` megaCorp.ref(123),
            TEST_TX_TIME + 7.days
    )

有用的(来自CommercialPaperTests.kt

我把它翻译成:

    private OwnableState getPaper() {
        PartyAndReference partyAndReference = new PartyAndReference((AbstractParty) this.megaCorp.getParty(), OpaqueBytes.of((byte) 0));
        Amount<Issued<Currency>> issuedAmount = Amount.fromDecimal(new BigDecimal(1000), new Issued<Currency> (partyAndReference, Currency.getInstance(Locale.US)));
        return (OwnableState) new CommercialPaper.State(this.megaCorp.ref((byte) 123), this.megaCorp.getParty(), issuedAmount, Instant.now().plus(7, ChronoUnit.DAYS));
    }

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)
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接