# Can we mock contract id when testing triggers?

**URL:** <https://forum.canton.network/t/can-we-mock-contract-id-when-testing-triggers/519>\
**Category:** App Development\
**Tags:** daml, scenario, trigger, test\
**Created:** [May 21, 2020, 1:24pm UTC](https://forum.canton.network/t/can-we-mock-contract-id-when-testing-triggers/519 "2020-05-21T13:24:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Kapolnai](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/richard_kapolnai/32/89_2.png) [@Richard\_Kapolnai](https://forum.canton.network/u/Richard_Kapolnai)\
**Post date:** [May 21, 2020, 1:24pm UTC](https://forum.canton.network/t/can-we-mock-contract-id-when-testing-triggers/519/1 "2020-05-21T13:24:11Z")

</div>

**Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful [Daml Script](https://docs.daml.com/daml-script/index.html). 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](https://daml.com/blog/engineering/daml-script-scenarios-2-0/).**

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](https://github.com/digital-asset/ex-supply-chain/blob/cb0005f6ef1947c0ffdb81ba52d391a076edaa85/src/test/java/com/digitalasset/refapps/supplychain/DeliveryCompleteBotTest.java)).

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

---

<div class="post-metadata">

**Author:** ![bernhard](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bernhard/32/356_2.png) [@bernhard](https://forum.canton.network/u/bernhard)\
**Post date:** [May 21, 2020, 3:29pm UTC](https://forum.canton.network/t/can-we-mock-contract-id-when-testing-triggers/519/2 "2020-05-21T15:29:53Z")

</div>

There’s an undocumented testing function called

```haskell
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.
