diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml index a6d7579cee..38308d23d3 100644 --- a/packages/vm/Cargo.toml +++ b/packages/vm/Cargo.toml @@ -29,6 +29,10 @@ cranelift = ["wasmer/cranelift"] # See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options bench = false +[[example]] +name = "check_contract" +required-features = ["iterator"] + [dependencies] clru = "0.4.0" # Uses the path when built locally; uses the given version from crates.io when published diff --git a/packages/vm/examples/check_contract.rs b/packages/vm/examples/check_contract.rs new file mode 100644 index 0000000000..d4221dca11 --- /dev/null +++ b/packages/vm/examples/check_contract.rs @@ -0,0 +1,36 @@ +use std::fs::File; +use std::io::Read; + +use clap::{App, Arg}; + +use cosmwasm_vm::features_from_csv; +use cosmwasm_vm::internals::{check_wasm, compile}; + +pub fn main() { + let matches = App::new("Contract checking") + .version("0.1.0") + .long_about("Checks the given wasm file (memories, exports, imports, supported features, and non-determinism).") + .author("Mauro Lacy ") + .arg( + Arg::with_name("WASM") + .help("Wasm file to read and compile") + .required(true) + .index(1), + ) + .get_matches(); + + // File + let path = matches.value_of("WASM").expect("Error parsing file name"); + let mut file = File::open(path).unwrap(); + + // Read wasm + let mut wasm = Vec::::new(); + file.read_to_end(&mut wasm).unwrap(); + + // Check wasm + check_wasm(&wasm, &features_from_csv("staking")).unwrap(); + + // Compile module + compile(&wasm, None).unwrap(); + println!("contract checks passed.") +} diff --git a/packages/vm/src/lib.rs b/packages/vm/src/lib.rs index c1b3bea5bc..b11e2b9ecf 100644 --- a/packages/vm/src/lib.rs +++ b/packages/vm/src/lib.rs @@ -57,5 +57,6 @@ pub mod internals { //! Please don't use any of these types directly, as //! they might change frequently or be removed in the future. + pub use crate::compatibility::check_wasm; pub use crate::wasm_backend::{compile, make_runtime_store}; }