-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathL2SystemConfig.t.sol
More file actions
132 lines (104 loc) · 4.79 KB
/
L2SystemConfig.t.sol
File metadata and controls
132 lines (104 loc) · 4.79 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// SPDX-License-Identifier: MIT
pragma solidity =0.8.24;
import {Test} from "forge-std/Test.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {L2SystemConfig} from "../L2/L2SystemConfig.sol";
contract L2SystemConfigTest is Test {
address public admin;
address public owner;
address public nonOwner;
L2SystemConfig public l2SystemConfig;
event BaseFeeOverheadUpdated(uint256 oldBaseFeeOverhead, uint256 newBaseFeeOverhead);
event BaseFeeScalarUpdated(uint256 oldBaseFeeScalar, uint256 newBaseFeeScalar);
function setUp() public {
admin = makeAddr("admin");
owner = makeAddr("owner");
nonOwner = makeAddr("nonOwner");
L2SystemConfig implementation = new L2SystemConfig();
address proxy = address(new TransparentUpgradeableProxy(address(implementation), admin, ""));
l2SystemConfig = L2SystemConfig(proxy);
l2SystemConfig.initialize(owner);
}
function test_Initialize() public {
// Test initialization
assertEq(l2SystemConfig.owner(), owner);
// revert when initialize again
vm.expectRevert("Initializable: contract is already initialized");
l2SystemConfig.initialize(owner);
}
function test_UpdateBaseFeeOverhead(uint256 newBaseFeeOverhead) public {
// Test that only owner can update base fee overhead
vm.prank(nonOwner);
vm.expectRevert("Ownable: caller is not the owner");
l2SystemConfig.updateBaseFeeOverhead(newBaseFeeOverhead);
// Test owner can update base fee overhead
assertEq(l2SystemConfig.baseFeeOverhead(), 0);
vm.prank(owner);
vm.expectEmit(true, true, true, true);
emit BaseFeeOverheadUpdated(0, newBaseFeeOverhead);
l2SystemConfig.updateBaseFeeOverhead(newBaseFeeOverhead);
assertEq(l2SystemConfig.baseFeeOverhead(), newBaseFeeOverhead);
}
function test_UpdateBaseFeeScalar(uint256 newBaseFeeScalar) public {
// Test that only owner can update base fee scalar
vm.prank(nonOwner);
vm.expectRevert("Ownable: caller is not the owner");
l2SystemConfig.updateBaseFeeScalar(newBaseFeeScalar);
// Test owner can update base fee scalar
assertEq(l2SystemConfig.baseFeeScalar(), 0);
vm.prank(owner);
vm.expectEmit(true, true, true, true);
emit BaseFeeScalarUpdated(0, newBaseFeeScalar);
l2SystemConfig.updateBaseFeeScalar(newBaseFeeScalar);
assertEq(l2SystemConfig.baseFeeScalar(), newBaseFeeScalar);
}
function test_GetL2BaseFee(
uint256 l1BaseFee,
uint256 baseFeeScalar,
uint256 baseFeeOverhead
) public {
l1BaseFee = bound(l1BaseFee, 0, type(uint64).max);
baseFeeScalar = bound(baseFeeScalar, 0, type(uint128).max);
baseFeeOverhead = bound(baseFeeOverhead, 0, type(uint128).max);
// Set up the contract state
vm.prank(owner);
l2SystemConfig.updateBaseFeeScalar(baseFeeScalar);
vm.prank(owner);
l2SystemConfig.updateBaseFeeOverhead(baseFeeOverhead);
// Calculate expected L2 base fee
uint256 expectedL2BaseFee = (l1BaseFee * baseFeeScalar) / 1e18 + baseFeeOverhead;
// Test getL2BaseFee function
uint256 actualL2BaseFee = l2SystemConfig.getL2BaseFee(l1BaseFee);
assertEq(actualL2BaseFee, expectedL2BaseFee);
}
function test_GetL2BaseFeeWithZeroL1BaseFee() public {
uint256 l1BaseFee = 0;
uint256 baseFeeScalar = 2000;
uint256 baseFeeOverhead = 1000;
// Set up the contract state
vm.prank(owner);
l2SystemConfig.updateBaseFeeScalar(baseFeeScalar);
vm.prank(owner);
l2SystemConfig.updateBaseFeeOverhead(baseFeeOverhead);
// Calculate expected L2 base fee
uint256 expectedL2BaseFee = baseFeeOverhead; // When L1 base fee is 0, only overhead is added
// Test getL2BaseFee function
uint256 actualL2BaseFee = l2SystemConfig.getL2BaseFee(l1BaseFee);
assertEq(actualL2BaseFee, expectedL2BaseFee);
}
function test_GetL2BaseFeeWithLargeValues() public {
uint256 l1BaseFee = 1e18; // 1 ETH
uint256 baseFeeScalar = 2e18; // 2x multiplier
uint256 baseFeeOverhead = 1e17; // 0.1 ETH
// Set up the contract state
vm.prank(owner);
l2SystemConfig.updateBaseFeeScalar(baseFeeScalar);
vm.prank(owner);
l2SystemConfig.updateBaseFeeOverhead(baseFeeOverhead);
// Calculate expected L2 base fee
uint256 expectedL2BaseFee = (l1BaseFee * baseFeeScalar) / 1e18 + baseFeeOverhead;
// Test getL2BaseFee function
uint256 actualL2BaseFee = l2SystemConfig.getL2BaseFee(l1BaseFee);
assertEq(actualL2BaseFee, expectedL2BaseFee);
}
}