Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check_contract utility #825

Merged
merged 4 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions packages/vm/examples/check_contract.rs
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>")
.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::<u8>::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.")
}
1 change: 1 addition & 0 deletions packages/vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}