Skip to content
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

chore: add archive BSC RPC support in test suite #10004

Merged
merged 4 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,70 @@ casttest!(block_number_hash, |_prj, cmd| {
assert_eq!(s.trim().parse::<u64>().unwrap(), 1, "{s}")
});

// Tests that `cast --disable-block-gas-limit` commands are working correctly for BSC
// <https://github.com/foundry-rs/foundry/pull/9996>
// Equivalent transaction on Binance Smart Chain Testnet:
// <https://testnet.bscscan.com/tx/0x0db4f279fc4d47dca1e6ace180f45f50c5bf12e2b968f210c217f57031e02744>
casttest!(run_disable_block_gas_limit_check, |_prj, cmd| {
let bsc_testnet_rpc_url = next_rpc_endpoint(NamedChain::BinanceSmartChainTestnet);

let latest_block_json: serde_json::Value = serde_json::from_str(
&cmd.args(["block", "--rpc-url", bsc_testnet_rpc_url.as_str(), "--json"])
.assert_success()
.get_output()
.stdout_lossy(),
)
.expect("Failed to parse latest block");

let latest_excessive_gas_limit_tx =
latest_block_json["transactions"].as_array().and_then(|txs| {
txs.iter()
.find(|tx| tx.get("gas").and_then(|gas| gas.as_str()) == Some("0x7fffffffffffffff"))
});

match latest_excessive_gas_limit_tx {
Some(tx) => {
let tx_hash =
tx.get("hash").and_then(|h| h.as_str()).expect("Transaction missing hash");

// If --disable-block-gas-limit is not provided, the transaction should fail as the gas
// limit exceeds the block gas limit.
cmd.cast_fuse()
.args(["run", "-v", tx_hash, "--quick", "--rpc-url", bsc_testnet_rpc_url.as_str()])
.assert_failure()
.stderr_eq(str![[r#"
Error: EVM error; transaction validation error: caller gas limit exceeds the block gas limit

"#]]);

// If --disable-block-gas-limit is provided, the transaction should succeed
// despite the gas limit exceeding the block gas limit.
cmd.cast_fuse()
.args([
"run",
"-v",
tx_hash,
"--quick",
"--rpc-url",
bsc_testnet_rpc_url.as_str(),
"--disable-block-gas-limit",
])
.assert_success()
.stdout_eq(str![[r#"
...
Transaction successfully executed.
[GAS]

"#]]);
}
None => {
eprintln!(
"Skipping test: No transaction with gas = 0x7fffffffffffffff found in the latest block."
);
}
}
});

casttest!(send_eip7702, async |_prj, cmd| {
let (_api, handle) =
anvil::spawn(NodeConfig::test().with_hardfork(Some(EthereumHardfork::PragueEOF.into())))
Expand Down
1 change: 1 addition & 0 deletions crates/forge/tests/it/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ pub fn rpc_endpoints() -> RpcEndpoints {
("optimism", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::Optimism))),
("arbitrum", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::Arbitrum))),
("polygon", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::Polygon))),
("bsc", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::BinanceSmartChain))),
("avaxTestnet", RpcEndpointUrl::Url("https://api.avax-test.network/ext/bc/C/rpc".into())),
("moonbeam", RpcEndpointUrl::Url("https://moonbeam-rpc.publicnode.com".into())),
("rpcEnvAlias", RpcEndpointUrl::Env("${RPC_ENV_ALIAS}".into())),
Expand Down
3 changes: 2 additions & 1 deletion crates/test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use foundry_config::{
NamedChain,
NamedChain::{Arbitrum, Base, Mainnet, Optimism, Polygon, Sepolia},
NamedChain::{Arbitrum, Base, BinanceSmartChainTestnet, Mainnet, Optimism, Polygon, Sepolia},
};
use rand::seq::SliceRandom;
use std::sync::{
Expand Down Expand Up @@ -178,6 +178,7 @@ fn next_url(is_ws: bool, chain: NamedChain) -> String {
Arbitrum => "arbitrum",
Polygon => "polygon",
Sepolia => "sepolia",
BinanceSmartChainTestnet => "bsc-testnet",
_ => "",
};
format!("lb.drpc.org/ogrpc?network={network}&dkey={key}")
Expand Down