Skip to content

Commit

Permalink
fix: update atomic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrobot committed Aug 8, 2024
1 parent 5f6bfb6 commit b4bb138
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
25 changes: 2 additions & 23 deletions contracts/atomic-order-example/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ fn handle_atomic_order_reply(
.map_err(ContractError::SubMsgFailure)
.unwrap();

deps.api.debug(">>>>>>>>>>");
let first_messsage = binding.msg_responses.first();

let order_response = Exchange::MsgCreateSpotMarketOrderResponse::decode(
Expand All @@ -169,29 +170,7 @@ fn handle_atomic_order_reply(
.results
.ok_or_else(|| ContractError::SubMsgFailure("No trade data".to_owned()))
.unwrap();
// let order_response: tx::MsgCreateSpotMarketOrderResponse = Message::parse_from_bytes(
// msg.result
// .into_result()
// .map_err(ContractError::SubMsgFailure)?
// .data
// .ok_or_else(|| ContractError::ReplyParseFailure {
// id,
// err: "Missing reply data".to_owned(),
// })?
// .as_slice(),
// )
// .map_err(|err| ContractError::ReplyParseFailure {
// id,
// err: err.to_string(),
// })?;

// // unwrap results into trade_data
// let trade_data = match order_response.results.into_option() {
// Some(trade_data) => Ok(trade_data),
// None => Err(ContractError::CustomError {
// val: "No trade data in order response".to_string(),
// }),
// }?;

let quantity = FPDecimal::from_str(&trade_data.quantity)? / dec_scale_factor;
let price = FPDecimal::from_str(&trade_data.price)? / dec_scale_factor;
let fee = FPDecimal::from_str(&trade_data.fee)? / dec_scale_factor;
Expand Down
21 changes: 13 additions & 8 deletions contracts/atomic-order-example/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::str::FromStr;

use cosmwasm_std::testing::{mock_info, MockApi, MockStorage};
use cosmwasm_std::testing::{message_info, MockApi, MockStorage};
use cosmwasm_std::{
coins, to_json_binary, BankMsg, Binary, ContractResult, CosmosMsg, OwnedDeps, QuerierResult,
Reply, SubMsgResponse, SubMsgResult, SystemResult, Uint128,
coins, to_json_binary, Addr, BankMsg, Binary, ContractResult, CosmosMsg, MsgResponse,
OwnedDeps, QuerierResult, Reply, SubMsgResponse, SubMsgResult, SystemResult, Uint128,
};

use injective_cosmwasm::InjectiveMsg::CreateSpotMarketOrder;
Expand Down Expand Up @@ -33,7 +33,7 @@ fn proper_initialization() {
)
.expect("failed to create market_id"),
};
let info = mock_info(sender_addr, &coins(1000, "earth"));
let info = message_info(&Addr::unchecked(sender_addr), &coins(1000, "earth"));

// we can just call .unwrap() to assert this was a success
let res = instantiate(test_deps().as_mut_deps(), inj_mock_env(), info, msg).unwrap();
Expand All @@ -52,12 +52,12 @@ fn test_swap() {
let msg = InstantiateMsg {
market_id: market_id.clone(),
};
let info = mock_info(contract_addr, &coins(1000, "earth"));
let info = message_info(&Addr::unchecked(contract_addr), &coins(1000, "earth"));
let mut deps = test_deps();
let env = inj_mock_env();
let _ = instantiate(deps.as_mut_deps(), env.clone(), info, msg);

let info = mock_info(sender_addr, &coins(9000, "usdt"));
let info = message_info(&Addr::unchecked(sender_addr), &coins(9000, "usdt"));
let msg = ExecuteMsg::SwapSpot {
quantity: i32_to_dec(8),
price: i32_to_dec(1000),
Expand Down Expand Up @@ -96,12 +96,17 @@ fn test_swap() {
);

let binary_response = Binary::from_base64("CkIweGRkNzI5MmY2ODcwMzIwOTc2YTUxYTUwODBiMGQ2NDU5M2NhZjE3OWViM2YxOTNjZWVlZGFiNGVhNWUxNDljZWISQwoTODAwMDAwMDAwMDAwMDAwMDAwMBIWMTAwMDAwMDAwMDAwMDAwMDAwMDAwMBoUMzYwMDAwMDAwMDAwMDAwMDAwMDA=").unwrap();
#[allow(deprecated)]
let reply_msg = Reply {
id: ATOMIC_ORDER_REPLY_ID,
result: SubMsgResult::Ok(SubMsgResponse {
events: vec![],
data: Some(binary_response),
msg_responses: vec![],
data: None,
msg_responses: vec![MsgResponse {
type_url: "/injective.exchange.v1beta1.MsgCreateSpotMarketOrderResponse"
.to_string(),
value: binary_response,
}],
}),
payload: Binary::default(),
gas_used: 0,
Expand Down
8 changes: 5 additions & 3 deletions contracts/dummy/src/mock_pyth_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ pub fn execute_trigger_pyth_update(
mod tests {
use std::marker::PhantomData;

use cosmwasm_std::testing::{mock_env, mock_info, MockApi, MockStorage};
use cosmwasm_std::{Api, CustomQuery, DepsMut, OwnedDeps, Querier, QuerierWrapper, Storage};
use cosmwasm_std::testing::{message_info, mock_env, MockApi, MockStorage};
use cosmwasm_std::{
Addr, Api, CustomQuery, DepsMut, OwnedDeps, Querier, QuerierWrapper, Storage,
};

use injective_cosmwasm::{InjectiveQueryWrapper, WasmMockQuerier};

Expand All @@ -58,7 +60,7 @@ mod tests {
let sender_addr = "inj1x2ck0ql2ngyxqtw8jteyc0tchwnwxv7npaungt";

let msg = ExecuteMsg::TriggerPythUpdate { price: 10000 };
let info = mock_info(sender_addr, &[]);
let info = message_info(&Addr::unchecked(sender_addr), &[]);
let env = mock_env();
let res = execute(inj_mock_deps().as_mut_deps(), env, info, msg);
assert!(res.is_ok())
Expand Down

0 comments on commit b4bb138

Please sign in to comment.