#provenance #smart-contracts #blockchain #unit-testing #defi #finance

provwasm-mocks

Rust mocks that enable unit testing of CosmWasm smart contracts that interact with custom modules in the Provenance Blockchain

24 releases (11 stable)

new 2.5.0 Nov 8, 2024
2.3.0 Jul 19, 2024
2.2.0 Mar 28, 2024
2.1.0 Dec 13, 2023
0.14.0-beta1 Mar 29, 2021

#37 in Magic Beans

Download history 15/week @ 2024-07-22 37/week @ 2024-07-29 2/week @ 2024-08-05 15/week @ 2024-09-16 36/week @ 2024-09-23 171/week @ 2024-09-30 8/week @ 2024-10-07 1/week @ 2024-10-14 16/week @ 2024-10-21 9/week @ 2024-10-28 100/week @ 2024-11-04

127 downloads per month
Used in provwasm-tutorial

Apache-2.0

1.5MB
26K SLoC

provwasm-mocks

This crate provides mocks that enable unit testing of CosmWasm smart contracts that interact with custom modules in the Provenance Blockchain.

License

This crate is part of the provwasm repository, licensed under the Apache License 2.0 (see the LICENSE).

Example Usage

// Example unit test:
// Uses provwasm mocks to test a resolve query against the provenance name module.

// ref: contracts/name/src/msg.rs

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(provwasm_std::Name)]
    Resolve { name: String },
    #[returns(provwasm_std::Names)]
    Lookup { address: String },
}

// ref: contracts/name/src/contract.rs

use cosmwasm_std::testing::mock_env;
use cosmwasm_std::from_binary;
use provwasm_mocks::mock_dependencies;
use provwasm_std::Name;

#[test]
fn query_resolve() {
    // Create provenance mock deps with a single bound name.
    let mut deps = mock_dependencies(&[]);
    deps.querier
        .with_names(&[("a.pb", "tp1y0txdp3sqmxjvfdaa8hfvwcljl8ugcfv26uync", false)]);

    // Call the smart contract query function to resolve the address for our test name.
    let bin = query(
        deps.as_ref(),
        mock_env(),
        QueryMsg::Resolve {
            name: "a.pb".into(),
        },
    )
        .unwrap();

    // Ensure that we got the expected address.
    let rep: Name = from_binary(&bin).unwrap();
    assert_eq!(rep.address, "tp1y0txdp3sqmxjvfdaa8hfvwcljl8ugcfv26uync")
}

Dependencies

~6–9.5MB
~183K SLoC