Skip to content

Commit 9c79172

Browse files
committed
use standalone ethers Interface as revert test placeholder
1 parent 21a4bae commit 9c79172

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

test/utils/AddressUtils.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ describe('AddressUtils', async () => {
1717

1818
// the custom errors are not available on the $AddressUtils ABI
1919
// a placeholder interface is needed in order to expose them to revertedWithCustomError matcher
20-
const placeholder = { interface: AddressUtils__factory.createInterface() };
20+
const placeholder = {
21+
interface: new ethers.Interface([
22+
'error TestError()',
23+
'error AddressUtils__FailedCall()',
24+
'error AddressUtils__FailedCallWithValue()',
25+
'error AddressUtils__FailedDelegatecall()',
26+
]),
27+
};
2128

2229
beforeEach(async () => {
2330
[deployer] = await ethers.getSigners();
@@ -209,7 +216,7 @@ describe('AddressUtils', async () => {
209216

210217
it('target contract reverts, with provided custom error', async () => {
211218
// unrelated custom error, but it must exist on the contract due to limitiations with revertedWithCustomError matcher
212-
const customError = 'AddressUtils__InsufficientBalance';
219+
const customError = 'TestError';
213220
const revertReason =
214221
placeholder.interface.getError(customError)?.selector!;
215222

@@ -223,7 +230,7 @@ describe('AddressUtils', async () => {
223230
[
224231
'$functionCall(address,bytes,bytes4)'
225232
](await targetContract.getAddress(), '0x', revertReason),
226-
).to.be.revertedWithCustomError(instance, customError);
233+
).to.be.revertedWithCustomError(placeholder, customError);
227234
});
228235
});
229236
});
@@ -449,7 +456,7 @@ describe('AddressUtils', async () => {
449456
it('target function is not payable and value is included, with provided custom error', async () => {
450457
const value = 2n;
451458
// unrelated custom error, but it must exist on the contract due to limitiations with revertedWithCustomError matcher
452-
const customError = 'AddressUtils__InsufficientBalance';
459+
const customError = 'TestError';
453460
const revertReason =
454461
placeholder.interface.getError(customError)?.selector!;
455462

@@ -472,7 +479,7 @@ describe('AddressUtils', async () => {
472479
[
473480
'$functionCallWithValue(address,bytes,uint256,bytes4)'
474481
](await targetContract.getAddress(), data, value, revertReason),
475-
).to.be.revertedWithCustomError(instance, customError);
482+
).to.be.revertedWithCustomError(placeholder, customError);
476483
});
477484

478485
it('target contract reverts, with target contract error message', async () => {
@@ -500,7 +507,7 @@ describe('AddressUtils', async () => {
500507

501508
it('target contract reverts, with provided custom error', async () => {
502509
// unrelated custom error, but it must exist on the contract due to limitiations with revertedWithCustomError matcher
503-
const customError = 'AddressUtils__InsufficientBalance';
510+
const customError = 'TestError';
504511
const revertReason =
505512
placeholder.interface.getError(customError)?.selector!;
506513

@@ -514,7 +521,7 @@ describe('AddressUtils', async () => {
514521
[
515522
'$functionCallWithValue(address,bytes,uint256,bytes4)'
516523
](await targetContract.getAddress(), '0x', 0, revertReason),
517-
).to.be.revertedWithCustomError(instance, customError);
524+
).to.be.revertedWithCustomError(placeholder, customError);
518525
});
519526
});
520527
});
@@ -661,7 +668,7 @@ describe('AddressUtils', async () => {
661668

662669
it('target contract reverts, with provided custom error', async () => {
663670
// unrelated custom error, but it must exist on the contract due to limitiations with revertedWithCustomError matcher
664-
const customError = 'AddressUtils__InsufficientBalance';
671+
const customError = 'TestError';
665672
const revertReason =
666673
placeholder.interface.getError(customError)?.selector!;
667674

@@ -675,10 +682,7 @@ describe('AddressUtils', async () => {
675682
[
676683
'$functionDelegateCall(address,bytes,bytes4)'
677684
](await targetContract.getAddress(), '0x', revertReason),
678-
).to.be.revertedWithCustomError(
679-
placeholder,
680-
'AddressUtils__InsufficientBalance',
681-
);
685+
).to.be.revertedWithCustomError(placeholder, customError);
682686
});
683687
});
684688
});

0 commit comments

Comments
 (0)