# How can I listen to the archival of a contract

**URL:** <https://forum.canton.network/t/how-can-i-listen-to-the-archival-of-a-contract/6132>\
**Category:** App Development\
**Tags:** bindings, java\
**Created:** [February 16, 2023, 3:52pm UTC](https://forum.canton.network/t/how-can-i-listen-to-the-archival-of-a-contract/6132 "2023-02-16T15:52:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [February 16, 2023, 3:52pm UTC](https://forum.canton.network/t/how-can-i-listen-to-the-archival-of-a-contract/6132/1 "2023-02-16T15:52:03Z")

</div>

G-d willing

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?

Thanks,

---

<div class="post-metadata">

**Author:** ![stefanobaghino-da](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stefanobaghino-da/32/7057_2.png) [@stefanobaghino-da](https://forum.canton.network/u/stefanobaghino-da)\
**Post date:** [February 16, 2023, 4:08pm UTC](https://forum.canton.network/t/how-can-i-listen-to-the-archival-of-a-contract/6132/2 "2023-02-16T16:08:37Z")

</div>

> [@cohen.avraham](#):
>
> 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?

1. Spin up a sandbox
2. Have the Java application create the contract
  - retain the contract ID in your test

3. Have the Java application exercise the choice on your contract
4. Have your test fetch the ACS for the relevant template
5. Inspect the result
6. 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).

---

<div class="post-metadata">

**Author:** ![cohen.avraham](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@cohen.avraham](https://forum.canton.network/u/cohen.avraham)\
**Post date:** [February 16, 2023, 4:36pm UTC](https://forum.canton.network/t/how-can-i-listen-to-the-archival-of-a-contract/6132/3 "2023-02-16T16:36:20Z")

</div>

> [@stefanobaghino-da](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![VictorShneer](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/victorshneer/32/5413_2.png) [@VictorShneer](https://forum.canton.network/u/VictorShneer)\
**Post date:** [February 21, 2023, 9:31pm UTC](https://forum.canton.network/t/how-can-i-listen-to-the-archival-of-a-contract/6132/4 "2023-02-21T21:31:57Z")

</div>

There is an additional option to observe the archived event from a Java app using [this library](https://github.com/digital-asset/lib-daml-jvm-test).  
There is a function:  
`TreeEvent observeEvent(String party, MessageTester<TreeEvent> eventTester)`  
That one can use like this:

```haskell
sandbox.getLedgerAdapter().observeEvent(ALICE_PARTY, ContractArchived.apply(MyTemplate.TEMPLATE_ID, contractId));

```

More details are in the README. The library works with daml \> 2.0
