pub struct App<Bank = BankKeeper, Api = MockApi, Storage = MockStorage, Custom = FailingModule<Empty, Empty, Empty>, Wasm = WasmKeeper<Empty, Empty>, Staking = StakeKeeper, Distr = DistributionKeeper, Ibc = IbcFailingModule, Gov = GovFailingModule, Stargate = StargateFailing> { /* private fields */ }
Expand description
§Blockchain application simulator
This structure is the main component of the real-life blockchain simulator.
Implementations§
Source§impl App
impl App
Sourcepub fn new<F>(init_fn: F) -> Selfwhere
F: FnOnce(&mut Router<BankKeeper, FailingModule<Empty, Empty, Empty>, WasmKeeper<Empty, Empty>, StakeKeeper, DistributionKeeper, IbcFailingModule, GovFailingModule, StargateFailing>, &MockApi, &mut dyn Storage),
pub fn new<F>(init_fn: F) -> Selfwhere
F: FnOnce(&mut Router<BankKeeper, FailingModule<Empty, Empty, Empty>, WasmKeeper<Empty, Empty>, StakeKeeper, DistributionKeeper, IbcFailingModule, GovFailingModule, StargateFailing>, &MockApi, &mut dyn Storage),
Creates new default App
implementation working with Empty custom messages.
Source§impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
Sourcepub fn router(
&self,
) -> &Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
pub fn router( &self, ) -> &Router<BankT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>
Returns a shared reference to application’s router.
Sourcepub fn storage_mut(&mut self) -> &mut StorageT
pub fn storage_mut(&mut self) -> &mut StorageT
Returns a mutable reference to application’s storage.
Sourcepub fn init_modules<F, T>(&mut self, init_fn: F) -> T
pub fn init_modules<F, T>(&mut self, init_fn: F) -> T
Initializes modules.
Source§impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
Sourcepub fn store_code(
&mut self,
code: Box<dyn Contract<CustomT::ExecT, CustomT::QueryT>>,
) -> u64
pub fn store_code( &mut self, code: Box<dyn Contract<CustomT::ExecT, CustomT::QueryT>>, ) -> u64
Registers contract code (like uploading wasm bytecode on a chain), so it can later be used to instantiate a contract.
Sourcepub fn store_code_with_creator(
&mut self,
creator: Addr,
code: Box<dyn Contract<CustomT::ExecT, CustomT::QueryT>>,
) -> u64
pub fn store_code_with_creator( &mut self, creator: Addr, code: Box<dyn Contract<CustomT::ExecT, CustomT::QueryT>>, ) -> u64
Registers contract code (like store_code), but takes the address of the code creator as an additional argument.
Sourcepub fn store_code_with_id(
&mut self,
creator: Addr,
code_id: u64,
code: Box<dyn Contract<CustomT::ExecT, CustomT::QueryT>>,
) -> AnyResult<u64>
pub fn store_code_with_id( &mut self, creator: Addr, code_id: u64, code: Box<dyn Contract<CustomT::ExecT, CustomT::QueryT>>, ) -> AnyResult<u64>
Registers contract code (like store_code_with_creator), but takes the code identifier as an additional argument.
Sourcepub fn duplicate_code(&mut self, code_id: u64) -> AnyResult<u64>
pub fn duplicate_code(&mut self, code_id: u64) -> AnyResult<u64>
Duplicates the contract code identified by code_id
and returns
the identifier of the newly created copy of the contract code.
§Examples
use cosmwasm_std::Addr;
use cw_multi_test::App;
// contract implementation
mod echo {
// contract entry points not shown here
pub fn contract() -> Box<dyn Contract<Empty>> {
// should return the contract
}
}
let mut app = App::default();
// store a new contract, save the code id
let code_id = app.store_code(echo::contract());
// duplicate the existing contract, duplicated contract has different code id
assert_ne!(code_id, app.duplicate_code(code_id).unwrap());
// zero is an invalid identifier for contract code, returns an error
assert_eq!("code id: invalid", app.duplicate_code(0).unwrap_err().to_string());
// there is no contract code with identifier 100 stored yet, returns an error
assert_eq!("code id 100: no such code", app.duplicate_code(100).unwrap_err().to_string());
Sourcepub fn contract_data(&self, address: &Addr) -> AnyResult<ContractData>
pub fn contract_data(&self, address: &Addr) -> AnyResult<ContractData>
Returns ContractData
for the contract with specified address.
Sourcepub fn dump_wasm_raw(&self, address: &Addr) -> Vec<Record>
pub fn dump_wasm_raw(&self, address: &Addr) -> Vec<Record>
Returns a raw state dump of all key-values held by a contract with specified address.
Sourcepub fn contract_storage<'a>(
&'a self,
contract_addr: &Addr,
) -> Box<dyn Storage + 'a>
pub fn contract_storage<'a>( &'a self, contract_addr: &Addr, ) -> Box<dyn Storage + 'a>
Returns read-only storage for a contract with specified address.
Sourcepub fn contract_storage_mut<'a>(
&'a mut self,
contract_addr: &Addr,
) -> Box<dyn Storage + 'a>
pub fn contract_storage_mut<'a>( &'a mut self, contract_addr: &Addr, ) -> Box<dyn Storage + 'a>
Returns read-write storage for a contract with specified address.
Sourcepub fn prefixed_storage<'a>(&'a self, namespace: &[u8]) -> Box<dyn Storage + 'a>
pub fn prefixed_storage<'a>(&'a self, namespace: &[u8]) -> Box<dyn Storage + 'a>
Returns read-only prefixed storage with specified namespace.
Sourcepub fn prefixed_storage_mut<'a>(
&'a mut self,
namespace: &[u8],
) -> Box<dyn Storage + 'a>
pub fn prefixed_storage_mut<'a>( &'a mut self, namespace: &[u8], ) -> Box<dyn Storage + 'a>
Returns mutable prefixed storage with specified namespace.
Sourcepub fn prefixed_multilevel_storage<'a>(
&'a self,
namespaces: &[&[u8]],
) -> Box<dyn Storage + 'a>
pub fn prefixed_multilevel_storage<'a>( &'a self, namespaces: &[&[u8]], ) -> Box<dyn Storage + 'a>
Returns read-only prefixed, multilevel storage with specified namespaces.
Sourcepub fn prefixed_multilevel_storage_mut<'a>(
&'a mut self,
namespaces: &[&[u8]],
) -> Box<dyn Storage + 'a>
pub fn prefixed_multilevel_storage_mut<'a>( &'a mut self, namespaces: &[&[u8]], ) -> Box<dyn Storage + 'a>
Returns mutable prefixed, multilevel storage with specified namespaces.
Source§impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
Sourcepub fn update_block<F: Fn(&mut BlockInfo)>(&mut self, action: F)
pub fn update_block<F: Fn(&mut BlockInfo)>(&mut self, action: F)
Updates the current block applying the specified closure, usually next_block.
Sourcepub fn block_info(&self) -> BlockInfo
pub fn block_info(&self) -> BlockInfo
Returns a copy of the current block info.
Sourcepub fn wrap(&self) -> QuerierWrapper<'_, CustomT::QueryT>
pub fn wrap(&self) -> QuerierWrapper<'_, CustomT::QueryT>
Simple helper so we get access to all the QuerierWrapper helpers, e.g. wrap().query_wasm_smart, query_all_balances, …
Sourcepub fn execute_multi(
&mut self,
sender: Addr,
msgs: Vec<CosmosMsg<CustomT::ExecT>>,
) -> AnyResult<Vec<AppResponse>>
pub fn execute_multi( &mut self, sender: Addr, msgs: Vec<CosmosMsg<CustomT::ExecT>>, ) -> AnyResult<Vec<AppResponse>>
Runs multiple CosmosMsg in one atomic operation. This will create a cache before the execution, so no state changes are persisted if any of them return an error. But all writes are persisted on success.
Sourcepub fn wasm_sudo<T: Serialize, U: Into<Addr>>(
&mut self,
contract_addr: U,
msg: &T,
) -> AnyResult<AppResponse>
pub fn wasm_sudo<T: Serialize, U: Into<Addr>>( &mut self, contract_addr: U, msg: &T, ) -> AnyResult<AppResponse>
Call a smart contract in “sudo” mode. This will create a cache before the execution, so no state changes are persisted if this returns an error, but all are persisted on success.
Sourcepub fn sudo(&mut self, msg: SudoMsg) -> AnyResult<AppResponse>
pub fn sudo(&mut self, msg: SudoMsg) -> AnyResult<AppResponse>
Runs arbitrary SudoMsg. This will create a cache before the execution, so no state changes are persisted if this returns an error, but all are persisted on success.
Trait Implementations§
Source§impl<Bank: Clone, Api: Clone, Storage: Clone, Custom: Clone, Wasm: Clone, Staking: Clone, Distr: Clone, Ibc: Clone, Gov: Clone, Stargate: Clone> Clone for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>
impl<Bank: Clone, Api: Clone, Storage: Clone, Custom: Clone, Wasm: Clone, Staking: Clone, Distr: Clone, Ibc: Clone, Gov: Clone, Stargate: Clone> Clone for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>
Source§impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> Executor<<CustomT as Module>::ExecT> for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> Executor<<CustomT as Module>::ExecT> for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
Source§fn execute(
&mut self,
sender: Addr,
msg: CosmosMsg<CustomT::ExecT>,
) -> AnyResult<AppResponse>
fn execute( &mut self, sender: Addr, msg: CosmosMsg<CustomT::ExecT>, ) -> AnyResult<AppResponse>
CosmosMsg
.
This will create a cache before the execution,
so no state changes are persisted if this returns an error,
but all are persisted on success.Source§fn instantiate_contract<T: Serialize, U: Into<String>>(
&mut self,
code_id: u64,
sender: Addr,
init_msg: &T,
send_funds: &[Coin],
label: U,
admin: Option<String>,
) -> AnyResult<Addr>
fn instantiate_contract<T: Serialize, U: Into<String>>( &mut self, code_id: u64, sender: Addr, init_msg: &T, send_funds: &[Coin], label: U, admin: Option<String>, ) -> AnyResult<Addr>
Source§fn instantiate2_contract<M, L, A, S>(
&mut self,
code_id: u64,
sender: Addr,
init_msg: &M,
funds: &[Coin],
label: L,
admin: A,
salt: S,
) -> AnyResult<Addr>
fn instantiate2_contract<M, L, A, S>( &mut self, code_id: u64, sender: Addr, init_msg: &M, funds: &[Coin], label: L, admin: A, salt: S, ) -> AnyResult<Addr>
WasmMsg::Instantiate2
message.Source§fn execute_contract<T: Serialize + Debug>(
&mut self,
sender: Addr,
contract_addr: Addr,
msg: &T,
send_funds: &[Coin],
) -> AnyResult<AppResponse>
fn execute_contract<T: Serialize + Debug>( &mut self, sender: Addr, contract_addr: Addr, msg: &T, send_funds: &[Coin], ) -> AnyResult<AppResponse>
WasmMsg::Execute
message, but in this case we parse out the data field
to that what is returned by the contract (not the protobuf wrapper).Source§fn migrate_contract<T: Serialize>(
&mut self,
sender: Addr,
contract_addr: Addr,
msg: &T,
new_code_id: u64,
) -> AnyResult<AppResponse>
fn migrate_contract<T: Serialize>( &mut self, sender: Addr, contract_addr: Addr, msg: &T, new_code_id: u64, ) -> AnyResult<AppResponse>
WasmMsg::Migrate
message.Source§fn send_tokens(
&mut self,
sender: Addr,
recipient: Addr,
amount: &[Coin],
) -> AnyResult<AppResponse>
fn send_tokens( &mut self, sender: Addr, recipient: Addr, amount: &[Coin], ) -> AnyResult<AppResponse>
BankMsg::Send
message.Source§impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> Querier for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
impl<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT> Querier for App<BankT, ApiT, StorageT, CustomT, WasmT, StakingT, DistrT, IbcT, GovT, StargateT>where
CustomT::ExecT: CustomMsg + DeserializeOwned + 'static,
CustomT::QueryT: CustomQuery + DeserializeOwned + 'static,
WasmT: Wasm<CustomT::ExecT, CustomT::QueryT>,
BankT: Bank,
ApiT: Api,
StorageT: Storage,
CustomT: Module,
StakingT: Staking,
DistrT: Distribution,
IbcT: Ibc,
GovT: Gov,
StargateT: Stargate,
Source§fn raw_query(&self, bin_request: &[u8]) -> QuerierResult
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult
Auto Trait Implementations§
impl<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate> Freeze for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>
impl<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate> RefUnwindSafe for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>where
Api: RefUnwindSafe,
Storage: RefUnwindSafe,
Wasm: RefUnwindSafe,
Bank: RefUnwindSafe,
Custom: RefUnwindSafe,
Staking: RefUnwindSafe,
Distr: RefUnwindSafe,
Ibc: RefUnwindSafe,
Gov: RefUnwindSafe,
Stargate: RefUnwindSafe,
impl<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate> Send for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>
impl<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate> Sync for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>
impl<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate> Unpin for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>
impl<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate> UnwindSafe for App<Bank, Api, Storage, Custom, Wasm, Staking, Distr, Ibc, Gov, Stargate>where
Api: UnwindSafe,
Storage: UnwindSafe,
Wasm: UnwindSafe,
Bank: UnwindSafe,
Custom: UnwindSafe,
Staking: UnwindSafe,
Distr: UnwindSafe,
Ibc: UnwindSafe,
Gov: UnwindSafe,
Stargate: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more