Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed Nov 11, 2024
1 parent f3a1332 commit dea7856
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
31 changes: 29 additions & 2 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use anvil::{EthereumHardfork, NodeConfig};
use foundry_test_utils::{
casttest, file,
rpc::{
next_http_rpc_endpoint, next_mainnet_etherscan_api_key, next_rpc_endpoint,
next_ws_rpc_endpoint,
next_etherscan_api_key, next_http_rpc_endpoint, next_mainnet_etherscan_api_key,
next_rpc_endpoint, next_ws_rpc_endpoint,
},
str,
util::OutputExt,
Expand Down Expand Up @@ -1503,3 +1503,30 @@ casttest!(fetch_constructor_args_from_etherscan, |_prj, cmd| {
"#]]);
});

// <https://github.com/foundry-rs/foundry/issues/3473>
casttest!(test_non_mainnet_traces, |_prj, cmd| {
cmd.args([
"run",
"0x8346762a8c1d7ce70be23c1b68ff920ffb6bca8fd62323e6c1d108f209e0b45d",
"--rpc-url",
next_rpc_endpoint(NamedChain::Optimism).as_str(),
"--etherscan-api-key",
next_etherscan_api_key(NamedChain::Optimism).as_str(),
])
.assert_success()
.stdout_eq(str![[r#"
Executing previous transactions from the block.
Traces:
[429891] FuturesMarket::modifyPositionWithTracking(79573547589616810 [7.957e16], 0x4b57454e54410000000000000000000000000000000000000000000000000000)
├─ [9111] SystemStatus::requireFuturesMarketActive(0x7345544800000000000000000000000000000000000000000000000000000000) [staticcall]
│ └─ ← [Stop]
├─ [2789] SystemStatus::requireSynthActive(0x7345544800000000000000000000000000000000000000000000000000000000) [staticcall]
│ └─ ← [Stop]
├─ [70705] ExchangeCircuitBreaker::rateWithBreakCircuit(0x7345544800000000000000000000000000000000000000000000000000000000)
│ ├─ [399] SystemStatus::systemSuspended() [staticcall]
│ │ └─ ← [Return] false
...
"#]]);
});
16 changes: 15 additions & 1 deletion crates/test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! RPC API keys utilities.
use foundry_config::NamedChain;
use foundry_config::{NamedChain, NamedChain::Optimism};
use rand::seq::SliceRandom;
use std::sync::{
atomic::{AtomicUsize, Ordering},
Expand Down Expand Up @@ -75,6 +75,10 @@ static ETHERSCAN_MAINNET_KEYS: LazyLock<Vec<&'static str>> = LazyLock::new(|| {
keys
});

// List of etherscan keys for Optimisim

Check failure on line 78 in crates/test-utils/src/rpc.rs

View workflow job for this annotation

GitHub Actions / codespell

Optimisim ==> Optimism
static ETHERSCAN_OPTIMISM_KEYS: LazyLock<Vec<&'static str>> =
LazyLock::new(|| vec!["JQNGFHINKS1W7Y5FRXU4SPBYF43J3NYK46"]);

/// Returns the next index to use.
fn next() -> usize {
static NEXT_INDEX: AtomicUsize = AtomicUsize::new(0);
Expand Down Expand Up @@ -127,6 +131,16 @@ pub fn next_mainnet_etherscan_api_key() -> String {
ETHERSCAN_MAINNET_KEYS[idx].to_string()
}

/// Returns the next etherscan api key for given chain.
pub fn next_etherscan_api_key(chain: NamedChain) -> String {
let keys = match chain {
Optimism => &ETHERSCAN_OPTIMISM_KEYS,
_ => &ETHERSCAN_MAINNET_KEYS,
};
let idx = next() % keys.len();
keys[idx].to_string()
}

fn next_url(is_ws: bool, chain: NamedChain) -> String {
use NamedChain::*;

Expand Down

0 comments on commit dea7856

Please sign in to comment.