@layerzerolabs/utils-upgradeable-evm-contracts 0.2.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-lint.log +491 -0
- package/.turbo/turbo-test.log +1356 -0
- package/LICENSE +23 -0
- package/contracts/access/AccessControl2StepUpgradeable.sol +144 -0
- package/contracts/allowlist/AllowlistBaseUpgradeable.sol +184 -0
- package/contracts/allowlist/AllowlistRBACUpgradeable.sol +55 -0
- package/contracts/fee-accounting/FeeHandlerBaseUpgradeable.sol +69 -0
- package/contracts/fee-accounting/FeeHandlerRBACUpgradeable.sol +34 -0
- package/contracts/fee-config/FeeConfigBaseUpgradeable.sol +128 -0
- package/contracts/fee-config/FeeConfigRBACUpgradeable.sol +44 -0
- package/contracts/libs/EnumerableSetPagination.sol +77 -0
- package/contracts/pause/PauseBaseUpgradeable.sol +107 -0
- package/contracts/pause/PauseRBACUpgradeable.sol +47 -0
- package/contracts/pause-by-id/PauseByIDBaseUpgradeable.sol +127 -0
- package/contracts/pause-by-id/PauseByIDRBACUpgradeable.sol +74 -0
- package/contracts/rate-limiter/RateLimiterBaseUpgradeable.sol +636 -0
- package/contracts/rate-limiter/RateLimiterRBACUpgradeable.sol +89 -0
- package/contracts/rate-limiter/libs/RateLimiterUtils.sol +82 -0
- package/foundry.toml +27 -0
- package/package.json +34 -0
- package/solhint.config.js +3 -0
- package/test/AccessControl2StepUpgradeable.t.sol +374 -0
- package/test/AllowlistBaseUpgradeable.t.sol +380 -0
- package/test/AllowlistRBACUpgradeable.t.sol +84 -0
- package/test/EnumerableSetPagination.t.sol +445 -0
- package/test/FeeConfigBaseUpgradeable.t.sol +232 -0
- package/test/FeeConfigRBACUpgradeable.t.sol +59 -0
- package/test/FeeHandlerBaseUpgradeable.t.sol +78 -0
- package/test/FeeHandlerRBACUpgradeable.t.sol +45 -0
- package/test/PauseBaseUpgradeable.t.sol +244 -0
- package/test/PauseByIDBaseUpgradeable.t.sol +337 -0
- package/test/PauseByIDRBACUpgradeable.t.sol +414 -0
- package/test/PauseRBACUpgradeable.t.sol +258 -0
- package/test/RateLimiterBaseUpgradeable.t.sol +826 -0
- package/test/RateLimiterRBACUpgradeable.t.sol +128 -0
- package/test/RateLimiterRBACUpgradeableInvariant.t.sol +444 -0
- package/test/RateLimiterUtils.t.sol +137 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.22;
|
|
3
|
+
|
|
4
|
+
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
5
|
+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
6
|
+
import { FeeConfigRBACUpgradeable } from "./../contracts/fee-config/FeeConfigRBACUpgradeable.sol";
|
|
7
|
+
import { FeeConfigBaseUpgradeableTest, IFeeConfigTestHelper } from "./FeeConfigBaseUpgradeable.t.sol";
|
|
8
|
+
|
|
9
|
+
contract FeeConfigRBACUpgradeableMock is FeeConfigRBACUpgradeable {
|
|
10
|
+
constructor() {
|
|
11
|
+
_disableInitializers();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function initialize(address _initialAdmin) public initializer {
|
|
15
|
+
__AccessControl2Step_init(_initialAdmin);
|
|
16
|
+
_grantRole(FEE_CONFIG_MANAGER_ROLE, _initialAdmin);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
contract FeeConfigRBACUpgradeableTest is FeeConfigBaseUpgradeableTest {
|
|
21
|
+
address alice = makeAddr("alice");
|
|
22
|
+
|
|
23
|
+
function _deployFeeConfigHelper() internal virtual override returns (IFeeConfigTestHelper) {
|
|
24
|
+
FeeConfigRBACUpgradeableMock impl = new FeeConfigRBACUpgradeableMock();
|
|
25
|
+
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
26
|
+
address(impl),
|
|
27
|
+
address(this),
|
|
28
|
+
abi.encodeWithSelector(FeeConfigRBACUpgradeableMock.initialize.selector, address(this))
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return IFeeConfigTestHelper(address(proxy));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function test_setDefaultFeeBps_Revert_Unauthorized() public {
|
|
35
|
+
bytes32 feeConfigManagerRole = FeeConfigRBACUpgradeableMock(address(feeConfigHelper)).FEE_CONFIG_MANAGER_ROLE();
|
|
36
|
+
vm.expectRevert(
|
|
37
|
+
abi.encodeWithSelector(
|
|
38
|
+
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
39
|
+
alice,
|
|
40
|
+
feeConfigManagerRole
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
vm.prank(alice);
|
|
44
|
+
feeConfigHelper.setDefaultFeeBps(100);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function test_setFeeBps_Revert_Unauthorized() public {
|
|
48
|
+
bytes32 feeConfigManagerRole = FeeConfigRBACUpgradeableMock(address(feeConfigHelper)).FEE_CONFIG_MANAGER_ROLE();
|
|
49
|
+
vm.expectRevert(
|
|
50
|
+
abi.encodeWithSelector(
|
|
51
|
+
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
52
|
+
alice,
|
|
53
|
+
feeConfigManagerRole
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
vm.prank(alice);
|
|
57
|
+
feeConfigHelper.setFeeBps(1, 100, true);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.22;
|
|
3
|
+
|
|
4
|
+
import { IFeeHandler } from "@layerzerolabs/utils-evm-contracts/contracts/interfaces/IFeeHandler.sol";
|
|
5
|
+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
6
|
+
import { Test } from "forge-std/Test.sol";
|
|
7
|
+
import { FeeHandlerBaseUpgradeable } from "./../contracts/fee-accounting/FeeHandlerBaseUpgradeable.sol";
|
|
8
|
+
|
|
9
|
+
interface IFeeHandlerTestHelper is IFeeHandler {}
|
|
10
|
+
|
|
11
|
+
contract FeeHandlerBaseUpgradeableMock is FeeHandlerBaseUpgradeable {
|
|
12
|
+
constructor() {
|
|
13
|
+
_disableInitializers();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function initialize(address _feeDeposit) public initializer {
|
|
17
|
+
__FeeHandlerBase_init(_feeDeposit);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function setFeeDeposit(address _feeDeposit) public {
|
|
21
|
+
_setFeeDeposit(_feeDeposit);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
abstract contract FeeHandlerBaseUpgradeableTestCommon is Test {
|
|
26
|
+
IFeeHandlerTestHelper public feeHandlerHelper;
|
|
27
|
+
|
|
28
|
+
address alice = makeAddr("alice");
|
|
29
|
+
address bob = makeAddr("bob");
|
|
30
|
+
|
|
31
|
+
function setUp() public virtual {
|
|
32
|
+
feeHandlerHelper = _deployFeeHandlerHelper();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function _deployFeeHandlerHelper() internal virtual returns (IFeeHandlerTestHelper);
|
|
36
|
+
|
|
37
|
+
function test_feeDeposit() public view {
|
|
38
|
+
assertEq(feeHandlerHelper.feeDeposit(), alice);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function test_setFeeDeposit() public {
|
|
42
|
+
vm.expectEmit(true, true, true, true, address(feeHandlerHelper));
|
|
43
|
+
emit IFeeHandler.FeeDepositSet(bob);
|
|
44
|
+
feeHandlerHelper.setFeeDeposit(bob);
|
|
45
|
+
|
|
46
|
+
assertEq(feeHandlerHelper.feeDeposit(), bob);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function test_setFeeDeposit_Revert_ZeroAddress() public {
|
|
50
|
+
vm.expectRevert(IFeeHandler.InvalidFeeDeposit.selector);
|
|
51
|
+
feeHandlerHelper.setFeeDeposit(address(0));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function test_setFeeDeposit_Fuzz(address _newDeposit) public {
|
|
55
|
+
vm.assume(_newDeposit != address(0));
|
|
56
|
+
feeHandlerHelper.setFeeDeposit(_newDeposit);
|
|
57
|
+
assertEq(feeHandlerHelper.feeDeposit(), _newDeposit);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function test_storageHash() public pure {
|
|
61
|
+
bytes32 storageHash = keccak256(abi.encode(uint256(keccak256("layerzerov2.storage.feehandler")) - 1)) &
|
|
62
|
+
~bytes32(uint256(0xff));
|
|
63
|
+
assertEq(storageHash, 0xe32e0c5f1df3081ca85b86156deac82a46e8fb7b21b412e09f7ccdc5fca29900);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
contract FeeHandlerBaseUpgradeableTest is FeeHandlerBaseUpgradeableTestCommon {
|
|
68
|
+
function _deployFeeHandlerHelper() internal virtual override returns (IFeeHandlerTestHelper) {
|
|
69
|
+
FeeHandlerBaseUpgradeableMock impl = new FeeHandlerBaseUpgradeableMock();
|
|
70
|
+
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
71
|
+
address(impl),
|
|
72
|
+
address(this),
|
|
73
|
+
abi.encodeWithSelector(FeeHandlerBaseUpgradeableMock.initialize.selector, alice)
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return IFeeHandlerTestHelper(address(proxy));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.22;
|
|
3
|
+
|
|
4
|
+
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
|
|
5
|
+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
6
|
+
import { FeeHandlerRBACUpgradeable } from "./../contracts/fee-accounting/FeeHandlerRBACUpgradeable.sol";
|
|
7
|
+
import { FeeHandlerBaseUpgradeableTestCommon, IFeeHandlerTestHelper } from "./FeeHandlerBaseUpgradeable.t.sol";
|
|
8
|
+
|
|
9
|
+
contract FeeHandlerRBACUpgradeableMock is FeeHandlerRBACUpgradeable {
|
|
10
|
+
constructor() {
|
|
11
|
+
_disableInitializers();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function initialize(address _initialAdmin, address _feeDeposit) public initializer {
|
|
15
|
+
__FeeHandlerBase_init(_feeDeposit);
|
|
16
|
+
__AccessControl2Step_init(_initialAdmin);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
contract FeeHandlerRBACUpgradeableTest is FeeHandlerBaseUpgradeableTestCommon {
|
|
21
|
+
address charlie = makeAddr("charlie");
|
|
22
|
+
|
|
23
|
+
function _deployFeeHandlerHelper() internal virtual override returns (IFeeHandlerTestHelper) {
|
|
24
|
+
FeeHandlerRBACUpgradeableMock impl = new FeeHandlerRBACUpgradeableMock();
|
|
25
|
+
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
26
|
+
address(impl),
|
|
27
|
+
address(this),
|
|
28
|
+
abi.encodeWithSelector(FeeHandlerRBACUpgradeableMock.initialize.selector, address(this), alice)
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return IFeeHandlerTestHelper(address(proxy));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function test_setFeeDeposit_Revert_Unauthorized() public {
|
|
35
|
+
vm.expectRevert(
|
|
36
|
+
abi.encodeWithSelector(
|
|
37
|
+
IAccessControl.AccessControlUnauthorizedAccount.selector,
|
|
38
|
+
charlie,
|
|
39
|
+
FeeHandlerRBACUpgradeableMock(address(feeHandlerHelper)).DEFAULT_ADMIN_ROLE()
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
vm.prank(charlie);
|
|
43
|
+
feeHandlerHelper.setFeeDeposit(bob);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.22;
|
|
3
|
+
|
|
4
|
+
import { IPause } from "@layerzerolabs/utils-evm-contracts/contracts/interfaces/IPause.sol";
|
|
5
|
+
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
6
|
+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
|
|
7
|
+
import { Test } from "forge-std/Test.sol";
|
|
8
|
+
import { PauseBaseUpgradeable } from "./../contracts/pause/PauseBaseUpgradeable.sol";
|
|
9
|
+
|
|
10
|
+
interface IPauseTestHelper is IPause {
|
|
11
|
+
function pause() external;
|
|
12
|
+
function unpause() external;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
contract PauseBaseUpgradeableMock is PauseBaseUpgradeable {
|
|
16
|
+
uint256 public callCount;
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
_disableInitializers();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function initialize() public initializer {}
|
|
23
|
+
|
|
24
|
+
function pause() public {
|
|
25
|
+
_pause();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function unpause() public {
|
|
29
|
+
_unpause();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function assertNotPaused() public view {
|
|
33
|
+
_assertNotPaused();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function functionWithModifier() public whenNotPaused {
|
|
37
|
+
callCount++;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function functionWithModifierReturns() public view whenNotPaused returns (uint256) {
|
|
41
|
+
return 42;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
contract PauseBaseUpgradeableTest is Test {
|
|
46
|
+
IPauseTestHelper pauseHelper;
|
|
47
|
+
|
|
48
|
+
function setUp() public virtual {
|
|
49
|
+
PauseBaseUpgradeableMock impl = new PauseBaseUpgradeableMock();
|
|
50
|
+
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
|
|
51
|
+
address(impl),
|
|
52
|
+
address(this),
|
|
53
|
+
abi.encodeWithSelector(PauseBaseUpgradeableMock.initialize.selector)
|
|
54
|
+
);
|
|
55
|
+
pauseHelper = IPauseTestHelper(address(proxy));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function test_storageHash() public pure {
|
|
59
|
+
bytes32 storageHash = keccak256(abi.encode(uint256(keccak256("layerzerov2.storage.pause")) - 1)) &
|
|
60
|
+
~bytes32(uint256(0xff));
|
|
61
|
+
assertEq(storageHash, 0x27be0a968b102c71096101138efa2fc0db00aea7b287f10fdc298bfd2d4ec000);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function test_isPaused_InitialState() public view {
|
|
65
|
+
assertFalse(pauseHelper.isPaused());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function test_pause() public {
|
|
69
|
+
vm.expectEmit(false, false, false, true);
|
|
70
|
+
emit IPause.PauseSet(true);
|
|
71
|
+
pauseHelper.pause();
|
|
72
|
+
|
|
73
|
+
assertTrue(pauseHelper.isPaused());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function test_unpause() public {
|
|
77
|
+
pauseHelper.pause();
|
|
78
|
+
assertTrue(pauseHelper.isPaused());
|
|
79
|
+
|
|
80
|
+
vm.expectEmit(false, false, false, true);
|
|
81
|
+
emit IPause.PauseSet(false);
|
|
82
|
+
pauseHelper.unpause();
|
|
83
|
+
|
|
84
|
+
assertFalse(pauseHelper.isPaused());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function test_setPaused_Fuzz(bool _paused) public {
|
|
88
|
+
if (!_paused) {
|
|
89
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.PauseStateIdempotent.selector, false));
|
|
90
|
+
pauseHelper.unpause();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
vm.expectEmit(false, false, false, true);
|
|
95
|
+
emit IPause.PauseSet(_paused);
|
|
96
|
+
pauseHelper.pause();
|
|
97
|
+
assertEq(pauseHelper.isPaused(), _paused);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function test_setPaused_Success_ToggleMultipleTimes() public {
|
|
101
|
+
assertFalse(pauseHelper.isPaused());
|
|
102
|
+
|
|
103
|
+
pauseHelper.pause();
|
|
104
|
+
assertTrue(pauseHelper.isPaused());
|
|
105
|
+
|
|
106
|
+
pauseHelper.unpause();
|
|
107
|
+
assertFalse(pauseHelper.isPaused());
|
|
108
|
+
|
|
109
|
+
pauseHelper.pause();
|
|
110
|
+
assertTrue(pauseHelper.isPaused());
|
|
111
|
+
|
|
112
|
+
pauseHelper.unpause();
|
|
113
|
+
assertFalse(pauseHelper.isPaused());
|
|
114
|
+
|
|
115
|
+
pauseHelper.pause();
|
|
116
|
+
assertTrue(pauseHelper.isPaused());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function test_assertNotPaused_Success() public view {
|
|
120
|
+
PauseBaseUpgradeableMock(address(pauseHelper)).assertNotPaused();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function test_assertNotPaused_Revert_Paused() public {
|
|
124
|
+
pauseHelper.pause();
|
|
125
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
126
|
+
PauseBaseUpgradeableMock(address(pauseHelper)).assertNotPaused();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function test_assertNotPaused_Fuzz(bool _paused) public {
|
|
130
|
+
if (_paused) {
|
|
131
|
+
pauseHelper.pause();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (_paused) {
|
|
135
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
136
|
+
PauseBaseUpgradeableMock(address(pauseHelper)).assertNotPaused();
|
|
137
|
+
} else {
|
|
138
|
+
PauseBaseUpgradeableMock(address(pauseHelper)).assertNotPaused();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function test_initialize_Revert_AlreadyInitialized() public virtual {
|
|
143
|
+
vm.expectRevert(Initializable.InvalidInitialization.selector);
|
|
144
|
+
PauseBaseUpgradeableMock(address(pauseHelper)).initialize();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function test_setPaused_Idempotent_Reverts() public {
|
|
148
|
+
pauseHelper.pause();
|
|
149
|
+
|
|
150
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.PauseStateIdempotent.selector, true));
|
|
151
|
+
pauseHelper.pause();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function test_setPaused_Idempotent_InitialState_Reverts() public {
|
|
155
|
+
assertFalse(pauseHelper.isPaused());
|
|
156
|
+
|
|
157
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.PauseStateIdempotent.selector, false));
|
|
158
|
+
pauseHelper.unpause();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function test_whenNotPaused_Success() public {
|
|
162
|
+
PauseBaseUpgradeableMock mock = PauseBaseUpgradeableMock(address(pauseHelper));
|
|
163
|
+
mock.functionWithModifier();
|
|
164
|
+
assertEq(mock.callCount(), 1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function test_whenNotPaused_Revert_Paused() public {
|
|
168
|
+
pauseHelper.pause();
|
|
169
|
+
|
|
170
|
+
PauseBaseUpgradeableMock mock = PauseBaseUpgradeableMock(address(pauseHelper));
|
|
171
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
172
|
+
mock.functionWithModifier();
|
|
173
|
+
|
|
174
|
+
assertEq(mock.callCount(), 0);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function test_whenNotPaused_Success_AfterUnpause() public {
|
|
178
|
+
PauseBaseUpgradeableMock mock = PauseBaseUpgradeableMock(address(pauseHelper));
|
|
179
|
+
|
|
180
|
+
pauseHelper.pause();
|
|
181
|
+
|
|
182
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
183
|
+
mock.functionWithModifier();
|
|
184
|
+
|
|
185
|
+
pauseHelper.unpause();
|
|
186
|
+
|
|
187
|
+
mock.functionWithModifier();
|
|
188
|
+
assertEq(mock.callCount(), 1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function test_whenNotPaused_WithReturnValue() public view {
|
|
192
|
+
PauseBaseUpgradeableMock mock = PauseBaseUpgradeableMock(address(pauseHelper));
|
|
193
|
+
uint256 result = mock.functionWithModifierReturns();
|
|
194
|
+
assertEq(result, 42);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function test_whenNotPaused_Revert_WithReturnValue() public {
|
|
198
|
+
pauseHelper.pause();
|
|
199
|
+
|
|
200
|
+
PauseBaseUpgradeableMock mock = PauseBaseUpgradeableMock(address(pauseHelper));
|
|
201
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
202
|
+
mock.functionWithModifierReturns();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function test_whenNotPaused_Fuzz(bool _paused) public {
|
|
206
|
+
if (_paused) {
|
|
207
|
+
pauseHelper.pause();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
PauseBaseUpgradeableMock mock = PauseBaseUpgradeableMock(address(pauseHelper));
|
|
211
|
+
|
|
212
|
+
if (_paused) {
|
|
213
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
214
|
+
mock.functionWithModifier();
|
|
215
|
+
assertEq(mock.callCount(), 0);
|
|
216
|
+
} else {
|
|
217
|
+
mock.functionWithModifier();
|
|
218
|
+
assertEq(mock.callCount(), 1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function test_whenNotPaused_Success_MultipleCalls() public {
|
|
223
|
+
PauseBaseUpgradeableMock mock = PauseBaseUpgradeableMock(address(pauseHelper));
|
|
224
|
+
|
|
225
|
+
mock.functionWithModifier();
|
|
226
|
+
mock.functionWithModifier();
|
|
227
|
+
mock.functionWithModifier();
|
|
228
|
+
assertEq(mock.callCount(), 3);
|
|
229
|
+
|
|
230
|
+
pauseHelper.pause();
|
|
231
|
+
|
|
232
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
233
|
+
mock.functionWithModifier();
|
|
234
|
+
vm.expectRevert(abi.encodeWithSelector(IPause.Paused.selector));
|
|
235
|
+
mock.functionWithModifier();
|
|
236
|
+
assertEq(mock.callCount(), 3);
|
|
237
|
+
|
|
238
|
+
pauseHelper.unpause();
|
|
239
|
+
|
|
240
|
+
mock.functionWithModifier();
|
|
241
|
+
mock.functionWithModifier();
|
|
242
|
+
assertEq(mock.callCount(), 5);
|
|
243
|
+
}
|
|
244
|
+
}
|