@@ -654,127 +654,6 @@ contract GuardedExecutorTest is BaseTest {
654654 }
655655 }
656656
657- function testSetSpendLimitsEnabled () public {
658- Orchestrator.Intent memory u;
659- DelegatedEOA memory d = _randomEIP7702DelegatedEOA ();
660-
661- u.eoa = d.eoa;
662- u.combinedGas = 1000000 ;
663- u.nonce = d.d.getNonce (0 );
664-
665- PassKey memory k = _randomSecp256k1PassKey ();
666-
667- address token = LibClone.clone (address (paymentToken));
668- _mint (token, u.eoa, type (uint192 ).max);
669-
670- // Test that spend limits are enabled by default for the key
671- assertTrue (d.d.spendLimitsEnabled (k.keyHash), "Spend limits should be enabled by default " );
672-
673- // Authorize the key and set up spend limit
674- {
675- ERC7821 .Call[] memory calls = new ERC7821 .Call [](3 );
676- calls[0 ].data = abi.encodeWithSelector (IthacaAccount.authorize.selector , k.k);
677- // Only allow the key to execute on the token, not on the account itself
678- calls[1 ].data = abi.encodeWithSelector (
679- GuardedExecutor.setCanExecute.selector , k.keyHash, token, _ANY_FN_SEL, true
680- );
681- calls[2 ] = _setSpendLimitCall (k, token, GuardedExecutor.SpendPeriod.Day, 1 ether);
682-
683- u.executionData = abi.encode (calls);
684- u.nonce = 0xc1d0 << 240 ;
685- u.signature = _eoaSig (d.privateKey, u);
686-
687- assertEq (oc.execute (abi.encode (u)), 0 );
688- }
689-
690- // Test that non-EOA cannot call setSpendLimitsEnabled
691- {
692- ERC7821 .Call[] memory calls = new ERC7821 .Call [](1 );
693- calls[0 ].to = address (0 );
694- calls[0 ].data = abi.encodeWithSelector (
695- GuardedExecutor.setSpendLimitsEnabled.selector , k.keyHash, false
696- );
697-
698- u.nonce = d.d.getNonce (0 );
699- u.executionData = abi.encode (calls);
700- u.signature = _sig (k, u);
701-
702- // This should fail because setSpendLimitsEnabled requires msg.sender == address(this)
703- // and the key is not authorized to self-execute
704- assertEq (
705- oc.execute (abi.encode (u)),
706- bytes4 (keccak256 ("UnauthorizedCall(bytes32,address,bytes) " ))
707- );
708- }
709-
710- // Test that EOA can disable spend limits with event
711- {
712- ERC7821 .Call[] memory calls = new ERC7821 .Call [](1 );
713- calls[0 ].to = address (0 );
714- calls[0 ].data = abi.encodeWithSelector (
715- GuardedExecutor.setSpendLimitsEnabled.selector , k.keyHash, false
716- );
717-
718- u.nonce = d.d.getNonce (0 );
719- u.executionData = abi.encode (calls);
720- u.signature = _eoaSig (d.privateKey, u);
721-
722- vm.expectEmit (true , true , true , true );
723- emit GuardedExecutor.SpendLimitsEnabledSet (k.keyHash, false );
724-
725- assertEq (oc.execute (abi.encode (u)), 0 );
726- assertFalse (d.d.spendLimitsEnabled (k.keyHash), "Spend limits should be disabled " );
727- }
728-
729- // Test that when disabled, spend limits are not enforced (can spend beyond limit)
730- {
731- ERC7821 .Call[] memory calls = new ERC7821 .Call [](1 );
732- // Try to transfer 2 ether (exceeds the 1 ether daily limit)
733- calls[0 ] = _transferCall2 (token, address (0xb0b ), 2 ether);
734-
735- u.nonce = d.d.getNonce (0 );
736- u.executionData = abi.encode (calls);
737- u.signature = _sig (k, u);
738-
739- // Should succeed even though it exceeds the limit
740- assertEq (oc.execute (abi.encode (u)), 0 );
741- assertEq (_balanceOf (token, address (0xb0b )), 2 ether);
742- }
743-
744- // Test that EOA can re-enable spend limits with event
745- {
746- ERC7821 .Call[] memory calls = new ERC7821 .Call [](1 );
747- calls[0 ].to = address (0 );
748- calls[0 ].data = abi.encodeWithSelector (
749- GuardedExecutor.setSpendLimitsEnabled.selector , k.keyHash, true
750- );
751-
752- u.nonce = d.d.getNonce (0 );
753- u.executionData = abi.encode (calls);
754- u.signature = _eoaSig (d.privateKey, u);
755-
756- vm.expectEmit (true , true , true , true );
757- emit GuardedExecutor.SpendLimitsEnabledSet (k.keyHash, true );
758-
759- assertEq (oc.execute (abi.encode (u)), 0 );
760- assertTrue (d.d.spendLimitsEnabled (k.keyHash), "Spend limits should be enabled again " );
761- }
762-
763- // Test that when re-enabled, spend limits are enforced again
764- {
765- ERC7821 .Call[] memory calls = new ERC7821 .Call [](1 );
766- // Try to transfer 2 ether again (exceeds the 1 ether daily limit)
767- calls[0 ] = _transferCall2 (token, address (0xb0b ), 2 ether);
768-
769- u.nonce = d.d.getNonce (0 );
770- u.executionData = abi.encode (calls);
771- u.signature = _sig (k, u);
772-
773- // Should fail now that limits are enforced
774- assertEq (oc.execute (abi.encode (u)), bytes4 (keccak256 ("ExceededSpendLimit(address) " )));
775- }
776- }
777-
778657 function testSpends (bytes32 ) public {
779658 Orchestrator.Intent memory u;
780659 DelegatedEOA memory d = _randomEIP7702DelegatedEOA ();
0 commit comments