From 4234f9b94048ee8332ac6023b10c9f8ee7a579a4 Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 15:07:17 +0200
Subject: [PATCH 1/8] check: rename crate to `cosmwasm-check`

---
 Cargo.lock                             | 22 +++++++++++-----------
 packages/cw-check-contract/Cargo.toml  |  4 ++--
 packages/vm/examples/check_contract.rs |  4 ++--
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index b37920c60f..737de9a891 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -273,6 +273,17 @@ dependencies = [
  "windows-sys",
 ]
 
+[[package]]
+name = "cosmwasm-check"
+version = "1.0.0"
+dependencies = [
+ "anyhow",
+ "clap",
+ "colored",
+ "cosmwasm-std",
+ "cosmwasm-vm",
+]
+
 [[package]]
 name = "cosmwasm-crypto"
 version = "1.0.0"
@@ -613,17 +624,6 @@ dependencies = [
  "zeroize",
 ]
 
-[[package]]
-name = "cw-check-contract"
-version = "1.0.0"
-dependencies = [
- "anyhow",
- "clap",
- "colored",
- "cosmwasm-std",
- "cosmwasm-vm",
-]
-
 [[package]]
 name = "darling"
 version = "0.13.4"
diff --git a/packages/cw-check-contract/Cargo.toml b/packages/cw-check-contract/Cargo.toml
index e7ed801ffe..4e55faf765 100644
--- a/packages/cw-check-contract/Cargo.toml
+++ b/packages/cw-check-contract/Cargo.toml
@@ -1,9 +1,9 @@
 [package]
-name = "cw-check-contract"
+name = "cosmwasm-check"
 version = "1.0.0"
 authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
 edition = "2021"
-description = "VM bindings to run verify cosmos contracts."
+description = "A CLI tool for verifying CosmWasm smart contracts"
 repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/cw-check-contract"
 license = "Apache-2.0"
 
