Struct abstract_testing::MockQuerierBuilder
source · pub struct MockQuerierBuilder { /* private fields */ }
Expand description
MockQuerierBuilder
is a helper to build a MockQuerier
.
Usage:
use cosmwasm_std::{from_binary, to_binary};
use abstract_testing::MockQuerierBuilder;
use cosmwasm_std::testing::MockQuerier;
use abstract_testing::mock_module::MockModuleExecuteMsg;
let querier = MockQuerierBuilder::default().with_smart_handler("contract_address", |msg| {
// handle the message
let res = match from_binary::<MockModuleExecuteMsg>(msg).unwrap() {
// handle the message
_ => panic!("unexpected message"),
};
Ok(to_binary(&msg).unwrap())
}).build();
Implementations§
source§impl MockQuerierBuilder
impl MockQuerierBuilder
pub fn with_fallback_smart_handler<SH>(self, handler: SH) -> Selfwhere SH: Fn(&str, &Binary) -> Result<Binary, String> + 'static,
pub fn with_fallback_raw_handler<RH>(self, handler: RH) -> Selfwhere RH: Fn(&str, &Binary) -> Result<Binary, String> + 'static,
sourcepub fn with_smart_handler<SH>(self, contract: &str, handler: SH) -> Selfwhere
SH: Fn(&Binary) -> Result<Binary, String> + 'static,
pub fn with_smart_handler<SH>(self, contract: &str, handler: SH) -> Selfwhere SH: Fn(&Binary) -> Result<Binary, String> + 'static,
Add a smart contract handler to the mock querier. The handler will be called when the contract address is queried with the given message. Usage:
use cosmwasm_std::{from_binary, to_binary};
use abstract_testing::MockQuerierBuilder;
use cosmwasm_std::testing::MockQuerier;
use abstract_testing::mock_module::MockModuleExecuteMsg;
let querier = MockQuerierBuilder::default().with_smart_handler("contract_address", |msg| {
// handle the message
let res = match from_binary::<MockModuleExecuteMsg>(msg).unwrap() {
// handle the message
_ => panic!("unexpected message"),
};
Ok(to_binary(&msg).unwrap())
}).build();
pub fn with_raw_handler<RH>(self, contract: &str, handler: RH) -> Selfwhere RH: Fn(&str) -> Result<Binary, String> + 'static,
sourcepub fn with_contract_map_entry<'a, K, V>(
self,
contract: &str,
cw_map: Map<'a, K, V>,
entry: (K, V)
) -> Selfwhere
K: PrimaryKey<'a>,
V: Serialize + DeserializeOwned,
pub fn with_contract_map_entry<'a, K, V>( self, contract: &str, cw_map: Map<'a, K, V>, entry: (K, V) ) -> Selfwhere K: PrimaryKey<'a>, V: Serialize + DeserializeOwned,
Add a map entry to the querier for the given contract.
use cw_storage_plus::Map;
use abstract_testing::MockQuerierBuilder;
const MAP: Map<String, String> = Map::new("map");
MockQuerierBuilder::default()
.with_contract_map_entry(
"contract_address",
MAP,
("key".to_string(), "value".to_string())
);
pub fn with_contract_map_entries<'a, K, V>( self, contract: &str, cw_map: Map<'a, K, V>, entries: Vec<(K, V)> ) -> Selfwhere K: PrimaryKey<'a>, V: Serialize + DeserializeOwned,
sourcepub fn with_contract_map_key<'a, K, V>(
self,
contract: &str,
cw_map: Map<'a, K, V>,
key: K
) -> Selfwhere
K: PrimaryKey<'a>,
V: Serialize + DeserializeOwned,
pub fn with_contract_map_key<'a, K, V>( self, contract: &str, cw_map: Map<'a, K, V>, key: K ) -> Selfwhere K: PrimaryKey<'a>, V: Serialize + DeserializeOwned,
Add an empty map key to the querier for the given contract. This is useful when you want the item to exist, but not have a value.
sourcepub fn with_empty_contract_item<T>(
self,
contract: &str,
cw_item: Item<'_, T>
) -> Selfwhere
T: Serialize + DeserializeOwned,
pub fn with_empty_contract_item<T>( self, contract: &str, cw_item: Item<'_, T> ) -> Selfwhere T: Serialize + DeserializeOwned,
Add an empty item key to the querier for the given contract. This is useful when you want the item to exist, but not have a value.
sourcepub fn with_contract_item<T>(
self,
contract: &str,
cw_item: Item<'_, T>,
value: &T
) -> Selfwhere
T: Serialize + DeserializeOwned,
pub fn with_contract_item<T>( self, contract: &str, cw_item: Item<'_, T>, value: &T ) -> Selfwhere T: Serialize + DeserializeOwned,
Include a contract item in the mock querier.
use cw_storage_plus::Item;
use abstract_testing::MockQuerierBuilder;
const ITEM: Item<String> = Item::new("item");
MockQuerierBuilder::default()
.with_contract_item(
"contract_address",
ITEM,
&"value".to_string(),
);
sourcepub fn with_contract_version(self, contract: &str, version: impl ToString) -> Self
pub fn with_contract_version(self, contract: &str, version: impl ToString) -> Self
Add a specific version of the contract to the mock querier.
use abstract_testing::MockQuerierBuilder;
MockQuerierBuilder::default()
.with_contract_version("contract_address", "v1.0.0");
sourcepub fn build(self) -> MockQuerier
pub fn build(self) -> MockQuerier
Build the MockQuerier
.