如何获取输入状态以进行流量测试 [英] How to get Input states for flow testing

查看:39
本文介绍了如何获取输入状态以进行流量测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two flows, say their names are:


  • flow_out(需要1个输入状态)

  • flow_in(上面输入的
    状态/交易是由此存储的)

我的flow(flow_out)有1输入状态和1输出状态。输入状态是从流(flow_out)中的保管库中检索的,并且所有各方(在测试MockNetwork中目前有3个参与方)已在合同中验证了输入状态。

My flow(flow_out) have 1 input state and 1 output state. The input state is retrieved from vault in the flow(flow_out) and the same is verified in contract by all the parties(Currrently 3 parties in test MockNetwork).

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

Now the test case is failing as my flow(flow_out) is unable to get that state, as that transaction never occurred(it's part of a different flow i.e flow_in).

要解决这个问题,我也在Junit的@Before中启动了另一个流程(flow_in),以存储输入状态和所传递的一切所需的事务。

To get around it, I initiated the other flow(flow_in) also in @Before of Junit, to store the transaction required for input state and everything passed.

在Corda的流测试API 中还有哪些其他方法可以使
直接存储输入事务/状态,而无需运行仅
的流来存储那些输入交易?

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 s,因此可以直接在测试方法中构建,签名和存储事务od,而不是使用流:

Since you have access to the nodes' ServiceHubs, you can build, sign and store transactions directly in the test method, rather than using a flow:

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

这篇关于如何获取输入状态以进行流量测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