-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Market orders deprecation date remove #2536
Changes from all commits
6e7a660
8708c60
1c37cd1
15e1ffe
23e885e
05c3697
038f5fd
5e28857
b782f9a
80ddc22
f17e65f
45f42f5
7c66186
5bd29bf
84fb664
9349f04
0004af9
4622d85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ use { | |
BuyTokenDestination, | ||
EthflowData, | ||
OnchainOrderData, | ||
OnchainOrderPlacementError, | ||
Order, | ||
OrderBuilder, | ||
OrderClass, | ||
|
@@ -49,30 +48,17 @@ const DAI_PER_ETH: u32 = 1_000; | |
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn local_node_eth_flow() { | ||
async fn local_node_eth_flow_tx() { | ||
run_test(eth_flow_tx).await; | ||
} | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn local_node_eth_flow_insufficient_fee() { | ||
run_test(eth_flow_tx_insufficient_fee).await; | ||
} | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn local_node_eth_flow_indexing_after_refund() { | ||
run_test(eth_flow_indexing_after_refund).await; | ||
} | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn local_node_eth_flow_zero_fee() { | ||
run_test(eth_flow_tx_zero_fee).await; | ||
} | ||
|
||
/// Tests that eth flow orders can be created with 0 fee. | ||
async fn eth_flow_tx_zero_fee(web3: Web3) { | ||
async fn eth_flow_tx(web3: Web3) { | ||
let mut onchain = OnchainComponents::deploy(web3.clone()).await; | ||
|
||
let [solver] = onchain.make_solvers(to_wei(2)).await; | ||
|
@@ -105,11 +91,8 @@ async fn eth_flow_tx_zero_fee(web3: Web3) { | |
let valid_to = chrono::offset::Utc::now().timestamp() as u32 | ||
+ timestamp_of_current_block_in_seconds(&web3).await.unwrap() | ||
+ 3600; | ||
let mut ethflow_order = | ||
let ethflow_order = | ||
ExtendedEthFlowOrder::from_quote("e, valid_to).include_slippage_bps(300); | ||
// Set fee_amount to 0 to make it behave like a limit order instead of a market | ||
// order. | ||
ethflow_order.0.fee_amount = 0.into(); | ||
|
||
submit_order(ðflow_order, trader.account(), onchain.contracts()).await; | ||
|
||
|
@@ -148,122 +131,6 @@ async fn eth_flow_tx_zero_fee(web3: Web3) { | |
.await; | ||
} | ||
|
||
async fn eth_flow_tx(web3: Web3) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this test removed, it still seems legit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I spent some time figuring out why some tests were removed. Would appreciate more context on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not actually removed, it's just code diff shows it in a weird way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and |
||
let mut onchain = OnchainComponents::deploy(web3.clone()).await; | ||
|
||
let [solver] = onchain.make_solvers(to_wei(2)).await; | ||
let [trader] = onchain.make_accounts(to_wei(2)).await; | ||
|
||
// Create token with Uniswap pool for price estimation | ||
let [dai] = onchain | ||
.deploy_tokens_with_weth_uni_v2_pools(to_wei(DAI_PER_ETH * 1_000), to_wei(1_000)) | ||
.await; | ||
|
||
// Get a quote from the services | ||
let buy_token = dai.address(); | ||
let receiver = H160([0x42; 20]); | ||
let sell_amount = to_wei(1); | ||
let intent = EthFlowTradeIntent { | ||
sell_amount, | ||
buy_token, | ||
receiver, | ||
}; | ||
|
||
let services = Services::new(onchain.contracts()).await; | ||
services.start_protocol(solver).await; | ||
|
||
let quote: OrderQuoteResponse = test_submit_quote( | ||
&services, | ||
&intent.to_quote_request(trader.account().address(), &onchain.contracts().weth), | ||
) | ||
.await; | ||
|
||
let valid_to = chrono::offset::Utc::now().timestamp() as u32 | ||
+ timestamp_of_current_block_in_seconds(&web3).await.unwrap() | ||
+ 3600; | ||
let ethflow_order = | ||
ExtendedEthFlowOrder::from_quote("e, valid_to).include_slippage_bps(300); | ||
|
||
submit_order(ðflow_order, trader.account(), onchain.contracts()).await; | ||
|
||
test_order_availability_in_api( | ||
&services, | ||
ðflow_order, | ||
&trader.address(), | ||
onchain.contracts(), | ||
) | ||
.await; | ||
|
||
tracing::info!("waiting for trade"); | ||
wait_for_condition(TIMEOUT, || async { services.solvable_orders().await == 1 }) | ||
.await | ||
.unwrap(); | ||
|
||
test_order_was_settled(&services, ðflow_order, &web3).await; | ||
|
||
test_trade_availability_in_api( | ||
services.client(), | ||
ðflow_order, | ||
&trader.address(), | ||
onchain.contracts(), | ||
) | ||
.await; | ||
} | ||
|
||
async fn eth_flow_tx_insufficient_fee(web3: Web3) { | ||
let mut onchain = OnchainComponents::deploy(web3.clone()).await; | ||
|
||
let [solver] = onchain.make_solvers(to_wei(2)).await; | ||
let [trader] = onchain.make_accounts(to_wei(2)).await; | ||
|
||
// Create token with Uniswap pool for price estimation | ||
let [dai] = onchain | ||
.deploy_tokens_with_weth_uni_v2_pools(to_wei(DAI_PER_ETH * 1_000), to_wei(1_000)) | ||
.await; | ||
|
||
// Get a quote from the services | ||
let buy_token = dai.address(); | ||
let receiver = H160([0x42; 20]); | ||
let sell_amount = to_wei(1); | ||
let intent = EthFlowTradeIntent { | ||
sell_amount, | ||
buy_token, | ||
receiver, | ||
}; | ||
|
||
let services = Services::new(onchain.contracts()).await; | ||
services.start_protocol(solver).await; | ||
|
||
let quote: OrderQuoteResponse = test_submit_quote( | ||
&services, | ||
&intent.to_quote_request(trader.account().address(), &onchain.contracts().weth), | ||
) | ||
.await; | ||
|
||
let valid_to = chrono::offset::Utc::now().timestamp() as u32 | ||
+ timestamp_of_current_block_in_seconds(&web3).await.unwrap() | ||
+ 3600; | ||
let mut ethflow_order = | ||
ExtendedEthFlowOrder::from_quote("e, valid_to).include_slippage_bps(300); | ||
// set a fee amount that is lower than the quoted fee amount | ||
ethflow_order.0.fee_amount = 1.into(); | ||
|
||
submit_order(ðflow_order, trader.account(), onchain.contracts()).await; | ||
|
||
let uid = ethflow_order.uid(onchain.contracts()).await; | ||
let is_available = || async { services.get_order(&uid).await.is_ok() }; | ||
wait_for_condition(TIMEOUT, is_available).await.unwrap(); | ||
|
||
let order = services.get_order(&uid).await.unwrap(); | ||
assert_eq!( | ||
order.metadata.onchain_order_data.unwrap().placement_error, | ||
Some(OnchainOrderPlacementError::InsufficientFee) | ||
); | ||
|
||
let auction_is_empty = || async { services.solvable_orders().await == 0 }; | ||
wait_for_condition(TIMEOUT, auction_is_empty).await.unwrap(); | ||
} | ||
|
||
async fn eth_flow_indexing_after_refund(web3: Web3) { | ||
let mut onchain = OnchainComponents::deploy(web3.clone()).await; | ||
|
||
|
@@ -542,16 +409,7 @@ async fn test_order_parameters( | |
placement_error: None, | ||
}) | ||
); | ||
|
||
match order.0.fee_amount.is_zero() { | ||
true => { | ||
assert_eq!(response.metadata.class, OrderClass::Limit); | ||
} | ||
false => { | ||
assert_eq!(response.metadata.class, OrderClass::Market); | ||
} | ||
} | ||
|
||
assert_eq!(response.metadata.class, OrderClass::Limit); | ||
assert!(order | ||
.is_valid_cowswap_signature(&response.signature, contracts) | ||
.await | ||
|
@@ -609,7 +467,7 @@ impl ExtendedEthFlowOrder { | |
sell_amount: quote.sell_amount, | ||
buy_amount: quote.buy_amount, | ||
app_data: ethcontract::Bytes(quote.app_data.hash().0), | ||
fee_amount: quote.fee_amount, | ||
fee_amount: 0.into(), | ||
valid_to, // note: valid to in the quote is always unlimited | ||
partially_fillable: quote.partially_fillable, | ||
quote_id: quote_response.id.expect("No quote id"), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests strike me as useful as a chocolate teapot, basically whenever they fail we just rerun the assertion and update the value (so it's not really testing anything useful).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the proper assert here would be
trader_b_eth_balance_after >= 49 eth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed as suggested by myself 😄