Is there a way to wrap a block of Daml script with the semantics “this whole block should fail”?
For context, in my specific use case:
- I can send a first command
- I can send a second command
- I can’t send the second command twice
If I wanted to write the test first, TDD style, but my ability to do TDD breaks down because I can’t find a way to call the same script twice (steps 2 and 3) with the semantics “the first should pass and the second should fail”
test = script do
a <- allocateParty "Alice"
b <- allocateParty "Bob"
c <- allocateParty "Carol"
p <- allocateParty "Public"
aFirstCommandResults <- sendFirstCommand a p
bFirstCommandResults <- sendFirstCommand b p
cFirstCommandResults <- sendFirstCommand c p
aSecondCommandResults <- sendSecondCommand a p aFirstCommandResults [bFirstCommandResults, cFirstCommandResults]
bSecondCommandResults <- sendSecondCommand b p bFirstCommandResults [aFirstCommandResults, cFirstCommandResults]
cSecondCommandResults <- sendSecondCommand c p cFirstCommandResults [aFirstCommandResults, bFirstCommandResults]
-- WOULD BE COOL IF I COULD USE THIS SYNTAX
-- mustFail do
-- aThirdCommandResults <- sendSecondCommand a p aSecondCommandResults [bSecondCommandResults, cSecondCommandResults]
-- INSTEAD I HAD TO EITHER DUPLICATE MY HELPER SCRIPT
aThirdCommandResults <- sendSecondCommandMustFail a p aSecondCommandResults [bSecondCommandResults, cSecondCommandResults]
-- OR MANUALLY COPY PASTE IT
submitMultiMustFail [a] [p] do
createAndExerciseCmd (Coordinator with owner = a, collector = aSecondCommandResults._2, signers = [bSecondCommandResults._1, cSecondCommandResults._1]) (Go)
return ()
I’m looking for a way to call sendSecondCommand
again and see that it fails, but because I can’t find a way to have a mustFail block I have to copy-paste the implementation of sendSecondCommand
with a submitMultiMustFail
instead of submitMulti
(or create a second sendSecondCommandMustFail
script with the same copypasta)