-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added base WasmMockQuerier implementation (QueryRequest::Stargate)
- Loading branch information
Andrei Zavgorodnii
committed
Feb 2, 2024
1 parent
45d6068
commit 679d4df
Showing
3 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
contracts/dao/neutron-chain-manager/src/testing/mock_querier.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::marker::PhantomData; | ||
use cosmwasm_std::{ContractResult, Empty, from_json, OwnedDeps, Querier, QuerierResult, QueryRequest, SystemError, SystemResult, to_json_binary}; | ||
use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage}; | ||
use crate::msg::{ParamsCron, ParamsResponseCron}; | ||
|
||
pub fn mock_dependencies() -> OwnedDeps<MockStorage, MockApi, WasmMockQuerier> { | ||
let custom_storage = MockStorage::default(); | ||
let custom_querier = WasmMockQuerier::new(MockQuerier::new(&[])); | ||
|
||
OwnedDeps { | ||
storage: custom_storage, | ||
api: MockApi::default(), | ||
querier: custom_querier, | ||
custom_query_type: PhantomData, | ||
} | ||
} | ||
|
||
pub struct WasmMockQuerier { | ||
base: MockQuerier, | ||
} | ||
|
||
impl Querier for WasmMockQuerier { | ||
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult { | ||
let request: QueryRequest<Empty> = match from_json(bin_request) { | ||
Ok(v) => v, | ||
Err(e) => { | ||
return QuerierResult::Err(SystemError::InvalidRequest { | ||
error: format!("Parsing query request: {}", e), | ||
request: bin_request.into(), | ||
}); | ||
} | ||
}; | ||
self.handle_query(&request) | ||
} | ||
} | ||
|
||
impl WasmMockQuerier { | ||
pub fn handle_query(&self, request: &QueryRequest<Empty>) -> QuerierResult { | ||
match &request { | ||
QueryRequest::Stargate { path, data: _} => { | ||
match path.as_str() { | ||
"/neutron.cron.Query/Params" => { | ||
let resp = to_json_binary(&ParamsResponseCron{ | ||
params: ParamsCron{ | ||
security_address: "neutron_dao_address".to_string(), | ||
limit: 10, | ||
} | ||
}); | ||
SystemResult::Ok(ContractResult::from(resp)) | ||
} | ||
_ => todo!() | ||
} | ||
} | ||
_ => self.base.handle_query(request), | ||
} | ||
} | ||
} | ||
|
||
impl WasmMockQuerier { | ||
fn new(base: MockQuerier) -> WasmMockQuerier { | ||
WasmMockQuerier { base } | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod tests; | ||
mod mock_querier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters