Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/stargate tester contract #220

Merged
merged 26 commits into from
Sep 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9d50d68
initial contract startgate example
jbernal87 Apr 24, 2024
122e45c
make query functional
jbernal87 Apr 24, 2024
f82826b
small refactor
jbernal87 Apr 24, 2024
7295a31
add subaccount deposit test
jbernal87 Apr 25, 2024
1585aa2
test: add auction tests and some clean ups
gorgos Apr 26, 2024
b657d5d
complete stargate queries
jbernal87 Apr 25, 2024
ebbb001
merge with dev
jbernal87 Jun 17, 2024
9d2c6ea
merge with dev fix
jbernal87 Jun 17, 2024
01e5f5a
chore: fix broken tests.
jbernal87 Jun 17, 2024
752c205
Merge branch 'dev' into feat/stargate-tester-contract
gorgos Jun 25, 2024
8fc14a0
chore: add to proto string helper to FPDecimal
gorgos Jun 28, 2024
a20cb20
chore: fix Cargo tomls
gorgos Jun 28, 2024
a8c5aee
feat: add more stargate examples
gorgos Jun 28, 2024
ebf0280
feat: authz tests.
jbernal87 Jul 1, 2024
825207d
chore: lints.
jbernal87 Jul 1, 2024
42ab0c6
chore: fix compilation issue
Kishan-Dhakan Jul 26, 2024
342efc6
feat: merged with dev
maxrobot Sep 16, 2024
0d5be4e
fix: linters
maxrobot Sep 16, 2024
5718e0b
chore: merge with other stargate branch
maxrobot Sep 16, 2024
41e822a
fix: incorrect message
maxrobot Sep 16, 2024
e43ad9a
chore: fix typo
maxrobot Sep 16, 2024
cd84611
Merge pull request #228 from InjectiveLabs/feat/stargate-tester-authz…
maxrobot Sep 16, 2024
2cfe4a1
fix: cargo conflict
maxrobot Sep 16, 2024
9b4741f
Merge remote-tracking branch 'origin' into feat/stargate-tester-contract
jbernal87 Sep 16, 2024
c92a4ad
chore merge dev
jbernal87 Sep 16, 2024
8a0f953
Merge remote-tracking branch 'origin/feat/stargate-tester-contract' i…
jbernal87 Sep 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
complete stargate queries
jbernal87 committed May 2, 2024
commit b657d5dab71e8015d686331eaa7353a5fbee1569
36 changes: 28 additions & 8 deletions contracts/injective-cosmwasm-stargate-example/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use crate::{
error::ContractError,
handle::{handle_test_transient_derivative_order, handle_test_transient_spot_order},
msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
query::handle_query_stargate,
reply::{handle_create_derivative_order_reply_stargate, handle_create_order_reply_stargate},
};
use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult};
use cw2::set_contract_version;
use injective_cosmwasm::{create_deposit_msg, InjectiveMsgWrapper, InjectiveQueryWrapper};
use injective_cosmwasm::{InjectiveMsgWrapper, InjectiveQueryWrapper};

