Skip to content

Add cw check contract to packages #1389

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

Merged
merged 9 commits into from
Aug 17, 2022
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
30 changes: 29 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ workflows:
jobs:
- arm64
- package_crypto
- package_cw_check_contract
- package_schema
- package_schema_derive
- package_std
Expand Down Expand Up @@ -160,6 +161,33 @@ jobs:
- target/debug/deps
key: cargocache-v2-package_crypto-rust:1.59.0-{{ checksum "Cargo.lock" }}

package_cw_check_contract:
docker:
- image: rust:1.59.0
steps:
- checkout
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
- restore_cache:
keys:
- cargocache-v2-package_cw_check_contract-rust:1.59.0-{{ checksum "Cargo.lock" }}
- run:
name: Build
working_directory: ~/project/packages/cw-check-contract
command: cargo build --locked
- run:
name: Run tests
working_directory: ~/project/packages/cw-check-contract
command: cargo test --locked
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
key: cargocache-v2-package_cw_check_contract-rust:1.59.0-{{ checksum "Cargo.lock" }}

package_schema:
docker:
- image: rust:1.59.0
Expand Down Expand Up @@ -1188,7 +1216,7 @@ jobs:
command: |
echo "Checking all contracts under ./artifacts"
docker run --volumes-from with_code rust:1.59.0 \
/bin/bash -e -c 'export GLOBIGNORE="../../artifacts/floaty.wasm"; cd ./code/packages/vm; cargo install cw-check-contract; cw-check_contract ../../artifacts/*.wasm'
/bin/bash -e -c 'export GLOBIGNORE="../../artifacts/floaty.wasm"; cd ./code/packages/vm; cargo run --bin cw-check-contract ../../artifacts/*.wasm'
docker cp with_code:/code/artifacts .
- run:
name: Publish artifacts on GitHub
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to
4. `Instance::required_features` to `Instance::required_capabilities`
5. `AnalysisReport::required_features` to
`AnalysisReport::required_capabilities`.
- cosmwasm-vm/check_contract: Copied to cosmwasm/packages.
cosmwasm-vm/check_contract will soon be deprecated.

[#1374]: https://github.com/CosmWasm/cosmwasm/pull/1374

Expand Down
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions packages/cw-check-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "cw-check-contract"
version = "1.0.0"
authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
edition = "2021"
description = "VM bindings to run verify cosmos contracts."
repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/cw-check-contract"
license = "Apache-2.0"

[dependencies]
cosmwasm-vm = { path = "../vm", version = "1.0.0" }
cosmwasm-std = { path = "../std", version = "1.0.0" }
clap = "2.33.3"
6 changes: 6 additions & 0 deletions packages/cw-check-contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# cw-check-contract

It allows checking if the wasm binary is a proper smart contract ready to upload
to the blockchain.

Install using cargo install cw-check-contract
53 changes: 53 additions & 0 deletions packages/cw-check-contract/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::fs::File;
use std::io::Read;

use clap::{App, Arg};

use cosmwasm_vm::capabilities_from_csv;
use cosmwasm_vm::internals::{check_wasm, compile};

const DEFAULT_SUPPORTED_FEATURES: &str = "iterator,staking,stargate";

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 <mauro@lacy.com.es>")
.arg(
Arg::with_name("FEATURES")
// `long` setting required to turn the position argument into an option 🤷
.long("supported-features")
.value_name("FEATURES")
.help("Sets the supported features that the desired target chain supports")
.takes_value(true)
)
.arg(
Arg::with_name("WASM")
.help("Wasm file to read and compile")
.required(true)
.index(1),
)
.get_matches();

// Supported features
let supported_features_csv = matches
.value_of("FEATURES")
.unwrap_or(DEFAULT_SUPPORTED_FEATURES);
let supported_features = capabilities_from_csv(supported_features_csv);
println!("Supported features: {:?}", supported_features);

// 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, &supported_features).unwrap();

// Compile module
compile(&wasm, None, &[]).unwrap();
println!("contract checks passed.")
}