-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description #2149 # Changes Adds WETH price to the Auction cache if it doesn't exist. Also adds WETH address to the Orders cache which should be refactored in the future. ## How to test Added e2e test ## Related Issues Fixes #2149
- Loading branch information
1 parent
0a1fb46
commit aeed381
Showing
4 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use { | ||
e2e::{ | ||
setup::{safe::Safe, *}, | ||
tx, | ||
}, | ||
ethcontract::U256, | ||
model::{ | ||
order::{OrderCreation, OrderKind, BUY_ETH_ADDRESS}, | ||
signature::EcdsaSigningScheme, | ||
}, | ||
secp256k1::SecretKey, | ||
shared::ethrpc::Web3, | ||
web3::signing::SecretKeyRef, | ||
}; | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn local_node_test() { | ||
run_test(test).await; | ||
} | ||
|
||
async fn test(web3: Web3) { | ||
tracing::info!("Setting up chain state."); | ||
let mut onchain = OnchainComponents::deploy(web3.clone()).await; | ||
|
||
let [solver] = onchain.make_solvers(to_wei(10)).await; | ||
let [trader] = onchain.make_accounts(to_wei(10)).await; | ||
let safe = Safe::deploy(trader.clone(), &web3).await; | ||
let [token] = onchain | ||
.deploy_tokens_with_weth_uni_v2_pools(to_wei(1000), to_wei(1000)) | ||
.await; | ||
|
||
token.mint(trader.address(), to_wei(4)).await; | ||
tx!( | ||
trader.account(), | ||
token.approve(onchain.contracts().allowance, to_wei(4)) | ||
); | ||
|
||
tracing::info!("Starting services."); | ||
let solver_endpoint = colocation::start_solver(onchain.contracts().weth.address()).await; | ||
colocation::start_driver(onchain.contracts(), &solver_endpoint, &solver); | ||
|
||
let services = Services::new(onchain.contracts()).await; | ||
services.start_autopilot(vec![ | ||
"--enable-colocation=true".to_string(), | ||
"--drivers=test_solver|http://localhost:11088/test_solver".to_string(), | ||
]); | ||
services | ||
.start_api(vec!["--enable-eth-smart-contract-payments=true".to_string()]) | ||
.await; | ||
|
||
tracing::info!("Placing order"); | ||
let balance = onchain | ||
.contracts() | ||
.weth | ||
.balance_of(safe.address()) | ||
.call() | ||
.await | ||
.unwrap(); | ||
assert_eq!(balance, 0.into()); | ||
let order = OrderCreation { | ||
sell_token: token.address(), | ||
sell_amount: to_wei(4), | ||
buy_token: BUY_ETH_ADDRESS, | ||
buy_amount: to_wei(3), | ||
valid_to: model::time::now_in_epoch_seconds() + 300, | ||
partially_fillable: true, | ||
kind: OrderKind::Sell, | ||
receiver: Some(safe.address()), | ||
..Default::default() | ||
} | ||
.sign( | ||
EcdsaSigningScheme::Eip712, | ||
&onchain.contracts().domain_separator, | ||
SecretKeyRef::from(&SecretKey::from_slice(trader.private_key()).unwrap()), | ||
); | ||
services.create_order(&order).await.unwrap(); | ||
|
||
tracing::info!("Waiting for trade."); | ||
let trade_happened = || async { | ||
let safe_balance = web3.eth().balance(safe.address(), None).await.unwrap(); | ||
// the balance is slightly less because of the fee | ||
(3_899_000_000_000_000_000_u128..4_000_000_000_000_000_000_u128) | ||
.contains(&safe_balance.as_u128()) | ||
}; | ||
wait_for_condition(TIMEOUT, trade_happened).await.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters