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

Difficult to match revert messages #183

Open
daltonclaybrook opened this issue Feb 28, 2022 · 1 comment
Open

Difficult to match revert messages #183

daltonclaybrook opened this issue Feb 28, 2022 · 1 comment

Comments

@daltonclaybrook
Copy link

I'm trying to test using expectRevert and assert on a specific error message:

await expectRevert(
    lock.collect(1, accounts[1], max, max, { from: accounts[1] }),
    'Not authorized'
);

I'm expecting the error message to be "Not authorized" because that is the exact text I use in my require condition in my contract. Instead, I'm getting this message:

Transaction: 0x2795a7ddf35519454e294df60a84efccc4b41d906423efef4f1a41ec91a02389 exited with an error (status 0). Reason given: Not authorized.
     Please check that the transaction:
     - satisfies all conditions set by Solidity `require` statements.
     - does not trigger a Solidity `revert` statement.

This message is a bit more difficult to match against because, in addition to the several newline and whitespace characters, it also contains the transaction hash which may be different between test runs.

Is this a bug, or perhaps a change in later versions of the Solidity compiler? The docs for expectRevert don't seem to mention this kind of verbose error message. Is there anything I can do differently to get around this? One thought I had was to allow passing a predicate function in place of the string so I could check the string within the function and return true or false if it matches my expectation, e.g.

await expectRevert(
    lock.collect(1, accounts[1], max, max, { from: accounts[1] }),
    (str) => str.indexOf('Reason given: Not authorized') != -1
);
@frangio
Copy link
Contributor

frangio commented Mar 4, 2022

I believe this is due to a change in the latest version of Ganache.

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