clarinet icon indicating copy to clipboard operation
clarinet copied to clipboard

Improve event assertion functions failed test error message

Open vini-btc opened this issue 1 year ago • 2 comments

Sometimes when debugging tests it is hard to understand why a given test fails when using the events assertion functions. For example, while writing tests I created an assertion that looked something like this:

 block.receipts[0].events.expectNonFungibleTokenMintEvent(
    "token-id"
    caller.address,
    contractAddress,
    "1",
  );

This test failed with the error Error: Unable to retrieve expected NonFungibleTokenMintEvent, but there was no explanation of why it was failing and what it was expecting, making it hard to debug the test.

Ideally, every assertion would have a more detailed message. In my case, I mixed the token id with the asset id, plus, I wasn't using the right type for the asset id. I'd expect the error message to read something like this:

Unable to retrieve expected NonFungibleTokenMintEvent:
- expected token id to be "token-id", but it was "1" instead;
- expected asset id to be u1, but it was "token-id" instead;

vini-btc avatar Aug 15 '23 18:08 vini-btc

Hello @vicnicius, It will be part of the new test framework, see here: https://github.com/hirosystems/clarinet/issues/1109 We can keep this issue open since it gives more details 👌

hugocaillard avatar Aug 16 '23 08:08 hugocaillard

Great to hear. I'll follow #1109 closely. Thanks!

vini-btc avatar Aug 16 '23 16:08 vini-btc