github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/test/legacy/L1BlockNumber.t.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 // Testing utilities 5 import { Test } from "forge-std/Test.sol"; 6 7 // Target contract dependencies 8 import { L1Block } from "src/L2/L1Block.sol"; 9 import { Predeploys } from "src/libraries/Predeploys.sol"; 10 11 // Target contract 12 import { L1BlockNumber } from "src/legacy/L1BlockNumber.sol"; 13 14 contract L1BlockNumberTest is Test { 15 L1Block lb; 16 L1BlockNumber bn; 17 18 uint64 constant number = 99; 19 20 /// @dev Sets up the test suite. 21 function setUp() external { 22 vm.etch(Predeploys.L1_BLOCK_ATTRIBUTES, address(new L1Block()).code); 23 lb = L1Block(Predeploys.L1_BLOCK_ATTRIBUTES); 24 bn = new L1BlockNumber(); 25 vm.prank(lb.DEPOSITOR_ACCOUNT()); 26 27 lb.setL1BlockValues({ 28 _number: number, 29 _timestamp: uint64(2), 30 _basefee: 3, 31 _hash: bytes32(uint256(10)), 32 _sequenceNumber: uint64(4), 33 _batcherHash: bytes32(uint256(0)), 34 _l1FeeOverhead: 2, 35 _l1FeeScalar: 3 36 }); 37 } 38 39 /// @dev Tests that `getL1BlockNumber` returns the set block number. 40 function test_getL1BlockNumber_succeeds() external { 41 assertEq(bn.getL1BlockNumber(), number); 42 } 43 44 /// @dev Tests that `fallback` is correctly dispatched. 45 function test_fallback_succeeds() external { 46 (bool success, bytes memory ret) = address(bn).call(hex""); 47 assertEq(success, true); 48 assertEq(ret, abi.encode(number)); 49 } 50 51 /// @dev Tests that `receive` is correctly dispatched. 52 function test_receive_succeeds() external { 53 (bool success, bytes memory ret) = address(bn).call{ value: 1 }(hex""); 54 assertEq(success, true); 55 assertEq(ret, abi.encode(number)); 56 } 57 }