Skip to content

Commit

Permalink
start fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 15, 2024
1 parent f516e52 commit 544f5b7
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 109 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 64 additions & 32 deletions contracts/neutron_interchain_queries/src/testing/mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ 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, OwnedDeps, Querier,
QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, Validator,
};
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,41 +67,75 @@ impl Querier for WasmMockQuerier {
}

impl WasmMockQuerier {
pub fn handle_query(&self, request: &QueryRequest<NeutronQuery>) -> QuerierResult {
pub fn handle_query(&self, request: &QueryRequest) -> QuerierResult {
match &request {
QueryRequest::Custom(NeutronQuery::InterchainQueryResult { query_id }) => {
SystemResult::Ok(ContractResult::Ok(
(*self.query_responses.get(query_id).unwrap()).clone(),
))
}
QueryRequest::Custom(NeutronQuery::RegisteredInterchainQuery { query_id }) => {
SystemResult::Ok(ContractResult::Ok(
(*self.registered_queries.get(query_id).unwrap()).clone(),
))
}
QueryRequest::Custom(NeutronQuery::RegisteredInterchainQueries {
owners: _owners,
connection_id: _connection_id,
pagination: _pagination,
}) => {
todo!()
}
QueryRequest::Custom(NeutronQuery::InterchainAccountAddress { .. }) => {
todo!()
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();
println!("AAAAOKAAAAY");
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();
println!("BBBBOKAAAAY");
SystemResult::Ok(ContractResult::Ok(
(*self.registered_queries.get(&request.query_id).unwrap()).clone(),
))
} else if quoted_path == QueryRegisteredQueriesRequest::TYPE_URL.to_string() {
todo!()
} else {
println!("PATH: {}", quoted_path);
println!("SHOULD BE: {}", QueryRegisteredQueryRequest::TYPE_URL);
self.base.handle_query(&request)
}
}
_ => self.base.handle_query(request),
}
}

pub fn _update_staking(
&mut self,
denom: &str,
validators: &[Validator],
delegations: &[FullDelegation],
) {
self.base.staking.update(denom, validators, delegations);


// TODO: remove
// match &request {
// QueryRequest::Grpc(GrpcQuery{ path: ref type_url, data: _, }) => {
// SystemResult::Ok(ContractResult::Ok(
// (*self.query_responses.get(query_id).unwrap()).clone(),
// ))
// }
// QueryRequest::Custom(NeutronQuery::InterchainQueryResult { query_id }) => {
// SystemResult::Ok(ContractResult::Ok(
// (*self.query_responses.get(query_id).unwrap()).clone(),
// ))
// }
// QueryRequest::Custom(NeutronQuery::RegisteredInterchainQuery { query_id }) => {
// SystemResult::Ok(ContractResult::Ok(
// (*self.registered_queries.get(query_id).unwrap()).clone(),
// ))
// }
// QueryRequest::Custom(NeutronQuery::RegisteredInterchainQueries {
// owners: _owners,
// connection_id: _connection_id,
// pagination: _pagination,
// }) => {
// todo!()
// }
// QueryRequest::Custom(NeutronQuery::InterchainAccountAddress { .. }) => {
// todo!()
// }
// _ => self.base.handle_query(request),
// }
}

// pub fn _update_staking(
// &mut self,
// denom: &str,
// validators: &[Validator],
// delegations: &[FullDelegation],
// ) {
// self.base.staking.update(denom, validators, delegations);
// }

pub fn add_query_response(&mut self, query_id: u64, response: Binary) {
self.query_responses.insert(query_id, response);
}
Expand Down
Loading

0 comments on commit 544f5b7

Please sign in to comment.