Skip to content

Commit

Permalink
chore: fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrobot committed Oct 30, 2024
1 parent fe28cfc commit a694d8f
Show file tree
Hide file tree
Showing 13 changed files with 4,990 additions and 426 deletions.
245 changes: 61 additions & 184 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cosmwasm-std = { version = "2.1.0", features = [ "abort", "cosmwasm_1_2",
cw-storage-plus = { version = "2.0.0" }
cw-utils = { version = "2.0.0" }
cw2 = { version = "2.0.0" }
injective-cosmwasm = { version = "0.3.0" }
injective-cosmwasm = { version = "=0.3.0" }
injective-math = { version = "0.3.0" }
injective-std = { version = "1.13.0" }
injective-test-tube = { version = "1.13.2" }
Expand All @@ -21,6 +21,7 @@ schemars = { version = "0.8.16", features = [ "enumset" ] }
serde = { version = "1.0.193", default-features = false, features = [ "derive" ] }
serde-json-wasm = { version = "1.0.1" }
serde_json = { version = "1.0.120" }
test-tube-inj = { version = "=2.0.1" }
thiserror = { version = "1.0.52" }

[profile.release]
Expand Down
3 changes: 2 additions & 1 deletion contracts/swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cw2 = { workspace = true }
injective-cosmwasm = { workspace = true }
injective-math = { workspace = true }
injective-std = { workspace = true }
injective-testing = { workspace = true }
prost = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
Expand All @@ -37,3 +36,5 @@ thiserror = { workspace = true }
[dev-dependencies]
injective-std = { workspace = true }
injective-test-tube = { workspace = true }
injective-testing = { workspace = true }
test-tube-inj = { workspace = true }
2 changes: 1 addition & 1 deletion contracts/swap/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
types::{CurrentSwapOperation, CurrentSwapStep, FPCoin, SwapEstimationAmount, SwapQuantityMode, SwapResults},
};

use cosmwasm_std::{BankMsg, Coin, DepsMut, Env, Event, MessageInfo, Reply, Response, StdResult, SubMsg, Uint128};
use cosmwasm_std::{BankMsg, Coin, DepsMut, Env, Event, MessageInfo, Reply, Response, StdResult, SubMsg};
use injective_cosmwasm::{
create_spot_market_order_msg, get_default_subaccount_id_for_checked_address, InjectiveMsgWrapper, InjectiveQuerier, InjectiveQueryWrapper,
OrderType, SpotOrder,
Expand Down
50 changes: 15 additions & 35 deletions contracts/swap/src/testing/authz_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ use crate::{
msg::ExecuteMsg,
testing::test_utils::{
create_contract_authorization, create_realistic_atom_usdt_sell_orders_from_spreadsheet,
create_realistic_eth_usdt_buy_orders_from_spreadsheet, init_rich_account,
init_self_relaying_contract_and_get_address, launch_realistic_atom_usdt_spot_market,
launch_realistic_weth_usdt_spot_market, must_init_account_with_funds, str_coin, Decimals,
ATOM, ETH, INJ, USDT,
create_realistic_eth_usdt_buy_orders_from_spreadsheet, init_rich_account, init_self_relaying_contract_and_get_address,
launch_realistic_atom_usdt_spot_market, launch_realistic_weth_usdt_spot_market, must_init_account_with_funds, str_coin, Decimals, ATOM, ETH,
INJ, USDT,
},
};

use cosmos_sdk_proto::{cosmwasm::wasm::v1::MsgExecuteContract, traits::MessageExt};
use injective_std::{shim::Any, types::cosmos::authz::v1beta1::MsgExec};
use injective_std::{
shim::Any,
types::{cosmos::authz::v1beta1::MsgExec, cosmwasm::wasm::v1::MsgExecuteContract},
};
use injective_test_tube::{Account, Authz, Exchange, InjectiveTestApp, Module, Wasm};
use prost::Message;

#[test]
pub fn set_route_for_third_party_test() {
Expand All @@ -33,11 +35,7 @@ pub fn set_route_for_third_party_test() {
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)],
);
let contr_addr = init_self_relaying_contract_and_get_address(&wasm, &owner, &[str_coin("1_000", USDT, Decimals::Six)]);

let trader1 = init_rich_account(&app);
let trader2 = init_rich_account(&app);
Expand All @@ -53,29 +51,15 @@ pub fn set_route_for_third_party_test() {
None,
);

create_realistic_eth_usdt_buy_orders_from_spreadsheet(
&app,
&spot_market_1_id,
&trader1,
&trader2,
);
create_realistic_atom_usdt_sell_orders_from_spreadsheet(
&app,
&spot_market_2_id,
&trader1,
&trader2,
&trader3,
);
create_realistic_eth_usdt_buy_orders_from_spreadsheet(&app, &spot_market_1_id, &trader1, &trader2);
create_realistic_atom_usdt_sell_orders_from_spreadsheet(&app, &spot_market_2_id, &trader1, &trader2, &trader3);

app.increase_time(1);

let set_route_msg = ExecuteMsg::SetRoute {
source_denom: ETH.to_string(),
target_denom: ATOM.to_string(),
route: vec![
spot_market_1_id.as_str().into(),
spot_market_2_id.as_str().into(),
],
route: vec![spot_market_1_id.as_str().into(), spot_market_2_id.as_str().into()],
};

let execute_msg = MsgExecuteContract {
Expand All @@ -85,12 +69,11 @@ pub fn set_route_for_third_party_test() {
funds: vec![],
};

// execute on more time to excercise account sequence
let msg = MsgExec {
grantee: trader1.address().to_string(),
msgs: vec![Any {
type_url: "/cosmwasm.wasm.v1.MsgExecuteContract".to_string(),
value: execute_msg.to_bytes().unwrap(),
value: execute_msg.encode_to_vec(),
}],
};

Expand All @@ -101,13 +84,10 @@ pub fn set_route_for_third_party_test() {
grantee: trader1.address().to_string(),
msgs: vec![Any {
type_url: "/cosmwasm.wasm.v1.MsgExecuteContract".to_string(),
value: execute_msg.to_bytes().unwrap(),
value: execute_msg.encode_to_vec(),
}],
};

let err = authz.exec(msg, &trader1).unwrap_err();
assert!(
err.to_string().contains("failed to update grant with key"),
"incorrect error returned by execute"
);
assert!(err.to_string().contains("failed to get grant with given granter"));
}
23 changes: 8 additions & 15 deletions contracts/swap/src/testing/config_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::testing::{mock_env, mock_info};
use cosmwasm_std::testing::{message_info, mock_env};
use cosmwasm_std::{coins, Addr};

use injective_cosmwasm::{inj_mock_deps, OwnedDepsExt};
Expand All @@ -17,14 +17,12 @@ pub fn admin_can_update_config() {
fee_recipient: Addr::unchecked(TEST_CONTRACT_ADDR),
admin: Addr::unchecked(TEST_USER_ADDR),
};
CONFIG
.save(deps.as_mut_deps().storage, &config)
.expect("could not save config");
CONFIG.save(deps.as_mut_deps().storage, &config).expect("could not save config");

let new_admin = Addr::unchecked("new_admin");
let new_fee_recipient = Addr::unchecked("new_fee_recipient");

let info = mock_info(TEST_USER_ADDR, &coins(12, "eth"));
let info = message_info(&Addr::unchecked(TEST_USER_ADDR), &coins(12, "eth"));

let msg = ExecuteMsg::UpdateConfig {
admin: Some(new_admin.clone()),
Expand All @@ -36,18 +34,15 @@ pub fn admin_can_update_config() {

let config = CONFIG.load(deps.as_mut_deps().storage).unwrap();
assert_eq!(config.admin, new_admin, "admin was not updated");
assert_eq!(
config.fee_recipient, new_fee_recipient,
"fee_recipient was not updated"
);
assert_eq!(config.fee_recipient, new_fee_recipient, "fee_recipient was not updated");

res.events
.iter()
.find(|e| e.ty == "config_updated")
.expect("update_config event expected")
.attributes
.iter()
.find(|a| a.key == "admin" && a.value == new_admin)
.find(|a| a.key == "admin" && a.value == new_admin.to_string())
.expect("admin attribute expected");

res.events
Expand All @@ -56,7 +51,7 @@ pub fn admin_can_update_config() {
.expect("update_config event expected")
.attributes
.iter()
.find(|a| a.key == "fee_recipient" && a.value == new_fee_recipient)
.find(|a| a.key == "fee_recipient" && a.value == new_fee_recipient.to_string())
.expect("fee_recipient attribute expected");
}

Expand All @@ -68,14 +63,12 @@ pub fn non_admin_cannot_update_config() {
fee_recipient: Addr::unchecked(TEST_CONTRACT_ADDR),
admin: Addr::unchecked(TEST_USER_ADDR),
};
CONFIG
.save(deps.as_mut_deps().storage, &config)
.expect("could not save config");
CONFIG.save(deps.as_mut_deps().storage, &config).expect("could not save config");

let new_admin = Addr::unchecked("new_admin");
let new_fee_recipient = Addr::unchecked("new_fee_recipient");

let info = mock_info("non_admin", &coins(12, "eth"));
let info = message_info(&Addr::unchecked("non_admin"), &coins(12, "eth"));

let msg = ExecuteMsg::UpdateConfig {
admin: Some(new_admin),
Expand Down
Loading

0 comments on commit a694d8f

Please sign in to comment.