@@ -3,19 +3,18 @@ import {
33 encodeExecutionCalldatas ,
44 encodePermissionContexts ,
55 createCaveatBuilder ,
6- getDelegationHashOffchain ,
76} from '@metamask/delegation-toolkit/utils' ;
87import {
98 createDelegation ,
109 createExecution ,
10+ createCaveatEnforcerClient ,
11+ type CaveatEnforcerClient ,
1112 Implementation ,
1213 toMetaMaskSmartAccount ,
1314 ExecutionMode ,
1415 type MetaMaskSmartAccount ,
1516} from '@metamask/delegation-toolkit' ;
1617import {
17- createCaveatEnforcerClient ,
18- type CaveatEnforcerClient ,
1918 getErc20PeriodTransferEnforcerAvailableAmount ,
2019 getErc20StreamingEnforcerAvailableAmount ,
2120 getMultiTokenPeriodEnforcerAvailableAmount ,
@@ -212,7 +211,7 @@ describe('ERC20PeriodTransferEnforcer', () => {
212211 signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
213212 } ;
214213
215- const beforeResult =
214+ const beforeResult =
216215 await caveatClient . getErc20PeriodTransferEnforcerAvailableAmount ( {
217216 delegation : signedDelegation ,
218217 } ) ;
@@ -289,7 +288,7 @@ describe('ERC20PeriodTransferEnforcer', () => {
289288 signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
290289 } ;
291290
292- // Should be a new period, availableAmount reset to periodAmount
291+ // Should be a new period, availableAmount reset to periodAmount
293292 const beforeResult =
294293 await caveatClient . getErc20PeriodTransferEnforcerAvailableAmount ( {
295294 delegation : signedDelegation ,
@@ -377,7 +376,7 @@ describe('ERC20StreamingEnforcer', () => {
377376 } ;
378377
379378 // Get delegation hash
380- // Check available amount before redemption
379+ // Check available amount before redemption
381380 const beforeResult =
382381 await caveatClient . getErc20StreamingEnforcerAvailableAmount ( {
383382 delegation : signedDelegation ,
@@ -472,7 +471,7 @@ describe('ERC20StreamingEnforcer', () => {
472471 } ) ,
473472 } ;
474473
475- const beforeResult =
474+ const beforeResult =
476475 await caveatClient . getErc20StreamingEnforcerAvailableAmount ( {
477476 delegation : signedDelegation ,
478477 } ) ;
@@ -550,7 +549,7 @@ describe('ERC20StreamingEnforcer', () => {
550549 } ) ,
551550 } ;
552551
553- const beforeResult =
552+ const beforeResult =
554553 await caveatClient . getErc20StreamingEnforcerAvailableAmount ( {
555554 delegation : signedDelegation ,
556555 } ) ;
@@ -647,7 +646,7 @@ describe('MultiTokenPeriodEnforcer', () => {
647646 } ;
648647
649648 // Get delegation hash
650- // Prepare args for multi-token enforcer (token selector)
649+ // Prepare args for multi-token enforcer (token selector)
651650 const args = encodePacked ( [ 'uint256' ] , [ BigInt ( 0 ) ] ) ; // token index 0
652651 signedDelegation . caveats [ 0 ] . args = args ;
653652
@@ -740,7 +739,7 @@ describe('MultiTokenPeriodEnforcer', () => {
740739 } ) ,
741740 } ;
742741
743- // Prepare args for multi-token enforcer (token selector)
742+ // Prepare args for multi-token enforcer (token selector)
744743 const args = encodePacked ( [ 'uint256' ] , [ BigInt ( 0 ) ] ) ; // token index 0
745744 signedDelegation . caveats [ 0 ] . args = args ;
746745
@@ -824,7 +823,7 @@ describe('MultiTokenPeriodEnforcer', () => {
824823 } ) ,
825824 } ;
826825
827- // Prepare args for multi-token enforcer (token selector)
826+ // Prepare args for multi-token enforcer (token selector)
828827 const args = encodePacked ( [ 'uint256' ] , [ BigInt ( 0 ) ] ) ; // token index 0
829828 signedDelegation . caveats [ 0 ] . args = args ;
830829
@@ -912,7 +911,7 @@ describe('NativeTokenPeriodTransferEnforcer', () => {
912911 } ;
913912
914913 // Get delegation hash
915- // Check available amount before redemption
914+ // Check available amount before redemption
916915 const beforeResult =
917916 await caveatClient . getNativeTokenPeriodTransferEnforcerAvailableAmount ( {
918917 delegation : signedDelegation ,
@@ -998,7 +997,7 @@ describe('NativeTokenPeriodTransferEnforcer', () => {
998997 } ) ,
999998 } ;
1000999
1001- const beforeResult =
1000+ const beforeResult =
10021001 await caveatClient . getNativeTokenPeriodTransferEnforcerAvailableAmount ( {
10031002 delegation : signedDelegation ,
10041003 } ) ;
@@ -1070,7 +1069,7 @@ describe('NativeTokenPeriodTransferEnforcer', () => {
10701069 } ) ,
10711070 } ;
10721071
1073- const beforeResult =
1072+ const beforeResult =
10741073 await caveatClient . getNativeTokenPeriodTransferEnforcerAvailableAmount ( {
10751074 delegation : signedDelegation ,
10761075 } ) ;
@@ -1151,7 +1150,7 @@ describe('NativeTokenStreamingEnforcer', () => {
11511150 } ;
11521151
11531152 // Get delegation hash
1154- // Check available amount before redemption
1153+ // Check available amount before redemption
11551154 const beforeResult =
11561155 await caveatClient . getNativeTokenStreamingEnforcerAvailableAmount ( {
11571156 delegation : signedDelegation ,
@@ -1240,7 +1239,7 @@ describe('NativeTokenStreamingEnforcer', () => {
12401239 } ) ,
12411240 } ;
12421241
1243- const beforeResult =
1242+ const beforeResult =
12441243 await caveatClient . getNativeTokenStreamingEnforcerAvailableAmount ( {
12451244 delegation : signedDelegation ,
12461245 } ) ;
@@ -1312,7 +1311,7 @@ describe('NativeTokenStreamingEnforcer', () => {
13121311 } ) ,
13131312 } ;
13141313
1315- const beforeResult =
1314+ const beforeResult =
13161315 await caveatClient . getNativeTokenStreamingEnforcerAvailableAmount ( {
13171316 delegation : signedDelegation ,
13181317 } ) ;
@@ -1402,7 +1401,7 @@ describe('Generic caveat utils functionality', () => {
14021401 } ;
14031402
14041403 // Get delegation hash
1405- // Use generic method
1404+ // Use generic method
14061405 const result =
14071406 await caveatClient . getErc20PeriodTransferEnforcerAvailableAmount ( {
14081407 delegation : signedDelegation ,
@@ -1412,46 +1411,6 @@ describe('Generic caveat utils functionality', () => {
14121411 expect ( result . isNewPeriod ) . toBe ( true ) ;
14131412 expect ( result . currentPeriod ) . toBeDefined ( ) ;
14141413 } ) ;
1415-
1416- test ( 'should work with custom delegation manager' , async ( ) => {
1417- const customDelegationManager = randomAddress ( ) ;
1418- const periodAmount = parseEther ( '2' ) ;
1419- const periodDuration = 3600 ;
1420-
1421- // Create delegation with custom delegation manager
1422- const delegation = createDelegation ( {
1423- to : bobSmartAccount . address ,
1424- from : aliceSmartAccount . address ,
1425- caveats : createCaveatBuilder ( aliceSmartAccount . environment ) . addCaveat (
1426- 'erc20PeriodTransfer' ,
1427- {
1428- tokenAddress : erc20TokenAddress ,
1429- periodAmount,
1430- periodDuration,
1431- startDate : currentTime ,
1432- } ,
1433- ) ,
1434- } ) ;
1435-
1436- const signedDelegation = {
1437- ...delegation ,
1438- signature : await aliceSmartAccount . signDelegation ( {
1439- delegation,
1440- } ) ,
1441- } ;
1442-
1443- // Get delegation hash
1444- // This should fail with custom delegation manager since it's not the real one
1445- const result =
1446- await caveatClient . getErc20PeriodTransferEnforcerAvailableAmount ( {
1447- delegation : signedDelegation , delegationManager : customDelegationManager ,
1448- } ) ;
1449-
1450- // Should still return a result, check structure
1451- expect ( result ) . toHaveProperty ( 'availableAmount' ) ;
1452- expect ( result ) . toHaveProperty ( 'isNewPeriod' ) ;
1453- expect ( result ) . toHaveProperty ( 'currentPeriod' ) ;
1454- } ) ;
14551414} ) ;
14561415
14571416describe ( 'Individual action functions vs client extension methods' , ( ) => {
@@ -1478,8 +1437,9 @@ describe('Individual action functions vs client extension methods', () => {
14781437 signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
14791438 } ;
14801439
1481- const params = {
1482- delegation : signedDelegation , } ;
1440+ const params = {
1441+ delegation : signedDelegation ,
1442+ } ;
14831443
14841444 // Test both approaches
14851445 const [ clientResult , functionResult ] = await Promise . all ( [
@@ -1521,8 +1481,9 @@ describe('Individual action functions vs client extension methods', () => {
15211481 signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
15221482 } ;
15231483
1524- const params = {
1525- delegation : signedDelegation , } ;
1484+ const params = {
1485+ delegation : signedDelegation ,
1486+ } ;
15261487
15271488 // Test both approaches
15281489 const [ clientResult , functionResult ] = await Promise . all ( [
@@ -1563,9 +1524,11 @@ describe('Individual action functions vs client extension methods', () => {
15631524 signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
15641525 } ;
15651526
1566- const args = encodePacked ( [ 'uint256' ] , [ BigInt ( 0 ) ] ) ; // token index 0
1527+ signedDelegation . caveats [ 0 ] . args = encodePacked ( [ 'uint256' ] , [ BigInt ( 0 ) ] ) ; // token index 0
1528+
15671529 const params = {
1568- delegation : signedDelegation , } ;
1530+ delegation : signedDelegation ,
1531+ } ;
15691532
15701533 // Test both approaches
15711534 const [ clientResult , functionResult ] = await Promise . all ( [
@@ -1604,8 +1567,9 @@ describe('Individual action functions vs client extension methods', () => {
16041567 signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
16051568 } ;
16061569
1607- const params = {
1608- delegation : signedDelegation , } ;
1570+ const params = {
1571+ delegation : signedDelegation ,
1572+ } ;
16091573
16101574 // Test both approaches
16111575 const [ clientResult , functionResult ] = await Promise . all ( [
@@ -1646,8 +1610,9 @@ describe('Individual action functions vs client extension methods', () => {
16461610 signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
16471611 } ;
16481612
1649- const params = {
1650- delegation : signedDelegation , } ;
1613+ const params = {
1614+ delegation : signedDelegation ,
1615+ } ;
16511616
16521617 // Test both approaches
16531618 const [ clientResult , functionResult ] = await Promise . all ( [
@@ -1662,49 +1627,4 @@ describe('Individual action functions vs client extension methods', () => {
16621627 expect ( clientResult ) . toEqual ( functionResult ) ;
16631628 expect ( clientResult . availableAmount ) . toBe ( initialAmount ) ;
16641629 } ) ;
1665-
1666- test ( 'should work with custom parameters (delegation manager and enforcer address)' , async ( ) => {
1667- const periodAmount = parseEther ( '2.5' ) ;
1668- const periodDuration = 3600 ;
1669-
1670- const delegation = createDelegation ( {
1671- to : bobSmartAccount . address ,
1672- from : aliceSmartAccount . address ,
1673- caveats : createCaveatBuilder ( aliceSmartAccount . environment ) . addCaveat (
1674- 'erc20PeriodTransfer' ,
1675- {
1676- tokenAddress : erc20TokenAddress ,
1677- periodAmount,
1678- periodDuration,
1679- startDate : currentTime ,
1680- } ,
1681- ) ,
1682- } ) ;
1683-
1684- const signedDelegation = {
1685- ...delegation ,
1686- signature : await aliceSmartAccount . signDelegation ( { delegation } ) ,
1687- } ;
1688-
1689- const customParams = {
1690- delegation : signedDelegation , delegationManager : aliceSmartAccount . environment . DelegationManager ,
1691- enforcerAddress :
1692- aliceSmartAccount . environment . caveatEnforcers
1693- . ERC20PeriodTransferEnforcer ,
1694- } ;
1695-
1696- // Test both approaches with custom parameters
1697- const [ clientResult , functionResult ] = await Promise . all ( [
1698- caveatClient . getErc20PeriodTransferEnforcerAvailableAmount ( customParams ) ,
1699- getErc20PeriodTransferEnforcerAvailableAmount (
1700- publicClient ,
1701- aliceSmartAccount . environment ,
1702- customParams ,
1703- ) ,
1704- ] ) ;
1705-
1706- expect ( clientResult ) . toEqual ( functionResult ) ;
1707- expect ( clientResult . availableAmount ) . toBe ( periodAmount ) ;
1708- expect ( clientResult . isNewPeriod ) . toBe ( true ) ;
1709- } ) ;
17101630} ) ;
0 commit comments