Testing choice observers

Is there a way to write a test (using Scripts of course) to test that a party observes a choice, specifically if we are using Choice Observers?

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

1 Like

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:

template Fetcher
    stakeholder : Party
    fetcher : Party
   signatory stakeholder
   choice Fetch : T
     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.

1 Like

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

1 Like

Only the transaction tree stream 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.


Thank you.

1 Like