Skip to content

Commit

Permalink
Better tests values
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Mar 14, 2024
1 parent 9548109 commit faba3dc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
80 changes: 40 additions & 40 deletions crates/driver/src/tests/cases/protocol_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ async fn price_improvement_fee_partial_buy_in_market_order_not_capped() {
// high enough so we don't get capped by volume fee
max_volume_factor: 1.0,
quote: Quote {
sell: 49.ether().into_wei(),
sell: 39.ether().into_wei(),
buy: 40.ether().into_wei(),
network_fee: 1.ether().into_wei(),
},
Expand All @@ -752,18 +752,18 @@ async fn price_improvement_fee_partial_buy_in_market_order_not_capped() {
fee_policy,
order: Order {
// Demanding to sell more than quoted (in-market)
sell_amount: 60.ether().into_wei(),
sell_amount: 50.ether().into_wei(),
buy_amount: 40.ether().into_wei(),
side: order::Side::Buy,
},
execution: Execution {
// Sell 5 ETH less than quoted, half of which is kept by the protocol
// Sell 10 ETH less than quoted, half of which is kept by the protocol
solver: Amounts {
sell: 20.ether().into_wei(),
sell: 10.ether().into_wei(),
buy: 20.ether().into_wei(),
},
driver: Amounts {
sell: "22.5".ether().into_wei(),
sell: 15.ether().into_wei(),
buy: 20.ether().into_wei(),
},
},
Expand Down Expand Up @@ -793,14 +793,14 @@ async fn price_improvement_fee_partial_sell_in_market_order_not_capped() {
side: order::Side::Sell,
},
execution: Execution {
// Receive 5 ETH more than quoted, half of which gets captured by the protocol
// Receive 10 ETH more than quoted, half of which gets captured by the protocol
solver: Amounts {
sell: 25.ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 30.ether().into_wei(),
},
driver: Amounts {
sell: 25.ether().into_wei(),
buy: "27.5".ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 25.ether().into_wei(),
},
},
};
Expand All @@ -816,7 +816,7 @@ async fn price_improvement_fee_partial_buy_out_of_market_order_not_capped() {
max_volume_factor: 1.0,
quote: Quote {
sell: 59.ether().into_wei(),
buy: 40.ether().into_wei(),
buy: 50.ether().into_wei(),
network_fee: 1.ether().into_wei(),
},
};
Expand All @@ -825,17 +825,17 @@ async fn price_improvement_fee_partial_buy_out_of_market_order_not_capped() {
order: Order {
// Demanding to sell less than quoted (out-market)
sell_amount: 50.ether().into_wei(),
buy_amount: 40.ether().into_wei(),
buy_amount: 50.ether().into_wei(),
side: order::Side::Buy,
},
execution: Execution {
// Sell 5 ETH less than requested, half of which is kept by the protocol
// Sell 10 ETH less than requested, half of which is kept by the protocol
solver: Amounts {
sell: 20.ether().into_wei(),
sell: 10.ether().into_wei(),
buy: 20.ether().into_wei(),
},
driver: Amounts {
sell: "22.5".ether().into_wei(),
sell: 15.ether().into_wei(),
buy: 20.ether().into_wei(),
},
},
Expand Down Expand Up @@ -865,14 +865,14 @@ async fn price_improvement_fee_partial_sell_out_of_market_order_not_capped() {
side: order::Side::Sell,
},
execution: Execution {
// Receive 5 ETH more than quoted, half of which gets captured by the protocol
// Receive 10 ETH more than quoted, half of which gets captured by the protocol
solver: Amounts {
sell: 25.ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 30.ether().into_wei(),
},
driver: Amounts {
sell: 25.ether().into_wei(),
buy: "27.5".ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 25.ether().into_wei(),
},
},
};
Expand All @@ -885,10 +885,10 @@ async fn price_improvement_fee_partial_buy_in_market_order_capped() {
let fee_policy = Policy::PriceImprovement {
factor: 0.5,
// low enough so we get capped by volume fee
max_volume_factor: 0.05,
max_volume_factor: 0.1,
quote: Quote {
sell: 49.ether().into_wei(),
buy: 40.ether().into_wei(),
buy: 50.ether().into_wei(),
network_fee: 1.ether().into_wei(),
},
};
Expand All @@ -897,17 +897,17 @@ async fn price_improvement_fee_partial_buy_in_market_order_capped() {
order: Order {
// Demanding to sell more than quoted (in-market)
sell_amount: 60.ether().into_wei(),
buy_amount: 40.ether().into_wei(),
buy_amount: 50.ether().into_wei(),
side: order::Side::Buy,
},
execution: Execution {
// Fee is capped at 5% of solver proposed sell volume
// Fee is capped at 10% of solver proposed sell volume
solver: Amounts {
sell: 20.ether().into_wei(),
sell: 10.ether().into_wei(),
buy: 20.ether().into_wei(),
},
driver: Amounts {
sell: 21.ether().into_wei(),
sell: 11.ether().into_wei(),
buy: 20.ether().into_wei(),
},
},
Expand All @@ -921,7 +921,7 @@ async fn price_improvement_fee_partial_sell_in_market_order_capped() {
let fee_policy = Policy::PriceImprovement {
factor: 0.5,
// low enough so we get capped by volume fee
max_volume_factor: 0.05,
max_volume_factor: 0.1,
quote: Quote {
sell: 49.ether().into_wei(),
buy: 50.ether().into_wei(),
Expand All @@ -937,14 +937,14 @@ async fn price_improvement_fee_partial_sell_in_market_order_capped() {
side: order::Side::Sell,
},
execution: Execution {
// Fee is capped at 5% of solver proposed buy volume
// Fee is capped at 10% of solver proposed buy volume
solver: Amounts {
sell: 25.ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 30.ether().into_wei(),
},
driver: Amounts {
sell: 25.ether().into_wei(),
buy: "28.5".ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 27.ether().into_wei(),
},
},
};
Expand All @@ -957,10 +957,10 @@ async fn price_improvement_fee_partial_buy_out_of_market_order_capped() {
let fee_policy = Policy::PriceImprovement {
factor: 0.5,
// low enough so we get capped by volume fee
max_volume_factor: 0.05,
max_volume_factor: 0.1,
quote: Quote {
sell: 59.ether().into_wei(),
buy: 40.ether().into_wei(),
buy: 50.ether().into_wei(),
network_fee: 1.ether().into_wei(),
},
};
Expand All @@ -969,17 +969,17 @@ async fn price_improvement_fee_partial_buy_out_of_market_order_capped() {
order: Order {
// Demanding to sell less than quoted (out-market)
sell_amount: 50.ether().into_wei(),
buy_amount: 40.ether().into_wei(),
buy_amount: 50.ether().into_wei(),
side: order::Side::Buy,
},
execution: Execution {
// Fee is capped at 5% of solver proposed sell volume
// Fee is capped at 10% of solver proposed sell volume
solver: Amounts {
sell: 20.ether().into_wei(),
sell: 10.ether().into_wei(),
buy: 20.ether().into_wei(),
},
driver: Amounts {
sell: 21.ether().into_wei(),
sell: 11.ether().into_wei(),
buy: 20.ether().into_wei(),
},
},
Expand All @@ -993,7 +993,7 @@ async fn price_improvement_fee_partial_sell_out_of_market_order_capped() {
let fee_policy = Policy::PriceImprovement {
factor: 0.5,
// low enough so we get capped by volume fee
max_volume_factor: 0.05,
max_volume_factor: 0.1,
quote: Quote {
sell: 49.ether().into_wei(),
buy: 40.ether().into_wei(),
Expand All @@ -1009,14 +1009,14 @@ async fn price_improvement_fee_partial_sell_out_of_market_order_capped() {
side: order::Side::Sell,
},
execution: Execution {
// Fee is capped at 5% of solver proposed buy volume
// Fee is capped at 10% of solver proposed buy volume
solver: Amounts {
sell: 25.ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 30.ether().into_wei(),
},
driver: Amounts {
sell: 25.ether().into_wei(),
buy: "28.5".ether().into_wei(),
sell: 20.ether().into_wei(),
buy: 27.ether().into_wei(),
},
},
};
Expand Down
10 changes: 8 additions & 2 deletions crates/driver/src/tests/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,14 @@ impl<'a> SolveOk<'a> {
fulfillment.quoted_order.buy,
),
};
assert!(u256(trade.get("sellAmount").unwrap()) == expected_sell);
assert!(u256(trade.get("buyAmount").unwrap()) == expected_buy);
let u257 = u256(trade.get("sellAmount").unwrap());
let u258 = u256(trade.get("buyAmount").unwrap());
tracing::info!("newlog u257={:?}", u257);
tracing::info!("newlog expected_sell={:?}", expected_sell);
tracing::info!("newlog u258={:?}", u258);
tracing::info!("newlog expected_buy={:?}", expected_buy);
assert!(u257 == expected_sell);
assert!(u258 == expected_buy);
}
self
}
Expand Down

0 comments on commit faba3dc

Please sign in to comment.