Reputation: 360
I have a flow that queries an oracle to get signed random data (representing a dice roll) which then becomes the output of a resulting transaction. Specifically, a new DiceRollState is issued.
In my unit tests, I need to ensure a given DiceRollState has a certain value (reflecting the number of pips on the dice) to test resulting logic. For example - I need to do task X when the DiceRollState has a value of 5 and another action when it has a value of 6.
Below is a snippet of code I'm using to run the flow in my unit test.
val rollDiceFlow = RollDiceFlow(gameBoardState.linearId)
val futureWithDiceRollPlayer1 = nodeA.startFlow(rollDiceFlow)
// Can I do anything here to check the value
// of the outputted DiceRollState and revert / Rerun as required?
network.runNetwork()
futureWithDiceRollPlayer1.getOrThrow()
Is there any way to revert if the outcome of a mock flow is undesirable? Could I do any of the following?
Take a deep copy of the mock network prior to running the flow?
Somehow revert the impacts of the completable future after inspecting its contents?
Use a better pattern to mock the response from the oracle?
Upvotes: 0
Views: 82
Reputation: 360
The answer here (unfortunately) is that this isn't a testable design pattern for Corda. Reverting a mock network to a previous state might be a useful feature for current testing but isn't currently available.
The solutions are to:
I opted to refactor rollDiceFlow to accept a constructed dice roll. The constructed dice roll is retrieved by the oracle in a wrapping flow in the actual CorDapp, but can be provided directly for testing purposes.
Upvotes: 1