Skip to content

Commit

Permalink
Fix revertedWith functionality (TrueFiEng#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
malyfko authored Feb 26, 2021
1 parent 246281f commit 9223982
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion waffle-chai/src/matchers/revertedWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ export function supportRevertedWith(Assertion: Chai.AssertionStatic) {
error = error.error;
}

const reasonsList = error.results && Object.values(error.results).map((o: any) => o.reason);
const message = (error instanceof Object && 'message' in error) ? error.message : JSON.stringify(error);
const isReverted = message.search('revert') >= 0 && message.search(revertReason) >= 0;
const isReverted = reasonsList
? reasonsList.some((r: string) => r === revertReason)
: message.search('revert') >= 0 && message.search(revertReason) >= 0;
const isThrown = message.search('invalid opcode') >= 0 && revertReason === '';

this.assert(
Expand Down
12 changes: 12 additions & 0 deletions waffle-chai/test/matchers/reverted.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ describe('INTEGRATION: Matchers: revertedWith', () => {
await expect(matchers.doRevertAndModify()).to.be.revertedWith('Revert cause');
});

it('Revert with modification: fail when not full message match', async () => {
await expect(
expect(matchers.doRevertAndModify()).to.be.revertedWith('cause')
).to.eventually.be.rejected;
});

it('Revert with modification: fail when empty string', async () => {
await expect(
expect(matchers.doRevertAndModify()).to.be.revertedWith('')
).to.eventually.be.rejected;
});

it('Revert with modification: fail when different message was thrown', async () => {
await expect(
expect(matchers.doRevertAndModify()).to.be.revertedWith('Different message')
Expand Down

0 comments on commit 9223982

Please sign in to comment.