Skip to content

Commit

Permalink
🦊 Handle revertedWith with an empty revertString (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzadp committed Mar 25, 2022
1 parent 1180864 commit bf0a18e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 7 additions & 7 deletions waffle-chai/src/matchers/revertedWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export function supportRevertedWith(Assertion: Chai.AssertionStatic) {

const onError = (error: any) => {
const revertString = error?.receipt?.revertString ?? decodeRevertString(error);
if (revertString) {
if (revertString !== undefined) {
this.assert(
revertString === revertReason,
`Expected transaction to be reverted with ${revertReason}, but other reason was found: ${revertString}`,
`Expected transaction NOT to be reverted with ${revertReason}`,
`Transaction reverted with ${revertReason}.`,
`Expected transaction to be reverted with "${revertReason}", but other reason was found: "${revertString}"`,
`Expected transaction NOT to be reverted with "${revertReason}"`,
`Transaction reverted with "${revertReason}".`,
error
);
return error;
Expand All @@ -51,9 +51,9 @@ export function supportRevertedWith(Assertion: Chai.AssertionStatic) {

this.assert(
isReverted || isThrown,
`Expected transaction to be reverted with ${revertReason}, but other exception was thrown: ${error}`,
`Expected transaction NOT to be reverted with ${revertReason}`,
`Transaction reverted with ${revertReason}.`,
`Expected transaction to be reverted with "${revertReason}", but other exception was thrown: ${error}`,
`Expected transaction NOT to be reverted with "${revertReason}"`,
`Transaction reverted with "${revertReason}".`,
error
);
return error;
Expand Down
7 changes: 7 additions & 0 deletions waffle-chai/test/matchers/reverted.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ describe('INTEGRATION: Matchers: revertedWith', () => {
await expect(matchers.doThrowAndModify()).to.be.revertedWith('');
});

it('Throw with modification: success, properly handle common substring', async () => {
// https://github.com/NomicFoundation/hardhat/issues/2234#issuecomment-1045974424
await expect(
expect(matchers.doThrowAndModify()).to.be.revertedWith('fa')
).to.eventually.be.rejectedWith('Expected transaction to be reverted with "fa", but other reason was found: ""');
});

it('Throw with modification: fail when message is expected', async () => {
await expect(
expect(matchers.doThrowAndModify()).to.be.revertedWith('Message other than empty string')
Expand Down

0 comments on commit bf0a18e

Please sign in to comment.