I have learned a lot from this exercise and got a lot of inspiration for my own projects.
One very useful trick I have found is a method for writing unit tests for your DAM code.
I recommend checking it out to anybody, I use it every day since I have discovered it.
The essence of the approach is that you define three scenarios and test if they fit together:
- A “given” scenario, which describes the test setup, which is usually the same for all the test cases.
- A “when” scenario which describes the test action, that is the input of a specific test case.
- A “then” scenario which describes the test condition, that is the expected outcome of the test case.
The general pattern is the following, you can check out the details on the link inserted above:
data Test a b = Test with given : Scenario a when : a -> Scenario b then_ : a -> b -> Scenario Bool ... gwt = scenario do let correct_iou_amount = Test with given = given_fixture when = when_action then_ = then_condition run correct_iou_amount
gwt (shorthand for “given - when - then”) scenario doesn’t report any errors, you can rest assured your code is correct.
And Georg says that you can also run the test with the daml CLI like this:
daml run damlc -- test daml/ApprovalChain.daml
(which I didn’t try yet, because I found enough that the test file doesn’t report any errors.)