Hello,
I want to write a small java application that tests a consumable choice of a contract. The Java application simply creates the contract and exercises its choice. And once it is exercised the contract should be archived. What is the best way to verify it?
Have the Java application exercise the choice on your contract
Have your test fetch the ACS for the relevant template
Inspect the result
Assert that there is no contract with the ID you retained above
Another possibility is to have a choice that just fetches the contract and use that instead of asking for the ACS, but this means changing the Daml model for debugging purposes, which might not fit your intention.
Another possibility, if you application consumes the ACS already and keeps an up-to-date copy of it locally as its operational data store (ODS) you might want to use your application’s facilities to this end.
With that said, an important note: the Ledger API is thoroughly tested to ensure that consuming choice actually consume the contract on which they are defined. If by any chance you believe you might be testing the Ledger API rather than your application, I would recommend to “raise the abstraction level” of the test to make sure that the application-specific outcome is tested, rather than the Ledger API’s behavior (you wouldn’t test that a DELETE statement deletes a row on the database, you would ensure that the services that rely on that row being there behave as you would expect).
I 100% agree and know that as well. However, there is a great challenge with my specific case since by exercising the consuming choice, there are multiple Holding contracts that are created. And verifying that is a somewhat complicated.
There is an additional option to observe the archived event from a Java app using this library.
There is a function: TreeEvent observeEvent(String party, MessageTester<TreeEvent> eventTester)
That one can use like this: