diff --git a/test/foundry/ERC20RollupEventInbox.t.sol b/test/foundry/ERC20RollupEventInbox.t.sol index 008e3f6d..1fde0922 100644 --- a/test/foundry/ERC20RollupEventInbox.t.sol +++ b/test/foundry/ERC20RollupEventInbox.t.sol @@ -15,6 +15,12 @@ import {ERC20PresetMinterPauser} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"; contract ERC20RollupEventInboxTest is AbsRollupEventInboxTest { + // 7 gwei basefee + uint256 public constant L2_BASEFEE = 7_000_000_000; + + // 80 gwei L1 basefee + uint256 public constant L1_BASEFEE = 80_000_000_000; + function setUp() public { rollupEventInbox = IRollupEventInbox(TestUtil.deployProxy(address(new ERC20RollupEventInbox()))); @@ -107,18 +113,76 @@ contract ERC20RollupEventInboxTest is AbsRollupEventInboxTest { rollupEventInbox.rollupInitialized(chainId, chainConfig); } + function testFuzz_rollupInitialized(uint256 exchangeRate) public { + _setSequencerInbox(true); + + uint256 chainId = 500; + string memory chainConfig = "chainConfig2"; + + // check if call will overflow due to too high exchange rate + bool expectedToOverflow = false; + { + unchecked { + uint256 mul = (L1_BASEFEE + L2_BASEFEE) * exchangeRate; + if (exchangeRate != 0 && ((mul / exchangeRate) != (L1_BASEFEE + L2_BASEFEE))) { + expectedToOverflow = true; + } + } + } + + if (expectedToOverflow) { + vm.mockCall( + address( + ISequencerInbox(rollupEventInbox.bridge().sequencerInbox()).feeTokenPricer() + ), + abi.encodeWithSelector(IFeeTokenPricer.getExchangeRate.selector), + abi.encode(exchangeRate) + ); + vm.mockCall( + address(0x6c), + abi.encodeWithSignature("getL1BaseFeeEstimate()"), + abi.encode(L1_BASEFEE) + ); + vm.fee(L2_BASEFEE); + vm.expectRevert(stdError.arithmeticError); + } else { + uint8 expectedInitMsgVersion = 1; + uint256 expectedCurrentDataCost = _calculateExpectedCurrentDataCost(exchangeRate, true); + bytes memory expectedInitMsg = abi.encodePacked( + chainId, expectedInitMsgVersion, expectedCurrentDataCost, chainConfig + ); + + // expect event + vm.expectEmit(true, true, true, true); + emit MessageDelivered( + 0, + bytes32(0), + address(rollupEventInbox), + INITIALIZATION_MSG_TYPE, + address(0), + keccak256(expectedInitMsg), + uint256(0), + uint64(block.timestamp) + ); + + vm.expectEmit(true, true, true, true); + emit InboxMessageDelivered(0, expectedInitMsg); + } + + vm.prank(rollup); + rollupEventInbox.rollupInitialized(chainId, chainConfig); + } + function _calculateExpectedCurrentDataCost(uint256 exchangeRate, bool isArbHosted) internal returns (uint256) { - // 7 gwei basefee - uint256 l2Fee = 7_000_000_000; + uint256 l2Fee = L2_BASEFEE; vm.fee(l2Fee); uint256 l1Fee = 0; if (isArbHosted) { - // 80 gwei L1 basefee - l1Fee = 80_000_000_000; + l1Fee = L1_BASEFEE; vm.mockCall( address(0x6c), abi.encodeWithSignature("getL1BaseFeeEstimate()"), abi.encode(l1Fee) );