Can we mock contract id when testing triggers?

Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.

I’d like to test a DAML trigger, and the trigger needs a complex contract like this:
template MyTemplate
field: ContractId ComplicatedTemplate

In a Java integration test, it’s easy to mock such a contract id by simply instantiating it (example Java test mocking contract id).

Can we avoid creating a valid contract in a DAML test?

1 Like

There’s an undocumented testing function called

coerceContractId : ContractId a -> ContractId b

Use at your own risk. It may go away at any point and can cause runtime type errors for obvious reasons.

The function is there to test that DAML is secure against malicious users passing in contact IDs of the wrong type.

3 Likes