Test is failing

G-d willing

Hello,
I wrote this small java class that creates a proposal contract, followed by validating that the contract exists.

@QuarkusTest
public class RentApp {
    public static final String DAML_FOLDER = "./";
    public static final String DAR_FOLDER = "./.daml/dist/java-binding-0.0.1.dar";
    public static final Path DAML_ROOT = Path.of(DAML_FOLDER).toAbsolutePath();
    public static final String TEST_MODULE = "Main";
    public static final String TEST_START_SCRIPT = "initializeScript";
    public static final String CUSTOM_PORT = "6865";
    public static final Integer SANDBOX_WAIT_TIMEOUT = 18000;
    public static final Integer OBSERVATION_TIMEOUT = 0;
    public static final String[] PARTIES = new String [] {};
    public static final Path DAR_PATH = Path.of(DAR_FOLDER).toAbsolutePath();
    public static final BiConsumer<DamlLedgerClient, ManagedChannel> SETUP_APPLICATION = (Client, Channel) -> {};
    public static final Boolean USE_WALLCLOCK_TIME = Boolean.FALSE;

    protected static final SandboxManager sandbox = new SandboxManager(
            DAML_ROOT, Optional.of(TEST_MODULE), Optional.of(TEST_START_SCRIPT), Optional.of(Integer.parseInt(CUSTOM_PORT)),
            Duration.ofSeconds(SANDBOX_WAIT_TIMEOUT), Duration.ofSeconds(OBSERVATION_TIMEOUT),
            PARTIES, DAR_PATH, SETUP_APPLICATION, USE_WALLCLOCK_TIME);

    @BeforeAll
    public static void ConnectToSandbox() throws TimeoutException, IOException, InterruptedException {
        sandbox.start();
    }

    @Test
    public void testRentProposalContractWasCreated (){
        Party landlord = sandbox.getPartyId("Alice");
        Party tenant = sandbox.getPartyId("Bob");

        DamlRecord rentProposalRecord = record(
                field("landlord", landlord),
                field("tenant", tenant),
                field("terms", text("some terms"))
        );
        sandbox.getLedgerAdapter().createContract(landlord, RentProposal.TEMPLATE_ID, rentProposalRecord);

        RentProposal.ContractId rentProposalContractId = sandbox.getLedgerAdapter().
                getCreatedContractId(landlord, RentProposal.TEMPLATE_ID, RentProposal.ContractId::new);
    }

    @AfterAll
    public static void stopTheSandbox() {
        sandbox.stop();
    }
}

However, the test fails to indicate the following:

Expected:

Identifier{packageId='ff575e916a57ab6a9e853c6623d5fc1e8b7a911b3488d83c4e41e35db8a714e0', moduleName='Main', entityName='RentProposal'} - {CAPTURE:internal-cid-query}

But no events observed via ledger channel

If there were a problem with the daml code, I would expect to the first command, which uses createContract, to fail. However, the error comes from the line that comes afterward, using the getCreatedContractId command. How is it possible to succeed in creating the contract but failing to find it right away? Can you see what am I doing wrong?

Here is a screenshot from the error report:

@cohen.avraham I’m not familiar with the library you use. Could you confirm that observation timeout set to 0 means an infinite/very large wait?

The code snippet that I attached it is indicating

Is there some other place that I need to check for it?

So what if you use a non-zero value, say 5000? To me the name of that value says “the time to wait for observing a command completion before timing out”, hence I feel a direct connection to the exception thrown by the library you used. Could you as well point me to the library you utilize here? it seems to be related to the Java Bindings but It has methods I’m not familiar with.

Changing the value to 5000 seems to solve the problem.
It does not make any sense to me since executing the tests takes more than 5 seconds, so I did expect to have the tests fail. And using 0 should have worked since I am not limiting the test at any time.
I wonder, in this case, what the value 0 means in here… :face_with_diagonal_mouth:

So in the code you create a contract, then immediately after you get the created contract. The creation is most likely non blocking, meaning it does not wait for any confirmation, just submits the create command. I believe the timeout is important for the second part, when you try to get the created contract immediately. Creation takes some time, and with that option you control how much time such a getCreatedContract (and maybe others as well) is willing to wait before giving up on observing the event. If you set it to 0, I guess it just exits immediately, while with 5000 it most likely returns after a few milliseconds when the creation event is observed.

Still I do not have a reference of what kind of library you use, if I had, I maybe could verify my guesswork above.

in my previous message, I forgot to mention the library I am using.
It is com.daml.extensions.testing