|
| 1 | +use crate::{ |
| 2 | + msg::{ExecuteMsg, QueryMsg}, |
| 3 | + testing::test_utils::{ |
| 4 | + create_generic_authorization, create_realistic_atom_usdt_sell_orders_from_spreadsheet, |
| 5 | + create_realistic_eth_usdt_buy_orders_from_spreadsheet, human_to_dec, init_rich_account, |
| 6 | + init_self_relaying_contract_and_get_address, launch_realistic_atom_usdt_spot_market, |
| 7 | + launch_realistic_weth_usdt_spot_market, must_init_account_with_funds, str_coin, Decimals, |
| 8 | + ATOM, ETH, INJ, USDT, |
| 9 | + }, |
| 10 | + types::SwapEstimationResult, |
| 11 | +}; |
| 12 | + |
| 13 | +use cosmos_sdk_proto::{cosmwasm::wasm::v1::MsgExecuteContract, traits::MessageExt}; |
| 14 | +use injective_std::{ |
| 15 | + shim::Any, |
| 16 | + types::cosmos::authz::v1beta1::{MsgExec, MsgExecResponse}, |
| 17 | +}; |
| 18 | +use injective_test_tube::{ |
| 19 | + Account, Exchange, ExecuteResponse, InjectiveTestApp, Module, Runner, Wasm, |
| 20 | +}; |
| 21 | + |
| 22 | +#[test] |
| 23 | +pub fn set_route_for_third_party_test() { |
| 24 | + let app = InjectiveTestApp::new(); |
| 25 | + let wasm = Wasm::new(&app); |
| 26 | + let exchange = Exchange::new(&app); |
| 27 | + |
| 28 | + let owner = must_init_account_with_funds( |
| 29 | + &app, |
| 30 | + &[ |
| 31 | + str_coin("1", ETH, Decimals::Eighteen), |
| 32 | + str_coin("1", ATOM, Decimals::Six), |
| 33 | + str_coin("1_000", USDT, Decimals::Six), |
| 34 | + str_coin("10_000", INJ, Decimals::Eighteen), |
| 35 | + ], |
| 36 | + ); |
| 37 | + |
| 38 | + let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); |
| 39 | + let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); |
| 40 | + |
| 41 | + let contr_addr = init_self_relaying_contract_and_get_address( |
| 42 | + &wasm, |
| 43 | + &owner, |
| 44 | + &[str_coin("1_000", USDT, Decimals::Six)], |
| 45 | + ); |
| 46 | + |
| 47 | + let trader1 = init_rich_account(&app); |
| 48 | + let trader2 = init_rich_account(&app); |
| 49 | + let trader3 = init_rich_account(&app); |
| 50 | + |
| 51 | + create_generic_authorization( |
| 52 | + &app, |
| 53 | + &owner, |
| 54 | + trader1.address().to_string(), |
| 55 | + "/cosmwasm.wasm.v1.MsgExecuteContract".to_string(), |
| 56 | + None, |
| 57 | + ); |
| 58 | + |
| 59 | + create_realistic_eth_usdt_buy_orders_from_spreadsheet( |
| 60 | + &app, |
| 61 | + &spot_market_1_id, |
| 62 | + &trader1, |
| 63 | + &trader2, |
| 64 | + ); |
| 65 | + create_realistic_atom_usdt_sell_orders_from_spreadsheet( |
| 66 | + &app, |
| 67 | + &spot_market_2_id, |
| 68 | + &trader1, |
| 69 | + &trader2, |
| 70 | + &trader3, |
| 71 | + ); |
| 72 | + |
| 73 | + app.increase_time(1); |
| 74 | + |
| 75 | + let eth_to_swap = "4.08"; |
| 76 | + |
| 77 | + let set_route_msg = ExecuteMsg::SetRoute { |
| 78 | + source_denom: ETH.to_string(), |
| 79 | + target_denom: ATOM.to_string(), |
| 80 | + route: vec![ |
| 81 | + spot_market_1_id.as_str().into(), |
| 82 | + spot_market_2_id.as_str().into(), |
| 83 | + ], |
| 84 | + }; |
| 85 | + |
| 86 | + let execute_msg = MsgExecuteContract { |
| 87 | + contract: contr_addr.clone(), |
| 88 | + sender: owner.address().to_string(), |
| 89 | + msg: serde_json_wasm::to_vec(&set_route_msg).unwrap(), |
| 90 | + funds: vec![], |
| 91 | + }; |
| 92 | + |
| 93 | + // execute on more time to excercise account sequence |
| 94 | + let msg = MsgExec { |
| 95 | + grantee: trader1.address().to_string(), |
| 96 | + msgs: vec![Any { |
| 97 | + type_url: "/cosmwasm.wasm.v1.MsgExecuteContract".to_string(), |
| 98 | + value: execute_msg.to_bytes().unwrap(), |
| 99 | + }], |
| 100 | + }; |
| 101 | + |
| 102 | + let _res: ExecuteResponse<MsgExecResponse> = app |
| 103 | + .execute(msg, "/cosmos.authz.v1beta1.MsgExec", &trader1) |
| 104 | + .unwrap(); |
| 105 | + |
| 106 | + let _query_result: SwapEstimationResult = wasm |
| 107 | + .query( |
| 108 | + &contr_addr, |
| 109 | + &QueryMsg::GetOutputQuantity { |
| 110 | + source_denom: ETH.to_string(), |
| 111 | + target_denom: ATOM.to_string(), |
| 112 | + from_quantity: human_to_dec(eth_to_swap, Decimals::Eighteen), |
| 113 | + }, |
| 114 | + ) |
| 115 | + .unwrap(); |
| 116 | +} |
0 commit comments