Skip to content

Commit 3e208a3

Browse files
authored
chore: add archive BSC RPC support in test suite (foundry-rs#10004)
* add bnb, currently API keys have not enabled the app * add foundry-rs#9996 test * given BSC archive node is not available, even testnet, workaround by fetching latest excessive gas transaction (system tx) in the latest block and running against that
1 parent 3665ff5 commit 3e208a3

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

crates/cast/tests/cli/main.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,70 @@ casttest!(block_number_hash, |_prj, cmd| {
16761676
assert_eq!(s.trim().parse::<u64>().unwrap(), 1, "{s}")
16771677
});
16781678

1679+
// Tests that `cast --disable-block-gas-limit` commands are working correctly for BSC
1680+
// <https://github.com/foundry-rs/foundry/pull/9996>
1681+
// Equivalent transaction on Binance Smart Chain Testnet:
1682+
// <https://testnet.bscscan.com/tx/0x0db4f279fc4d47dca1e6ace180f45f50c5bf12e2b968f210c217f57031e02744>
1683+
casttest!(run_disable_block_gas_limit_check, |_prj, cmd| {
1684+
let bsc_testnet_rpc_url = next_rpc_endpoint(NamedChain::BinanceSmartChainTestnet);
1685+
1686+
let latest_block_json: serde_json::Value = serde_json::from_str(
1687+
&cmd.args(["block", "--rpc-url", bsc_testnet_rpc_url.as_str(), "--json"])
1688+
.assert_success()
1689+
.get_output()
1690+
.stdout_lossy(),
1691+
)
1692+
.expect("Failed to parse latest block");
1693+
1694+
let latest_excessive_gas_limit_tx =
1695+
latest_block_json["transactions"].as_array().and_then(|txs| {
1696+
txs.iter()
1697+
.find(|tx| tx.get("gas").and_then(|gas| gas.as_str()) == Some("0x7fffffffffffffff"))
1698+
});
1699+
1700+
match latest_excessive_gas_limit_tx {
1701+
Some(tx) => {
1702+
let tx_hash =
1703+
tx.get("hash").and_then(|h| h.as_str()).expect("Transaction missing hash");
1704+
1705+
// If --disable-block-gas-limit is not provided, the transaction should fail as the gas
1706+
// limit exceeds the block gas limit.
1707+
cmd.cast_fuse()
1708+
.args(["run", "-v", tx_hash, "--quick", "--rpc-url", bsc_testnet_rpc_url.as_str()])
1709+
.assert_failure()
1710+
.stderr_eq(str![[r#"
1711+
Error: EVM error; transaction validation error: caller gas limit exceeds the block gas limit
1712+
1713+
"#]]);
1714+
1715+
// If --disable-block-gas-limit is provided, the transaction should succeed
1716+
// despite the gas limit exceeding the block gas limit.
1717+
cmd.cast_fuse()
1718+
.args([
1719+
"run",
1720+
"-v",
1721+
tx_hash,
1722+
"--quick",
1723+
"--rpc-url",
1724+
bsc_testnet_rpc_url.as_str(),
1725+
"--disable-block-gas-limit",
1726+
])
1727+
.assert_success()
1728+
.stdout_eq(str![[r#"
1729+
...
1730+
Transaction successfully executed.
1731+
[GAS]
1732+
1733+
"#]]);
1734+
}
1735+
None => {
1736+
eprintln!(
1737+
"Skipping test: No transaction with gas = 0x7fffffffffffffff found in the latest block."
1738+
);
1739+
}
1740+
}
1741+
});
1742+
16791743
casttest!(send_eip7702, async |_prj, cmd| {
16801744
let (_api, handle) =
16811745
anvil::spawn(NodeConfig::test().with_hardfork(Some(EthereumHardfork::PragueEOF.into())))

crates/forge/tests/it/test_helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ pub fn rpc_endpoints() -> RpcEndpoints {
352352
("optimism", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::Optimism))),
353353
("arbitrum", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::Arbitrum))),
354354
("polygon", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::Polygon))),
355+
("bsc", RpcEndpointUrl::Url(next_rpc_endpoint(NamedChain::BinanceSmartChain))),
355356
("avaxTestnet", RpcEndpointUrl::Url("https://api.avax-test.network/ext/bc/C/rpc".into())),
356357
("moonbeam", RpcEndpointUrl::Url("https://moonbeam-rpc.publicnode.com".into())),
357358
("rpcEnvAlias", RpcEndpointUrl::Env("${RPC_ENV_ALIAS}".into())),

crates/test-utils/src/rpc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use foundry_config::{
44
NamedChain,
5-
NamedChain::{Arbitrum, Base, Mainnet, Optimism, Polygon, Sepolia},
5+
NamedChain::{Arbitrum, Base, BinanceSmartChainTestnet, Mainnet, Optimism, Polygon, Sepolia},
66
};
77
use rand::seq::SliceRandom;
88
use std::sync::{
@@ -178,6 +178,7 @@ fn next_url(is_ws: bool, chain: NamedChain) -> String {
178178
Arbitrum => "arbitrum",
179179
Polygon => "polygon",
180180
Sepolia => "sepolia",
181+
BinanceSmartChainTestnet => "bsc-testnet",
181182
_ => "",
182183
};
183184
format!("lb.drpc.org/ogrpc?network={network}&dkey={key}")

0 commit comments

Comments
 (0)