Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Add verbose to assert fails #395

Closed
OscBacon opened this issue Jun 7, 2023 · 3 comments
Closed

[Suggestion] Add verbose to assert fails #395

OscBacon opened this issue Jun 7, 2023 · 3 comments

Comments

@OscBacon
Copy link

OscBacon commented Jun 7, 2023

Hi, first off, great testing library!
It would be nice to have more verbose on assert fails. As of right now, I have to add log statements to find out which assert exactly failed.

For example, on a series assert.entityCount, this message is not helpful enough:

X𝖷 (assert.equals) Expected value was '1' but actual value was '0'

(and the backtrace doesn't say much)

Secondly, having assert functions with a message field could help too, a la nodejs assert: https://nodejs.org/api/assert.html

If I understand correctly, AS doesn't allow for function overloading or optional arguments. One solution could be to have an assert namespace, and an assertMessage namespace with the same functions, but that throw a custom message when the assert fails

@dimitrovmaksim
Copy link
Member

dimitrovmaksim commented Jun 8, 2023

Hey @OscBacon, matchstick version 0.6.0-beta3 and matchstick-as version 0.6.0-beta.0 are now available, which add optional 3rd argument message to each assert function. You can try them now. matchstick 0.6.0-beta3 should also be backwards compatible with matchstick-as 0.5.2. Keep in mind also that this is a beta and also includes fixes for derived fields for entities with Bytes Id's and log.critical interrupting the tests execution, so there could be some bugs and issues in general.

import { assert, describe, test } from "matchstick-as";
import { ethereum, Address } from "@graphprotocol/graph-ts";

describe("Asserts", () => {
  test("assert.equals", () => {
    assert.equals(ethereum.Value.fromI32(1), ethereum.Value.fromI32(2), "Value should equal 1");
  });

  test("assert.I32Equals", () => {
    assert.i32Equals(1, 2, "I32 should equal 1");
  });

  test("assert.AddressEquals", () => {
    assert.addressEquals(
      Address.zero(),
      Address.fromString("0x0000000000000000000000000000000000000001"),
      "Address should equal zero address"
    );
  });
});
yarn test -rv 0.6.0-beta3 asserts

___  ___      _       _         _   _      _
|  \/  |     | |     | |       | | (_)    | |
| .  . | __ _| |_ ___| |__  ___| |_ _  ___| | __
| |\/| |/ _` | __/ __| '_ \/ __| __| |/ __| |/ /
| |  | | (_| | || (__| | | \__ \ |_| | (__|   <
\_|  |_/\__,_|\__\___|_| |_|___/\__|_|\___|_|\_\
    
Compiling...

💬 Compiling asserts...

Igniting tests 🔥

asserts
--------------------------------------------------
  Asserts:
    𝖷 assert.equals - 0.565ms
    𝖷 assert.I32Equals - 0.107ms
    𝖷 assert.AddressEquals - 0.135ms

Failed tests:

asserts
  assert.equals
        𝖷 Value should equal 1
        🛠  Mapping aborted at ~lib/matchstick-as/assert.ts, line 38, column 7, with message: assert.equals Assertion Error
wasm backtrace:
    0: 0x1aee - <unknown>!start:tests/asserts.test~anonymous|0~anonymous|0


  assert.I32Equals
        𝖷 I32 should equal 1
        🛠  Mapping aborted at ~lib/matchstick-as/assert.ts, line 94, column 7, with message: assert.i32Equals Assertion Error
wasm backtrace:
    0: 0x1b37 - <unknown>!start:tests/asserts.test~anonymous|0~anonymous|1


  assert.AddressEquals
        𝖷 Address should equal zero address
        🛠  Mapping aborted at ~lib/matchstick-as/assert.ts, line 66, column 7, with message: assert.addressEquals Assertion Error
wasm backtrace:
    0: 0x1bfd - <unknown>!start:tests/asserts.test~anonymous|0~anonymous|2


3 failed, 0 passed, 3 total

@OscBacon
Copy link
Author

OscBacon commented Jun 9, 2023

Looks promising!

@dimitrovmaksim
Copy link
Member

Should be resolved by #408, can be tested with https://github.com/LimeChain/matchstick/releases/tag/0.6.0-rc.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants