diff --git a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs index ed4d64a..6213738 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs @@ -1,4 +1,6 @@ -use injective_test_tube::{Account, Bank, Exchange, InjectiveTestApp, Module, RunnerResult, Wasm}; +use injective_test_tube::{ + Account, Bank, Exchange, InjectiveTestApp, Module, RunnerResult, SigningAccount, Wasm, +}; use std::ops::Neg; use crate::helpers::Scaled; @@ -35,36 +37,14 @@ use crate::types::{FPCoin, SwapEstimationResult}; In all tests contract is configured to self-relay trades and thus receive a 60% fee discount. */ -#[test] -fn happy_path_two_hops_swap_eth_atom_realistic_values_self_relaying() { - let app = InjectiveTestApp::new(); +pub fn happy_path_two_hops_test(app: InjectiveTestApp, owner: SigningAccount, contr_addr: String) { let wasm = Wasm::new(&app); let exchange = Exchange::new(&app); let bank = Bank::new(&app); - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); set_route_and_assert_success( &wasm, &owner, @@ -227,6 +207,35 @@ fn happy_path_two_hops_swap_eth_atom_realistic_values_self_relaying() { ); } +#[test] +fn happy_path_two_hops_swap_eth_atom_realistic_values_self_relaying() { + let app = InjectiveTestApp::new(); + let wasm = Wasm::new(&app); + + let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); + + let _validator = app + .get_first_validator_signing_account(INJ.to_string(), 1.2f64) + .unwrap(); + let owner = must_init_account_with_funds( + &app, + &[ + str_coin("1", ETH, Decimals::Eighteen), + str_coin("1", ATOM, Decimals::Six), + str_coin("1_000", USDT, Decimals::Six), + str_coin("10_000", INJ, Decimals::Eighteen), + ], + ); + + let contr_addr = init_self_relaying_contract_and_get_address( + &wasm, + &owner, + &[str_coin("1_000", USDT, Decimals::Six)], + ); + + happy_path_two_hops_test(app, owner, contr_addr); +} + #[test] fn happy_path_two_hops_swap_inj_eth_realistic_values_self_relaying() { let app = InjectiveTestApp::new(); diff --git a/contracts/swap/src/testing/migration_test.rs b/contracts/swap/src/testing/migration_test.rs new file mode 100644 index 0000000..73dc413 --- /dev/null +++ b/contracts/swap/src/testing/migration_test.rs @@ -0,0 +1,109 @@ +use crate::{ + msg::{FeeRecipient, InstantiateMsg, MigrateMsg}, + testing::{ + integration_realistic_tests_min_quantity::happy_path_two_hops_test, + test_utils::{ + must_init_account_with_funds, store_code, str_coin, Decimals, ATOM, ETH, INJ, USDT, + }, + }, +}; + +use cosmos_sdk_proto::cosmwasm::wasm::v1::{ + MsgMigrateContract, MsgMigrateContractResponse, QueryContractInfoRequest, + QueryContractInfoResponse, +}; +use cosmwasm_std::Addr; +use injective_test_tube::{Account, ExecuteResponse, InjectiveTestApp, Module, Runner, Wasm}; + +type V100InstantiateMsg = InstantiateMsg; + +#[test] +#[cfg_attr(not(feature = "integration"), ignore)] +fn test_migration_v100_to_v101() { + let app = InjectiveTestApp::new(); + let wasm = Wasm::new(&app); + + let wasm_byte_code = + std::fs::read("../../contracts/swap/src/testing/test_artifacts/swap-contract-v100.wasm") + .unwrap(); + + let owner = must_init_account_with_funds( + &app, + &[ + str_coin("1", ETH, Decimals::Eighteen), + str_coin("1", ATOM, Decimals::Six), + str_coin("1_000", USDT, Decimals::Six), + str_coin("10_000", INJ, Decimals::Eighteen), + ], + ); + + let swap_v100_code_id = wasm + .store_code(&wasm_byte_code, None, &owner) + .unwrap() + .data + .code_id; + + let swap_v100_address: String = wasm + .instantiate( + swap_v100_code_id, + &V100InstantiateMsg { + admin: Addr::unchecked(owner.address()), + fee_recipient: FeeRecipient::SwapContract, + }, + Some(&owner.address()), + Some("swap-contract"), + &[str_coin("1_000", USDT, Decimals::Six)], + &owner, + ) + .unwrap() + .data + .address; + + let res: QueryContractInfoResponse = app + .query( + "/cosmwasm.wasm.v1.Query/ContractInfo", + &QueryContractInfoRequest { + address: swap_v100_address.clone(), + }, + ) + .unwrap(); + let contract_info = res.contract_info.unwrap(); + + assert_eq!(res.address, swap_v100_address); + assert_eq!(contract_info.code_id, swap_v100_code_id); + assert_eq!(contract_info.creator, owner.address()); + assert_eq!(contract_info.label, "swap-contract"); + + let swap_v110_code_id = store_code(&wasm, &owner, "swap_contract".to_string()); + + let _res: ExecuteResponse = app + .execute( + MsgMigrateContract { + sender: owner.address(), + contract: swap_v100_address.clone(), + code_id: swap_v110_code_id, + msg: serde_json_wasm::to_vec(&MigrateMsg {}).unwrap(), + }, + "/cosmwasm.wasm.v1.MsgMigrateContract", + &owner, + ) + .unwrap(); + + let res: QueryContractInfoResponse = app + .query( + "/cosmwasm.wasm.v1.Query/ContractInfo", + &QueryContractInfoRequest { + address: swap_v100_address.clone(), + }, + ) + .unwrap(); + + let contract_info = res.contract_info.unwrap(); + + assert_eq!(res.address, swap_v100_address); + assert_eq!(contract_info.code_id, swap_v110_code_id); + assert_eq!(contract_info.creator, owner.address()); + assert_eq!(contract_info.label, "swap-contract"); + + happy_path_two_hops_test(app, owner, swap_v100_address); +} diff --git a/contracts/swap/src/testing/mod.rs b/contracts/swap/src/testing/mod.rs index 91e596c..ed9f565 100644 --- a/contracts/swap/src/testing/mod.rs +++ b/contracts/swap/src/testing/mod.rs @@ -2,6 +2,7 @@ mod config_tests; mod integration_logic_tests; mod integration_realistic_tests_exact_quantity; mod integration_realistic_tests_min_quantity; +mod migration_test; mod queries_tests; mod storage_tests; mod swap_tests; diff --git a/contracts/swap/src/testing/test_artifacts/swap-contract-v100.wasm b/contracts/swap/src/testing/test_artifacts/swap-contract-v100.wasm new file mode 100644 index 0000000..4bdd560 Binary files /dev/null and b/contracts/swap/src/testing/test_artifacts/swap-contract-v100.wasm differ