AppBuilder

AppBuilder

AppBuilder (opens in a new tab) is an implementation of the Builder Pattern (opens in a new tab) that provides a flexible and modular way to construct the App blockchain simulator. It allows smart contract developers to configure various components of the blockchain simulator (e.g., Bank, Staking, Gov, IBC) individually through dedicated with_* methods. Each method modifies and returns a new instance of the builder, enabling method chaining for a fluent interface. The build method finalizes the construction process, ensuring that all components are correctly initialized and integrated.

The following sections detail all builder functions, providing specific usage examples.

default

(WIP)

new

(WIP)

new_custom

(WIP)

with_api

(WIP)

with_bank

(WIP)

with_block

While the default block configuration is sufficient for most test cases, you can initialize the chain with a custom BlockInfo (opens in a new tab) using the with_block (opens in a new tab) method provided by AppBuilder (opens in a new tab).

The following example demonstrates this use case in detail.

use cosmwasm_std::{BlockInfo, Timestamp};
use cw_multi_test::{no_init, AppBuilder};
 
// create the chain builder
let builder = AppBuilder::default();
 
// prepare the custom block
let block = BlockInfo {
    height: 1,
    time: Timestamp::from_seconds(1723627489),
    chain_id: "starship-testnet".to_string(),
};
 
// build the chain initialized with the custom block
let app = builder.with_block(block).build(no_init);
 
// get the current block properties
let block = app.block_info();
 
// now the block height is 21
assert_eq!(1, block.height);
 
// now the block timestamp is Wed Aug 14 2024 09:24:49 GMT+0000
assert_eq!(1723627489, block.time.seconds());
 
// now the chain identifier is "starship-testnet"
assert_eq!("starship-testnet", block.chain_id);

The AppBuilder (opens in a new tab) is initialized with default settings in line 5. A custom block is created in lines 8-12 and passed to the with_block (opens in a new tab) method in line 15. Since this is the only customization in this example, the blockchain construction is finalized in the same line by calling the build method.

The current block metadata is retrieved in line 18, followed by value checks:

  • line 21: the block height is now 1,
  • line 24: the block time is set to the Unix timestamp 1723627489, representing Wednesday, August 14, 2024, 09:24:49 GMT,
  • line 27: the chain identifier is now "starship-testnet".

The with_block (opens in a new tab) method of AppBuilder (opens in a new tab) can be combined with any other with_* methods to configure a custom starting block.

with_custom

(WIP)

with_distribution

(WIP)

with_gov

(WIP)

with_ibc

(WIP)

with_staking

(WIP)

with_stargate

(WIP)

with_storage

(WIP)

with_wasm

(WIP)

build

(WIP)