Skip to content

Commit d1b0886

Browse files
authored
Merge pull request #1389 from CosmWasm/packages_cw_check_contract
Add cw check contract to packages
2 parents 2281a4c + 9e94a83 commit d1b0886

File tree

6 files changed

+112
-1
lines changed

6 files changed

+112
-1
lines changed

.circleci/config.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ workflows:
99
jobs:
1010
- arm64
1111
- package_crypto
12+
- package_cw_check_contract
1213
- package_schema
1314
- package_schema_derive
1415
- package_std
@@ -160,6 +161,33 @@ jobs:
160161
- target/debug/deps
161162
key: cargocache-v2-package_crypto-rust:1.59.0-{{ checksum "Cargo.lock" }}
162163

164+
package_cw_check_contract:
165+
docker:
166+
- image: rust:1.59.0
167+
steps:
168+
- checkout
169+
- run:
170+
name: Version information
171+
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
172+
- restore_cache:
173+
keys:
174+
- cargocache-v2-package_cw_check_contract-rust:1.59.0-{{ checksum "Cargo.lock" }}
175+
- run:
176+
name: Build
177+
working_directory: ~/project/packages/cw-check-contract
178+
command: cargo build --locked
179+
- run:
180+
name: Run tests
181+
working_directory: ~/project/packages/cw-check-contract
182+
command: cargo test --locked
183+
- save_cache:
184+
paths:
185+
- /usr/local/cargo/registry
186+
- target/debug/.fingerprint
187+
- target/debug/build
188+
- target/debug/deps
189+
key: cargocache-v2-package_cw_check_contract-rust:1.59.0-{{ checksum "Cargo.lock" }}
190+
163191
package_schema:
164192
docker:
165193
- image: rust:1.59.0
@@ -1188,7 +1216,7 @@ jobs:
11881216
command: |
11891217
echo "Checking all contracts under ./artifacts"
11901218
docker run --volumes-from with_code rust:1.59.0 \
1191-
/bin/bash -e -c 'export GLOBIGNORE="../../artifacts/floaty.wasm"; cd ./code/packages/vm; cargo install cw-check-contract; cw-check_contract ../../artifacts/*.wasm'
1219+
/bin/bash -e -c 'export GLOBIGNORE="../../artifacts/floaty.wasm"; cd ./code/packages/vm; cargo run --bin cw-check-contract ../../artifacts/*.wasm'
11921220
docker cp with_code:/code/artifacts .
11931221
- run:
11941222
name: Publish artifacts on GitHub

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ and this project adheres to
4545
4. `Instance::required_features` to `Instance::required_capabilities`
4646
5. `AnalysisReport::required_features` to
4747
`AnalysisReport::required_capabilities`.
48+
- cosmwasm-vm/check_contract: Copied to cosmwasm/packages.
49+
cosmwasm-vm/check_contract will soon be deprecated.
4850

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

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cw-check-contract/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "cw-check-contract"
3+
version = "1.0.0"
4+
authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
5+
edition = "2021"
6+
description = "VM bindings to run verify cosmos contracts."
7+
repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/cw-check-contract"
8+
license = "Apache-2.0"
9+
10+
[dependencies]
11+
cosmwasm-vm = { path = "../vm", version = "1.0.0" }
12+
cosmwasm-std = { path = "../std", version = "1.0.0" }
13+
clap = "2.33.3"

packages/cw-check-contract/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# cw-check-contract
2+
3+
It allows checking if the wasm binary is a proper smart contract ready to upload
4+
to the blockchain.
5+
6+
Install using cargo install cw-check-contract
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::fs::File;
2+
use std::io::Read;
3+
4+
use clap::{App, Arg};
5+
6+
use cosmwasm_vm::capabilities_from_csv;
7+
use cosmwasm_vm::internals::{check_wasm, compile};
8+
9+
const DEFAULT_SUPPORTED_FEATURES: &str = "iterator,staking,stargate";
10+
11+
pub fn main() {
12+
let matches = App::new("Contract checking")
13+
.version("0.1.0")
14+
.long_about("Checks the given wasm file (memories, exports, imports, supported features, and non-determinism).")
15+
.author("Mauro Lacy <mauro@lacy.com.es>")
16+
.arg(
17+
Arg::with_name("FEATURES")
18+
// `long` setting required to turn the position argument into an option 🤷
19+
.long("supported-features")
20+
.value_name("FEATURES")
21+
.help("Sets the supported features that the desired target chain supports")
22+
.takes_value(true)
23+
)
24+
.arg(
25+
Arg::with_name("WASM")
26+
.help("Wasm file to read and compile")
27+
.required(true)
28+
.index(1),
29+
)
30+
.get_matches();
31+
32+
// Supported features
33+
let supported_features_csv = matches
34+
.value_of("FEATURES")
35+
.unwrap_or(DEFAULT_SUPPORTED_FEATURES);
36+
let supported_features = capabilities_from_csv(supported_features_csv);
37+
println!("Supported features: {:?}", supported_features);
38+
39+
// File
40+
let path = matches.value_of("WASM").expect("Error parsing file name");
41+
let mut file = File::open(path).unwrap();
42+
43+
// Read wasm
44+
let mut wasm = Vec::<u8>::new();
45+
file.read_to_end(&mut wasm).unwrap();
46+
47+
// Check wasm
48+
check_wasm(&wasm, &supported_features).unwrap();
49+
50+
// Compile module
51+
compile(&wasm, None, &[]).unwrap();
52+
println!("contract checks passed.")
53+
}

0 commit comments

Comments
 (0)