Skip to content
CCPEDIAby Unity Nodes
App Development

Testing choice observers

5 posts483 views6 likesLast activity Jul 2021

  1. Leonid_RozenbergOP 1

    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).

  2. cocreature 1

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

  3. Leonid_Rozenberg 1

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

  4. cocreature 2

    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.

  5. Leonid_Rozenberg 1

    Thank you.