App
The App structure represents the blockchain simulator. Creating App
mimics the startup of a real-life blockchain within tests that utilize MultiTest.
default
The most straightforward way to create an App is by using the default
method, which is the equivalent of calling the new constructor with an empty initialization
callback no_init.
use cw_multi_test::App;
let app = App::default();use cw_multi_test::{no_init, App};
let app = App::new(no_init);In both cases, the newly created App object simulates a blockchain with the default
settings as summarized in the chapter Features summary.
new
Using the App::new constructor enables additional initialization of the blockchain
at startup, prior to executing any tests. Initialization is done inside the callback function passed
as an argument to the new constructor (lines 7-13 in the code snippet shown below).
Initialization callback function takes three arguments:
- router - provides access to other modules of the blockchain,
- api - provides access to CosmWasm API,
- storage - provides access to the blockchain’s storage.
An example of funds initialization inside the custom callback function is shown below:
use cosmwasm_std::coin;
use cw_multi_test::App;
let me = "me";
let my_funds = vec![coin(20, "OSMO")];
let app = App::new(|router, api, storage| {
let my_address = api.addr_make(me);
router
.bank
.init_balance(storage, &my_address, my_funds)
.unwrap();
});
let my_coins = app
.wrap()
.query_all_balances(app.api().addr_make(me))
.unwrap();
assert_eq!(1, my_coins.len());
assert_eq!("20OSMO", my_coins[0].to_string());no_init
The no_init function serves as an empty chain initialization callback, offering
a convenient option when no specific chain initialization is required. Usually used when calling
App::new or AppBuilder::build methods.