I’m writing unit tests, and I want to include tests for negative use cases. I can see two options:
-
sutmitMustFail
with no feedback about the error
I can use in the script the submitMustFail
or submitMultiMustFail
expression, which lets the script run without any error message. This is useful to know that the negative case would be rejected by the ledger, but it gives no feedback about the error message, so I cannot include easily the error message into an automatically generated test log.
- Let the script fail, with a possibly huge error message
If I run the failing script as part of daml test
, I get a feedback, but it contains too much information. This is a minimal example, where I messed up the choice in the skeleton template setup script with the following line:
choice Give : AssetId
with
newOwner : Party
controller owner
do
assertMsg "This is a test error message" False
create this with
owner = newOwner
When I run daml test
, I get the following message, which contains way more than I need. The message for a big contract can be huge:
gyorgybalazsi@BGY fail-test % daml test
File: daml/Main.daml
Hidden: no
Range: 26:1-26:6
Source: Script
Severity: DsError
Message:
Scenario execution failed on commit at Main:42:12:
Unhandled exception:
DA.Exception.AssertionFailed:AssertionFailed@3f4deaf145a15cdcfa762c058005e2edb9baa75bb7f95a4f8f6f937378e86415
with
message = "This is a test error message"
Ledger time: 1970-01-01T00:00:00Z
Partial transaction:
Failed exercise (unknown source):
exercises Give on #0:0 (Main:Asset)
with
newOwner = 'Bob'
Sub-transactions:
0
└─> 'Alice' exercises Give on #0:0 (Main:Asset)
with
newOwner = 'Bob'
Committed transactions:
TX 0 1970-01-01T00:00:00Z (Main:36:14)
#0:0
│ known to (since): 'Alice' (0)
└─> create Main:Asset
with
issuer = 'Alice'; owner = 'Alice'; name = "TV"
All I would need is just the error message.
Is there maybe a flag to set this? I couldn’t find any. If there isn’t, this is a feedback that it would be useful.