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

feat(anvil): remove old ethers-dependent anvil core types #6842

Merged
merged 11 commits into from
Jan 19, 2024
Prev Previous commit
Next Next commit
finish moving test providers
  • Loading branch information
Evalir committed Jan 18, 2024
commit 33dbc401ca6fb5883f56ecee93fe8cb575d47f46
9 changes: 6 additions & 3 deletions crates/anvil/src/eth/error.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Aggregated error type for this module

use crate::eth::pool::transactions::PoolTransaction;
use alloy_primitives::{SignatureError as AlloySignatureError, Bytes, U256};
use alloy_dyn_abi::DynSolType;
use alloy_primitives::{Bytes, SignatureError as AlloySignatureError, U256};
use alloy_signer::Error as AlloySignerError;
use alloy_transport::TransportError;
use anvil_rpc::{
error::{ErrorCode, RpcError},
response::ResponseResult,
};
use alloy_dyn_abi::DynSolType;
use foundry_common::SELECTOR_LEN;
use foundry_evm::{
backend::DatabaseError,
Expand Down Expand Up @@ -266,7 +266,10 @@ pub(crate) fn decode_revert_reason(out: impl AsRef<[u8]>) -> Option<String> {
if out.len() < SELECTOR_LEN {
return None
}
DynSolType::String.abi_decode(&out[SELECTOR_LEN..]).ok().and_then(|v| v.as_str().map(|s| s.to_owned()))
DynSolType::String
.abi_decode(&out[SELECTOR_LEN..])
.ok()
.and_then(|v| v.as_str().map(|s| s.to_owned()))
}

/// Helper trait to easily convert results to rpc results
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/anvil.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! tests for anvil specific logic

use crate::utils::ethers_http_provider;
use anvil::{spawn, NodeConfig};
use ethers::{prelude::Middleware, types::Address};
use foundry_common::types::ToAlloy;
use crate::utils::ethers_http_provider;

#[tokio::test(flavor = "multi_thread")]
async fn test_can_change_mining_mode() {
Expand Down
5 changes: 4 additions & 1 deletion crates/anvil/tests/it/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! general eth api tests

use crate::{abi::{MulticallContract, SimpleStorage}, utils::ethers_http_provider};
use crate::{
abi::{MulticallContract, SimpleStorage},
utils::ethers_http_provider,
};
use alloy_primitives::{Address as rAddress, B256, U256 as rU256};
use alloy_providers::provider::TempProvider;
use alloy_rpc_types::{
Expand Down
5 changes: 4 additions & 1 deletion crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! various fork related test

use crate::{abi::*, utils::{self, ethers_http_provider}};
use crate::{
abi::*,
utils::{self, ethers_http_provider},
};
use alloy_primitives::U256 as rU256;
use alloy_providers::provider::TempProvider;
use alloy_rpc_types::{BlockNumberOrTag, CallRequest};
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/gas.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Gas related tests

use crate::utils::ethers_http_provider;
use alloy_primitives::U256;
use anvil::{eth::fees::INITIAL_BASE_FEE, spawn, NodeConfig};
use ethers::{
Expand All @@ -10,7 +11,6 @@ use ethers::{
},
};
use foundry_common::types::ToAlloy;
use crate::utils::ethers_http_provider;

const GAS_TRANSFER: u64 = 21_000u64;

Expand Down
5 changes: 4 additions & 1 deletion crates/anvil/tests/it/logs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! log/event related tests

use crate::{abi::*, utils::{ethers_ws_provider, ethers_http_provider}};
use crate::{
abi::*,
utils::{ethers_http_provider, ethers_ws_provider},
};
use alloy_signer::Signer as AlloySigner;
use anvil::{spawn, NodeConfig};
use ethers::{
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/tests/it/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Tests for OP chain support.

use crate::utils::ethers_http_provider;
use anvil::{spawn, Hardfork, NodeConfig};
use ethers::{
abi::Address,
Expand All @@ -12,7 +13,6 @@ use ethers::{
use ethers_core::types::{Bytes, H256};
use foundry_common::types::ToAlloy;
use std::str::FromStr;
use crate::utils::ethers_http_provider;

#[tokio::test(flavor = "multi_thread")]
async fn test_deposits_not_supported_if_optimism_disabled() {
Expand Down
5 changes: 4 additions & 1 deletion crates/anvil/tests/it/otterscan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! tests for otterscan endpoints
use crate::{abi::MulticallContract, utils::{ethers_ws_provider, ethers_http_provider}};
use crate::{
abi::MulticallContract,
utils::{ethers_http_provider, ethers_ws_provider},
};
use alloy_primitives::U256 as rU256;
use alloy_rpc_types::{BlockNumberOrTag, BlockTransactions};
use alloy_signer::Signer as AlloySigner;
Expand Down
17 changes: 9 additions & 8 deletions crates/anvil/tests/it/pubsub.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! tests for subscriptions

use crate::utils::{ethers_http_provider, ethers_ws_provider};
use alloy_signer::Signer as AlloySigner;
use anvil::{spawn, NodeConfig};
use ethers::{
Expand All @@ -18,7 +19,7 @@ use std::sync::Arc;
async fn test_sub_new_heads() {
let (api, handle) = spawn(NodeConfig::test()).await;

let provider = handle.ethers_ws_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());

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

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

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_ws_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());

let alloy_wallet = handle.dev_wallets().next().unwrap();
let wallet = Wallet::new_with_signer(
Expand Down Expand Up @@ -80,7 +81,7 @@ async fn test_sub_logs() {
abigen!(EmitLogs, "test-data/emit_logs.json");

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_ws_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());

let alloy_wallet = handle.dev_wallets().next().unwrap();
let wallet = Wallet::new_with_signer(
Expand Down Expand Up @@ -123,7 +124,7 @@ async fn test_sub_logs_impersonated() {
abigen!(EmitLogs, "test-data/emit_logs.json");

let (api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_ws_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());

// impersonate account
let impersonate = Address::random();
Expand Down Expand Up @@ -154,7 +155,7 @@ async fn test_sub_logs_impersonated() {

let tx = TransactionRequest::new().from(impersonate).to(contract.address()).data(data);

let provider = handle.ethers_http_provider();
let provider = ethers_http_provider(&handle.http_endpoint());

let receipt = provider.send_transaction(tx, None).await.unwrap().await.unwrap().unwrap();

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

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_http_provider();
let provider = ethers_http_provider(&handle.http_endpoint());

let alloy_wallet = handle.dev_wallets().next().unwrap();
let wallet = Wallet::new_with_signer(
Expand Down Expand Up @@ -215,7 +216,7 @@ async fn test_filters() {
abigen!(EmitLogs, "test-data/emit_logs.json");

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_http_provider();
let provider = ethers_http_provider(&handle.http_endpoint());

let alloy_wallet = handle.dev_wallets().next().unwrap();
let wallet = Wallet::new_with_signer(
Expand Down Expand Up @@ -280,7 +281,7 @@ async fn test_subscriptions() {
async fn test_sub_new_heads_fast() {
let (api, handle) = spawn(NodeConfig::test()).await;

let provider = handle.ethers_ws_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());

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

Expand Down
9 changes: 5 additions & 4 deletions crates/anvil/tests/it/sign.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils::ethers_http_provider;
use alloy_dyn_abi::TypedData;
use alloy_signer::Signer as AlloySigner;
use anvil::{spawn, NodeConfig};
Expand Down Expand Up @@ -286,7 +287,7 @@ async fn can_sign_typed_data_os() {
#[tokio::test(flavor = "multi_thread")]
async fn rejects_different_chain_id() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_http_provider();
let provider = ethers_http_provider(&handle.http_endpoint());

let alloy_wallet = handle.dev_wallets().next().unwrap();
let wallet = Wallet::new_with_signer(
Expand All @@ -300,7 +301,7 @@ async fn rejects_different_chain_id() {

let res = client.send_transaction(tx, None).await;
let err = res.unwrap_err();
assert!(err.to_string().contains("signed for another chain"));
assert!(err.to_string().contains("signed for another chain"), "{}", err.to_string());
}

#[tokio::test(flavor = "multi_thread")]
Expand All @@ -313,7 +314,7 @@ async fn rejects_invalid_chain_id() {
alloy_wallet.chain_id().unwrap(),
);
let wallet = wallet.with_chain_id(99u64);
let provider = handle.ethers_http_provider();
let provider = ethers_http_provider(&handle.http_endpoint());
let client = SignerMiddleware::new(provider, wallet);
let tx = TransactionRequest::new().to(Address::random()).value(100u64);
let res = client.send_transaction(tx, None).await;
Expand Down Expand Up @@ -504,6 +505,6 @@ async fn can_sign_typed_seaport_data() {

assert_eq!(
signature,
"0xed9afe7f377155ee3a42b25b696d79b55d441aeac7790b97a51b54ad0569b9665ea30bf8e8df12d6ee801c4dcb85ecfb8b23a6f7ae166d5af9acac9befb905451c".to_string()
"0xed9afe7f377155ee3a42b25b696d79b55d441aeac7790b97a51b54ad0569b9665ea30bf8e8df12d6ee801c4dcb85ecfb8b23a6f7ae166d5af9acac9befb9054500".to_string()
);
}
28 changes: 16 additions & 12 deletions crates/anvil/tests/it/traces.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::fork::fork_config;
use crate::{
fork::fork_config,
utils::{ethers_http_provider, ethers_ws_provider},
};
use alloy_primitives::U256;
use alloy_signer::Signer as AlloySigner;
use anvil::{spawn, NodeConfig};
Expand All @@ -18,7 +21,7 @@ use std::sync::Arc;
#[tokio::test(flavor = "multi_thread")]
async fn test_get_transfer_parity_traces() {
let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_http_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());

let alloy_wallets = handle.dev_wallets().collect::<Vec<_>>();
let accounts = alloy_wallets
Expand Down Expand Up @@ -85,7 +88,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_ws_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());
let alloy_wallets = handle.dev_wallets().collect::<Vec<_>>();
let wallets = alloy_wallets
.into_iter()
Expand All @@ -106,13 +109,15 @@ contract Contract {
let contract = ContractInstance::new(
contract.address(),
abi.unwrap(),
SignerMiddleware::new(handle.ethers_http_provider(), wallets[1].clone()),
SignerMiddleware::new(ethers_http_provider(&handle.http_endpoint()), wallets[1].clone()),
);
let call = contract.method::<_, ()>("goodbye", ()).unwrap();
let tx = call.send().await.unwrap().await.unwrap().unwrap();

let traces =
handle.ethers_http_provider().trace_transaction(tx.transaction_hash).await.unwrap();
let traces = ethers_http_provider(&handle.http_endpoint())
.trace_transaction(tx.transaction_hash)
.await
.unwrap();
assert!(!traces.is_empty());
assert_eq!(traces[1].action_type, ActionType::Suicide);
}
Expand Down Expand Up @@ -143,7 +148,7 @@ contract Contract {
let (abi, bytecode, _) = contract.into_contract_bytecode().into_parts();

let (_api, handle) = spawn(NodeConfig::test()).await;
let provider = handle.ethers_ws_provider();
let provider = ethers_ws_provider(&handle.ws_endpoint());
let alloy_wallets = handle.dev_wallets().collect::<Vec<_>>();
let wallets = alloy_wallets
.into_iter()
Expand All @@ -164,12 +169,11 @@ contract Contract {
let contract = ContractInstance::new(
contract.address(),
abi.unwrap(),
SignerMiddleware::new(handle.ethers_http_provider(), wallets[1].clone()),
SignerMiddleware::new(ethers_http_provider(&handle.http_endpoint()), wallets[1].clone()),
);
let call = contract.method::<_, ()>("goodbye", ()).unwrap();

let traces = handle
.ethers_http_provider()
let traces = ethers_http_provider(&handle.http_endpoint())
.debug_trace_call(call.tx, None, GethDebugTracingCallOptions::default())
.await
.unwrap();
Expand All @@ -192,7 +196,7 @@ contract Contract {
#[tokio::test(flavor = "multi_thread")]
async fn test_trace_address_fork() {
let (api, handle) = spawn(fork_config().with_fork_block_number(Some(15291050u64))).await;
let provider = handle.ethers_http_provider();
let provider = ethers_http_provider(&handle.http_endpoint());

let input = hex::decode("43bcfab60000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000e0bd811c8769a824b00000000000000000000000000000000000000000000000e0ae9925047d8440b60000000000000000000000002e4777139254ff76db957e284b186a4507ff8c67").unwrap();

Expand Down Expand Up @@ -385,7 +389,7 @@ async fn test_trace_address_fork() {
#[tokio::test(flavor = "multi_thread")]
async fn test_trace_address_fork2() {
let (api, handle) = spawn(fork_config().with_fork_block_number(Some(15314401u64))).await;
let provider = handle.ethers_http_provider();
let provider = ethers_http_provider(&handle.http_endpoint());

let input = hex::decode("30000003000000000000000000000000adda1059a6c6c102b0fa562b9bb2cb9a0de5b1f4000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a300000004fffffffffffffffffffffffffffffffffffffffffffff679dc91ecfe150fb980c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2f4d2888d29d722226fafa5d9b24f9164c092421e000bb8000000000000004319b52bf08b65295d49117e790000000000000000000000000000000000000000000000008b6d9e8818d6141f000000000000000000000000000000000000000000000000000000086a23af210000000000000000000000000000000000000000000000000000000000").unwrap();

Expand Down
Loading
Loading