@@ -5,6 +5,9 @@ const { PANIC_CODES } = require('@nomicfoundation/hardhat-chai-matchers/panic');
5
5
6
6
const coder = ethers . AbiCoder . defaultAbiCoder ( ) ;
7
7
8
+ const fakeContract = { interface : ethers . Interface . from ( [ 'error SomeCustomErrorWithoutArgs()' ] ) } ;
9
+ const returndata = fakeContract . interface . encodeErrorResult ( 'SomeCustomErrorWithoutArgs' ) ;
10
+
8
11
async function fixture ( ) {
9
12
const [ recipient , other ] = await ethers . getSigners ( ) ;
10
13
@@ -274,8 +277,56 @@ describe('Address', function () {
274
277
275
278
describe ( 'verifyCallResult' , function ( ) {
276
279
it ( 'returns returndata on success' , async function ( ) {
277
- const returndata = '0x123abc' ;
278
- expect ( await this . mock . $verifyCallResult ( true , returndata ) ) . to . equal ( returndata ) ;
280
+ await expect ( this . mock . $verifyCallResult ( true , returndata ) ) . to . eventually . equal ( returndata ) ;
281
+ } ) ;
282
+
283
+ it ( 'bubble returndata on failure' , async function ( ) {
284
+ await expect ( this . mock . $verifyCallResult ( false , returndata ) ) . to . be . revertedWithCustomError (
285
+ fakeContract ,
286
+ 'SomeCustomErrorWithoutArgs' ,
287
+ ) ;
288
+ } ) ;
289
+
290
+ it ( 'standard error on failure without returndata' , async function ( ) {
291
+ await expect ( this . mock . $verifyCallResult ( false , '0x' ) ) . to . be . revertedWithCustomError ( this . mock , 'FailedCall' ) ;
292
+ } ) ;
293
+ } ) ;
294
+
295
+ describe ( 'verifyCallResultFromTarget' , function ( ) {
296
+ it ( 'success with non-empty returndata' , async function ( ) {
297
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . mock , true , returndata ) ) . to . eventually . equal ( returndata ) ;
298
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . recipient , true , returndata ) ) . to . eventually . equal (
299
+ returndata ,
300
+ ) ;
301
+ } ) ;
302
+
303
+ it ( 'success with empty returndata' , async function ( ) {
304
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . mock , true , '0x' ) ) . to . eventually . equal ( '0x' ) ;
305
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . recipient , true , '0x' ) )
306
+ . to . be . revertedWithCustomError ( this . mock , 'AddressEmptyCode' )
307
+ . withArgs ( this . recipient ) ;
308
+ } ) ;
309
+
310
+ it ( 'failure with non-empty returndata' , async function ( ) {
311
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . mock , false , returndata ) ) . to . revertedWithCustomError (
312
+ fakeContract ,
313
+ 'SomeCustomErrorWithoutArgs' ,
314
+ ) ;
315
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . recipient , false , returndata ) ) . to . revertedWithCustomError (
316
+ fakeContract ,
317
+ 'SomeCustomErrorWithoutArgs' ,
318
+ ) ;
319
+ } ) ;
320
+
321
+ it ( 'failure with empty returndata' , async function ( ) {
322
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . mock , false , '0x' ) ) . to . be . revertedWithCustomError (
323
+ this . mock ,
324
+ 'FailedCall' ,
325
+ ) ;
326
+ await expect ( this . mock . $verifyCallResultFromTarget ( this . recipient , false , '0x' ) ) . to . be . revertedWithCustomError (
327
+ this . mock ,
328
+ 'FailedCall' ,
329
+ ) ;
279
330
} ) ;
280
331
} ) ;
281
332
} ) ;
0 commit comments