Skip to content

Commit

Permalink
deprecate market order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Mar 19, 2024
1 parent 8708c60 commit 1c37cd1
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 148 deletions.
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/app_data_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn order_creation_checks_metadata_signer(web3: Web3) {
app_data,
sell_token: token_a.address(),
sell_amount: to_wei(2),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token_b.address(),
buy_amount: to_wei(1),
valid_to,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn onchain_settlement_without_liquidity(web3: Web3) {
let order = OrderCreation {
sell_token: token_a.address(),
sell_amount: to_wei(9),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token_b.address(),
buy_amount: to_wei(5),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
6 changes: 3 additions & 3 deletions crates/e2e/tests/e2e/eth_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn eth_integration(web3: Web3) {
kind: OrderKind::Buy,
sell_token: token.address(),
sell_amount: to_wei(50),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: BUY_ETH_ADDRESS,
buy_amount: to_wei(49),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand All @@ -91,7 +91,7 @@ async fn eth_integration(web3: Web3) {
kind: OrderKind::Sell,
sell_token: token.address(),
sell_amount: to_wei(50),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: BUY_ETH_ADDRESS,
buy_amount: to_wei(49),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down Expand Up @@ -125,6 +125,6 @@ async fn eth_integration(web3: Web3) {
);
assert_eq!(
trader_b_eth_balance_after - trader_b_eth_balance_before,
49_776_284_258_574_379_601_u128.into()
49_776_118_111_704_762_174_u128.into()
);
}
4 changes: 2 additions & 2 deletions crates/e2e/tests/e2e/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn allowance(web3: Web3) {
let order = OrderCreation {
sell_token: cow.address(),
sell_amount: to_wei(4),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: onchain.contracts().weth.address(),
buy_amount: to_wei(3),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down Expand Up @@ -245,7 +245,7 @@ async fn signature(web3: Web3) {
from: Some(safe.address()),
sell_token: token.address(),
sell_amount: to_wei(4),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: onchain.contracts().weth.address(),
buy_amount: to_wei(3),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
132 changes: 0 additions & 132 deletions crates/e2e/tests/e2e/limit_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ async fn local_node_limit_does_not_apply_to_in_market_orders_test() {
run_test(limit_does_not_apply_to_in_market_orders_test).await;
}

#[tokio::test]
#[ignore]
async fn local_node_mixed_limit_and_market_orders() {
run_test(mixed_limit_and_market_orders_test).await;
}

/// The block number from which we will fetch state for the forked tests.
const FORK_BLOCK_MAINNET: u64 = 18477910;
/// USDC whale address as per [FORK_BLOCK_MAINNET].
Expand Down Expand Up @@ -297,132 +291,6 @@ async fn two_limit_orders_test(web3: Web3) {
assert!(balance_after_b.checked_sub(balance_before_b).unwrap() >= to_wei(2));
}

async fn mixed_limit_and_market_orders_test(web3: Web3) {
let mut onchain = OnchainComponents::deploy(web3.clone()).await;

let [solver] = onchain.make_solvers(to_wei(1)).await;
let [trader_a, trader_b] = onchain.make_accounts(to_wei(1)).await;
let [token_a, token_b] = onchain
.deploy_tokens_with_weth_uni_v2_pools(to_wei(1_000), to_wei(1_000))
.await;

// Fund trader accounts
token_a.mint(trader_a.address(), to_wei(10)).await;
token_b.mint(trader_b.address(), to_wei(6)).await;
token_a.mint(solver.address(), to_wei(1000)).await;
token_b.mint(solver.address(), to_wei(1000)).await;

// Create and fund Uniswap pool
tx!(
solver.account(),
onchain
.contracts()
.uniswap_v2_factory
.create_pair(token_a.address(), token_b.address())
);
tx!(
solver.account(),
token_a.approve(
onchain.contracts().uniswap_v2_router.address(),
to_wei(1000)
)
);
tx!(
solver.account(),
token_b.approve(
onchain.contracts().uniswap_v2_router.address(),
to_wei(1000)
)
);
tx!(
solver.account(),
onchain.contracts().uniswap_v2_router.add_liquidity(
token_a.address(),
token_b.address(),
to_wei(1000),
to_wei(1000),
0_u64.into(),
0_u64.into(),
solver.address(),
U256::max_value(),
)
);

// Approve GPv2 for trading
tx!(
trader_a.account(),
token_a.approve(onchain.contracts().allowance, to_wei(10))
);
tx!(
trader_b.account(),
token_b.approve(onchain.contracts().allowance, to_wei(6))
);

// Place Orders
let services = Services::new(onchain.contracts()).await;
services.start_protocol(solver).await;

let order_a = OrderCreation {
sell_token: token_a.address(),
sell_amount: to_wei(10),
buy_token: token_b.address(),
buy_amount: to_wei(5),
valid_to: model::time::now_in_epoch_seconds() + 300,
kind: OrderKind::Sell,
..Default::default()
}
.sign(
EcdsaSigningScheme::Eip712,
&onchain.contracts().domain_separator,
SecretKeyRef::from(&SecretKey::from_slice(trader_a.private_key()).unwrap()),
);
let order_id = services.create_order(&order_a).await.unwrap();

let limit_order = services.get_order(&order_id).await.unwrap();
assert!(limit_order.metadata.class.is_limit());

let order_b = OrderCreation {
sell_token: token_b.address(),
sell_amount: to_wei(5),
fee_amount: to_wei(1),
buy_token: token_a.address(),
buy_amount: to_wei(2),
valid_to: model::time::now_in_epoch_seconds() + 300,
kind: OrderKind::Sell,
..Default::default()
}
.sign(
EcdsaSigningScheme::EthSign,
&onchain.contracts().domain_separator,
SecretKeyRef::from(&SecretKey::from_slice(trader_b.private_key()).unwrap()),
);
let order_id = services.create_order(&order_b).await.unwrap();

let limit_order = services.get_order(&order_id).await.unwrap();
assert_eq!(limit_order.metadata.class, OrderClass::Market);

wait_for_condition(TIMEOUT, || async { services.solvable_orders().await == 2 })
.await
.unwrap();

// Drive solution
tracing::info!("Waiting for trade.");
let balance_before_a = token_b.balance_of(trader_a.address()).call().await.unwrap();
let balance_before_b = token_a.balance_of(trader_b.address()).call().await.unwrap();
wait_for_condition(TIMEOUT, || async { services.solvable_orders().await == 2 })
.await
.unwrap();

wait_for_condition(TIMEOUT, || async { services.solvable_orders().await == 0 })
.await
.unwrap();

let balance_after_a = token_b.balance_of(trader_a.address()).call().await.unwrap();
let balance_after_b = token_a.balance_of(trader_b.address()).call().await.unwrap();
assert!(balance_after_a.checked_sub(balance_before_a).unwrap() >= to_wei(5));
assert!(balance_after_b.checked_sub(balance_before_b).unwrap() >= to_wei(2));
}

async fn too_many_limit_orders_test(web3: Web3) {
let mut onchain = OnchainComponents::deploy(web3.clone()).await;

Expand Down
4 changes: 2 additions & 2 deletions crates/e2e/tests/e2e/onchain_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async fn onchain_settlement(web3: Web3) {
let order_a = OrderCreation {
sell_token: token_a.address(),
sell_amount: to_wei(100),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token_b.address(),
buy_amount: to_wei(80),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand All @@ -116,7 +116,7 @@ async fn onchain_settlement(web3: Web3) {
let order_b = OrderCreation {
sell_token: token_b.address(),
sell_amount: to_wei(50),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token_a.address(),
buy_amount: to_wei(40),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/smart_contract_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn smart_contract_orders(web3: Web3) {
kind: OrderKind::Sell,
sell_token: token.address(),
sell_amount: to_wei(4),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: onchain.contracts().weth.address(),
buy_amount: to_wei(3),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/solver_competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn solver_competition(web3: Web3) {
let order = OrderCreation {
sell_token: token_a.address(),
sell_amount: to_wei(9),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: onchain.contracts().weth.address(),
buy_amount: to_wei(5),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn test_cancel_on_expiry(web3: Web3) {
let order = OrderCreation {
sell_token: onchain.contracts().weth.address(),
sell_amount: to_wei(2),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token.address(),
buy_amount: to_wei(1),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
4 changes: 2 additions & 2 deletions crates/e2e/tests/e2e/tracking_insufficient_funds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn test(web3: Web3) {
let order_a = OrderCreation {
sell_token: onchain.contracts().weth.address(),
sell_amount: to_wei(2),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token.address(),
buy_amount: to_wei(1),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand All @@ -75,7 +75,7 @@ async fn test(web3: Web3) {
let order_b = OrderCreation {
sell_token: onchain.contracts().weth.address(),
sell_amount: to_wei(2),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token.address(),
buy_amount: to_wei(1),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/univ2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn test(web3: Web3) {
let order = OrderCreation {
sell_token: onchain.contracts().weth.address(),
sell_amount: to_wei(2),
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: token.address(),
buy_amount: to_wei(1),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e/tests/e2e/vault_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn vault_balances(web3: Web3) {
sell_token: token.address(),
sell_amount: to_wei(9),
sell_token_balance: SellTokenSource::External,
fee_amount: to_wei(1),
fee_amount: 0.into(),
buy_token: onchain.contracts().weth.address(),
buy_amount: to_wei(8),
valid_to: model::time::now_in_epoch_seconds() + 300,
Expand Down

0 comments on commit 1c37cd1

Please sign in to comment.