44 releases (stable)

4.0.1 Feb 25, 2023
3.0.2 Dec 14, 2022
3.0.0 Nov 21, 2022
2.7.0 Oct 24, 2022
0.5.9 Jul 27, 2022

#173 in Magic Beans

Download history 56/week @ 2023-12-10 143/week @ 2023-12-17 20/week @ 2023-12-24 62/week @ 2023-12-31 59/week @ 2024-01-07 13/week @ 2024-01-14 116/week @ 2024-01-21 136/week @ 2024-01-28 95/week @ 2024-02-04 50/week @ 2024-02-11 44/week @ 2024-02-18 165/week @ 2024-02-25 44/week @ 2024-03-03 59/week @ 2024-03-10 125/week @ 2024-03-17 214/week @ 2024-03-24

457 downloads per month

Apache-2.0

81KB
1.5K SLoC

Cosm-Orc

cosm-orc on crates.io Docs

Rust Cosmwasm smart contract integration testing and gas profiling library.

Store, instantiate, execute, and query Cosmwasm smart contracts against a configured Cosmos based chain.

Optionally, profile gas usage of the smart contract operations.

If you need a more general Cosmos SDK client library try cosm-tome, which we use here under the hood.

Potential uses:

  • Integration tests
  • Deployments / Bootstrapping environments
  • Gas profiling
  • Realistic adversarial testing

This project is not intended to be used for mainnet.

Quick Start

// juno_local.yaml has the `cw20_base` code_id already stored
// If the smart contract has not been stored on the chain yet use: `cosm_orc::store_contracts()`
let mut cosm_orc = CosmOrc::new(Config::from_yaml("./example-configs/juno_local.yaml")?, false)?;
let key = SigningKey {
   name: "validator".to_string(),
   key: Key::Mnemonic("word1 word2 ...".to_string()),
   derivation_path: "m/44'/118'/0'/0/0".to_string(),
};

cosm_orc.instantiate(
   "cw20_base",
   "meme_token_test",
   &InstantiateMsg {
       name: "Meme Token".to_string(),
       symbol: "MEME".to_string(),
       decimals: 6,
       initial_balances: vec![],
       mint: None,
       marketing: None,
   },
   &key,
   None,
   vec![]
)?;

let res = cosm_orc.query(
   "cw20_base",
   &QueryMsg::TokenInfo {},
)?;
let res: TokenInfoResponse = res.data()?;

See here for example usages.

Optimize and Store Contracts

If config.yaml doesn't have the pre-stored contract code ids, you can call optimize_contracts() and store_contracts():

let mut cosm_orc = CosmOrc::new(Config::from_yaml("./example-configs/juno_local.yaml")?, false)?;
let key = SigningKey {
   name: "validator".to_string(),
   key: Key::Mnemonic("word1 word2 ...".to_string()),
   derivation_path: "m/44'/118'/0'/0/0".to_string(),
};

// Build + optimize all smart contracts in current workspace
// This will save the optimized wasm files in `./artifacts`
cosm_orc.optimize_contracts("./Cargo.toml")?;

// NOTE: currently cosm-orc is expecting a wasm filed called: `cw20_base.wasm`
// to be in `/artifacts`, since `cw20_base` is used as the contract name in the instantiate()/query() calls below:
cosm_orc.store_contracts("./artifacts", &key, None)?;

cosm_orc.instantiate(
   "cw20_base",
   "meme_token_test",
   &InstantiateMsg {
       name: "Meme Token".to_string(),
       symbol: "MEME".to_string(),
       decimals: 6,
       initial_balances: vec![],
       mint: None,
       marketing: None,
   },
   &key,
   None,
   vec![]
)?;

let res = cosm_orc.query(
   "cw20_base",
   &QueryMsg::TokenInfo {},
)?;
let res: TokenInfoResponse = res.data()?;

Gas Profiling

let mut cosm_orc = CosmOrc::new(Config::from_yaml("config.yaml")?, true)?;

cosm_orc.instantiate(
   "cw20_base",
   "meme_token_test",
   &InstantiateMsg {
       name: "Meme Token".to_string(),
       symbol: "MEME".to_string(),
       decimals: 6,
       initial_balances: vec![],
       mint: None,
       marketing: None,
   },
   &key,
   None,
   vec![]
)?;

let reports = cosm_orc.gas_profiler_report();

Gas Report Github Action

Use the cosm-orc-github-action to view the cosm-orc gas usage as a PR comment.

Github action also supports showing the diff between 2 different reports.

Examples:

Configuration

See ./example-configs directory for example yaml configs.

Dependencies

~32–57MB
~1M SLoC