Skip to content
CCPEDIAby Unity Nodes
App Development

Testing strategy for non-contract related Daml code

3 posts381 views4 likesLast activity Aug 2021

  1. sullyOP 1

    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!

  2. cocreature 2

    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.

  3. sully 1

    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.