Skip to content

Commit 16bb1f1

Browse files
authored
feat: add-basic-rust-tests (#394)
* feat: add-basic-rust-tests Signed-off-by: Night Owl <nightowl121@protonmail.com> * chore: add .cargo in root Signed-off-by: Night Owl <nightowl121@protonmail.com> * fix: update path of schema Signed-off-by: Night Owl <nightowl121@protonmail.com> * fix: fix clippy warnings Signed-off-by: Night Owl <nightowl121@protonmail.com> * feat: add cargo.lock in git Signed-off-by: Night Owl <nightowl121@protonmail.com> * fix: exclude test-utils from wasm file generation Signed-off-by: Night Owl <nightowl121@protonmail.com> * feat: change clippy warning level Signed-off-by: Night Owl <nightowl121@protonmail.com> * fix: clippy warnings fixes Signed-off-by: Night Owl <nightowl121@protonmail.com> * check: if overwritten Signed-off-by: Night Owl <nightowl121@protonmail.com> * feat: add schema files for cw-xcall and cw-icon-light-client Signed-off-by: Night Owl <nightowl121@protonmail.com> * feat: run schema generation script in ci Signed-off-by: Night Owl <nightowl121@protonmail.com> * fix: path of scripts Signed-off-by: Night Owl <nightowl121@protonmail.com> * ci: debug Signed-off-by: Night Owl <nightowl121@protonmail.com> --------- Signed-off-by: Night Owl <nightowl121@protonmail.com>
1 parent 4b06be7 commit 16bb1f1

23 files changed

+6832
-9
lines changed

.cargo/config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[alias]
2+
wasm = "build --workspace --exclude test-utils --release --lib --target wasm32-unknown-unknown"
3+
unit-test = "test --lib"
4+
schema = "run --bin schema"

.github/workflows/basic-rust.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Based on https://github.com/actions-rs/example/blob/master/.github/workflows/quickstart.yml
2+
name: Test and Lint CW contracts
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- "**"
8+
paths:
9+
- "contracts/cosmwasm-vm/**"
10+
- ".github/workflows/basic-rust.yml"
11+
push:
12+
branches:
13+
- main
14+
15+
jobs:
16+
17+
test:
18+
name: Test Suite
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout sources
23+
uses: actions/checkout@v3
24+
25+
- name: Install Rust
26+
run: rustup update stable
27+
28+
- name: Cache Rust dependencies
29+
uses: Swatinem/rust-cache@v2
30+
31+
- name: Run unit tests
32+
run: |
33+
RUST_BACKTRACE=1 cargo unit-test --locked
34+
35+
- name: Install wasm32
36+
run: |
37+
rustup target add wasm32-unknown-unknown
38+
39+
- name: Compile WASM contract
40+
run: |
41+
RUSTFLAGS='-C link-arg=-s' cargo wasm --locked
42+
43+
lints:
44+
name: Lints
45+
runs-on: ubuntu-latest
46+
defaults:
47+
run:
48+
working-directory: contracts/cosmwasm-vm
49+
steps:
50+
- name: Checkout sources
51+
uses: actions/checkout@v3
52+
53+
- name: Install Rust
54+
run: rustup update stable
55+
56+
- name: Cache Rust dependencies
57+
uses: Swatinem/rust-cache@v2
58+
59+
- name: Run cargo fmt
60+
run: |
61+
cargo fmt --all -- --check
62+
63+
- name: Run cargo clippy
64+
run: |
65+
cargo clippy
66+
67+
- name: Generate schema
68+
run: |
69+
../../scripts/run_in_subprojects.sh cw-xcall cw-icon-light-client
70+
71+
- name: Verify schema
72+
uses: tj-actions/verify-changed-files@v14
73+
id: verify-schema
74+
with:
75+
files: |
76+
contracts/cosmwasm-vm/*/schema/**
77+
78+
- name: Display changed schemas
79+
if: steps.verify-schema.outputs.files_changed == 'true'
80+
run: |
81+
echo "Changed files: ${{ steps.verify-schema.outputs.changed_files }}"

.github/workflows/cosmwasm-contracts-code-coverage.yml

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
submodules: true
2828
- name: Install Rust
2929
run: rustup update stable
30+
- name: Cache Rust dependencies
31+
uses: Swatinem/rust-cache@v2
3032
- name: Install cargo-llvm-cov
3133
uses: taiki-e/install-action@cargo-llvm-cov
3234
- name: Generate code coverage

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ artifacts/*
4646

4747
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
4848
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
49-
Cargo.lock
49+
#Cargo.lock
5050
artifacts
5151

5252
# These are backup files generated by rustfmt

0 commit comments

Comments
 (0)