Skip to content

Commit

Permalink
e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Oct 4, 2024
1 parent 153e6c4 commit 89b9a9d
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions crates/e2e/tests/e2e/cow_amm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,28 @@ async fn cow_amm_opposite_direction(web3: Web3) {
};

// Fund trader "bob" with DAI and approve allowance
dai.mint(bob.address(), to_wei(230)).await;
dai.mint(bob.address(), to_wei(250)).await;
tx!(
bob.account(),
dai.approve(onchain.contracts().allowance, U256::MAX)
);

// Get balances before the trade
let amm_weth_balance_before = onchain
.contracts()
.weth
.balance_of(cow_amm.address())
.call()
.await
.unwrap();
let bob_weth_balance_before = onchain
.contracts()
.weth
.balance_of(bob.address())
.call()
.await
.unwrap();

// Place user order where bob sells DAI to buy WETH (opposite direction)
let user_order = OrderCreation {
sell_token: dai.address(),
Expand All @@ -839,23 +855,9 @@ async fn cow_amm_opposite_direction(web3: Web3) {
);
let user_order_id = services.create_order(&user_order).await.unwrap();

// Get balances before the trade
let amm_weth_balance_before = onchain
.contracts()
.weth
.balance_of(cow_amm.address())
.call()
.await
.unwrap();
let bob_weth_balance_before = onchain
.contracts()
.weth
.balance_of(bob.address())
.call()
.await
.unwrap();

let fee = U256::exp10(15); // 0.001 WETH
// Set the fees appropriately
let fee_cow_amm = U256::exp10(16); // 0.01 WETH
let fee_user = to_wei(1); // 1 DAI

// Configure the mock solver's solution
mock_solver.configure_solution(Some(Solution {
Expand All @@ -880,13 +882,13 @@ async fn cow_amm_opposite_direction(web3: Web3) {
signing_scheme: SigningScheme::Eip1271,
signature,
},
executed_amount: cow_amm_order.sell_amount - fee,
fee: Some(fee),
executed_amount: cow_amm_order.sell_amount - fee_cow_amm,
fee: Some(fee_cow_amm),
}),
solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment {
order: user_order_id.0,
executed_amount: user_order.sell_amount - fee,
fee: Some(fee),
executed_amount: user_order.sell_amount - fee_user,
fee: Some(fee_user),
}),
],
pre_interactions: vec![cow_amm_commitment],
Expand All @@ -913,11 +915,11 @@ async fn cow_amm_opposite_direction(web3: Web3) {
.await
.unwrap();

let amm_weth_received = amm_weth_balance_after - amm_weth_balance_before;
let amm_weth_sent = amm_weth_balance_before - amm_weth_balance_after;
let bob_weth_received = bob_weth_balance_after - bob_weth_balance_before;

// Bob should receive WETH, CoW AMM's WETH balance decreases
bob_weth_received >= user_order.buy_amount - fee && amm_weth_received <= U256::zero()
bob_weth_received >= user_order.buy_amount && amm_weth_sent >= cow_amm_order.sell_amount
})
.await
.unwrap();
Expand Down

0 comments on commit 89b9a9d

Please sign in to comment.