Skip to content

bug(forge test): forked tests are crashing when using WSS RPC URL #10326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
Abelaby opened this issue Apr 17, 2025 · 4 comments · Fixed by #10327
Closed
2 tasks done

bug(forge test): forked tests are crashing when using WSS RPC URL #10326

Abelaby opened this issue Apr 17, 2025 · 4 comments · Fixed by #10327
Labels
A-releases Area: releases/packaging C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug

Comments

@Abelaby
Copy link

Abelaby commented Apr 17, 2025

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.1.0-nightly Commit SHA: 1da4d32 Build Timestamp: 2025-04-17T06:02:01.528588390Z (1744869721) Build Profile: maxperf

What version of Foundryup are you on?

Commit SHA: 1da4d32 Build Timestamp: 2025-04-17T06:02:01.528588390Z (1744869721) Build Profile: maxperf

What command(s) is the bug in?

forge test

Operating System

Windows

Describe the bug

I'm running in wsl and encountered this issue while running tests for an audit. Foundryup didn't fix the issue. Non fork tests seem to be running fine. Providing console output here.

 forge test --mt testCreationFeeSetter
Warning: This is a nightly build of Foundry. It is recommended to use the latest stable version. Visit https://book.getfoundry.sh/announcements for more information. 
To mute this warning set `FOUNDRY_DISABLE_NIGHTLY_WARNING` in your environment. 

[⠰] Compiling...
No files changed, compilation skipped
The application panicked (crashed).
Message:  no process-level CryptoProvider available -- call CryptoProvider::install_default() before this point
Location: /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rustls-0.23.26/src/crypto/mod.rs:249

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

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 7 frames hidden ⋮                               
   8: core::option::expect_failed::h653f5dbca1fa5fc0
      at <unknown source file>:<unknown line>
   9: rustls::client::client_conn::ClientConfig::builder::hf0ebf99aa8219d6a
      at <unknown source file>:<unknown line>
  10: tokio_tungstenite::tls::encryption::rustls::wrap_stream::{{closure}}::hc6b64d4c9f474e80
      at <unknown source file>:<unknown line>
  11: <alloy_transport_ws::native::WsConnect as alloy_pubsub::connect::PubSubConnect>::connect::{{closure}}::hefa261edce7b5106
      at <unknown source file>:<unknown line>
  12: foundry_common::provider::runtime_transport::RuntimeTransport::request::{{closure}}::h159716b212edebf5
      at <unknown source file>:<unknown line>
  13: <alloy_transport::layers::retry::RetryBackoffService<S,P> as tower_service::Service<alloy_json_rpc::packet::RequestPacket>>::call::{{closure}}::h4af5e38f4e58e099
      at <unknown source file>:<unknown line>
  14: <alloy_rpc_client::call::CallState<Params> as core::future::future::Future>::poll::h21e3d103e36b8476
      at <unknown source file>:<unknown line>
  15: <alloy_provider::provider::prov_call::ProviderCall<Params,Resp,Output,Map> as core::future::future::Future>::poll::hdb13e10bc8267f4b
      at <unknown source file>:<unknown line>
  16: foundry_evm_core::fork::multi::create_fork::{{closure}}::ha2cd5c9837d6b158
      at <unknown source file>:<unknown line>
  17: <foundry_evm_core::fork::multi::MultiForkHandler as core::future::future::Future>::poll::hca0ea01b4960453b
      at <unknown source file>:<unknown line>
  18: std::sys::backtrace::__rust_begin_short_backtrace::h512162b21f5533e8
      at <unknown source file>:<unknown line>
  19: core::ops::function::FnOnce::call_once{{vtable.shim}}::h85533318a00665a9
      at <unknown source file>:<unknown line>
  20: std::sys::pal::unix::thread::Thread::new::thread_start::hcc5ed016d554f327
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
Aborted (core dumped)
@Abelaby Abelaby added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Apr 17, 2025
@github-project-automation github-project-automation bot moved this to Todo in Foundry Apr 17, 2025
@grandizzy
Copy link
Collaborator

@Abelaby can you provide code sample to reproduce? thank you

@yash-atreya
Copy link
Member

@Abelaby can you also confirm whether you're using a WebSocket URL?

@Abelaby
Copy link
Author

Abelaby commented Apr 17, 2025

Hi @grandizzy ,

Using this script

// SPDX-License-Identifier: MIT

pragma solidity 0.8.10;

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

contract ForkTest is Test{

    address internal constant wethAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    IWETH weth;

    function setUp() public{
        
        vm.createSelectFork(
           "mainnet"
        );
        weth = IWETH(wethAddress);
    }

    function testDepositWETH() public{
        address alice = makeAddr("alice");
        vm.deal(alice, 1 ether);

        vm.startPrank(alice);
        IWETH(weth).deposit{value: 1 ether}();
      
    }
}

interface IWETH{
    function deposit() external payable;
    function withdraw(uint wad) external;
    function balanceOf(address owner) external view returns (uint);
}

I'm able to reproduce the issue, I've added my rpc in .env file. And running forge test --mt testDepositWETH -vvvv gives me the issue.

One thing I've noticed is that, this happens only when using public rpc like wss://ethereum-rpc.publicnode.com , wss://sonic.callstaticrpc.com , wss://ws.json-rpc.evm.iotaledger.net. Its perfectly fine if I use my private rpc from providers like alchemy.

@Abelaby
Copy link
Author

Abelaby commented Apr 17, 2025

@yash-atreya yes I was, seems like that was the issue.

@grandizzy grandizzy added A-releases Area: releases/packaging and removed T-needs-triage Type: this issue needs to be labelled labels Apr 17, 2025
@grandizzy grandizzy changed the title Tests are crashing when using forked tests. Tests are crashing when using wss forked tests. Apr 17, 2025
@zerosnacks zerosnacks changed the title Tests are crashing when using wss forked tests. bug(forge test): forked tests are crashing when using WSS RPC URL Apr 17, 2025
@zerosnacks zerosnacks added C-forge Command: forge Cmd-forge-test Command: forge test labels Apr 17, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-releases Area: releases/packaging C-forge Command: forge Cmd-forge-test Command: forge test T-bug Type: bug
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants