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