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

provwasm-mocks

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

8 releases

0.16.0 Aug 19, 2021
0.14.3 Jul 27, 2021
0.14.1 Jun 16, 2021
0.14.0 May 4, 2021
0.13.3 Feb 19, 2021

#205 in Magic Beans

Download history 8/week @ 2021-06-30 9/week @ 2021-07-07 34/week @ 2021-07-14 14/week @ 2021-07-21 34/week @ 2021-07-28 22/week @ 2021-08-04 22/week @ 2021-08-11 28/week @ 2021-08-18 8/week @ 2021-08-25 7/week @ 2021-09-08 7/week @ 2021-09-15 3/week @ 2021-09-22 16/week @ 2021-09-29 5/week @ 2021-10-06 19/week @ 2021-10-13

83 downloads per month

Apache-2.0

79KB
1.5K 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

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
    Resolve { name: 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.as_str(),
        "tp1y0txdp3sqmxjvfdaa8hfvwcljl8ugcfv26uync"
    )
}

Dependencies

~2–3.5MB
~73K SLoC