foundry
foundry copied to clipboard
Arbitrum fork can't fork Arbitrum block number on tests
Component
Forge
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
What version of Foundry are you on?
forge 0.2.0 (b174c3a 2024-02-09T00:19:10.198273000Z)
What command(s) is the bug in?
forge test
Operating System
macOS (Apple Silicon)
Describe the bug
I'm trying to use an Arbitrum fork in my tests, but I can't set the block number.
For some reason instead of using the arbitrum block number that I'm passing it, it is using a different block number. It recognizes the chainId change to Arbitrum but not the block number.
I'm simply running forge test -vv
because the instructions for the fork are indicated inside the setup() function
I'm thinking this might be an issue with foundry
Sample code to reproduce the error
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import "forge-std/Test.sol";
contract SomeTest is Test {
function setUp() external {
console.log("1block.chainid:", block.chainid);
console.log("1block.number:", block.number);
console.log("1block.timestamp:", block.timestamp);
vm.createSelectFork(vm.envString("RPC_ARB_MAINNET"), 179_639_839);
console.log("2block.chainid:", block.chainid); // This must be 179_639_839 but it isn't
console.log("2block.number:", block.number);
console.log("2block.timestamp:", block.timestamp);
}
function test_ArbitrumBlockNumber() public {
console.log("Something");
}
}
that's by intent the L1 block see https://github.com/foundry-rs/foundry/blob/master/crates/evm/core/src/utils.rs#L70C1-L75C41
// on arbitrum `block.number` is the L1 block which is included in the
// `l1BlockNumber` field
that's by intent the L1 block see https://github.com/foundry-rs/foundry/blob/master/crates/evm/core/src/utils.rs#L70C1-L75C41
// on arbitrum `block.number` is the L1 block which is included in the // `l1BlockNumber` field
If that is intentional how can I run tests on an arbitrum fork (with a specific arbitrum block) because it overrides the value with the mainnet block?
Or how can I disable that behavior, I don't need the Ethereum block, I need the arbitrum block.
Also is there any explanation of why this override of the block number is needed? Why if I'm testing arbitrum it changes to Ethereum blocks?
that's by intent the L1 block see https://github.com/foundry-rs/foundry/blob/master/crates/evm/core/src/utils.rs#L70C1-L75C41
// on arbitrum `block.number` is the L1 block which is included in the // `l1BlockNumber` field
If that is intentional how can I run tests on an arbitrum fork (with a specific arbitrum block) because it overrides the value with the mainnet block?
Or how can I disable that behavior, I don't need the Ethereum block, I need the arbitrum block.
Also is there any explanation of why this override of the block number is needed? Why if I'm testing arbitrum it changes to Ethereum blocks?
I think you would need to test your contracts with correct chain behaviour https://docs.arbitrum.io/for-devs/concepts/differences-between-arbitrum-ethereum/block-numbers-and-time#ethereum-block-numbers-within-arbitrum
Marking as duplicate of https://github.com/foundry-rs/foundry/issues/5085