foundry: `forge test` crashes with `Message: called Option::unwrap() on a None value`

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (ea2eff9 2024-05-28T00:17:45.727606000Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

The bug lies in the updated Foundry version.

Steps to reproduce:

  1. Clone the repository
git clone https://github.com/exp-table/pigeon
  1. Add your RPC URLs to the .env file
ETH_MAINNET_RPC_URL=
POLYGON_MAINNET_RPC_URL=
ARBITRUM_MAINNET_RPC_URL=

# Optional
ENABLE_CELER_ESTIMATES=true
ENABLE_HYPERLANE_ESTIMATES=false
ENABLE_LZ_ESTIMATES=true
  1. Run the tests using forge test

Logs:

[⠊] Compiling...
No files changed, compilation skipped

Ran 5 tests for test/Celer.t.sol:CelerHelperTest
[PASS] testCustomOrderingCeler() (gas: 108685)
[PASS] testFancyCeler() (gas: 123722)
[PASS] testMultiDstCeler() (gas: 151884)
[PASS] testSimpleCeler() (gas: 72229)
[PASS] testSimpleCelerWithEstimates() (gas: 77270)
Suite result: ok. 5 passed; 0 failed; 0 skipped; finished in 7.69s (1.91s CPU time)

Ran 4 tests for test/Axelar.t.sol:AxelarHelperTest
[PASS] testCustomOrderingAxelar() (gas: 341805)
[PASS] testFancyAxelar() (gas: 236169)
[PASS] testMultiDstAxelar() (gas: 391397)
[PASS] testSimpleAxelar() (gas: 189999)
Suite result: ok. 4 passed; 0 failed; 0 skipped; finished in 11.48s (3.90s CPU time)
The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/revm-9.0.0/src/journaled_state.rs:641

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 8 frames hidden ⋮                               
   9: core::panicking::panic::hc59c8a709a9b37ae
      at <unknown source file>:<unknown line>
  10: core::option::unwrap_failed::h64934fbe08d33633
      at <unknown source file>:<unknown line>
  11: revm::journaled_state::JournaledState::sload::hb292ab2772e652cb
      at <unknown source file>:<unknown line>
  12: <revm::context::Context<EXT,DB> as revm_interpreter::host::Host>::sload::h7c2eadaa276e2317
      at <unknown source file>:<unknown line>
  13: revm_interpreter::instructions::host::sload::h1c9497870d645e6c
      at <unknown source file>:<unknown line>
  14: revm::inspector::handler_register::inspector_instruction::{{closure}}::h03e2dc73635a341d
      at <unknown source file>:<unknown line>
  15: revm::handler::mainnet::execution::execute_frame::h026fc75de773d06f
      at <unknown source file>:<unknown line>
  16: revm::evm::Evm<EXT,DB>::transact::h235456cda0c49183
      at <unknown source file>:<unknown line>
  17: foundry_evm::executors::Executor::call_raw_with_env::he2005afc97600e72
      at <unknown source file>:<unknown line>
  18: foundry_evm::executors::Executor::execute_test::h9cc3b93e2c860177
      at <unknown source file>:<unknown line>
  19: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &F>::call_mut::h44e499dd908e19bc
      at <unknown source file>:<unknown line>
  20: rayon::iter::plumbing::bridge_producer_consumer::helper::h2693959307ecc7a2
      at <unknown source file>:<unknown line>
  21: rayon_core::join::join_context::{{closure}}::h6ffee74b42c8d4bf
      at <unknown source file>:<unknown line>
  22: rayon::iter::plumbing::bridge_producer_consumer::helper::h2693959307ecc7a2
      at <unknown source file>:<unknown line>
  23: rayon_core::join::join_context::{{closure}}::h6ffee74b42c8d4bf
      at <unknown source file>:<unknown line>
  24: rayon::iter::plumbing::bridge_producer_consumer::helper::h2693959307ecc7a2
      at <unknown source file>:<unknown line>
  25: rayon_core::join::join_context::{{closure}}::h6ffee74b42c8d4bf
      at <unknown source file>:<unknown line>
  26: rayon::iter::plumbing::bridge_producer_consumer::helper::h2693959307ecc7a2
      at <unknown source file>:<unknown line>
  27: forge::runner::ContractRunner::run_tests::h1f32def75e6f25bf
      at <unknown source file>:<unknown line>
  28: forge::multi_runner::MultiContractRunner::run_tests::hac520a5a0e7c1729
      at <unknown source file>:<unknown line>
  29: rayon::iter::plumbing::bridge_producer_consumer::helper::h16cdcbd0a900c75f
      at <unknown source file>:<unknown line>
  30: rayon_core::join::join_context::{{closure}}::h3308bff5d566a6dc
      at <unknown source file>:<unknown line>
  31: rayon::iter::plumbing::bridge_producer_consumer::helper::h16cdcbd0a900c75f
      at <unknown source file>:<unknown line>
  32: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute::hbcf434872e4b1d95
      at <unknown source file>:<unknown line>
  33: rayon_core::registry::WorkerThread::wait_until_cold::hc2f2f5c5d2ac906c
      at <unknown source file>:<unknown line>
  34: std::sys_common::backtrace::__rust_begin_short_backtrace::h26c5ce7ae435c375
      at <unknown source file>:<unknown line>
  35: core::ops::function::FnOnce::call_once{{vtable.shim}}::h7359e7db922f9b5d
      at <unknown source file>:<unknown line>
  36: std::sys::pal::unix::thread::Thread::new::thread_start::h9266fbbdd0c3d8be
      at <unknown source file>:<unknown line>
  37: __pthread_joiner_wake<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
zsh: abort      forge test

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (1 by maintainers)

Most upvoted comments

So below, I’ve attached a mock file, which we use for our token bridging simulation. We switch fork and deal tokens to mock a cross-chain bridging action that primarily runs into the same issue. This is a PoC, but we might sometimes need the state of the other fork, so that’s why we cannot use the vm. makePersistent

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";

contract Counter is Test {
    function dealMock(uint256 forkId1, uint256 forkId2) external {
        vm.selectFork(forkId1);
        deal(0xdAC17F958D2ee523a2206206994597C13D831ec7, address(420), 1e18);
        vm.selectFork(forkId2);
    }
}

contract DealTest is Test {
    uint256 forkId1;
    uint256 forkId2;

    Counter counter;

    function setUp() public {
        forkId1 = vm.createFork("https://eth.llamarpc.com");
        forkId2 = vm.createSelectFork("https://binance.llamarpc.com");

        counter = new Counter();
    }

    function test_deal() public {
        counter.dealMock(forkId1, forkId2);
    }
}

IMO any Test contract that manage forks (create / select / roll) should be made persistent,

good point, I think this is the right call. we could autoset it based on the caller?

Oh, right, I think that’s best option, so when fork changed if caller not persistent we autoset it

Thanks for the prompt response. That works, for now, I hope this issue is fixed in the Foundry as it could break the users of the library, too, I assume.

simplified version of test to reproduce issue

contract TestHelper is Test {
    uint256 public curState;

    function changeState(uint256 dstForkId) external {
        uint256 prevForkId = vm.activeFork();
        vm.selectFork(dstForkId);
        curState += 1; // here it crash as when we select dstForkId the state of this contract is reloaded
        vm.selectFork(prevForkId);
    }
}

contract MultipleForksTest is Test {
    uint256 L1_FORK_ID;
    uint256 POLYGON_FORK_ID;
    uint256 ARBITRUM_FORK_ID;

    string RPC_ETH_MAINNET = vm.envString("ETH_MAINNET_RPC_URL");
    string RPC_POLYGON_MAINNET = vm.envString("POLYGON_MAINNET_RPC_URL");
    string RPC_ARBITRUM_MAINNET = vm.envString("ARBITRUM_MAINNET_RPC_URL");

    TestHelper helper;

    function setUp() external {
        L1_FORK_ID = vm.createSelectFork(RPC_ETH_MAINNET);
        helper = new TestHelper();

        POLYGON_FORK_ID = vm.createSelectFork(RPC_POLYGON_MAINNET);

        ARBITRUM_FORK_ID = vm.createSelectFork(RPC_ARBITRUM_MAINNET, 38063686);
    }

    function testHelperContract() external {
        vm.selectFork(L1_FORK_ID);
        helper.changeState(ARBITRUM_FORK_ID);
        vm.selectFork(POLYGON_FORK_ID);
    }
}

@sujithsomraaj please make wormholeHelper persistent for fixing it for the moment

        wormholeHelper = new WormholeHelper();
        vm.makePersistent(address(wormholeHelper));

what likely happens is that since you create / select multiple forks in setup the wormholeHelper is ending up in a different fork env than the active one used when calling vm.load in _prepareWormhole

    function setUp() external {
        L1_FORK_ID = vm.createSelectFork(RPC_ETH_MAINNET);
        wormholeHelper = new WormholeHelper();

        ...

        POLYGON_FORK_ID = vm.createSelectFork(RPC_POLYGON_MAINNET);

        ...

        ARBITRUM_FORK_ID = vm.createSelectFork(RPC_ARBITRUM_MAINNET, 38063686);
       
    }