forked from scroll-tech/scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL2GasPriceOracle.t.sol
62 lines (47 loc) · 2.24 KB
/
L2GasPriceOracle.t.sol
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
// SPDX-License-Identifier: MIT
pragma solidity =0.8.16;
import {DSTestPlus} from "solmate/test/utils/DSTestPlus.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {L2GasPriceOracle} from "../L1/rollup/L2GasPriceOracle.sol";
import {Whitelist} from "../L2/predeploys/Whitelist.sol";
contract L2GasPriceOracleTest is DSTestPlus {
L2GasPriceOracle private oracle;
Whitelist private whitelist;
uint256 fee;
event Log(address addr);
function setUp() public {
whitelist = new Whitelist(address(this));
oracle = L2GasPriceOracle(address(new ERC1967Proxy(address(new L2GasPriceOracle()), new bytes(0))));
oracle.initialize(1, 2, 1, 1);
oracle.updateWhitelist(address(whitelist));
address[] memory _accounts = new address[](1);
_accounts[0] = address(this);
whitelist.updateWhitelistStatus(_accounts, true);
}
function testCalculateIntrinsicGasFee() external {
uint256 intrinsicGasFee = oracle.calculateIntrinsicGasFee(hex"00");
assertEq(intrinsicGasFee, 2);
uint64 zeroGas = 5;
uint64 nonZeroGas = 10;
oracle.setIntrinsicParams(20000, 50000, zeroGas, nonZeroGas);
intrinsicGasFee = oracle.calculateIntrinsicGasFee(hex"001122");
// 20000 + 1 zero bytes * 5 + 2 nonzero byte * 10 = 20025
assertEq(intrinsicGasFee, 20025);
zeroGas = 50;
nonZeroGas = 100;
oracle.setIntrinsicParams(10000, 20000, zeroGas, nonZeroGas);
intrinsicGasFee = oracle.calculateIntrinsicGasFee(hex"0011220033");
// 10000 + 3 nonzero byte * 100 + 2 zero bytes * 50 = 10000 + 300 + 100 = 10400
assertEq(intrinsicGasFee, 10400);
}
function testSetIntrinsicParamsAccess() external {
hevm.startPrank(address(4));
hevm.expectRevert("Ownable: caller is not the owner");
oracle.setIntrinsicParams(1, 0, 0, 1);
}
// forge t --match-contract L2GasPriceOracleTest --match-test testBenchmark --gas-report
// function testBenchmark() external {
// // 50 bytes
// fee = oracle.calculateIntrinsicGasFee(hex"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
// }
}