diff --git a/contracts/injective-cosmwasm-mock/src/contract.rs b/contracts/injective-cosmwasm-mock/src/contract.rs index 9d9dc56c..8dda88be 100644 --- a/contracts/injective-cosmwasm-mock/src/contract.rs +++ b/contracts/injective-cosmwasm-mock/src/contract.rs @@ -125,6 +125,18 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Std QueryMsg::TestMarketAtomicExecutionFeeMultiplier { market_id } => { to_json_binary(&querier.query_market_atomic_execution_fee_multiplier(&market_id)?) } + QueryMsg::TestQueryGrants { + grantee, + granter, + msg_type_url, + pagination, + } => { + deps.api.debug("Before query in contract"); + let res = &querier.query_grants(grantee.as_str(), granter.as_str(), msg_type_url.as_str(), &pagination)?; + deps.api.debug(format!("{:?}", res).as_str()); + to_json_binary(&querier.query_grants(grantee.as_str(), granter.as_str(), msg_type_url.as_str(), &pagination)?) + } + QueryMsg::TestGranteeGrants { grantee, pagination } => to_json_binary(&querier.query_grantee_grants(grantee.as_str(), &pagination)?), } } diff --git a/contracts/injective-cosmwasm-mock/src/msg.rs b/contracts/injective-cosmwasm-mock/src/msg.rs index 16a1ed5f..e282c095 100644 --- a/contracts/injective-cosmwasm-mock/src/msg.rs +++ b/contracts/injective-cosmwasm-mock/src/msg.rs @@ -116,4 +116,14 @@ pub enum QueryMsg { TestMarketAtomicExecutionFeeMultiplier { market_id: MarketId, }, + TestQueryGrants { + grantee: String, + granter: String, + msg_type_url: String, + pagination: Option, + }, + TestGranteeGrants { + grantee: String, + pagination: Option, + }, } diff --git a/contracts/injective-cosmwasm-mock/src/testing/authz.rs b/contracts/injective-cosmwasm-mock/src/testing/authz.rs new file mode 100644 index 00000000..2d21f90e --- /dev/null +++ b/contracts/injective-cosmwasm-mock/src/testing/authz.rs @@ -0,0 +1,48 @@ +use crate::{ + msg::QueryMsg, + utils::{ExchangeType, Setup}, +}; + +use crate::utils::create_generic_authorization; +use injective_cosmwasm::authz::response::GrantsResponse; +use injective_test_tube::injective_cosmwasm::authz::response::GranteeGrantsResponse; +use injective_test_tube::{Account, Module, RunnerResult, Wasm}; + +#[test] +#[cfg_attr(not(feature = "integration"), ignore)] +fn test_query_grants() { + let env = Setup::new(ExchangeType::None); + let wasm = Wasm::new(&env.app); + + let msg_type_url = "/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder".to_string(); + let granter = &env.users[0].account; + let grantee = env.contract_address.clone(); + + create_generic_authorization(&env.app, granter, grantee.to_owned(), msg_type_url.to_owned(), None); + + let query_msg = QueryMsg::TestQueryGrants { + grantee, + granter: granter.address(), + msg_type_url, + pagination: None, + }; + let _res: RunnerResult = wasm.query(&env.contract_address, &query_msg); + //todo fix query +} + +#[test] +#[cfg_attr(not(feature = "integration"), ignore)] +fn test_query_grantee_grants() { + let env = Setup::new(ExchangeType::None); + let wasm = Wasm::new(&env.app); + + let msg_type_url = "/injective.exchange.v1beta1.MsgCreateDerivativeMarketOrder".to_string(); + let granter = &env.users[0].account; + let grantee = env.contract_address.clone(); + + create_generic_authorization(&env.app, granter, grantee.to_owned(), msg_type_url.to_owned(), None); + + let query_msg = QueryMsg::TestGranteeGrants { grantee, pagination: None }; + let _res: RunnerResult = wasm.query(&env.contract_address, &query_msg); + //todo fix query +} diff --git a/contracts/injective-cosmwasm-mock/src/testing/mod.rs b/contracts/injective-cosmwasm-mock/src/testing/mod.rs index 87210135..b78f1959 100644 --- a/contracts/injective-cosmwasm-mock/src/testing/mod.rs +++ b/contracts/injective-cosmwasm-mock/src/testing/mod.rs @@ -1,2 +1,3 @@ +mod authz; mod query_exchange_derivative_tests; mod query_exchange_tests; diff --git a/contracts/injective-cosmwasm-mock/src/testing/query_exchange_derivative_tests.rs b/contracts/injective-cosmwasm-mock/src/testing/query_exchange_derivative_tests.rs index 131b57ec..c973ad33 100644 --- a/contracts/injective-cosmwasm-mock/src/testing/query_exchange_derivative_tests.rs +++ b/contracts/injective-cosmwasm-mock/src/testing/query_exchange_derivative_tests.rs @@ -356,7 +356,6 @@ fn test_query_trader_transient_derivative_orders() { .and_then(|event| event.attributes.iter().find(|a| a.key == "query_str")); assert!(transient_query.is_some()); - println!("{:?}", transient_query); let expected_order_info = "Ok(TraderDerivativeOrdersResponse { orders: Some([TrimmedDerivativeLimitOrder { price: FPDecimal { num: 9700000000000000000000000, sign: 1 }, quantity: FPDecimal { num: 100000000000000000, sign: 1 }, margin: FPDecimal { num: 1940000000000000000000000, sign: 1 }, fillable: FPDecimal { num: 100000000000000000, sign: 1 }, isBuy: true"; assert!(transient_query.unwrap().value.contains(expected_order_info)); } diff --git a/contracts/injective-cosmwasm-mock/src/testing/query_exchange_tests.rs b/contracts/injective-cosmwasm-mock/src/testing/query_exchange_tests.rs index 2519e0ff..c2f94a56 100644 --- a/contracts/injective-cosmwasm-mock/src/testing/query_exchange_tests.rs +++ b/contracts/injective-cosmwasm-mock/src/testing/query_exchange_tests.rs @@ -1,13 +1,12 @@ use crate::{ msg::{ExecuteMsg, QueryMsg}, utils::{ - add_spot_initial_liquidity, add_spot_order_as, add_spot_orders, dec_to_proto, get_initial_liquidity_orders_vector, get_spot_market_id, - human_to_dec, human_to_proto, scale_price_quantity_for_spot_market, str_coin, ExchangeType, HumanOrder, Setup, BASE_DECIMALS, BASE_DENOM, - QUOTE_DECIMALS, QUOTE_DENOM, + add_spot_initial_liquidity, add_spot_order_as, add_spot_orders, dec_to_proto, execute_all_authorizations, + get_initial_liquidity_orders_vector, get_spot_market_id, human_to_dec, human_to_proto, scale_price_quantity_for_spot_market, + scale_price_quantity_for_spot_market_dec, str_coin, ExchangeType, HumanOrder, Setup, BASE_DECIMALS, BASE_DENOM, QUOTE_DECIMALS, QUOTE_DENOM, }, }; -use crate::utils::{execute_all_authorizations, scale_price_quantity_for_spot_market_dec}; use cosmwasm_std::{Addr, Coin}; use injective_cosmwasm::{ checked_address_to_subaccount_id, @@ -20,8 +19,8 @@ use injective_math::FPDecimal; use injective_std::types::injective::exchange::v1beta1::{ Deposit, MsgDeposit, MsgInstantSpotMarketLaunch, OrderType, QueryAggregateMarketVolumeResponse, QuerySubaccountDepositsRequest, }; -use injective_test_tube::injective_cosmwasm::get_default_subaccount_id_for_checked_address; -use injective_test_tube::{Account, Exchange, Module, RunnerResult, Wasm}; + +use injective_test_tube::{injective_cosmwasm::get_default_subaccount_id_for_checked_address, Account, Exchange, Module, RunnerResult, Wasm}; #[test] #[cfg_attr(not(feature = "integration"), ignore)] @@ -71,37 +70,24 @@ fn test_query_subaccount_deposit() { let subaccount_id = checked_address_to_subaccount_id(&Addr::unchecked(env.users[0].account.address()), 1u32); - { + let make_deposit = |amount: &str, denom_key: &str| { exchange .deposit( MsgDeposit { sender: env.users[0].account.address(), subaccount_id: subaccount_id.to_string(), amount: Some(injective_std::types::cosmos::base::v1beta1::Coin { - amount: "10000000000000000000".to_string(), - denom: env.denoms["base"].clone(), + amount: amount.to_string(), + denom: env.denoms[denom_key].clone(), }), }, &env.users[0].account, ) .unwrap(); - } + }; - { - exchange - .deposit( - MsgDeposit { - sender: env.users[0].account.address(), - subaccount_id: subaccount_id.to_string(), - amount: Some(injective_std::types::cosmos::base::v1beta1::Coin { - amount: "100000000".to_string(), - denom: env.denoms["quote"].clone(), - }), - }, - &env.users[0].account, - ) - .unwrap(); - } + make_deposit("10000000000000000000", "base"); + make_deposit("100000000", "quote"); let response = exchange .query_subaccount_deposits(&QuerySubaccountDepositsRequest { @@ -218,7 +204,7 @@ fn test_query_trader_spot_orders() { let res: TraderSpotOrdersResponse = wasm.query(&env.contract_address, &query_msg).unwrap(); let orders = res.orders.clone().unwrap(); - assert_eq!(orders.len(), 1); + assert_eq!(orders.len(), 1, "Expected exactly one order in the response"); let expected_orders = TrimmedSpotLimitOrder { price: human_to_dec("10.01", QUOTE_DECIMALS - BASE_DECIMALS), quantity: human_to_dec("5.1", BASE_DECIMALS), diff --git a/contracts/injective-cosmwasm-mock/src/utils.rs b/contracts/injective-cosmwasm-mock/src/utils.rs index 44c534ff..24ad57db 100644 --- a/contracts/injective-cosmwasm-mock/src/utils.rs +++ b/contracts/injective-cosmwasm-mock/src/utils.rs @@ -637,6 +637,7 @@ pub fn create_send_authorization(app: &InjectiveTestApp, granter: &SigningAccoun pub fn execute_all_authorizations(app: &InjectiveTestApp, granter: &SigningAccount, grantee: String) { create_generic_authorization(app, granter, grantee.clone(), MSG_CREATE_SPOT_LIMIT_ORDER_ENDPOINT.to_string(), None); + create_generic_authorization( app, granter,