# Testing choice observers

**URL:** <https://forum.canton.network/t/testing-choice-observers/2309>\
**Category:** App Development\
**Tags:** choice-observers\
**Created:** [March 22, 2021, 2:38pm UTC](https://forum.canton.network/t/testing-choice-observers/2309 "2021-03-22T14:38:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [March 22, 2021, 2:38pm UTC](https://forum.canton.network/t/testing-choice-observers/2309/1 "2021-03-22T14:38:44Z")

</div>

Is there a way to write a test (using [Scripts](https://docs.daml.com/daml-script/api/Daml-Script.html) of course) to test that a party observes a choice, specifically if we are using [Choice Observers](https://docs.daml.com/concepts/ledger-model/ledger-privacy.html#choice-observers)?

I can see that these observers are correctly recorded in the script result (witnesses with the detailed disclosure checked).

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [March 22, 2021, 3:11pm UTC](https://forum.canton.network/t/testing-choice-observers/2309/2 "2021-03-22T15:11:44Z")

</div>

You can’t directly test that the exercise was observed. You can however test if you can observe the consequences. E.g., if the exercise resulted in a create, test that you can try fetching that to make sure that it has been divulged. Note that `queryContractId` is not sufficient for that. This will only return contracts you are a stakeholder on. But you can do something like the following:

```haskell
template Fetcher
  with
    stakeholder : Party
    fetcher : Party
  where
   signatory stakeholder
   choice Fetch : T
    with
     cid : ContractId T
    controller fetcher
    do fetch cid

```

`stakeholder` needs to be a stakeholder of the contract to get past the authorization check. If `fetcher` has observed the creation or a fetch of `cid`, this will succeed, otherwise it will fail.

```haskell

```

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [July 13, 2021, 8:04pm UTC](https://forum.canton.network/t/testing-choice-observers/2309/3 "2021-07-13T20:04:46Z")

</div>

@cocreature How would one see an exercise from the Ledger API, would it be visible via the completion api?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [July 14, 2021, 4:18am UTC](https://forum.canton.network/t/testing-choice-observers/2309/4 "2021-07-14T04:18:59Z")

</div>

Only the [transaction tree stream](https://docs.daml.com/app-dev/services.html#transaction-and-transaction-trees) exposes exercise events.

The completion stream is only useful to see if a command that you submitted succeeded or failed but id does not contain the resulting transaction. It does however contain the transaction id so you can use that to query the transaction by id.

---

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [July 14, 2021, 2:12pm UTC](https://forum.canton.network/t/testing-choice-observers/2309/5 "2021-07-14T14:12:08Z")

</div>

Thank you.
