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

In Corda, what does `getPaper()` mean in the tutorial “Writing a contract test”?

我正在学习以下 Corda 教程:https://docs.corda.net/tutorial-test-dsl.html

谁能解释一下 val inState = getPaper() 行?它没有出现在这个页面之前。

这只是return一种新的商业票据状态的测试方法。

目前,除了 Hello, World!教程(https://docs.corda.net/hello-world-introduction.html and https://docs.corda.net/tut-two-party-introduction.html),这些教程不应该相互跟随来创建一个完整的 CorDapp。它们只是各种功能如何工作的示例。

查看此处定义的各种示例 CorDapp 可能也会有所帮助:https://www.corda.net/samples/

一个简单的方法如下

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

我找到了

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