Skip to content

Commit

Permalink
chore: move foundry_common::rpc to foundry_test_utils (#7707)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Apr 18, 2024
1 parent 1c59fcc commit d1d0478
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 44 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ path = "src/anvil.rs"
required-features = ["cli"]

[build-dependencies]
vergen = { workspace = true, default-features = false, features = [
"build",
"git",
"gitcl",
] }
vergen = { workspace = true, default-features = false, features = ["build", "git", "gitcl"] }

[dependencies]
# foundry internal
Expand Down Expand Up @@ -81,11 +77,7 @@ rand = "0.8"
eyre.workspace = true

# cli
clap = { version = "4", features = [
"derive",
"env",
"wrap_help",
], optional = true }
clap = { version = "4", features = ["derive", "env", "wrap_help"], optional = true }
clap_complete = { version = "4", optional = true }
chrono.workspace = true
auto_impl = "1"
Expand All @@ -102,8 +94,9 @@ alloy-json-abi.workspace = true
ethers = { workspace = true, features = ["abigen", "optimism"] }
ethers-core = { workspace = true, features = ["optimism"] }
foundry-compilers = { workspace = true, features = ["project-util", "full"] }
foundry-test-utils.workspace = true

pretty_assertions = "1.3.0"
pretty_assertions.workspace = true
tokio = { version = "1", features = ["full"] }
crc = "3.0.1"

Expand Down
3 changes: 1 addition & 2 deletions crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ use ethers::{
};
use foundry_common::{
provider::alloy::get_http_provider,
rpc,
rpc::next_http_rpc_endpoint,
types::{ToAlloy, ToEthers},
};
use foundry_config::Config;
use foundry_test_utils::rpc::{self, next_http_rpc_endpoint};
use futures::StreamExt;
use std::{sync::Arc, time::Duration};

Expand Down
7 changes: 5 additions & 2 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Contains various tests for checking cast commands
use foundry_common::rpc::{next_http_rpc_endpoint, next_ws_rpc_endpoint};
use foundry_test_utils::{casttest, util::OutputExt};
use foundry_test_utils::{
casttest,
rpc::{next_http_rpc_endpoint, next_ws_rpc_endpoint},
util::OutputExt,
};
use std::{fs, io::Write, path::Path};

// tests `--help` is printed to std out
Expand Down
8 changes: 1 addition & 7 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ reqwest_ethers = { package = "reqwest", version = "0.11", default-features = fal

alloy-dyn-abi = { workspace = true, features = ["arbitrary", "eip712"] }
alloy-json-abi.workspace = true
alloy-primitives = { workspace = true, features = [
"serde",
"getrandom",
"arbitrary",
"rlp",
] }
alloy-primitives = { workspace = true, features = ["serde", "getrandom", "arbitrary", "rlp"] }
alloy-rpc-types.workspace = true
alloy-rpc-client.workspace = true
alloy-provider.workspace = true
Expand All @@ -55,7 +50,6 @@ glob = "0.3"
globset = "0.4"
hex.workspace = true
once_cell = "1"
rand.workspace = true
reqwest = { version = "0.12", default-features = false }
semver = "1"
serde_json.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub mod fs;
pub mod glob;
pub mod provider;
pub mod retry;
pub mod rpc;
pub mod runtime_client;
pub mod selectors;
pub mod serde_helpers;
Expand Down
10 changes: 4 additions & 6 deletions crates/evm/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ foundry-macros.workspace = true

alloy-dyn-abi = { workspace = true, features = ["arbitrary", "eip712"] }
alloy-json-abi.workspace = true
alloy-primitives = { workspace = true, features = [
"serde",
"getrandom",
"arbitrary",
"rlp",
] }
alloy-primitives = { workspace = true, features = ["serde", "getrandom", "arbitrary", "rlp"] }
alloy-genesis.workspace = true
alloy-provider.workspace = true
alloy-transport.workspace = true
Expand Down Expand Up @@ -59,3 +54,6 @@ thiserror = "1"
tokio = { version = "1", features = ["time", "macros"] }
tracing = "0.1"
url = "2"

[dev-dependencies]
foundry-test-utils.workspace = true
2 changes: 1 addition & 1 deletion crates/evm/core/src/fork/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ mod tests {
/// `AccountInfo`
#[tokio::test(flavor = "multi_thread")]
async fn fork_db_insert_basic_default() {
let rpc = foundry_common::rpc::next_http_rpc_endpoint();
let rpc = foundry_test_utils::rpc::next_http_rpc_endpoint();
let provider = get_http_provider(rpc.clone());
let meta = BlockchainDbMeta {
cfg_env: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ impl EtherscanClient for Client {
#[cfg(test)]
mod tests {
use super::*;
use foundry_common::rpc::next_etherscan_api_key;
use foundry_compilers::Artifact;
use foundry_test_utils::rpc::next_etherscan_api_key;
use hex::ToHex;
use std::collections::BTreeMap;

Expand Down
4 changes: 2 additions & 2 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Contains various tests for checking forge's commands
use crate::constants::*;
use foundry_common::rpc::next_etherscan_api_key;
use foundry_compilers::{artifacts::Metadata, remappings::Remapping, ConfigurableContractArtifact};
use foundry_config::{parse_with_profile, BasicConfig, Chain, Config, SolidityErrorCode};
use foundry_test_utils::{
foundry_compilers::PathStyle,
rpc::next_etherscan_api_key,
util::{pretty_err, read_string, OutputExt, TestCommand},
};
use semver::Version;
Expand Down Expand Up @@ -796,7 +796,7 @@ forgetest!(
.to_string();
println!("project root: \"{root}\"");

let eth_rpc_url = foundry_common::rpc::next_http_archive_rpc_endpoint();
let eth_rpc_url = foundry_test_utils::rpc::next_http_archive_rpc_endpoint();
let dss_exec_lib = "src/DssSpell.sol:DssExecLib:0xfD88CeE74f7D78697775aBDAE53f9Da1559728E4";

cmd.args([
Expand Down
5 changes: 2 additions & 3 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use crate::constants::TEMPLATE_CONTRACT;
use alloy_primitives::{Address, Bytes};
use anvil::{spawn, NodeConfig};
use foundry_common::rpc;
use foundry_test_utils::{util::OutputExt, ScriptOutcome, ScriptTester};
use foundry_test_utils::{rpc, util::OutputExt, ScriptOutcome, ScriptTester};
use regex::Regex;
use serde_json::Value;
use std::{env, path::PathBuf, str::FromStr};
Expand Down Expand Up @@ -32,7 +31,7 @@ contract ContractScript is Script {
)
.unwrap();

let rpc = foundry_common::rpc::next_http_rpc_endpoint();
let rpc = foundry_test_utils::rpc::next_http_rpc_endpoint();

cmd.arg("script").arg(script).args(["--fork-url", rpc.as_str(), "-vvvvv"]).assert_success();
}
Expand Down
9 changes: 6 additions & 3 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Contains various tests for checking `forge test`
use foundry_common::rpc;
//! Contains various tests for `forge test`.
use foundry_config::Config;
use foundry_test_utils::util::{OutputExt, OTHER_SOLC_VERSION, SOLC_VERSION};
use foundry_test_utils::{
rpc,
util::{OutputExt, OTHER_SOLC_VERSION, SOLC_VERSION},
};
use std::{path::PathBuf, str::FromStr};

// tests that test filters are handled correctly
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/tests/it/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn test_rpc_fork() {
/// Tests that we can launch in forking mode
#[tokio::test(flavor = "multi_thread")]
async fn test_launch_fork() {
let rpc_url = foundry_common::rpc::next_http_archive_rpc_endpoint();
let rpc_url = foundry_test_utils::rpc::next_http_archive_rpc_endpoint();
let runner = TEST_DATA_DEFAULT.forked_runner(&rpc_url).await;
let filter = Filter::new(".*", ".*", &format!(".*fork{RE_PATH_SEPARATOR}Launch"));
TestConfig::with_filter(runner, filter).run().await;
Expand All @@ -75,7 +75,7 @@ async fn test_launch_fork() {
/// Smoke test that forking workings with websockets
#[tokio::test(flavor = "multi_thread")]
async fn test_launch_fork_ws() {
let rpc_url = foundry_common::rpc::next_ws_archive_rpc_endpoint();
let rpc_url = foundry_test_utils::rpc::next_ws_archive_rpc_endpoint();
let runner = TEST_DATA_DEFAULT.forked_runner(&rpc_url).await;
let filter = Filter::new(".*", ".*", &format!(".*fork{RE_PATH_SEPARATOR}Launch"));
TestConfig::with_filter(runner, filter).run().await;
Expand Down
1 change: 1 addition & 0 deletions crates/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ serde_json.workspace = true
tracing = "0.1"
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }
walkdir = "2"
rand.workspace = true

[features]
# feature for integration tests that test external projects
Expand Down
2 changes: 2 additions & 0 deletions crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ extern crate tracing;
// Macros useful for testing.
mod macros;

pub mod rpc;

pub mod fd_lock;

mod filter;
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions crates/test-utils/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ impl ExtTester {

test_cmd.envs(self.envs.iter().map(|(k, v)| (k, v)));
if let Some(fork_block) = self.fork_block {
test_cmd
.env("FOUNDRY_ETH_RPC_URL", foundry_common::rpc::next_http_archive_rpc_endpoint());
test_cmd.env("FOUNDRY_ETH_RPC_URL", crate::rpc::next_http_archive_rpc_endpoint());
test_cmd.env("FOUNDRY_FORK_BLOCK_NUMBER", fork_block.to_string());
}

Expand Down

0 comments on commit d1d0478

Please sign in to comment.