Crates.io | provwasm-mocks |
lib.rs | provwasm-mocks |
version | 2.5.0 |
source | src |
created_at | 2021-02-10 17:18:38.222664 |
updated_at | 2024-11-08 21:43:46.634343 |
description | Rust mocks that enable unit testing of CosmWasm smart contracts that interact with custom modules in the Provenance Blockchain |
homepage | |
repository | https://github.com/provenance-io/provwasm |
max_upload_size | |
id | 353316 |
size | 35,091 |
This crate provides mocks that enable unit testing of CosmWasm smart contracts that interact with custom modules in the Provenance Blockchain.
This crate is part of the provwasm repository, licensed under the Apache License 2.0 (see the LICENSE).
// 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")
}