App
The App
(opens in a new tab) structure represents the blockchain simulator. Creating App
(opens in a new tab)
mimics the startup of a real-life blockchain within tests that utilize MultiTest
.
default
The most straightforward way to create an App
(opens in a new tab) is by using the default
method, which is the equivalent of calling the new
constructor with an empty initialization
callback no_init
(opens in a new tab).
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
(opens in a new tab) object simulates a blockchain with the default
settings as summarized in the chapter Features summary.
new
Using the App::new
(opens in a new tab) 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
(opens in a new tab) 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
(opens in a new tab) or AppBuilder::build
(opens in a new tab) methods.