问题
I am trying to write a FlowTest for a Flow with a LinearState. In the setup, I need to create a LinearState and then create a second version of that state (with the same unique identifier) by consuming the first in a second transaction. I followed the steps in the v2.0 tutorial on the corda docs.
However, when I query for the states in the vault, I get two unconsumed states. I would have expected one of them to have been consumed (and thus have Vault.StateStatus.UNCONSUMED
).
I have written a driver based integration test for the real code, and that works fine. So I'm presuming I have incorrectly set up the test for this situation.
Any ideas what I need to do to have only one unconsumed state in the vault?
Similar test code to reproduce here
Many thanks :-)
回答1:
In your test code, you generate the two transactions first, then record them both at once using the following code:
member1.database.transaction {
member1.services.recordTransactions(tx1, tx2)
}
If you modify your code so that you record the first transaction before the second, the flow tests pass:
member1.database.transaction {
member1.services.recordTransactions(tx1)
member1.services.recordTransactions(tx2)
}
It looks like recordTransactions
doesn't necessarily record the transactions in the order in which they are passed in as arguments. If tx2
is recorded first, it can't find the output state of tx1
to mark as consumed. The output state of tx1
therefore remains unconsumed.
来源:https://stackoverflow.com/questions/48645099/linearstate-with-two-unconsumed-states-in-corda-flowtest-setup