Programmatically check whether a contract has been divulged

I would like to unit test my contract’s privacy properties. When executing my script, I can see whether a contract has been divulged to a party by looking for the “D” in that column. Is there a way I can check this from my Script so that my Script will fail if something is divulged that shouldn’t be?

2 Likes

Hi @ryantrinkle ,
I’m using the example from the Daml quickstart here.
One way of testing privacy is to test if a party in fact cannot see a contract.

I’ve modified the Main.daml file a bit, the below, I’m asserting that Alice can in fact NOT see Bob’s contract.

  aliceIouCid <- submit alice do
    exerciseCmd iouTransferAliceCid IouTransfer_Accept
  bobIouCid <- submit bob do
    exerciseCmd iouTransferBobCid IouTransfer_Accept

-- Testing privacy here:
  optContract <- queryContractId alice (bobIouCid)
  assertMsg "If it isNone, can't see it" (isNone optContract)

queryContractId doesn’t test for divulgence. It only returns the contract if you’re a stakeholder.

There is no super straightforward way to test this but you can try fetching it. See Assert for divulgence in a script - #2 by cocreature for an example.

2 Likes

Welcome to the Daml community @ryantrinkle; great to have you here!

1 Like