diff --git a/packages/vm/examples/check_contract.rs b/packages/vm/examples/check_contract.rs
index 4ac4121b98..401421cd7b 100644
--- a/packages/vm/examples/check_contract.rs
+++ b/packages/vm/examples/check_contract.rs
@@ -9,8 +9,8 @@ use cosmwasm_vm::internals::{check_wasm, compile};
 const DEFAULT_AVAILABLE_CAPABILITIES: &str = "iterator,staking,stargate";
 
 pub fn main() {
-    eprintln!("`check_contract` will be removed from the next version of `cosmwasm-vm` - please use `cw-check-contract` instead.");
-    eprintln!("> cargo install cw-check-contract");
+    eprintln!("`check_contract` will be removed from the next version of `cosmwasm-vm` - please use `cosmwasm-check` instead.");
+    eprintln!("> cargo install cosmwasm-check");
 
     let matches = App::new("Contract checking")
         .version("0.1.0")

From a88b281bc3548e0af8e01d41fbd1e40f30175dad Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 15:30:19 +0200
Subject: [PATCH 2/8] rename `cw-check-contract` folder to `check`

---
 .circleci/config.yml                              | 14 +++++++-------
 devtools/check_workspace.sh                       |  1 +
 packages/{cw-check-contract => check}/Cargo.toml  |  2 +-
 packages/check/README.md                          | 11 +++++++++++
 packages/{cw-check-contract => check}/src/main.rs |  0
 packages/cw-check-contract/README.md              |  6 ------
 6 files changed, 20 insertions(+), 14 deletions(-)
 rename packages/{cw-check-contract => check}/Cargo.toml (94%)
 create mode 100644 packages/check/README.md
 rename packages/{cw-check-contract => check}/src/main.rs (100%)
 delete mode 100644 packages/cw-check-contract/README.md

diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1d96e10bc2..9c08e76b05 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,7 +9,7 @@ workflows:
     jobs:
       - arm64
       - package_crypto
-      - package_cw_check_contract
+      - package_check
       - package_schema
       - package_schema_derive
       - package_std
@@ -161,7 +161,7 @@ jobs:
             - target/debug/deps
           key: cargocache-v2-package_crypto-rust:1.59.0-{{ checksum "Cargo.lock" }}
 
-  package_cw_check_contract:
+  package_check:
     docker:
       - image: rust:1.59.0
     steps:
@@ -171,14 +171,14 @@ jobs:
           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" }}
+            - cargocache-v2-package_check-rust:1.59.0-{{ checksum "Cargo.lock" }}
       - run:
           name: Build
-          working_directory: ~/project/packages/cw-check-contract
+          working_directory: ~/project/packages/check
           command: cargo build --locked
       - run:
           name: Run tests
-          working_directory: ~/project/packages/cw-check-contract
+          working_directory: ~/project/packages/check
           command: cargo test --locked
       - save_cache:
           paths:
@@ -186,7 +186,7 @@ jobs:
             - target/debug/.fingerprint
             - target/debug/build
             - target/debug/deps
-          key: cargocache-v2-package_cw_check_contract-rust:1.59.0-{{ checksum "Cargo.lock" }}
+          key: cargocache-v2-package_check-rust:1.59.0-{{ checksum "Cargo.lock" }}
 
   package_schema:
     docker:
@@ -1216,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; cargo run --bin cw-check-contract artifacts/*.wasm'
+              /bin/bash -e -c 'export GLOBIGNORE="artifacts/floaty.wasm"; cd ./code; cargo run --bin cosmwasm-check artifacts/*.wasm'
             docker cp with_code:/code/artifacts .
       - run:
           name: Publish artifacts on GitHub
diff --git a/devtools/check_workspace.sh b/devtools/check_workspace.sh
index f35dafb7c7..1c0d0bcaac 100755
--- a/devtools/check_workspace.sh
+++ b/devtools/check_workspace.sh
@@ -19,3 +19,4 @@ cargo fmt
 (cd packages/schema && cargo build && cargo clippy --all-targets -- -D warnings)
 (cd packages/schema-derive && cargo build && cargo clippy --all-targets -- -D warnings)
 (cd packages/vm && cargo build --features iterator,stargate && cargo clippy --all-targets --features iterator,stargate -- -D warnings)
+(cd packages/check && cargo build && cargo clippy --all-targets -- -D warnings)
diff --git a/packages/cw-check-contract/Cargo.toml b/packages/check/Cargo.toml
similarity index 94%
rename from packages/cw-check-contract/Cargo.toml
rename to packages/check/Cargo.toml
index 4e55faf765..8309f98dde 100644
--- a/packages/cw-check-contract/Cargo.toml
+++ b/packages/check/Cargo.toml
@@ -4,7 +4,7 @@ version = "1.0.0"
 authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
 edition = "2021"
 description = "A CLI tool for verifying CosmWasm smart contracts"
-repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/cw-check-contract"
+repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/check"
 license = "Apache-2.0"
 
 [dependencies]
diff --git a/packages/check/README.md b/packages/check/README.md
new file mode 100644
index 0000000000..2b41ae3afc
--- /dev/null
+++ b/packages/check/README.md
@@ -0,0 +1,11 @@
+# cosmwasm-check
+
+It allows checking if the Wasm binary is a proper smart contract that's ready to be uploaded
+to the blockchain.
+
+Installation:
+
+``` sh
+cargo install cosmwasm-check
+```
+
diff --git a/packages/cw-check-contract/src/main.rs b/packages/check/src/main.rs
similarity index 100%
rename from packages/cw-check-contract/src/main.rs
rename to packages/check/src/main.rs
diff --git a/packages/cw-check-contract/README.md b/packages/cw-check-contract/README.md
deleted file mode 100644
index f123dcdfc1..0000000000
--- a/packages/cw-check-contract/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-# 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

From 83224b7731ac9457f250408804bfa2b7093c2820 Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 15:30:34 +0200
Subject: [PATCH 3/8] make 1.64.0 clippy happy

---
 packages/profiler/src/instrumentation.rs | 2 +-
 packages/vm/src/modules/versioning.rs    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/packages/profiler/src/instrumentation.rs b/packages/profiler/src/instrumentation.rs
index eb1b164a62..e20a77a40d 100644
--- a/packages/profiler/src/instrumentation.rs
+++ b/packages/profiler/src/instrumentation.rs
@@ -257,7 +257,7 @@ impl FunctionMiddleware for FunctionProfiling {
                         Operator::Call{ function_index: self.indexes.start_measurement.as_u32() },
                     ]);
                 }
-                self.accumulated_ops.push((&operator).into());
+                self.accumulated_ops.push(OperatorSymbol::from(&operator));
             }
         }
 
diff --git a/packages/vm/src/modules/versioning.rs b/packages/vm/src/modules/versioning.rs
index 3810e2b914..86ce486f8b 100644
--- a/packages/vm/src/modules/versioning.rs
+++ b/packages/vm/src/modules/versioning.rs
@@ -33,7 +33,7 @@ pub fn current_wasmer_module_version() -> u32 {
     }
 
     let metadata = &header[header.len() - METADATA_HEADER_LEN..];
-    u32::from_le_bytes((&metadata[8..12]).try_into().unwrap())
+    u32::from_le_bytes((metadata[8..12]).try_into().unwrap())
 }
 
 #[cfg(test)]

From 36d7590661cc6dbe2576e27faec174c8dac4cb17 Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 15:56:54 +0200
Subject: [PATCH 4/8] Update READMEs with `cosmwasm-check` info

---
 README.md                | 5 +++++
 packages/check/README.md | 7 +++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 0d80b3fac1..3b803f83e1 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@ The following packages are maintained here:
 | cosmwasm-std     | Contract development | [![cosmwasm-std on crates.io](https://img.shields.io/crates/v/cosmwasm-std.svg)](https://crates.io/crates/cosmwasm-std)             | [![Docs](https://docs.rs/cosmwasm-std/badge.svg)](https://docs.rs/cosmwasm-std)         | [![Coverage][cov-badge-std]][cov-link-std]         |
 | cosmwasm-storage | Contract development | [![cosmwasm-storage on crates.io](https://img.shields.io/crates/v/cosmwasm-storage.svg)](https://crates.io/crates/cosmwasm-storage) | [![Docs](https://docs.rs/cosmwasm-storage/badge.svg)](https://docs.rs/cosmwasm-storage) | [![Coverage][cov-badge-storage]][cov-link-storage] |
 | cosmwasm-vm      | Host environments    | [![cosmwasm-vm on crates.io](https://img.shields.io/crates/v/cosmwasm-vm.svg)](https://crates.io/crates/cosmwasm-vm)                | [![Docs](https://docs.rs/cosmwasm-vm/badge.svg)](https://docs.rs/cosmwasm-vm)           | ([#1151])                                          |
+| cosmwasm-check   | Contract development | [![cosmwasm-check on crates.io](https://img.shields.io/crates/v/cosmwasm-check.svg)](https://crates.io/crates/cosmwasm-check)       | [![Docs](https://docs.rs/cosmwasm-check/badge.svg)](https://docs.rs/cosmwasm-check)     | N/A                                                |
 
 [cov-badge-crypto]:
   https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-crypto
@@ -96,6 +97,10 @@ This code is compiled into Wasm bytecode as part of the smart contract.
   WebAssembly smart contracts. It can be run as is, or you can import the
   `x/wasm` module from it and use it in your blockchain. It is designed to be
   imported and customized for other blockchains, rather than forked.
+- [cosmwasm-check](https://github.com/CosmWasm/cosmwasm/tree/main/packages/check) -
+  A CLI tool and a crate in this workspace. Used to verify a Wasm binary is a
+  CosmWasm smart contract suitable for uploading to a blockchain with a given
+  set of capabilities.
 
 ## Creating a Smart Contract
 
diff --git a/packages/check/README.md b/packages/check/README.md
index 2b41ae3afc..6593b1310d 100644
--- a/packages/check/README.md
+++ b/packages/check/README.md
@@ -1,11 +1,10 @@
 # cosmwasm-check
 
-It allows checking if the Wasm binary is a proper smart contract that's ready to be uploaded
-to the blockchain.
+It allows checking if the Wasm binary is a proper smart contract that's ready to
+be uploaded to the blockchain.
 
 Installation:
 
-``` sh
+```sh
 cargo install cosmwasm-check
 ```
-

From 4ec04c2e28e5ea16e406fc78e3ef80f9f45e9425 Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 16:08:41 +0200
Subject: [PATCH 5/8] update README.md

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 3b803f83e1..e3b39ee9a1 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ The following packages are maintained here:
 | cosmwasm-std     | Contract development | [![cosmwasm-std on crates.io](https://img.shields.io/crates/v/cosmwasm-std.svg)](https://crates.io/crates/cosmwasm-std)             | [![Docs](https://docs.rs/cosmwasm-std/badge.svg)](https://docs.rs/cosmwasm-std)         | [![Coverage][cov-badge-std]][cov-link-std]         |
 | cosmwasm-storage | Contract development | [![cosmwasm-storage on crates.io](https://img.shields.io/crates/v/cosmwasm-storage.svg)](https://crates.io/crates/cosmwasm-storage) | [![Docs](https://docs.rs/cosmwasm-storage/badge.svg)](https://docs.rs/cosmwasm-storage) | [![Coverage][cov-badge-storage]][cov-link-storage] |
 | cosmwasm-vm      | Host environments    | [![cosmwasm-vm on crates.io](https://img.shields.io/crates/v/cosmwasm-vm.svg)](https://crates.io/crates/cosmwasm-vm)                | [![Docs](https://docs.rs/cosmwasm-vm/badge.svg)](https://docs.rs/cosmwasm-vm)           | ([#1151])                                          |
-| cosmwasm-check   | Contract development | [![cosmwasm-check on crates.io](https://img.shields.io/crates/v/cosmwasm-check.svg)](https://crates.io/crates/cosmwasm-check)       | [![Docs](https://docs.rs/cosmwasm-check/badge.svg)](https://docs.rs/cosmwasm-check)     | N/A                                                |
+| cosmwasm-check   | Contract development | [![cosmwasm-check on crates.io](https://img.shields.io/crates/v/cosmwasm-check.svg)](https://crates.io/crates/cosmwasm-check)       | `cosmwasm-check -h`                                                                     | N/A                                                |
 
 [cov-badge-crypto]:
   https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-crypto

From 760956954035d8ef57cde888157b936e3b450218 Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 16:10:11 +0200
Subject: [PATCH 6/8] check: include proper version in the CLI tool

---
 packages/check/src/main.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/check/src/main.rs b/packages/check/src/main.rs
index c2affd0986..98541f5f8f 100644
--- a/packages/check/src/main.rs
+++ b/packages/check/src/main.rs
@@ -14,7 +14,7 @@ const DEFAULT_AVAILABLE_CAPABILITIES: &str = "iterator,staking,stargate";
 
 pub fn main() {
     let matches = App::new("Contract checking")
-        .version("0.1.0")
+        .version(env!("CARGO_PKG_VERSION"))
         .long_about("Checks the given wasm file (memories, exports, imports, available capabilities, and non-determinism).")
         .author("Mauro Lacy <mauro@lacy.com.es>")
         .arg(

From 970f24f9f987c6a382b19113c6a3db72b84f16c2 Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 16:10:58 +0200
Subject: [PATCH 7/8] check: attribute the original author :)

---
 packages/check/Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/check/Cargo.toml b/packages/check/Cargo.toml
index 8309f98dde..549b4f548b 100644
--- a/packages/check/Cargo.toml
+++ b/packages/check/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "cosmwasm-check"
 version = "1.0.0"
-authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"]
+authors = ["Mauro Lacy <mauro@lacy.com.es>"]
 edition = "2021"
 description = "A CLI tool for verifying CosmWasm smart contracts"
 repository = "https://github.com/CosmWasm/cosmwasm/tree/main/packages/check"

From 66f37fc8afcf3e948cd1470739930e1954d5a146 Mon Sep 17 00:00:00 2001
From: Tomasz Kurcz <uint@lavabit.com>
Date: Mon, 22 Aug 2022 16:40:15 +0200
Subject: [PATCH 8/8] check: update README.md

---
 packages/check/README.md | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/packages/check/README.md b/packages/check/README.md
index 6593b1310d..16f7b35402 100644
--- a/packages/check/README.md
+++ b/packages/check/README.md
@@ -3,8 +3,41 @@
 It allows checking if the Wasm binary is a proper smart contract that's ready to
 be uploaded to the blockchain.
 
-Installation:
+## Installation
 
 ```sh
 cargo install cosmwasm-check
 ```
+
+## Usage
+
+Get help and info:
+
+```sh
+cosmwasm-check -h
+```
+
+Check some contracts:
+
+```sh
+cosmwasm-check artifacts/hackatom.wasm artifacts/burner.wasm
+```
+
+Check an entire directory of contracts (shell dependent):
+
+```sh
+cosmwasm-check artifacts/*.wasm
+```
+
+Check if a contract would ran on a blockchain with a specific set of
+capabilities:
+
+```sh
+cosmwasm-check --available-capabilities iterator,osmosis,friendship artifacts/hackatom.wasm
+```
+
+## License
+
+This package is part of the cosmwasm repository, licensed under the Apache
+License 2.0 (see [NOTICE](https://github.com/CosmWasm/cosmwasm/blob/main/NOTICE)
+and [LICENSE](https://github.com/CosmWasm/cosmwasm/blob/main/LICENSE)).