Assert for divulgence in a script

There isn’t a great way of doing that unfortunately. At this point you can try fetching it but that results in a warning since that behavior is deprecated. I think it’s the best you can do atm though:

template Fetcher
  with
    stakeholder : Party
    fetcher : Party
  where
    signatory stakeholder
    observer fetcher

    nonconsuming choice FetchSecret : Secret
      with
        cid : ContractId Secret
      controller fetcher
      do fetch cid

example = script do
  owner <- allocateParty "owner"    
  player <- allocateParty "player"
  secretId <- submit owner do createCmd Secret with secret = 42,..
  game <- submitMulti [owner, player] [] do createCmd Game with ..

  cid <- submit owner $ createCmd (Fetcher owner player)

  submitMustFail player $ exerciseCmd cid (FetchSecret secretId)
  
  submit owner do exerciseCmd game Divulge with ..

  submit player $ exerciseCmd cid (FetchSecret secretId)
  return ()  

Ideally you would test this by looking at the transaction tree stream of player and seeing the fetch there but that also fails for two reasons:

  1. Daml Script does not yet expose transaction tree streams.
  2. Transaction tree streams omit fetches so you wouldn’t actually see it in there.
1 Like