Skip to content

Commit

Permalink
chore: lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbernal87 committed Jul 1, 2024
1 parent ebf0280 commit 825207d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
48 changes: 26 additions & 22 deletions contracts/injective-cosmwasm-stargate-example/src/testing/authz.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use cosmos_sdk_proto::cosmos::authz::v1beta1::{QueryGranteeGrantsRequest, QueryGranterGrantsRequest, QueryGrantsRequest };
use crate::{
encode_helper::encode_proto_message,
msg::{QueryMsg, QueryStargateResponse},
utils::{
execute_all_authorizations,
ExchangeType, Setup,
},
utils::{execute_all_authorizations, ExchangeType, Setup},
};
use injective_test_tube::{Account, Module, RunnerResult, Wasm};
use cosmos_sdk_proto::cosmos::authz::v1beta1::{QueryGranteeGrantsRequest, QueryGranterGrantsRequest, QueryGrantsRequest};
use injective_test_tube::RunnerError::QueryError;
use injective_test_tube::{Account, Module, RunnerResult, Wasm};

use crate::testing::type_helpers::{Authorization, Grants, StargateQueryGranteeGrantsResponse, StargateQueryGranterGrantsResponse};
use crate::utils::get_stargate_query_result;


#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_grantee_grants() {
Expand All @@ -39,10 +35,22 @@ fn test_query_grantee_grants() {
"/injective.exchange.v1beta1.MsgWithdraw",
];

let response_user0 = create_stargate_response(messages.clone(), env.users[0].account.address().to_string(), env.users[1].account.address().to_string());
let response_user2 = create_stargate_response(messages, env.users[2].account.address().to_string(), env.users[1].account.address().to_string());

let combined_grants = response_user0.grants.into_iter().chain(response_user2.grants.into_iter()).collect::<Vec<_>>();
let response_user0 = create_stargate_response(
messages.clone(),
env.users[0].account.address().to_string(),
env.users[1].account.address().to_string(),
);
let response_user2 = create_stargate_response(
messages,
env.users[2].account.address().to_string(),
env.users[1].account.address().to_string(),
);

let combined_grants = response_user0
.grants
.into_iter()
.chain(response_user2.grants.into_iter())
.collect::<Vec<_>>();
let query_result = get_stargate_query_result::<StargateQueryGranteeGrantsResponse>(wasm.query(&env.contract_address, &query_msg)).unwrap();

let all_grants_present = combined_grants.iter().all(|grant| query_result.grants.contains(grant));
Expand Down Expand Up @@ -81,10 +89,8 @@ fn test_query_granter_grants() {

let query_result = get_stargate_query_result::<StargateQueryGranterGrantsResponse>(wasm.query(&env.contract_address, &query_msg)).unwrap();
assert_eq!(query_result.grants.len(), 0);

}


#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_query_grants() {
Expand Down Expand Up @@ -123,28 +129,26 @@ fn test_query_grants() {

if let Err(QueryError { msg }) = contract_response {
assert_eq!(
msg,
"Generic error: Querier contract error: codespace: authz, code: 2: query wasm contract failed",
msg, "Generic error: Querier contract error: codespace: authz, code: 2: query wasm contract failed",
"The error message does not match the expected value"
);
} else {
assert!(false, "Expected an error, but got a success: {:?}", contract_response);
}


}

fn create_stargate_response(messages: Vec<&str>, granter: String, grantee: String) -> StargateQueryGranteeGrantsResponse {
let grants = messages.into_iter().map(|msg| {
Grants {
let grants = messages
.into_iter()
.map(|msg| Grants {
granter: granter.clone(),
grantee: grantee.clone(),
authorization: Authorization {
type_str: "/cosmos.authz.v1beta1.GenericAuthorization".to_string(),
msg: msg.to_string(),
},
}
}).collect();
})
.collect();

StargateQueryGranteeGrantsResponse { grants }
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod authz;
mod test_auction;
mod test_auth;
mod test_bank;
mod test_exchange;
mod test_exchange_derivative;
mod test_oracle;
mod type_helpers;
mod authz;
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{
encode_helper::encode_proto_message,
msg::{QueryMsg, QueryStargateResponse},
testing::type_helpers::{BankParams, ParamResponse, QueryBalanceResponse, QuerySupplyOffResponse, QueryDenomMetadataResponse},
testing::type_helpers::{BankParams, ParamResponse, QueryBalanceResponse, QueryDenomMetadataResponse, QuerySupplyOffResponse},
utils::{ExchangeType, Setup},
};
use cosmos_sdk_proto::cosmos::bank::v1beta1::{QueryBalanceRequest, QueryDenomMetadataRequest, QuerySupplyOfRequest};
use cosmwasm_std::{Coin, Uint128};
use injective_test_tube::{Account, Module, TokenFactory, Wasm};
use injective_std::types::injective::tokenfactory::v1beta1::MsgCreateDenom;
use injective_test_tube::{Account, Module, TokenFactory, Wasm};

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ pub struct QuerySupplyOffResponse {
pub amount: Coin,
}


#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct QueryDenomMetadataResponse {
pub metadatas: Vec<Metadata>,
Expand Down Expand Up @@ -245,8 +244,6 @@ pub struct StargateQueryGranterGrantsResponse {
pub grants: Vec<Grants>,
}



#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Grants {
pub granter: String,
Expand All @@ -259,4 +256,4 @@ pub struct Authorization {
#[serde(rename = "@type")]
pub type_str: String,
pub msg: String,
}
}

0 comments on commit 825207d

Please sign in to comment.