如何获取流量测试的输入状态

How to get Input states for flow testing

我有两个流,说他们的名字是:

我的流程(flow_out)有 1 个输入状态和 1 个输出状态。输入状态从流程中的保险库中检索(flow_out),所有各方(目前在测试 MockNetwork 中有 3 方)在合同中验证了相同的状态。

现在测试用例失败了,因为我的流程 (flow_out) 无法获得该状态,因为该事务从未发生过(它是不同流程的一部分,即 flow_in)。

为了绕过它, 我也在 Junit 的 @Before 中启动了另一个流程(flow_in),以存储输入状态所需的事务以及所有通过的事务.

What are some other ways available in Corda's flow testing APIs to store input transaction/states directly without running the flows only to store those input transacations?

感谢您的帮助。

由于您可以访问节点的 ServiceHub,您可以直接在测试方法中构建、签署和存储交易,而不是使用流程:

class FlowTests {
    lateinit var network: MockNetwork
    lateinit var a: StartedMockNode
    lateinit var b: StartedMockNode

    @Before
    fun setup() {
        network = MockNetwork(listOf("com.example.contract"))
        a = network.createPartyNode()
        b = network.createPartyNode()
        listOf(a, b).forEach { it.registerInitiatedFlow(ExampleFlow.Acceptor::class.java) }
        network.runNetwork()
    }

    @After
    fun tearDown() {
        network.stopNodes()
    }

    @Test
    fun `a flow test`() {
        val lender = a.info.legalIdentities.first()
        val borrower = b.info.legalIdentities.first()

        val transactionBuilder = TransactionBuilder(network.defaultNotaryIdentity)
                .addOutputState(IOUState(99, lender, borrower), IOUContract.IOU_CONTRACT_ID)
                .addCommand(IOUContract.Commands.Create(), listOf(lender.owningKey, borrower.owningKey))

        a.transaction { transactionBuilder.verify(a.services) }
        val partSignedTransaction = a.services.signInitialTransaction(transactionBuilder)
        val signedTransaction = b.services.addSignature(partSignedTransaction)

        a.services.recordTransactions(signedTransaction)

        TODO("Test next flow.")
    }
}