Skip to content

Commit

Permalink
fix schema
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 16, 2024
1 parent 68af7b6 commit c01fb30
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 33 deletions.
2 changes: 1 addition & 1 deletion contracts/marketmap/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use marketmap::contract::InstantiateMsg;
use marketmap::msg::{InstantiateMsg, QueryMsg};

fn main() {
let mut out_dir = current_dir().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion contracts/marketmap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod contract;
mod msg;
pub mod msg;
22 changes: 16 additions & 6 deletions contracts/neutron_interchain_queries/src/testing/mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ use std::collections::HashMap;
use std::marker::PhantomData;

use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage};
use cosmwasm_std::{from_json, Binary, Coin, ContractResult, CustomQuery, FullDelegation, GrpcQuery, OwnedDeps, Querier, QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, Validator};
use neutron_std::types::neutron::interchainqueries::{QueryRegisteredQueriesRequest, QueryRegisteredQueryRequest, QueryRegisteredQueryResultRequest, QueryRegisteredQueryResultResponse, QueryResult};
use cosmwasm_std::{
from_json, Binary, Coin, ContractResult, CustomQuery, FullDelegation, GrpcQuery, OwnedDeps,
Querier, QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, Validator,
};
use neutron_std::types::neutron::interchainqueries::{
QueryRegisteredQueriesRequest, QueryRegisteredQueryRequest, QueryRegisteredQueryResultRequest,
QueryRegisteredQueryResultResponse, QueryResult,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -69,15 +75,19 @@ impl Querier for WasmMockQuerier {
impl WasmMockQuerier {
pub fn handle_query(&self, request: &QueryRequest) -> QuerierResult {
match &request {
QueryRequest::Grpc(GrpcQuery{ path, data, }) => {
QueryRequest::Grpc(GrpcQuery { path, data }) => {
let quoted_path = path.trim_matches('"').to_string();
if quoted_path == "/neutron.interchainqueries.Query/QueryResult".to_string() {
let request: QueryRegisteredQueryResultRequest = ::prost::Message::decode(&data[..]).unwrap();
let request: QueryRegisteredQueryResultRequest =
::prost::Message::decode(&data[..]).unwrap();
SystemResult::Ok(ContractResult::Ok(
(*self.query_responses.get(&request.query_id).unwrap()).clone(),
))
} else if quoted_path == "/neutron.interchainqueries.Query/RegisteredQuery".to_string() {
let request: QueryRegisteredQueryRequest = ::prost::Message::decode(&data[..]).unwrap();
} else if quoted_path
== "/neutron.interchainqueries.Query/RegisteredQuery".to_string()
{
let request: QueryRegisteredQueryRequest =
::prost::Message::decode(&data[..]).unwrap();
SystemResult::Ok(ContractResult::Ok(
(*self.registered_queries.get(&request.query_id).unwrap()).clone(),
))
Expand Down
57 changes: 34 additions & 23 deletions contracts/neutron_interchain_queries/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ use cosmos_sdk_proto::cosmos::staking::v1beta1::Validator as CosmosValidator;
use cosmos_sdk_proto::Any;
use cosmwasm_std::testing::{message_info, mock_env, MockApi, MockStorage};
use cosmwasm_std::{
from_json, Addr, Binary, Coin, Decimal, Env, MessageInfo, OwnedDeps, StdError,
Uint128,
from_json, Addr, Binary, Coin, Decimal, Env, MessageInfo, OwnedDeps, StdError, Uint128,
};
use neutron_sdk::interchain_queries::helpers::{decode_and_convert, kv_key_from_string};
use neutron_sdk::interchain_queries::hex::decode_hex;
use neutron_sdk::interchain_queries::types::{
QueryType, TransactionFilterItem, TransactionFilterOp, TransactionFilterValue,
};
Expand All @@ -41,7 +41,6 @@ use neutron_sdk::interchain_queries::v047::helpers::{
create_gov_proposal_votes_key, create_total_denom_key, create_validator_key,
create_validator_signing_info_key,
};
use neutron_std::types::cosmos::base::v1beta1::Coin as StdCoin;
use neutron_sdk::interchain_queries::v047::queries::{
BalanceResponse, DelegatorDelegationsResponse, FeePoolResponse, ProposalResponse,
ProposalVotesResponse, TotalSupplyResponse, ValidatorResponse, ValidatorSigningInfoResponse,
Expand All @@ -52,12 +51,15 @@ use neutron_sdk::interchain_queries::v047::types::{
ValidatorSigningInfo, WeightedVoteOption, DECIMAL_PLACES, RECIPIENT_FIELD,
};
use neutron_sdk::NeutronError;
use neutron_std::types::neutron::interchainqueries::{KvKey, QueryRegisteredQueryResponse, QueryRegisteredQueryResultResponse, QueryResult, RegisteredQuery, StorageValue};
use neutron_std::types::cosmos::base::v1beta1::Coin as StdCoin;
use neutron_std::types::ibc::core::client::v1::Height;
use neutron_std::types::neutron::interchainqueries::{
KvKey, QueryRegisteredQueryResponse, QueryRegisteredQueryResultResponse, QueryResult,
RegisteredQuery, StorageValue,
};
use prost::Message as ProstMessage;
use schemars::_serde_json::to_string;
use std::ops::Mul;
use neutron_sdk::interchain_queries::hex::decode_hex;
use neutron_std::types::ibc::core::client::v1::Height;

enum QueryParam {
Keys(Vec<KvKey>),
Expand All @@ -74,9 +76,7 @@ fn build_registered_query_response(
let mut transactions_filter = "".to_string();
match param {
QueryParam::Keys(keys) => registered_keys = keys,
QueryParam::TransactionsFilter(filter) => {
transactions_filter = filter
}
QueryParam::TransactionsFilter(filter) => transactions_filter = filter,
}

let resp = QueryRegisteredQueryResponse {
Expand Down Expand Up @@ -383,8 +383,7 @@ fn test_query_balances() {
);
let query_balance = QueryMsg::Balance { query_id: 1 };
let res = query(deps.as_ref(), mock_env(), query_balance);
let resp: BalanceResponse =
from_json(res.unwrap()).unwrap();
let resp: BalanceResponse = from_json(res.unwrap()).unwrap();
assert_eq!(
resp,
BalanceResponse {
Expand Down Expand Up @@ -440,8 +439,10 @@ fn test_bank_total_supply_query() {
};

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, Binary::from(::prost::Message::encode_to_vec(&total_supply_response).as_slice()));
deps.querier.add_query_response(
1,
Binary::from(::prost::Message::encode_to_vec(&total_supply_response).as_slice()),
);
let bank_total_balance = QueryMsg::BankTotalSupply { query_id: 1 };

let resp: TotalSupplyResponse =
Expand Down Expand Up @@ -541,8 +542,10 @@ fn test_gov_proposals_query() {
};

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, Binary::from(::prost::Message::encode_to_vec(&proposals_response).as_slice()));
deps.querier.add_query_response(
1,
Binary::from(::prost::Message::encode_to_vec(&proposals_response).as_slice()),
);

let government_proposal = QueryMsg::GovernmentProposals { query_id: 1 };
let resp: ProposalResponse =
Expand Down Expand Up @@ -661,8 +664,10 @@ fn test_gov_proposal_votes_query() {
};

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, Binary::from(::prost::Message::encode_to_vec(&proposals_votes_response).as_slice()));
deps.querier.add_query_response(
1,
Binary::from(::prost::Message::encode_to_vec(&proposals_votes_response).as_slice()),
);

let government_proposal_votes = QueryMsg::GovernmentProposalVotes { query_id: 1 };
let resp: ProposalVotesResponse =
Expand Down Expand Up @@ -745,8 +750,10 @@ fn test_staking_validators_query() {
};

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, Binary::from(::prost::Message::encode_to_vec(&validators_response).as_slice()));
deps.querier.add_query_response(
1,
Binary::from(::prost::Message::encode_to_vec(&validators_response).as_slice()),
);
let staking_validators = QueryMsg::StakingValidators { query_id: 1 };
let resp: ValidatorResponse =
from_json(query(deps.as_ref(), mock_env(), staking_validators).unwrap()).unwrap();
Expand Down Expand Up @@ -846,8 +853,10 @@ fn test_validators_signing_infos_query() {
};

deps.querier.add_registered_queries(1, registered_query);
deps.querier
.add_query_response(1, Binary::from(::prost::Message::encode_to_vec(&validators_response).as_slice()));
deps.querier.add_query_response(
1,
Binary::from(::prost::Message::encode_to_vec(&validators_response).as_slice()),
);
let validators_signing_infos = QueryMsg::ValidatorsSigningInfos { query_id: 1 };
let resp: ValidatorSigningInfoResponse =
from_json(query(deps.as_ref(), mock_env(), validators_signing_infos).unwrap()).unwrap();
Expand Down Expand Up @@ -982,8 +991,10 @@ fn test_query_delegator_delegations() {
let registered_query =
build_registered_query_response(1, QueryParam::Keys(keys), QueryType::KV, 987);

deps.querier
.add_query_response(1, Binary::from(::prost::Message::encode_to_vec(&delegations_response).as_slice()));
deps.querier.add_query_response(
1,
Binary::from(::prost::Message::encode_to_vec(&delegations_response).as_slice()),
);
deps.querier.add_registered_queries(1, registered_query);

let query_delegations = QueryMsg::GetDelegations { query_id: 1 };
Expand Down
3 changes: 1 addition & 2 deletions contracts/oracle/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use oracle::contract::InstantiateMsg;
use oracle::msg::QueryMsg;
use oracle::msg::{InstantiateMsg, QueryMsg};

fn main() {
let mut out_dir = current_dir().unwrap();
Expand Down

0 comments on commit c01fb30

Please sign in to comment.