Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Testing strategy for non-contract related Daml codeForum ↗

Testing strategy for non-contract related Daml code

App Development3 posts357 views4 likesLast activity Aug 2021
SU
sullyOP
Aug 2021

I am writing tests for some Daml code I am writing that does not use the ledger at all. I’m currently writing my tests as I would for contracts, using Script. Something like this made-up example:

testDedup : Script ()
testDedup = do
  assert $ dedup [1, 2, 3] == [1, 2, 3]
  assert $ dedup [1, 2, 2] == [1, 2]
  return ()

Is there a better way for me to write tests for non-contract related code? Preferably something that will get picked up when I run daml test?

Will a test written like this have much ledger-related overhead?

Thanks!

CO
cocreature
Aug 2021

Using a script for this is perfectly reasonable and your best option at the moment. There shouldn’t be any relevant ledger-related overhead. daml test runs in an in-memory ledger only used for scripts & scenarios and you should only pay for operations that actually interact with that ledger, i.e., submit.

SU
sully
Aug 2021

Just browsing and I noticed my code example could be improved with something @cocreature showed me:

import DA.Assert ((===))
import Daml.Script

testDedup : Script ()
testDedup = do
  dedup [1, 2, 3] === [1, 2, 3]
  dedup [1, 2, 2] === [1, 2]
  return ()

This version will produce more informative error messages.

← Back to Discussions