@@ -59,6 +59,24 @@ const buildRootPermissionContext = ({
5959 return encodeDelegations ( [ rootDelegation ] ) ;
6060} ;
6161
62+ const buildPermissionContextWithParentDelegate = (
63+ parentDelegate : Address ,
64+ { maxAmount = 1000n } : { maxAmount ?: bigint } = { } ,
65+ ) => {
66+ const rootDelegation = createDelegation ( {
67+ environment : mockEnvironment ,
68+ scope : {
69+ type : ScopeType . Erc20TransferAmount ,
70+ tokenAddress : '0xabc0000000000000000000000000000000000000' ,
71+ maxAmount,
72+ } ,
73+ to : parentDelegate ,
74+ from : '0x1000000000000000000000000000000000000001' ,
75+ } ) ;
76+
77+ return encodeDelegations ( [ rootDelegation ] ) ;
78+ } ;
79+
6280describe ( 'redelegatePermissionContext' , ( ) => {
6381 let client : ReturnType < typeof createWalletClient > ;
6482
@@ -83,7 +101,9 @@ describe('redelegatePermissionContext', () => {
83101 } ) ;
84102
85103 expect ( result . delegation . delegate ) . to . equal ( newDelegate ) ;
86- expect ( result . delegation . delegator ) . to . equal ( account . address ) ;
104+ expect ( result . delegation . delegator . toLowerCase ( ) ) . to . equal (
105+ account . address . toLowerCase ( ) ,
106+ ) ;
87107 expect ( result . delegation . signature ) . to . match ( / ^ 0 x [ a - f A - F 0 - 9 ] + $ / u) ;
88108 expect ( result . permissionContext ) . to . match ( / ^ 0 x [ a - f A - F 0 - 9 ] + $ / u) ;
89109
@@ -139,7 +159,9 @@ describe('redelegatePermissionContext', () => {
139159 } ) ;
140160
141161 expect ( result . delegation . delegate ) . to . equal ( newDelegate ) ;
142- expect ( result . delegation . delegator ) . to . equal ( account . address ) ;
162+ expect ( result . delegation . delegator . toLowerCase ( ) ) . to . equal (
163+ account . address . toLowerCase ( ) ,
164+ ) ;
143165 expect ( result . delegation . caveats ) . to . deep . equal ( [ ] ) ;
144166 expect ( result . delegation . signature ) . to . match ( / ^ 0 x [ a - f A - F 0 - 9 ] + $ / u) ;
145167 expect ( result . permissionContext ) . to . match ( / ^ 0 x [ a - f A - F 0 - 9 ] + $ / u) ;
@@ -148,6 +170,24 @@ describe('redelegatePermissionContext', () => {
148170 ) ;
149171 } ) ;
150172
173+ it ( "should use the parent delegation's delegate as from address" , async ( ) => {
174+ const parentDelegate : Address =
175+ '0x3000000000000000000000000000000000000003' ;
176+ const permissionContext =
177+ buildPermissionContextWithParentDelegate ( parentDelegate ) ;
178+ const newDelegate : Address = '0x2000000000000000000000000000000000000002' ;
179+
180+ const result = await redelegatePermissionContext ( client , {
181+ environment : mockEnvironment ,
182+ permissionContext,
183+ chainId : mockChainId ,
184+ to : newDelegate ,
185+ } ) ;
186+
187+ expect ( result . delegation . delegator ) . to . equal ( parentDelegate ) ;
188+ expect ( result . delegation . delegator ) . to . not . equal ( account . address ) ;
189+ } ) ;
190+
151191 it ( 'should allow scope override even with parent' , async ( ) => {
152192 const permissionContext = buildRootPermissionContext ( ) ;
153193 const newDelegate : Address = '0x2000000000000000000000000000000000000002' ;
@@ -220,7 +260,9 @@ describe('redelegatePermissionContext', () => {
220260 } ) ;
221261
222262 expect ( result . delegation . delegate ) . to . equal ( newDelegate ) ;
223- expect ( result . delegation . delegator ) . to . equal ( account . address ) ;
263+ expect ( result . delegation . delegator . toLowerCase ( ) ) . to . equal (
264+ account . address . toLowerCase ( ) ,
265+ ) ;
224266 } ) ;
225267} ) ;
226268
@@ -248,7 +290,9 @@ describe('redelegatePermissionContextOpen', () => {
248290 expect ( result . delegation . delegate ) . to . equal (
249291 '0x0000000000000000000000000000000000000a11' , // ANY_BENEFICIARY
250292 ) ;
251- expect ( result . delegation . delegator ) . to . equal ( account . address ) ;
293+ expect ( result . delegation . delegator . toLowerCase ( ) ) . to . equal (
294+ account . address . toLowerCase ( ) ,
295+ ) ;
252296 expect ( result . delegation . signature ) . to . match ( / ^ 0 x [ a - f A - F 0 - 9 ] + $ / u) ;
253297 } ) ;
254298
@@ -293,11 +337,29 @@ describe('redelegatePermissionContextOpen', () => {
293337 expect ( result . delegation . delegate ) . to . equal (
294338 '0x0000000000000000000000000000000000000a11' , // ANY_BENEFICIARY
295339 ) ;
296- expect ( result . delegation . delegator ) . to . equal ( account . address ) ;
340+ expect ( result . delegation . delegator . toLowerCase ( ) ) . to . equal (
341+ account . address . toLowerCase ( ) ,
342+ ) ;
297343 expect ( result . delegation . caveats ) . to . deep . equal ( [ ] ) ;
298344 expect ( result . delegation . signature ) . to . match ( / ^ 0 x [ a - f A - F 0 - 9 ] + $ / u) ;
299345 } ) ;
300346
347+ it ( "should use the parent delegation's delegate as from address" , async ( ) => {
348+ const parentDelegate : Address =
349+ '0x3000000000000000000000000000000000000003' ;
350+ const permissionContext =
351+ buildPermissionContextWithParentDelegate ( parentDelegate ) ;
352+
353+ const result = await redelegatePermissionContextOpen ( client , {
354+ environment : mockEnvironment ,
355+ permissionContext,
356+ chainId : mockChainId ,
357+ } ) ;
358+
359+ expect ( result . delegation . delegator ) . to . equal ( parentDelegate ) ;
360+ expect ( result . delegation . delegator ) . to . not . equal ( account . address ) ;
361+ } ) ;
362+
301363 it ( 'should allow scope override on an open redelegation' , async ( ) => {
302364 const permissionContext = buildRootPermissionContext ( ) ;
303365
@@ -366,7 +428,9 @@ describe('redelegatePermissionContextActions', () => {
366428 } ) ;
367429
368430 expect ( result . delegation . delegate ) . to . equal ( newDelegate ) ;
369- expect ( result . delegation . delegator ) . to . equal ( account . address ) ;
431+ expect ( result . delegation . delegator . toLowerCase ( ) ) . to . equal (
432+ account . address . toLowerCase ( ) ,
433+ ) ;
370434 } ) ;
371435
372436 it ( 'should extend a wallet client with redelegatePermissionContextOpen' , async ( ) => {
@@ -388,7 +452,9 @@ describe('redelegatePermissionContextActions', () => {
388452 expect ( result . delegation . delegate ) . to . equal (
389453 '0x0000000000000000000000000000000000000a11' , // ANY_BENEFICIARY
390454 ) ;
391- expect ( result . delegation . delegator ) . to . equal ( account . address ) ;
455+ expect ( result . delegation . delegator . toLowerCase ( ) ) . to . equal (
456+ account . address . toLowerCase ( ) ,
457+ ) ;
392458 } ) ;
393459
394460 it ( 'should throw error if chain is not configured and chainId is not provided (specific)' , async ( ) => {
0 commit comments