const CONTRACT_NAME: &str = "crates.io:injective:dummy-stargate-contract";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const CREATE_SPOT_ORDER_REPLY_ID: u64 = 0u64;
pub const CREATE_DERIVATIVE_ORDER_REPLY_ID: u64 = 1u64;
pub const MSG_EXEC: &str = "/cosmos.authz.v1beta1.MsgExec";

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(deps: DepsMut, _env: Env, _info: MessageInfo, _msg: InstantiateMsg) -> Result<Response, ContractError> {
@@ -21,15 +22,25 @@ pub fn instantiate(deps: DepsMut, _env: Env, _info: MessageInfo, _msg: Instantia

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut<InjectiveQueryWrapper>,
deps: DepsMut<InjectiveQueryWrapper>,
env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response<InjectiveMsgWrapper>, ContractError> {
match msg {
ExecuteMsg::TestDepositMsg { subaccount_id, amount } => {
Ok(Response::new().add_message(create_deposit_msg(env.contract.address, subaccount_id, amount)))
}
ExecuteMsg::TestTraderTransientSpotOrders {
market_id,
subaccount_id,
price,
quantity,
} => handle_test_transient_spot_order(deps, env, &info, market_id, subaccount_id, price, quantity),
ExecuteMsg::TestTraderTransientDerivativeOrders {
market_id,
subaccount_id,
price,
quantity,
margin,
} => handle_test_transient_derivative_order(deps, env, &info, market_id, subaccount_id, price, quantity, margin),
}
}

@@ -39,3 +50,12 @@ pub fn query(deps: Deps<InjectiveQueryWrapper>, _env: Env, msg: QueryMsg) -> Std
QueryMsg::QueryStargate { path, query_request } => handle_query_stargate(&deps.querier, path, query_request),
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(deps: DepsMut<InjectiveQueryWrapper>, _env: Env, msg: Reply) -> Result<Response, ContractError> {
match msg.id {
CREATE_SPOT_ORDER_REPLY_ID => handle_create_order_reply_stargate(deps, &msg),
CREATE_DERIVATIVE_ORDER_REPLY_ID => handle_create_derivative_order_reply_stargate(deps, &msg),
_ => Err(ContractError::UnrecognizedReply(msg.id)),
}
}
Comment on lines +63 to +70
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address potential conflict with existing reply IDs and improve error handling.

The past review comments indicate a potential conflict with the CREATE_SPOT_ORDER_REPLY_ID and CREATE_DERIVATIVE_ORDER_REPLY_ID constants across different modules. Please ensure that these constants are unique to avoid any unexpected behavior.

Additionally, consider improving the error handling in the reply function by providing a more descriptive error message for unrecognized reply IDs.

Apply this diff to improve the error handling:

-    _ => Err(ContractError::UnrecognizedReply(msg.id)),
+    _ => Err(ContractError::UnrecognizedReply(format!("Unrecognized reply ID: {}", msg.id))),

Committable suggestion was skipped due to low confidence.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
use base64::Engine;
use prost::Message;

pub fn encode_proto_message<T: Message>(msg: T) -> String {
let mut buf = vec![];
T::encode(&msg, &mut buf).unwrap();
BASE64_STANDARD.encode(&buf)
}
113 changes: 113 additions & 0 deletions contracts/injective-cosmwasm-stargate-example/src/handle.rs
Original file line number Diff line number Diff line change
@@ -1 +1,114 @@
use crate::{
contract::{CREATE_DERIVATIVE_ORDER_REPLY_ID, CREATE_SPOT_ORDER_REPLY_ID},
msg::{MSG_CREATE_DERIVATIVE_LIMIT_ORDER_ENDPOINT, MSG_CREATE_SPOT_LIMIT_ORDER_ENDPOINT},
order_management::{create_derivative_limit_order, create_spot_limit_order, create_stargate_msg, encode_bytes_message},
state::{CacheOrderInfo, ORDER_CALL_CACHE},
ContractError,
};
use cosmos_sdk_proto::{cosmos::authz::v1beta1::MsgExec, traits::Message, Any};
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, SubMsg};
use injective_cosmwasm::{InjectiveMsgWrapper, InjectiveQuerier, InjectiveQueryWrapper, MarketId, OrderType, SubaccountId};
use injective_math::{scale::Scaled, FPDecimal};

pub const MSG_EXEC: &str = "/cosmos.authz.v1beta1.MsgExec";

pub fn handle_test_transient_spot_order(
deps: DepsMut<InjectiveQueryWrapper>,
env: Env,
info: &MessageInfo,
market_id: MarketId,
subaccount_id: SubaccountId,
price: String,
quantity: String,
) -> Result<Response<InjectiveMsgWrapper>, ContractError> {
let querier = InjectiveQuerier::new(&deps.querier);
let spot_market = querier.query_spot_market(&market_id).unwrap().market.unwrap();

let order_msg = create_spot_limit_order(
FPDecimal::must_from_str(price.as_str()).scaled(18i32),
FPDecimal::must_from_str(quantity.as_str()).scaled(18i32),
OrderType::Sell,
info.sender.as_str(),
subaccount_id.as_str(),
&spot_market,
);

let order_bytes = encode_bytes_message(&order_msg).unwrap();

let msg_exec = MsgExec {
grantee: env.contract.address.to_string(),
msgs: vec![Any {
type_url: MSG_CREATE_SPOT_LIMIT_ORDER_ENDPOINT.to_string(),
value: order_bytes,
}],
};

let order_submessage = SubMsg::reply_on_success(
create_stargate_msg(MSG_EXEC, msg_exec.encode_to_vec()).unwrap(),
CREATE_SPOT_ORDER_REPLY_ID,
);

save_cache_info(deps, market_id, subaccount_id)?;

Ok(Response::new().add_submessage(order_submessage))
}

pub fn handle_test_transient_derivative_order(
deps: DepsMut<InjectiveQueryWrapper>,
env: Env,
info: &MessageInfo,
market_id: MarketId,
subaccount_id: SubaccountId,
price: String,
quantity: String,
margin: String,
) -> Result<Response<InjectiveMsgWrapper>, ContractError> {
let querier: InjectiveQuerier = InjectiveQuerier::new(&deps.querier);
let market = querier.query_derivative_market(&market_id).unwrap().market.unwrap();

let order_msg = create_derivative_limit_order(
FPDecimal::must_from_str(price.as_str()).scaled(18i32),
FPDecimal::must_from_str(quantity.as_str()).scaled(18i32),
FPDecimal::must_from_str(margin.as_str()).scaled(18i32),
OrderType::Buy,
info.sender.as_str(),
subaccount_id.as_str(),
&market,
);

let order_bytes = encode_bytes_message(&order_msg).unwrap();

let msg_exec = MsgExec {
grantee: env.contract.address.to_string(),
msgs: vec![Any {
type_url: MSG_CREATE_DERIVATIVE_LIMIT_ORDER_ENDPOINT.to_string(),
value: order_bytes,
}],
};

let order_submessage = SubMsg::reply_on_success(
create_stargate_msg(MSG_EXEC, msg_exec.encode_to_vec()).unwrap(),
CREATE_DERIVATIVE_ORDER_REPLY_ID,
);

save_cache_info(deps, market_id, subaccount_id)?;

Ok(Response::new().add_submessage(order_submessage))
}

fn save_cache_info(deps: DepsMut<InjectiveQueryWrapper>, market_id: MarketId, subaccount_id: SubaccountId) -> Result<(), ContractError> {
let cache_order_info = CacheOrderInfo {
subaccount: subaccount_id,
market_id,
};

let mut order_cache = match ORDER_CALL_CACHE.may_load(deps.storage)? {
Some(order_cache) => order_cache,
None => vec![],
};

order_cache.push(cache_order_info);

ORDER_CALL_CACHE.save(deps.storage, &order_cache)?;
Ok(())
}
3 changes: 3 additions & 0 deletions contracts/injective-cosmwasm-stargate-example/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
pub mod contract;
mod encode_helper;
mod error;
mod handle;
pub mod msg;
mod order_management;
mod query;
mod reply;
mod state;
#[cfg(test)]
mod testing;
mod types;
#[cfg(test)]
pub mod utils;

pub use crate::error::ContractError;
17 changes: 14 additions & 3 deletions contracts/injective-cosmwasm-stargate-example/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use cosmwasm_std::Coin;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use injective_cosmwasm::SubaccountId;
use injective_cosmwasm::{MarketId, SubaccountId};

pub const MSG_CREATE_SPOT_LIMIT_ORDER_ENDPOINT: &str = "/injective.exchange.v1beta1.MsgCreateSpotLimitOrder";
pub const MSG_CREATE_DERIVATIVE_LIMIT_ORDER_ENDPOINT: &str = "/injective.exchange.v1beta1.MsgCreateDerivativeLimitOrder";
@@ -13,7 +12,19 @@ pub struct InstantiateMsg {}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
TestDepositMsg { subaccount_id: SubaccountId, amount: Coin },
TestTraderTransientSpotOrders {
market_id: MarketId,
subaccount_id: SubaccountId,
price: String,
quantity: String,
},
TestTraderTransientDerivativeOrders {
market_id: MarketId,
subaccount_id: SubaccountId,
price: String,
quantity: String,
margin: String,
},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
82 changes: 82 additions & 0 deletions contracts/injective-cosmwasm-stargate-example/src/reply.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use crate::{encode_helper::encode_proto_message, query::handle_query_stargate, state::ORDER_CALL_CACHE, ContractError};
use cosmwasm_std::{DepsMut, Event, Reply, Response};
use injective_cosmwasm::InjectiveQueryWrapper;

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, Eq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize, ::schemars::JsonSchema)]
pub struct QueryTraderSpotOrdersRequest {
/// Market ID for the market
#[prost(string, tag = "1")]
#[serde(alias = "marketID")]
pub market_id: ::prost::alloc::string::String,
/// SubaccountID of the trader
#[prost(string, tag = "2")]
#[serde(alias = "subaccountID")]
pub subaccount_id: ::prost::alloc::string::String,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, Eq, ::prost::Message, ::serde::Serialize, ::serde::Deserialize, ::schemars::JsonSchema)]
pub struct QueryTraderDerivativeOrdersRequest {
/// Market ID for the market
#[prost(string, tag = "1")]
#[serde(alias = "marketID")]
pub market_id: ::prost::alloc::string::String,
/// SubaccountID of the trader
#[prost(string, tag = "2")]
#[serde(alias = "subaccountID")]
pub subaccount_id: ::prost::alloc::string::String,
}

