diff --git a/contracts/atomic-order-example/src/contract.rs b/contracts/atomic-order-example/src/contract.rs index eb7f3f67..841094b4 100644 --- a/contracts/atomic-order-example/src/contract.rs +++ b/contracts/atomic-order-example/src/contract.rs @@ -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( @@ -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; diff --git a/contracts/atomic-order-example/src/tests.rs b/contracts/atomic-order-example/src/tests.rs index d61b59b4..5c91e1a7 100644 --- a/contracts/atomic-order-example/src/tests.rs +++ b/contracts/atomic-order-example/src/tests.rs @@ -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; @@ -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(); @@ -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), @@ -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, diff --git a/contracts/dummy/src/mock_pyth_attestation.rs b/contracts/dummy/src/mock_pyth_attestation.rs index 1359b7d6..b1246ad1 100644 --- a/contracts/dummy/src/mock_pyth_attestation.rs +++ b/contracts/dummy/src/mock_pyth_attestation.rs @@ -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}; @@ -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())