@@ -2,13 +2,14 @@ const { ethers } = require('hardhat');
2
2
const { expect } = require ( 'chai' ) ;
3
3
const { loadFixture } = require ( '@nomicfoundation/hardhat-network-helpers' ) ;
4
4
const {
5
+ CALL_TYPE_CALL ,
6
+ CALL_TYPE_BATCH ,
7
+ CALL_TYPE_DELEGATE ,
5
8
EXEC_TYPE_DEFAULT ,
6
9
EXEC_TYPE_TRY ,
7
10
encodeSingle,
8
11
encodeBatch,
9
12
encodeDelegate,
10
- CALL_TYPE_CALL ,
11
- CALL_TYPE_BATCH ,
12
13
encodeMode,
13
14
} = require ( '../../helpers/erc7579' ) ;
14
15
const { selector } = require ( '../../helpers/methods' ) ;
@@ -29,6 +30,14 @@ describe('ERC7579Utils', function () {
29
30
Object . assign ( this , await loadFixture ( fixture ) ) ;
30
31
} ) ;
31
32
33
+ it ( 'constants' , async function ( ) {
34
+ await expect ( this . utils . $CALLTYPE_SINGLE ( ) ) . to . eventually . equal ( CALL_TYPE_CALL ) ;
35
+ await expect ( this . utils . $CALLTYPE_BATCH ( ) ) . to . eventually . equal ( CALL_TYPE_BATCH ) ;
36
+ await expect ( this . utils . $CALLTYPE_DELEGATECALL ( ) ) . to . eventually . equal ( CALL_TYPE_DELEGATE ) ;
37
+ await expect ( this . utils . $EXECTYPE_DEFAULT ( ) ) . to . eventually . equal ( EXEC_TYPE_DEFAULT ) ;
38
+ await expect ( this . utils . $EXECTYPE_TRY ( ) ) . to . eventually . equal ( EXEC_TYPE_TRY ) ;
39
+ } ) ;
40
+
32
41
describe ( 'execSingle' , function ( ) {
33
42
it ( 'calls the target with value' , async function ( ) {
34
43
const value = 0x012 ;
@@ -54,6 +63,18 @@ describe('ERC7579Utils', function () {
54
63
await expect ( ethers . provider . getBalance ( this . target ) ) . to . eventually . equal ( value ) ;
55
64
} ) ;
56
65
66
+ it ( 'default to calling self is target is address(0) (ERC-7821 calldata compression)' , async function ( ) {
67
+ const data = encodeSingle (
68
+ ethers . ZeroAddress , // address(0)
69
+ 0 ,
70
+ this . utils . interface . encodeFunctionData ( '$CALLTYPE_SINGLE' , [ ] ) ,
71
+ ) ;
72
+
73
+ await expect ( this . utils . $execSingle ( data , EXEC_TYPE_DEFAULT ) )
74
+ . to . emit ( this . utils , 'return$execSingle' )
75
+ . withArgs ( [ ethers . zeroPadBytes ( CALL_TYPE_CALL , 32 ) ] ) ;
76
+ } ) ;
77
+
57
78
it ( 'reverts when target reverts in default ExecType' , async function ( ) {
58
79
const value = 0x012 ;
59
80
const data = encodeSingle (
@@ -131,6 +152,17 @@ describe('ERC7579Utils', function () {
131
152
await expect ( ethers . provider . getBalance ( this . anotherTarget ) ) . to . eventually . equal ( value2 ) ;
132
153
} ) ;
133
154
155
+ it ( 'default to calling self is target is address(0) (ERC-7821 calldata compression)' , async function ( ) {
156
+ const data = encodeBatch (
157
+ [ ethers . ZeroAddress , 0 , this . utils . interface . encodeFunctionData ( '$CALLTYPE_SINGLE' , [ ] ) ] ,
158
+ [ ethers . ZeroAddress , 0 , this . utils . interface . encodeFunctionData ( '$CALLTYPE_BATCH' , [ ] ) ] ,
159
+ ) ;
160
+
161
+ await expect ( this . utils . $execBatch ( data , EXEC_TYPE_DEFAULT ) )
162
+ . to . emit ( this . utils , 'return$execBatch' )
163
+ . withArgs ( [ ethers . zeroPadBytes ( CALL_TYPE_CALL , 32 ) , ethers . zeroPadBytes ( CALL_TYPE_BATCH , 32 ) ] ) ;
164
+ } ) ;
165
+
134
166
it ( 'reverts when any target reverts in default ExecType' , async function ( ) {
135
167
const value1 = 0x012 ;
136
168
const value2 = 0x234 ;
@@ -193,6 +225,17 @@ describe('ERC7579Utils', function () {
193
225
await expect ( ethers . provider . getStorage ( this . utils . target , slot ) ) . to . eventually . equal ( value ) ;
194
226
} ) ;
195
227
228
+ it ( 'default to calling self is target is address(0) (ERC-7821 calldata compression)' , async function ( ) {
229
+ const data = encodeDelegate (
230
+ ethers . ZeroAddress ,
231
+ this . utils . interface . encodeFunctionData ( '$CALLTYPE_DELEGATECALL' , [ ] ) ,
232
+ ) ;
233
+
234
+ await expect ( this . utils . $execDelegateCall ( data , EXEC_TYPE_DEFAULT ) )
235
+ . to . emit ( this . utils , 'return$execDelegateCall' )
236
+ . withArgs ( [ ethers . zeroPadBytes ( CALL_TYPE_DELEGATE , 32 ) ] ) ;
237
+ } ) ;
238
+
196
239
it ( 'reverts when target reverts in default ExecType' , async function ( ) {
197
240
const data = encodeDelegate ( this . target , this . target . interface . encodeFunctionData ( 'mockFunctionRevertsReason' ) ) ;
198
241
await expect ( this . utils . $execDelegateCall ( data , EXEC_TYPE_DEFAULT ) ) . to . be . revertedWith (
0 commit comments