pub fn handle_create_order_reply_stargate(deps: DepsMut<InjectiveQueryWrapper>, _msg: &Reply) -> Result<Response, ContractError> {
let mut response_str = "Something went wrong".to_string();
if let Some(mut cache) = ORDER_CALL_CACHE.may_load(deps.storage)? {
if !cache.is_empty() {
let order_info = &cache[0];
let encode_query_message = encode_proto_message(QueryTraderSpotOrdersRequest {
market_id: order_info.market_id.clone().into(),
subaccount_id: order_info.subaccount.clone().into(),
});
let stargate_response = handle_query_stargate(
&deps.querier,
"/injective.exchange.v1beta1.Query/TraderSpotTransientOrders".to_string(),
encode_query_message,
);
response_str = match stargate_response {
Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {:?}", e)),
Err(e) => format!("Error: {:?}", e),
};
cache.clear();
ORDER_CALL_CACHE.save(deps.storage, &cache)?;
}
};

Ok(Response::new().add_event(Event::new("transient_order").add_attributes([("query_str", response_str)])))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize error handling in string operations.

- Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {:?}", e)),
+ Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {}", e)),

Change {:?} to {} for error formatting to ensure the error message is displayed correctly without debug formatting.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
pub fn handle_create_order_reply_stargate(deps: DepsMut<InjectiveQueryWrapper>, _msg: &Reply) -> Result<Response, ContractError> {
let mut response_str = "Something went wrong".to_string();
if let Some(mut cache) = ORDER_CALL_CACHE.may_load(deps.storage)? {
if !cache.is_empty() {
let order_info = &cache[0];
let encode_query_message = encode_proto_message(QueryTraderSpotOrdersRequest {
market_id: order_info.market_id.clone().into(),
subaccount_id: order_info.subaccount.clone().into(),
});
let stargate_response = handle_query_stargate(
&deps.querier,
"/injective.exchange.v1beta1.Query/TraderSpotTransientOrders".to_string(),
encode_query_message,
);
response_str = match stargate_response {
Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {:?}", e)),
Err(e) => format!("Error: {:?}", e),
};
cache.clear();
ORDER_CALL_CACHE.save(deps.storage, &cache)?;
}
};
Ok(Response::new().add_event(Event::new("transient_order").add_attributes([("query_str", response_str)])))
pub fn handle_create_order_reply_stargate(deps: DepsMut<InjectiveQueryWrapper>, _msg: &Reply) -> Result<Response, ContractError> {
let mut response_str = "Something went wrong".to_string();
if let Some(mut cache) = ORDER_CALL_CACHE.may_load(deps.storage)? {
if !cache.is_empty() {
let order_info = &cache[0];
let encode_query_message = encode_proto_message(QueryTraderSpotOrdersRequest {
market_id: order_info.market_id.clone().into(),
subaccount_id: order_info.subaccount.clone().into(),
});
let stargate_response = handle_query_stargate(
&deps.querier,
"/injective.exchange.v1beta1.Query/TraderSpotTransientOrders".to_string(),
encode_query_message,
);
response_str = match stargate_response {
Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {}", e)),
Err(e) => format!("Error: {:?}", e),
};
cache.clear();
ORDER_CALL_CACHE.save(deps.storage, &cache)?;
}
};
Ok(Response::new().add_event(Event::new("transient_order").add_attributes([("query_str", response_str)])))

}

pub fn handle_create_derivative_order_reply_stargate(deps: DepsMut<InjectiveQueryWrapper>, _msg: &Reply) -> Result<Response, ContractError> {
let mut response_str = "Something went wrong".to_string();

if let Some(mut cache) = ORDER_CALL_CACHE.may_load(deps.storage)? {
if !cache.is_empty() {
let order_info = &cache[0];
let encode_query_message = encode_proto_message(QueryTraderDerivativeOrdersRequest {
market_id: order_info.market_id.clone().into(),
subaccount_id: order_info.subaccount.clone().into(),
});
let stargate_response = handle_query_stargate(
&deps.querier,
"/injective.exchange.v1beta1.Query/TraderDerivativeTransientOrders".to_string(),
encode_query_message,
);
response_str = match stargate_response {
Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {:?}", e)),
Err(e) => format!("Error: {:?}", e),
};
cache.clear();
ORDER_CALL_CACHE.save(deps.storage, &cache)?;
}
};

Ok(Response::new().add_event(Event::new("transient_derivative_order").add_attributes([("query_str", response_str)])))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize error handling in string operations.

- Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {:?}", e)),
+ Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {}", e)),

Change {:?} to {} for error formatting to ensure the error message is displayed correctly without debug formatting.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
pub fn handle_create_derivative_order_reply_stargate(deps: DepsMut<InjectiveQueryWrapper>, _msg: &Reply) -> Result<Response, ContractError> {
let mut response_str = "Something went wrong".to_string();
if let Some(mut cache) = ORDER_CALL_CACHE.may_load(deps.storage)? {
if !cache.is_empty() {
let order_info = &cache[0];
let encode_query_message = encode_proto_message(QueryTraderDerivativeOrdersRequest {
market_id: order_info.market_id.clone().into(),
subaccount_id: order_info.subaccount.clone().into(),
});
let stargate_response = handle_query_stargate(
&deps.querier,
"/injective.exchange.v1beta1.Query/TraderDerivativeTransientOrders".to_string(),
encode_query_message,
);
response_str = match stargate_response {
Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {:?}", e)),
Err(e) => format!("Error: {:?}", e),
};
cache.clear();
ORDER_CALL_CACHE.save(deps.storage, &cache)?;
}
};
Ok(Response::new().add_event(Event::new("transient_derivative_order").add_attributes([("query_str", response_str)])))
pub fn handle_create_derivative_order_reply_stargate(deps: DepsMut<InjectiveQueryWrapper>, _msg: &Reply) -> Result<Response, ContractError> {
let mut response_str = "Something went wrong".to_string();
if let Some(mut cache) = ORDER_CALL_CACHE.may_load(deps.storage)? {
if !cache.is_empty() {
let order_info = &cache[0];
let encode_query_message = encode_proto_message(QueryTraderDerivativeOrdersRequest {
market_id: order_info.market_id.clone().into(),
subaccount_id: order_info.subaccount.clone().into(),
});
let stargate_response = handle_query_stargate(
&deps.querier,
"/injective.exchange.v1beta1.Query/TraderDerivativeTransientOrders".to_string(),
encode_query_message,
);
response_str = match stargate_response {
Ok(binary) => String::from_utf8(binary.0).unwrap_or_else(|e| format!("Failed to decode binary to string: {}", e)),
Err(e) => format!("Error: {:?}", e),
};
cache.clear();
ORDER_CALL_CACHE.save(deps.storage, &cache)?;
}
};
Ok(Response::new().add_event(Event::new("transient_derivative_order").add_attributes([("query_str", response_str)])))

}
2 changes: 1 addition & 1 deletion contracts/injective-cosmwasm-stargate-example/src/state.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use cosmwasm_schema::cw_serde;
use cw_storage_plus::Item;
use injective_cosmwasm::{MarketId, SubaccountId};

pub const ORDER_CALL_CACHE: Item<Vec<CacheOrderInfo>> = Item::new("order_call_cache");
pub const ORDER_CALL_CACHE: Item<Vec<CacheOrderInfo>> = Item::new("order_call_cache_stargate");

#[cw_serde]
pub struct CacheOrderInfo {
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
mod test_auction;
mod test_auth;
mod test_bank;
mod test_exchange;
mod test_exchange_derivative;
mod test_oracle;
mod type_helpers;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::{
encode_helper::encode_proto_message,
msg::{QueryMsg, QueryStargateResponse},
testing::type_helpers::{AuthParams, CosmosAuthQueryAccountsResponse, ParamResponse},
utils::{ExchangeType, Setup},
};
use cosmos_sdk_proto::cosmos::auth::v1beta1::QueryAccountRequest;
use injective_test_tube::{Account, Module, Wasm};

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_auth_params() {
let env = Setup::new(ExchangeType::None);
let wasm = Wasm::new(&env.app);
let query_msg = QueryMsg::QueryStargate {
path: "/cosmos.auth.v1beta1.Query/Params".to_string(),
query_request: "".to_string(),
};

let contract_response: QueryStargateResponse = wasm.query(&env.contract_address, &query_msg).unwrap();
let contract_response = contract_response.value;
let response: ParamResponse<AuthParams> = serde_json::from_str(&contract_response).unwrap();
assert_eq!(response.params.max_memo_characters, "256");
}

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_auth_account() {
let env = Setup::new(ExchangeType::None);
let wasm = Wasm::new(&env.app);

let user_address = env.users[0].account.address().to_string();
let query_msg = QueryMsg::QueryStargate {
path: "/cosmos.auth.v1beta1.Query/Account".to_string(),
query_request: encode_proto_message(QueryAccountRequest {
address: user_address.to_owned(),
}),
};

let contract_response: QueryStargateResponse = wasm.query(&env.contract_address, &query_msg).unwrap();
let contract_response = contract_response.value;
let response: CosmosAuthQueryAccountsResponse = serde_json::from_str(&contract_response).unwrap();
assert_eq!(response.account.base_account.address, user_address);
}
Loading