A small, self-contained Daml package that shows how to run unit tests (on
the in-memory IDE ledger) and integration tests (against a real local
Canton node) through dpm trace test, and wire both into CI/CD.
dpm trace test wraps dpm test and adds what it does not:
- renders each script's transaction tree (creates, exercises, archives,
submitMustFailguards, parties, arguments, source locations); - maps every failed test back to source — the test call site and the
contract invariant (
assertMsg/abort/ensure) that rejected it; - returns a non-zero exit code when any test fails, so it gates CI;
- emits a machine-readable report with
--print-jsonand JUnit XML with--junit.
daml/Asset.daml IOU-style Asset: Transfer, Split, Burn, ensure quantity > 0
unittests/daml/Test.daml Script unit tests — happy paths + submitMustFail guards
unittests/daml/FailureDemo.daml one deliberately failing test (non-gating source-mapped demo)
multi-package.yaml builds asset and unittests together
itests/ lit integration tests against a real local Canton
.github/workflows/ ci.yml = unit gate, integration.yml = integration gate
run-demo.sh green run -> inject a regression -> red run -> revert
Run on the in-memory IDE ledger — no Canton node — so they run anywhere a Daml toolchain runs.
The Script tests are a separate package, unittests/, that depends on the
asset DAR. That keeps daml-script out of the DAR uploaded to a ledger. Build
both first:
dpm build --all
dpm trace test unittests # all tests
dpm trace test unittests --files daml/Test.daml # only Test.daml
dpm trace test unittests --files daml/Test.daml --no-trees # no transaction trees
dpm trace test unittests --files daml/Test.daml --print-json # JSON report
dpm trace test unittests --files daml/Test.daml -p testSplit # tests matching a pattern| Test | What it exercises |
|---|---|
testIssue |
create, payload/observer visibility |
testTransfer |
consuming exercise → archive + child create |
testSplit |
exercise → two child creates |
testCannotIssueZero |
ensure quantity > 0 rejection (submitMustFail) |
testStrangerCannotTransfer |
authorization rejection (submitMustFail) |
testBadSplitFails |
in-choice assertMsg rejection (submitMustFail) |
To map a failure into the contract as well as the test, pass the asset
package's sources and DAR. --daml-yaml replaces the default, so name both:
dpm trace test unittests \
--daml-yaml unittests/daml.yaml --daml-yaml daml.yaml \
--dar .daml/dist/asset-1.0.0.darThe DAR is verified with damlc inspect before local sources are searched.
Run against a real local Canton node that dpm trace test --integration
boots, deploys this package's DAR to, allocates Alice/Bob on, runs the
suite over, and tears down. (The itests/ scaffolding came from
dpm trace test --init.)
dpm trace test . --integration itests \
--canton-jar "$HOME/.dpm/cache/components/canton-open-source/3.7.1/lib/canton-open-source-3.7.1.jar" \
--daml dpm \
--parties Alice@1,Bob@2,Issuer@1 \
--verboseEach test submits against the live ledger and asserts on the trace:
asset-create.test— issue an Asset and trace the committed transaction.asset-issue-to-bob.test— cross-participant: Alice (participant1) issues an Asset owned by Bob (participant2); the same update is traced from Bob's separate participant via%ledger2(run with--parties Alice@1,Bob@2).asset-split-rejected.test— a Split the contract rejects; the live rejection is captured and mapped back to the Asset source line.xfail-create-zero-asset.test— XFAIL: a submit theensureguard rejects; marked# XFAIL: .*so the failure output is visible in CI without breaking the gate.
--verbose passes -vv to lit (per-test command output, including XFAIL
failures) and prints the Canton log tail on failure — the CI job uses it so
every failed test is fully diagnosable in the job log.
Needs lit and FileCheck on PATH.
Two GitHub Actions workflows, both fetching dpm-trace via actions/checkout:
-
ci.yml— the unit gate, runs on every push/PR. The key line:dpm trace test unittests --files daml/Test.daml \ --daml-yaml unittests/daml.yaml --daml-yaml daml.yaml \ --dar .daml/dist/asset-1.0.0.dar --junit dpm-trace-results.xml --no-treesA non-zero exit fails the job; the JUnit XML is uploaded for the test-report UI; any failure is printed with its source location in the job log. A second non-blocking step runs
FailureDemo.damlso the source-mapped failure output is visible without failing the build. -
integration.yml— the integration gate, runs on pushes tomainand on demand. Boots Canton, runs theitests/suite with--verbose, and gates on the lit exit code.
./run-demo.sh shows the full story end to end: a green run, then it weakens
ensure quantity > 0 to >= 0, re-runs, and the zero-quantity guard test
fails with a source-mapped diagnostic and a non-zero exit code — then it
reverts.
FAIL testCannotIssueZero
message: ... Expected submit to fail but it succeeded
daml/Test.daml:63:3
> 63 | submitMustFail issuer do
^