#vm #unit-tests

dev cosmwasm-vm

VM bindings to run cosmwams contracts

46 releases (11 breaking)

0.12.0 Nov 19, 2020
0.11.2 Oct 26, 2020
0.10.0 Jul 30, 2020
0.7.2 Mar 23, 2020
0.5.1 Nov 29, 2019
Download history 149/week @ 2020-08-13 152/week @ 2020-08-20 169/week @ 2020-08-27 178/week @ 2020-09-03 88/week @ 2020-09-10 127/week @ 2020-09-17 187/week @ 2020-09-24 241/week @ 2020-10-01 151/week @ 2020-10-08 106/week @ 2020-10-15 139/week @ 2020-10-22 149/week @ 2020-10-29 218/week @ 2020-11-05 125/week @ 2020-11-12 128/week @ 2020-11-19 102/week @ 2020-11-26

671 downloads per month
Used in less than 9 crates

Apache-2.0

690KB
10K SLoC

CosmWasm VM

cosmwasm-vm on crates.io

This is an abstraction layer around the wasmer VM to expose just what we need to run cosmwasm contracts in a high-level manner. This is intended both for efficient writing of unit tests, as well as a public API to run contracts in eg. go-cosmwasm. As such it includes all glue code needed for typical actions, like fs caching.

Compatibility

A VM can support one or more contract-VM interface versions. The interface version is communicated by the contract via a Wasm import. This is the current compatibility list:

cosmwasm-vm Supported interface versions cosmwasm-std
0.12 cosmwasm_vm_version_4 0.11-0.12
0.11 cosmwasm_vm_version_4 0.11-0.12
0.10 cosmwasm_vm_version_3 0.10
0.9 cosmwasm_vm_version_2 0.9
0.8 cosmwasm_vm_version_1 0.8

Setup

There are demo files in testdata/*.wasm. Those are compiled and optimized versions of contracts/hackatom and contracts/staking run through rust-optimizer.

To rebuild the test contracts, go to the repo root and do

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="devcontract_cache_hackatom",target=/code/contracts/hackatom/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.10.5 ./contracts/hackatom \
  && cp artifacts/hackatom.wasm packages/vm/testdata/contract_0.12.wasm

Testing

By default, this repository is built and tested with the singlepass backend. This requires running Rust nighty:

cd packages/vm
cargo +nightly test

To test with Rust stable, you need to switch to cranelift:

cd packages/vm
cargo test --no-default-features --features default-cranelift

License

This package is part of the cosmwasm repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).

Dependencies

~8.5MB
~196K SLoC