-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Description
🎉 Description
In assertRevert, the desired behavior is to fail the test if the provided promise does not throw an error containing the substring revert. As-written it will pass even if the promise does not throw any error. This is because assert.fail() throws an error, which is caught in the catch, and in the error message is the string Expected revert not received, which contains the substring revert.
assert.fail() does not magically fail a test, it just throws an error (but regardless of its expected/actual content) like any other assert. Because the error message contains the substring revert, revertFound will be true even if the promise never threw anything.
- 🐛 This is a bug report.
- 📈 This is a feature request.
🔢 Code To Reproduce Issue [ Good To Have ]
mkdir assertfail
cd assertfail
mkdir test
npm i mocha
Then in the test directory add this as a file:
var assert = require('assert');
it('should not consider this a revert', () => {
try {
assert.fail('This is not a real revert');
} catch (error) {
const revertFound = error.message.search('revert') >= 0;
console.log(`Was a revert found? ${revertFound}`);
assert.strictEqual(revertFound, false, `Did not expect a revert, but the error message contained it as a substring: ${error}`);
}
});
Then run ./node_modules/mocha/bin/mocha
You will see this test fails. revertFound is true, but no EVM revert happened here.
👍 Other Information
The assert.fail() should go after (outside) the catch block, and there should be a return; at the end of (inside) the catch block.
@maurelian helped to discover this.