Skip to content

Commit

Permalink
Move ethcontract_errors into contracts crate (#3111)
Browse files Browse the repository at this point in the history
# Description
Moves some helper functions for `ethcontract` errors into the
`contracts` crate to further reduce the scope of the `shared` crate.
Only if you include the `contracts` crate should these helper functions
be relevant to you.
  • Loading branch information
MartinquaXD authored Nov 5, 2024
1 parent f953439 commit 46244b5
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AsExecutionError for ExecutionError {
pub fn testing_node_error() -> MethodError {
MethodError {
signature: String::new(),
inner: ExecutionError::Web3(web3::Error::Internal),
inner: ExecutionError::Web3(ethcontract::web3::Error::Internal),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::let_unit_value)]

pub use ethcontract;
pub mod errors;
use {
anyhow::{anyhow, bail, Result},
ethcontract::{
Expand Down
3 changes: 1 addition & 2 deletions crates/shared/src/bad_token/token_owner_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ use {
token_owner_list::TokenOwnerList,
},
baseline_solver::BaseTokens,
ethcontract_error::EthcontractErrorType,
ethrpc::{Web3, MAX_BATCH_SIZE},
http_client::HttpClientFactory,
sources::uniswap_v2::pair_provider::PairProvider,
},
anyhow::{Context, Result},
chain::Chain,
contracts::{BalancerV2Vault, IUniswapV3Factory, ERC20},
contracts::{errors::EthcontractErrorType, BalancerV2Vault, IUniswapV3Factory, ERC20},
ethcontract::U256,
futures::{Stream, StreamExt as _},
primitive_types::H160,
Expand Down
6 changes: 2 additions & 4 deletions crates/shared/src/code_simulation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! Abstraction for simulating calls with overrides.
use {
crate::{
ethcontract_error::EthcontractErrorType,
tenderly_api::{SimulationKind, SimulationRequest, StateObject, TenderlyApi},
},
crate::tenderly_api::{SimulationKind, SimulationRequest, StateObject, TenderlyApi},
anyhow::{ensure, Context as _, Result},
contracts::errors::EthcontractErrorType,
ethcontract::{errors::ExecutionError, H256},
ethrpc::{
extensions::{EthExt as _, StateOverride, StateOverrides},
Expand Down
1 change: 0 additions & 1 deletion crates/shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub mod conversions;
pub mod current_block;
pub mod db_order_conversions;
pub mod encoded_settlement;
pub mod ethcontract_error;
pub mod ethrpc;
pub mod event_handling;
pub mod event_storing_helpers;
Expand Down
3 changes: 1 addition & 2 deletions crates/shared/src/signature_validator/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
use {
super::{SignatureCheck, SignatureValidating, SignatureValidationError},
crate::ethcontract_error::EthcontractErrorType,
anyhow::Result,
contracts::ERC1271SignatureValidator,
contracts::{errors::EthcontractErrorType, ERC1271SignatureValidator},
ethcontract::Bytes,
ethrpc::Web3,
futures::future,
Expand Down
21 changes: 11 additions & 10 deletions crates/shared/src/sources/balancer_v2/pool_fetching/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use {
super::{internal::InternalPoolFetching, pool_storage::PoolStorage},
crate::{
ethcontract_error::EthcontractErrorType,
event_handling::{EventHandler, EventRetrieving},
maintenance::Maintaining,
recent_block_cache::Block,
Expand All @@ -16,7 +15,11 @@ use {
},
},
anyhow::Result,
contracts::{balancer_v2_base_pool_factory, BalancerV2BasePoolFactory},
contracts::{
balancer_v2_base_pool_factory,
errors::EthcontractErrorType,
BalancerV2BasePoolFactory,
},
ethcontract::{dyns::DynAllEventsBuilder, errors::MethodError, BlockId, Instance, H256},
ethrpc::{
block_stream::{BlockNumberHash, BlockRetrieving},
Expand Down Expand Up @@ -156,13 +159,11 @@ fn is_contract_error(err: &anyhow::Error) -> bool {
mod tests {
use {
super::*,
crate::{
ethcontract_error,
sources::balancer_v2::{
pools::{weighted, PoolKind},
swap::fixed_point::Bfp,
},
crate::sources::balancer_v2::{
pools::{weighted, PoolKind},
swap::fixed_point::Bfp,
},
contracts::errors::{testing_contract_error, testing_node_error},
};

#[tokio::test]
Expand All @@ -177,14 +178,14 @@ mod tests {
}),
})),
Ok(PoolStatus::Paused),
Err(ethcontract_error::testing_contract_error().into()),
Err(testing_contract_error().into()),
];
assert_eq!(collect_pool_results(results).unwrap().len(), 1);
}

#[tokio::test]
async fn collecting_results_forwards_node_error() {
let node_err = Err(ethcontract_error::testing_node_error().into());
let node_err = Err(testing_node_error().into());
assert!(collect_pool_results(vec![node_err]).is_err());
}
}
4 changes: 2 additions & 2 deletions crates/shared/src/sources/swapr/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ mod tests {
use {
super::*,
crate::{
ethcontract_error,
ethrpc::{create_env_test_transport, Web3},
recent_block_cache::Block,
sources::{uniswap_v2, BaselineSource},
},
contracts::errors::testing_contract_error,
ethcontract::H160,
maplit::hashset,
};
Expand Down Expand Up @@ -93,7 +93,7 @@ mod tests {
let address = H160::from_low_u64_be(1);
assert!(handle_results(
Ok(Some(Pool::uniswap(address, tokens, (0, 0)))),
Err(ethcontract_error::testing_contract_error()),
Err(testing_contract_error()),
)
.unwrap()
.is_none());
Expand Down
18 changes: 8 additions & 10 deletions crates/shared/src/sources/uniswap_v2/pool_fetching.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use {
super::pair_provider::PairProvider,
crate::{
baseline_solver::BaselineSolvable,
ethcontract_error::EthcontractErrorType,
ethrpc::Web3,
recent_block_cache::Block,
},
crate::{baseline_solver::BaselineSolvable, ethrpc::Web3, recent_block_cache::Block},
anyhow::Result,
contracts::{IUniswapLikePair, ERC20},
contracts::{errors::EthcontractErrorType, IUniswapLikePair, ERC20},
ethcontract::{errors::MethodError, BlockId, H160, U256},
futures::{
future::{self, BoxFuture},
Expand Down Expand Up @@ -366,7 +361,10 @@ pub mod test_util {

#[cfg(test)]
mod tests {
use {super::*, crate::ethcontract_error};
use {
super::*,
contracts::errors::{testing_contract_error, testing_node_error},
};

#[test]
fn test_get_amounts_out() {
Expand Down Expand Up @@ -499,7 +497,7 @@ mod tests {
#[test]
fn pool_fetcher_forwards_node_error() {
let fetched_pool = FetchedPool {
reserves: Err(ethcontract_error::testing_node_error()),
reserves: Err(testing_node_error()),
pair: Default::default(),
token0_balance: Ok(1.into()),
token1_balance: Ok(1.into()),
Expand All @@ -511,7 +509,7 @@ mod tests {
#[test]
fn pool_fetcher_skips_contract_error() {
let fetched_pool = FetchedPool {
reserves: Err(ethcontract_error::testing_contract_error()),
reserves: Err(testing_contract_error()),
pair: Default::default(),
token0_balance: Ok(1.into()),
token1_balance: Ok(1.into()),
Expand Down
4 changes: 2 additions & 2 deletions crates/shared/src/token_info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use {
crate::{ethcontract_error::EthcontractErrorType, ethrpc::Web3},
anyhow::Result,
async_trait::async_trait,
contracts::ERC20,
contracts::{errors::EthcontractErrorType, ERC20},
ethcontract::{errors::MethodError, H160},
ethrpc::Web3,
futures::{
future::{BoxFuture, Shared},
FutureExt,
Expand Down

0 comments on commit 46244b5

Please sign in to comment.