Skip to content

Commit d884bbe

Browse files
authored
Migrate testlib into alloy (#3850)
1 parent e7d7566 commit d884bbe

File tree

11 files changed

+72
-78
lines changed

11 files changed

+72
-78
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/shared/src/bad_token/trace_call.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,10 @@ mod tests {
739739
.await
740740
.unwrap()
741741
.pair_provider,
742-
base_tokens: base_tokens.to_vec(),
742+
base_tokens: base_tokens
743+
.iter()
744+
.map(|token| token.into_legacy())
745+
.collect::<Vec<_>>(),
743746
}),
744747
Arc::new(UniswapLikePairProviderFinder {
745748
inner: uniswap_v2::UniV2BaselineSourceParameters::from_baseline_source(
@@ -751,7 +754,10 @@ mod tests {
751754
.await
752755
.unwrap()
753756
.pair_provider,
754-
base_tokens: base_tokens.to_vec(),
757+
base_tokens: base_tokens
758+
.iter()
759+
.map(|token| token.into_legacy())
760+
.collect::<Vec<_>>(),
755761
}),
756762
Arc::new(BalancerVaultFinder(
757763
BalancerV2Vault::Instance::deployed(&web3.alloy)
@@ -763,7 +769,10 @@ mod tests {
763769
IUniswapV3Factory::Instance::deployed(&web3.alloy)
764770
.await
765771
.unwrap(),
766-
base_tokens.to_vec(),
772+
base_tokens
773+
.iter()
774+
.map(|token| token.into_legacy())
775+
.collect::<Vec<_>>(),
767776
FeeValues::Static,
768777
)
769778
.await
@@ -782,7 +791,7 @@ mod tests {
782791

783792
println!("testing good tokens");
784793
for &token in base_tokens {
785-
let result = token_cache.detect(token).await;
794+
let result = token_cache.detect(token.into_legacy()).await;
786795
println!("token {token:?} is {result:?}");
787796
}
788797

@@ -798,7 +807,7 @@ mod tests {
798807
async fn mainnet_univ3() {
799808
observe::tracing::initialize(&observe::Config::default().with_env_filter("shared=debug"));
800809
let web3 = Web3::new_from_env();
801-
let base_tokens = vec![testlib::tokens::WETH];
810+
let base_tokens = vec![testlib::tokens::WETH.into_legacy()];
802811
let settlement = GPv2Settlement::Instance::deployed(&web3.alloy)
803812
.await
804813
.unwrap();
@@ -817,7 +826,9 @@ mod tests {
817826
});
818827
let token_cache = TraceCallDetector::new(web3, settlement.address().into_legacy(), finder);
819828

820-
let result = token_cache.detect(testlib::tokens::USDC).await;
829+
let result = token_cache
830+
.detect(testlib::tokens::USDC.into_legacy())
831+
.await;
821832
dbg!(&result);
822833
assert!(result.unwrap().is_good());
823834

crates/shared/src/sources/uniswap_v2/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,22 @@ mod tests {
241241

242242
test(
243243
BaselineSource::UniswapV2,
244-
testlib::tokens::GNO,
245-
testlib::tokens::WETH,
244+
testlib::tokens::GNO.into_legacy(),
245+
testlib::tokens::WETH.into_legacy(),
246246
addr!("3e8468f66d30fc99f745481d4b383f89861702c6"),
247247
)
248248
.await;
249249
test(
250250
BaselineSource::SushiSwap,
251-
testlib::tokens::GNO,
252-
testlib::tokens::WETH,
251+
testlib::tokens::GNO.into_legacy(),
252+
testlib::tokens::WETH.into_legacy(),
253253
addr!("41328fdba556c8c969418ccccb077b7b8d932aa5"),
254254
)
255255
.await;
256256
test(
257257
BaselineSource::Swapr,
258258
addr!("a1d65E8fB6e87b60FECCBc582F7f97804B725521"),
259-
testlib::tokens::WETH,
259+
testlib::tokens::WETH.into_legacy(),
260260
addr!("b0Dc4B36e0B4d2e3566D2328F6806EA0B76b4F13"),
261261
)
262262
.await;

crates/shared/src/sources/uniswap_v2/pair_provider.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn create2_target_address(creator: H160, salt: &[u8; 32], init_code_digest: &[u8
3131

3232
#[cfg(test)]
3333
mod tests {
34-
use {super::*, hex_literal::hex};
34+
use {super::*, ethrpc::alloy::conversions::IntoLegacy, hex_literal::hex};
3535

3636
#[test]
3737
fn test_create2_mainnet() {
@@ -42,7 +42,11 @@ mod tests {
4242
"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
4343
),
4444
};
45-
let pair = TokenPair::new(testlib::tokens::GNO, testlib::tokens::WETH).unwrap();
45+
let pair = TokenPair::new(
46+
testlib::tokens::GNO.into_legacy(),
47+
testlib::tokens::WETH.into_legacy(),
48+
)
49+
.unwrap();
4650
assert_eq!(
4751
provider.pair_address(&pair),
4852
addr!("3e8468f66d30fc99f745481d4b383f89861702c6")

crates/shared/src/sources/uniswap_v3_pair_provider.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ pub fn pair_address(factory: &H160, pair: &TokenPair, fee: u32) -> H160 {
2424

2525
#[cfg(test)]
2626
mod tests {
27-
use super::*;
27+
use {super::*, ethrpc::alloy::conversions::IntoLegacy};
2828

2929
#[test]
3030
fn mainnet_pool() {
3131
// https://v3.info.uniswap.org/home#/pools/0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8
3232
let result = pair_address(
3333
&addr!("1F98431c8aD98523631AE4a59f267346ea31F984"),
34-
&TokenPair::new(testlib::tokens::WETH, testlib::tokens::USDC).unwrap(),
34+
&TokenPair::new(
35+
testlib::tokens::WETH.into_legacy(),
36+
testlib::tokens::USDC.into_legacy(),
37+
)
38+
.unwrap(),
3539
3000,
3640
);
3741
assert_eq!(result, addr!("8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8"));

crates/shared/src/token_list.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct Metrics {
130130

131131
#[cfg(test)]
132132
pub mod tests {
133-
use super::*;
133+
use {super::*, ethrpc::alloy::conversions::IntoLegacy};
134134

135135
// https://github.com/Uniswap/token-lists/blob/master/test/schema/example.tokenlist.json
136136
const EXAMPLE_LIST: &str = r#"
@@ -194,7 +194,7 @@ pub mod tests {
194194
tokens: vec![
195195
TokenModel {
196196
chain_id: 1,
197-
address: testlib::tokens::USDC,
197+
address: testlib::tokens::USDC.into_legacy(),
198198
},
199199
TokenModel {
200200
chain_id: 4,
@@ -217,7 +217,7 @@ pub mod tests {
217217
};
218218
let tokens = config.get_list(list.tokens);
219219
let instance = AutoUpdatingTokenList::new(tokens);
220-
assert!(instance.contains(&testlib::tokens::USDC));
220+
assert!(instance.contains(&testlib::tokens::USDC.into_legacy()));
221221
// Chain ID 4
222222
assert!(!instance.contains(&addr!("39AA39c021dfbaE8faC545936693aC917d5E7563")),);
223223
}
@@ -234,13 +234,13 @@ pub mod tests {
234234
hardcoded: Default::default(),
235235
};
236236
let tokens = config.get_external_list().await.unwrap();
237-
assert!(tokens.contains(&testlib::tokens::USDC));
237+
assert!(tokens.contains(&testlib::tokens::USDC.into_legacy()));
238238
let gc_token = addr!("39AA39c021dfbaE8faC545936693aC917d5E7563");
239239
assert!(!tokens.contains(&gc_token));
240240

241241
config.chain_id = 4;
242242
let tokens = config.get_list(list.tokens);
243-
assert!(!tokens.contains(&testlib::tokens::USDC));
243+
assert!(!tokens.contains(&testlib::tokens::USDC.into_legacy()));
244244
assert!(tokens.contains(&gc_token));
245245
}
246246
}

crates/solver/src/liquidity/slippage.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,37 +199,44 @@ fn absolute_slippage_amount(relative: &BigRational, amount: &BigInt) -> BigInt {
199199
mod tests {
200200
use {
201201
super::*,
202+
ethrpc::alloy::conversions::IntoLegacy,
202203
shared::externalprices,
203204
testlib::tokens::{GNO, USDC, WETH},
204205
};
205206

206207
#[test]
207208
fn amm_execution_slippage() {
208209
let calculator = SlippageCalculator::from_bps(100, Some(U256::exp10(18)));
209-
let prices = externalprices! { native_token: WETH };
210+
let prices = externalprices! { native_token: WETH.into_legacy() };
210211

211212
let slippage = calculator.context(&prices);
212213
let cases = [
213214
(
214215
AmmOrderExecution {
215-
input_max: TokenAmount::new(WETH, 1_000_000_000_000_000_000_u128),
216-
output: TokenAmount::new(GNO, 10_000_000_000_000_000_000_u128),
216+
input_max: TokenAmount::new(WETH.into_legacy(), 1_000_000_000_000_000_000_u128),
217+
output: TokenAmount::new(GNO.into_legacy(), 10_000_000_000_000_000_000_u128),
217218
internalizable: false,
218219
},
219220
1_010_000_000_000_000_000_u128.into(),
220221
),
221222
(
222223
AmmOrderExecution {
223-
input_max: TokenAmount::new(GNO, 10_000_000_000_000_000_000_000_u128),
224-
output: TokenAmount::new(WETH, 1_000_000_000_000_000_000_000_u128),
224+
input_max: TokenAmount::new(
225+
GNO.into_legacy(),
226+
10_000_000_000_000_000_000_000_u128,
227+
),
228+
output: TokenAmount::new(
229+
WETH.into_legacy(),
230+
1_000_000_000_000_000_000_000_u128,
231+
),
225232
internalizable: false,
226233
},
227234
10_010_000_000_000_000_000_000_u128.into(),
228235
),
229236
(
230237
AmmOrderExecution {
231-
input_max: TokenAmount::new(USDC, 200_000_000_u128),
232-
output: TokenAmount::new(GNO, 2_000_000_000_000_000_000_u128),
238+
input_max: TokenAmount::new(USDC.into_legacy(), 200_000_000_u128),
239+
output: TokenAmount::new(GNO.into_legacy(), 2_000_000_000_000_000_000_u128),
233240
internalizable: false,
234241
},
235242
202_000_000_u128.into(),

crates/testlib/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ edition = "2024"
66
license = "MIT OR Apache-2.0"
77

88
[dependencies]
9-
ethcontract = { workspace = true }
10-
ethcontract-mock = { workspace = true }
11-
hex-literal = { workspace = true }
9+
alloy = {workspace = true}
1210
anyhow = { workspace = true }
11+
hex-literal = { workspace = true }
1312
maplit = { workspace = true }
1413
serde_json = { workspace = true }
1514

crates/testlib/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Convenience utilities for unit-testing used across other crates.
22
3-
pub use ethcontract_mock::utils::*;
4-
53
pub mod json_matching;
64
pub mod protocol;
75
pub mod tokens;

crates/testlib/src/protocol.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
//! Mainnet addresses of protocol contracts.
22
3-
use ethcontract::H160;
3+
use alloy::primitives::{Address, address};
44

55
/// Address for the settlement contract.
6-
pub const SETTLEMENT: H160 = H160(hex_literal::hex!(
7-
"9008D19f58AAbD9eD0D60971565AA8510560ab41"
8-
));
6+
pub const SETTLEMENT: Address = address!("9008D19f58AAbD9eD0D60971565AA8510560ab41");
97

108
/// Address for the vault relayer contract.
11-
pub const RELAYER: H160 = H160(hex_literal::hex!(
12-
"C92E8bdf79f0507f65a392b0ab4667716BFE0110"
13-
));
9+
pub const RELAYER: Address = address!("C92E8bdf79f0507f65a392b0ab4667716BFE0110");
1410

1511
/// Address for the settlement contract.
16-
pub const AUTHENTICATOR: H160 = H160(hex_literal::hex!(
17-
"2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE"
18-
));
12+
pub const AUTHENTICATOR: Address = address!("2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE");

0 commit comments

Comments
 (0)