|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.19; |
| 3 | + |
| 4 | +import {AccountTestBase} from "../utils/AccountTestBase.sol"; |
| 5 | +import {TEST_DEFAULT_VALIDATION_ENTITY_ID} from "../utils/TestConstants.sol"; |
| 6 | +import {SemiModularAccount} from "src/account/SemiModularAccount.sol"; |
| 7 | +import {ValidationConfig} from "src/helpers/ValidationConfigLib.sol"; |
| 8 | + |
| 9 | +import {console} from "forge-std/Test.sol"; |
| 10 | +import {LibClone} from "solady/utils/LibClone.sol"; |
| 11 | + |
| 12 | +contract SemiModularAccountTest is AccountTestBase { |
| 13 | + SemiModularAccount internal _sma; |
| 14 | + |
| 15 | + address internal _other; |
| 16 | + |
| 17 | + function setUp() public { |
| 18 | + // This is separate from the equivalence testing framework (with the env boolean variable "SMA_TEST") with |
| 19 | + // the goal of testing specific SMA functionality, rather than equivalence. This is also why we deploy a |
| 20 | + // new account. |
| 21 | + SemiModularAccount impl = new SemiModularAccount(entryPoint); |
| 22 | + |
| 23 | + _other = address(0x4546b); |
| 24 | + |
| 25 | + bytes32 salt = bytes32(0); |
| 26 | + bytes memory immutables = abi.encodePacked(address(owner1)); |
| 27 | + (bool alreadyDeployed, address instance) = |
| 28 | + LibClone.createDeterministicERC1967(address(impl), immutables, salt); |
| 29 | + |
| 30 | + assertFalse(alreadyDeployed); |
| 31 | + |
| 32 | + _sma = SemiModularAccount(payable(instance)); |
| 33 | + } |
| 34 | + |
| 35 | + /* -------------------------------------------------------------------------- */ |
| 36 | + /* Negatives */ |
| 37 | + /* -------------------------------------------------------------------------- */ |
| 38 | + |
| 39 | + function test_Fail_InitializeDisabled() external { |
| 40 | + ValidationConfig config; |
| 41 | + bytes4[] memory selectors; |
| 42 | + bytes memory installData; |
| 43 | + bytes[] memory hooks; |
| 44 | + |
| 45 | + vm.expectRevert(SemiModularAccount.InitializerDisabled.selector); |
| 46 | + _sma.initializeWithValidation(config, selectors, installData, hooks); |
| 47 | + } |
| 48 | + |
| 49 | + function test_Fail_AccessControl_Functions() external { |
| 50 | + vm.expectRevert(_buildDirectCallDisallowedError(SemiModularAccount.setFallbackSignerDisabled.selector)); |
| 51 | + _sma.setFallbackSignerDisabled(true); |
| 52 | + |
| 53 | + vm.expectRevert(_buildDirectCallDisallowedError(SemiModularAccount.updateFallbackSigner.selector)); |
| 54 | + _sma.updateFallbackSigner(address(0)); |
| 55 | + } |
| 56 | + |
| 57 | + function test_Fail_ExecuteWithAuthorization_DisabledFallbackSigner() external { |
| 58 | + vm.prank(address(entryPoint)); |
| 59 | + _sma.setFallbackSignerDisabled(true); |
| 60 | + |
| 61 | + vm.expectRevert(SemiModularAccount.FallbackSignerDisabled.selector); |
| 62 | + vm.prank(owner1); |
| 63 | + _executeWithFallbackSigner(); |
| 64 | + } |
| 65 | + |
| 66 | + function test_Fail_ExecuteWithAuthorization_BytecodeOverriden() external { |
| 67 | + vm.prank(address(entryPoint)); |
| 68 | + _sma.updateFallbackSigner(_other); |
| 69 | + |
| 70 | + vm.expectRevert(SemiModularAccount.FallbackSignerMismatch.selector); |
| 71 | + vm.prank(owner1); |
| 72 | + _executeWithFallbackSigner(); |
| 73 | + } |
| 74 | + |
| 75 | + /* -------------------------------------------------------------------------- */ |
| 76 | + /* Positives */ |
| 77 | + /* -------------------------------------------------------------------------- */ |
| 78 | + |
| 79 | + function test_Pass_GetFallbackSigner_Bytecode() external { |
| 80 | + assertEq(_sma.getFallbackSigner(), owner1); |
| 81 | + } |
| 82 | + |
| 83 | + function test_Pass_GetFallbackSigner_Storage() external { |
| 84 | + vm.prank(address(entryPoint)); |
| 85 | + _sma.updateFallbackSigner(_other); |
| 86 | + |
| 87 | + assertEq(_sma.getFallbackSigner(), _other); |
| 88 | + } |
| 89 | + |
| 90 | + function test_Pass_ExecuteWithAuthorization_FallbackSigner() external { |
| 91 | + vm.prank(owner1); |
| 92 | + _executeWithFallbackSigner(); |
| 93 | + } |
| 94 | + |
| 95 | + /* -------------------------------------------------------------------------- */ |
| 96 | + /* Internals */ |
| 97 | + /* -------------------------------------------------------------------------- */ |
| 98 | + |
| 99 | + function _executeWithFallbackSigner() internal { |
| 100 | + // _signerValidation is already the ModuleEntity for fallback validation |
| 101 | + _sma.executeWithAuthorization( |
| 102 | + abi.encodeCall(account1.execute, (address(owner1), 0, "")), |
| 103 | + _encodeSignature(_signerValidation, GLOBAL_VALIDATION, "") |
| 104 | + ); |
| 105 | + } |
| 106 | +} |
0 commit comments