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: dedup abi values formatting, cleanups #6196

Merged
merged 8 commits into from
Nov 2, 2023
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
2 changes: 0 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use ethers::{
utils::{hex, keccak256, rlp},
};
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
use foundry_common::abi::format_token;
use foundry_common::fmt::format_token;
use foundry_evm::{
backend::{DatabaseError, DatabaseResult},
constants::DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE,
Expand Down
20 changes: 9 additions & 11 deletions crates/anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,22 @@ impl NodeHandle {
self.config.get_ipc_path()
}

/// Returns a Provider for the http endpoint
/// Constructs a [`RetryProvider`] for this handle's HTTP endpoint.
pub fn http_provider(&self) -> RetryProvider {
ProviderBuilder::new(self.http_endpoint())
ProviderBuilder::new(&self.http_endpoint())
.build()
.expect("Failed to connect using http provider")
.expect("failed to build HTTP provider")
.interval(Duration::from_millis(500))
}

/// Connects to the websocket Provider of the node
pub async fn ws_provider(&self) -> RetryProvider {
ProviderBuilder::new(self.ws_endpoint())
.build()
.expect("Failed to connect to node's websocket")
/// Constructs a [`RetryProvider`] for this handle's WS endpoint.
pub fn ws_provider(&self) -> RetryProvider {
ProviderBuilder::new(&self.ws_endpoint()).build().expect("failed to build WS provider")
}

/// Connects to the ipc endpoint of the node, if spawned
pub async fn ipc_provider(&self) -> Option<RetryProvider> {
ProviderBuilder::new(self.config.get_ipc_path()?).build().ok()
/// Constructs a [`RetryProvider`] for this handle's IPC endpoint, if any.
pub fn ipc_provider(&self) -> Option<RetryProvider> {
ProviderBuilder::new(&self.config.get_ipc_path()?).build().ok()
}

/// Signer accounts that can sign messages/transactions from the EVM node
Expand Down
7 changes: 3 additions & 4 deletions crates/anvil/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ impl TaskManager {
/// block
///
/// ```
/// use std::sync::Arc;
/// use anvil::{spawn, NodeConfig};
/// use ethers::providers::Provider;
/// use anvil::{NodeConfig, spawn};
/// use std::sync::Arc;
/// # async fn t() {
/// let endpoint = "http://....";
/// let (api, handle) = spawn(NodeConfig::default().with_eth_rpc_url(Some(endpoint))).await;
///
/// let provider = Arc::new(Provider::try_from(endpoint).unwrap());
///
/// handle.task_manager().spawn_reset_on_new_polled_blocks(provider, api);
///
/// # }
/// ```
pub fn spawn_reset_on_new_polled_blocks<P>(&self, provider: P, api: EthApi)
Expand Down Expand Up @@ -106,8 +105,8 @@ impl TaskManager {
/// block
///
/// ```
/// use anvil::{spawn, NodeConfig};
/// use ethers::providers::Provider;
/// use anvil::{NodeConfig, spawn};
/// # async fn t() {
/// let (api, handle) = spawn(NodeConfig::default().with_eth_rpc_url(Some("http://...."))).await;
///
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/tests/it/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn can_get_block_number_ipc() {
let block_num = api.block_number().unwrap();
assert_eq!(block_num, U256::zero());

let provider = handle.ipc_provider().await.unwrap();
let provider = handle.ipc_provider().unwrap();

let num = provider.get_block_number().await.unwrap();
assert_eq!(num, block_num.as_u64().into());
Expand All @@ -34,7 +34,7 @@ async fn can_get_block_number_ipc() {
async fn test_sub_new_heads_ipc() {
let (api, handle) = spawn(ipc_config()).await;

let provider = handle.ipc_provider().await.unwrap();
let provider = handle.ipc_provider().unwrap();

let blocks = provider.subscribe_blocks().await.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async fn watch_events() {
let mut stream = event.stream().await.unwrap();

// Also set up a subscription for the same thing
let ws = Arc::new(handle.ws_provider().await);
let ws = Arc::new(handle.ws_provider());
let contract2 = SimpleStorage::new(contract.address(), ws);
let event2 = contract2.event::<ValueChanged>();
let mut subscription = event2.subscribe().await.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions crates/anvil/tests/it/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down Expand Up @@ -180,7 +180,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down Expand Up @@ -284,7 +284,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down Expand Up @@ -373,7 +373,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let client = Arc::new(SignerMiddleware::new(provider, wallet));
Expand Down
10 changes: 5 additions & 5 deletions crates/anvil/tests/it/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::sync::Arc;
async fn test_sub_new_heads() {
let (api, handle) = spawn(NodeConfig::test()).await;

let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let blocks = provider.subscribe_blocks().await.unwrap();

Expand All @@ -34,7 +34,7 @@ async fn test_sub_logs_legacy() {
abigen!(EmitLogs, "test-data/emit_logs.json");

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let client = Arc::new(SignerMiddleware::new(provider, wallet));
Expand Down Expand Up @@ -73,7 +73,7 @@ async fn test_sub_logs() {
abigen!(EmitLogs, "test-data/emit_logs.json");

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let client = Arc::new(SignerMiddleware::new(provider, wallet));
Expand Down Expand Up @@ -111,7 +111,7 @@ async fn test_sub_logs_impersonated() {
abigen!(EmitLogs, "test-data/emit_logs.json");

let (api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

// impersonate account
let impersonate = Address::random();
Expand Down Expand Up @@ -253,7 +253,7 @@ async fn test_subscriptions() {
async fn test_sub_new_heads_fast() {
let (api, handle) = spawn(NodeConfig::test()).await;

let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let blocks = provider.subscribe_blocks().await.unwrap();

Expand Down
10 changes: 5 additions & 5 deletions crates/anvil/tests/it/revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let client = Arc::new(SignerMiddleware::new(provider, wallet));
Expand Down Expand Up @@ -75,7 +75,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down Expand Up @@ -107,7 +107,7 @@ async fn test_solc_revert_example() {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down Expand Up @@ -161,7 +161,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down Expand Up @@ -208,7 +208,7 @@ contract Contract {

let (_api, handle) = spawn(NodeConfig::test()).await;

let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/tests/it/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down Expand Up @@ -119,7 +119,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();
let wallets = handle.dev_wallets().collect::<Vec<_>>();
let client = Arc::new(SignerMiddleware::new(provider, wallets[0].clone()));

Expand Down
12 changes: 6 additions & 6 deletions crates/anvil/tests/it/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ async fn can_call_greeter_historic() {
#[tokio::test(flavor = "multi_thread")]
async fn can_deploy_greeter_ws() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let client = Arc::new(SignerMiddleware::new(provider, wallet));
Expand All @@ -382,7 +382,7 @@ async fn can_deploy_greeter_ws() {
#[tokio::test(flavor = "multi_thread")]
async fn can_deploy_get_code() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let client = Arc::new(SignerMiddleware::new(provider, wallet));
Expand Down Expand Up @@ -496,7 +496,7 @@ async fn call_past_state() {
async fn can_handle_multiple_concurrent_transfers_with_same_nonce() {
let (_api, handle) = spawn(NodeConfig::test()).await;

let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let accounts: Vec<_> = handle.dev_wallets().collect();
let from = accounts[0].address();
Expand Down Expand Up @@ -526,7 +526,7 @@ async fn can_handle_multiple_concurrent_transfers_with_same_nonce() {
#[tokio::test(flavor = "multi_thread")]
async fn can_handle_multiple_concurrent_deploys_with_same_nonce() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let from = wallet.address();
Expand Down Expand Up @@ -560,7 +560,7 @@ async fn can_handle_multiple_concurrent_deploys_with_same_nonce() {
#[tokio::test(flavor = "multi_thread")]
async fn can_handle_multiple_concurrent_transactions_with_same_nonce() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let wallet = handle.dev_wallets().next().unwrap();
let from = wallet.address();
Expand Down Expand Up @@ -778,7 +778,7 @@ async fn can_stream_pending_transactions() {
spawn(NodeConfig::test().with_blocktime(Some(Duration::from_secs(2)))).await;
let num_txs = 5;
let provider = handle.http_provider();
let ws_provider = handle.ws_provider().await;
let ws_provider = handle.ws_provider();

let accounts = provider.get_accounts().await.unwrap();
let tx = TransactionRequest::new().from(accounts[0]).to(accounts[0]).value(1e18 as u64);
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/tests/it/wsapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async fn can_get_block_number_ws() {
let block_num = api.block_number().unwrap();
assert_eq!(block_num, U256::zero());

let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let num = provider.get_block_number().await.unwrap();
assert_eq!(num, block_num.as_u64().into());
Expand All @@ -18,7 +18,7 @@ async fn can_get_block_number_ws() {
#[tokio::test(flavor = "multi_thread")]
async fn can_dev_get_balance_ws() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ws_provider().await;
let provider = handle.ws_provider();

let genesis_balance = handle.genesis_balance();
for acc in handle.genesis_accounts() {
Expand Down
37 changes: 15 additions & 22 deletions crates/binder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,21 @@ impl Binder {
///
/// # Example
///
/// ## Local repository
/// Local repository:
///
/// ```
/// # use foundry_binder::Binder;
/// # fn new() {
/// let binder = Binder::new("./aave-v3-core");
/// # }
/// use foundry_binder::Binder;
///
/// let binder = Binder::new("./aave-v3-core");
/// ```
///
/// ## Remote repository with default branch
/// Remote repository with default branch:
///
/// ```
/// # use url::Url;
/// use foundry_binder::Binder;
/// # fn new() {
/// let binder = Binder::new(Url::parse("https://github.com/aave/aave-v3-core").unwrap());
/// # }
/// use url::Url;
///
/// let binder = Binder::new(Url::parse("https://github.com/aave/aave-v3-core").unwrap());
/// ```
pub fn new(location: impl Into<SourceLocation>) -> Self {
Self {
Expand All @@ -76,14 +74,14 @@ impl Binder {
/// Add a `yarn install` command
///
/// ```
/// # use url::Url;
/// use foundry_binder::{Binder, RepositoryBuilder};
/// # fn new() {
/// use url::Url;
///
/// let binder = Binder::new(
/// RepositoryBuilder::new(Url::parse("https://github.com/aave/aave-v3-core").unwrap())
/// .tag("v1.16.0"),
/// ).command(["yarn", "install"]);
/// # }
/// )
/// .command(["yarn", "install"]);
/// ```
#[must_use]
pub fn command<I, S>(mut self, cmd: I) -> Self
Expand Down Expand Up @@ -122,20 +120,15 @@ impl Binder {
/// ## Example
///
/// ```
/// # use url::Url;
/// use foundry_binder::{Binder, Config, RepositoryBuilder};
/// # fn new() {
/// use url::Url;
///
/// let binder = Binder::new(
/// RepositoryBuilder::new(Url::parse("https://github.com/aave/aave-v3-core").unwrap())
/// .tag("v1.16.0"),
/// )
/// .command(["yarn", "install"])
/// .config(Config {
/// src: "src".into(),
/// out: "artifacts".into(),
/// ..Default::default()
/// });
/// # }
/// .config(Config { src: "src".into(), out: "artifacts".into(), ..Default::default() });
/// ```
#[must_use]
pub fn config(mut self, config: Config) -> Self {
Expand Down
Loading