测试CordaApp更改的最佳(最快)方法是什么?

时间:2018-10-31 07:59:37

标签: corda

我想知道如何为CordApp更改实现最短的反馈周期。现在,每次更改大约需要2分钟: gradle clean build deployNoded 和 运行节点 再次。

1 个答案:

答案 0 :(得分:0)

如果要更改合同,则应使用Corda的合同测试框架。这是来自IOU CorDapp's contract tests的示例:

@Test
fun `transaction must include Create command`() {
    ledgerServices.ledger {
        transaction {
            output(IOU_CONTRACT_ID, IOUState(1, miniCorp.party, megaCorp.party))
            fails()
            command(listOf(megaCorp.publicKey, miniCorp.publicKey), IOUContract.Commands.Create())
            verifies()
        }
    }
}

如果要进行其他CorDapp更改,则应使用Corda的流测试框架。这是来自IOU CorDapp's flow tests的示例:

@Test
fun `flow records the correct IOU in both parties' vaults`() {
    val iouValue = 1
    val flow = ExampleFlow.Initiator(1, b.info.singleIdentity())
    val future = a.startFlow(flow)
    network.runNetwork()
    future.getOrThrow()

    // We check the recorded IOU in both vaults.
    for (node in listOf(a, b)) {
        node.transaction {
            val ious = node.services.vaultService.queryBy<IOUState>().states
            assertEquals(1, ious.size)
            val recordedState = ious.single().state.data
            assertEquals(recordedState.value, iouValue)
            assertEquals(recordedState.lender, a.info.singleIdentity())
            assertEquals(recordedState.borrower, b.info.singleIdentity())
        }
    }
}

您可以在此处找到更多详细信息:https://docs.corda.net/api-testing.html#contract-testing