Creating native coins for tests with cw-multi-test


Rust tests are great for testing contracts but they are not enough when we need to test interaction with other smart contracts.

The cw-multi-test package is great to mock a blockchain environment without running a node or deploying on testnet.

The documentation is a bit light though and an important point that was missing was: “how to get native coins”.

Personally, the simplest way I’ve found is to use SudoMsg. Sudo Messages are messages from modules, and in this case they allow us to Mint new native coins of whatever denomination we want. Simply call the messages using App.sudo and voila! Your shiny, new native coins have been minted and are ready to be used in testing.

fn mint_native(app: &mut App, beneficiary: String, denom: String, amount: u128) {
        cw_multi_test::BankSudo::Mint {
            to_address: beneficiary,
            amount: vec![coin(amount, denom)],