From dbab7923de17da42fe43033c96153c1766724364 Mon Sep 17 00:00:00 2001 From: peartes Date: Fri, 23 Aug 2024 01:25:30 +0100 Subject: [PATCH 1/7] feat: workflow build release --- .cargo/{config => config.toml} | 2 + .github/workflows/Basic.yml | 18 +++++++-- .github/workflows/Release.yml | 39 ------------------- .github/workflows/artifacts.yml | 52 +++++++++++++++++++++++++ Cargo.toml | 2 +- contracts/account/examples/schema.rs | 10 +++++ contracts/account/src/auth/secp256r1.rs | 21 ++++------ contracts/treasury/examples/schema.rs | 10 +++++ contracts/treasury/src/lib.rs | 2 +- scripts/schema.sh | 20 ++++++++++ 10 files changed, 117 insertions(+), 59 deletions(-) rename .cargo/{config => config.toml} (67%) delete mode 100644 .github/workflows/Release.yml create mode 100644 .github/workflows/artifacts.yml create mode 100644 contracts/account/examples/schema.rs create mode 100644 contracts/treasury/examples/schema.rs create mode 100644 scripts/schema.sh diff --git a/.cargo/config b/.cargo/config.toml similarity index 67% rename from .cargo/config rename to .cargo/config.toml index 86f292b..89e2633 100644 --- a/.cargo/config +++ b/.cargo/config.toml @@ -1,3 +1,5 @@ [alias] wasm = "build --release --lib --target wasm32-unknown-unknown" +[env] +RUSTFLAGS = "-C link-arg=-s" \ No newline at end of file diff --git a/.github/workflows/Basic.yml b/.github/workflows/Basic.yml index 849c742..a81635d 100644 --- a/.github/workflows/Basic.yml +++ b/.github/workflows/Basic.yml @@ -5,14 +5,13 @@ on: branches: - main tags: - - 'v*.*.*' + - "v*.*.*" pull_request: name: Basic jobs: - test: name: Test Suite runs-on: ubuntu-latest @@ -35,7 +34,6 @@ jobs: env: RUST_BACKTRACE: 1 - lints: name: Lints runs-on: ubuntu-latest @@ -54,11 +52,23 @@ jobs: - name: Run cargo fmt uses: actions-rs/cargo@v1 with: + toolchain: stable command: fmt args: --all -- --check - name: Run cargo clippy uses: actions-rs/cargo@v1 with: + toolchain: stable command: clippy - args: -- -D warnings + args: --all-targets -- -D warnings + + - name: Generate Schema + run: ./scripts/schema.sh + + - name: Show Schema changes + run: git status --porcelain + + - name: Schema Changes + # fails if any changes not committed + run: test -z "$(git status --porcelain)" diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml deleted file mode 100644 index bbf8a95..0000000 --- a/.github/workflows/Release.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: release wasm - -on: - release: - types: [created] - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v2 - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: wasm32-unknown-unknown - override: true - - name: Compile WASM contract - uses: actions-rs/cargo@v1 - with: - command: wasm - args: --locked - env: - RUSTFLAGS: "-C link-arg=-s" - - name: Get release ID - id: get_release - uses: bruceadams/get-release@v1.2.3 - env: - GITHUB_TOKEN: ${{ github.token }} - - name: Upload optimized wasm - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ github.token }} - file: ./target/wasm32-unknown-unknown/release/*.wasm - tag: ${{ github.ref }} - overwrite: true - file_glob: true diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml new file mode 100644 index 0000000..1f4e9af --- /dev/null +++ b/.github/workflows/artifacts.yml @@ -0,0 +1,52 @@ +# Builds and commits the artifacts whenever a change is pushed to main. +name: artifact compiler + +permissions: + contents: write + +on: + push: + tags: + - "v*" + branches: + - main + - workflow + +jobs: + release-artifacts: + runs-on: ubuntu-latest + container: cosmwasm/workspace-optimizer:0.15.1 + steps: + - uses: actions/checkout@v3 + + # tar is required for cargo cache + - run: apk add --no-cache tar curl + + - name: Set up cargo cache + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Compile contracts + timeout-minutes: 30 + run: optimize.sh . + + - name: Upload contracts + uses: actions/upload-artifact@v4 + with: + name: contracts + path: artifacts/ + + - name: release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: artifacts/* + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/Cargo.toml b/Cargo.toml index 4780c33..3e50e5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,4 +30,4 @@ getrandom = { version = "0.2.10", features = ["custom"] } p256 = {version = "0.13.2", features = ["ecdsa-core", "arithmetic", "serde"]} prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]} cosmos-sdk-proto = {git = "https://github.com/burnt-labs/cosmos-rust.git", rev = "75e72f446629f98330e209e2f6268250d325cccb", default-features = false, features = ["std", "cosmwasm", "xion", "serde"]} -osmosis-std-derive = "0.13.2" +osmosis-std-derive = "0.13.2" \ No newline at end of file diff --git a/contracts/account/examples/schema.rs b/contracts/account/examples/schema.rs new file mode 100644 index 0000000..ba9fd69 --- /dev/null +++ b/contracts/account/examples/schema.rs @@ -0,0 +1,10 @@ +use ::account::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use cosmwasm_schema::write_api; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + query: QueryMsg, + execute: ExecuteMsg, + } +} diff --git a/contracts/account/src/auth/secp256r1.rs b/contracts/account/src/auth/secp256r1.rs index 6e833c9..afea7fb 100644 --- a/contracts/account/src/auth/secp256r1.rs +++ b/contracts/account/src/auth/secp256r1.rs @@ -34,23 +34,16 @@ mod tests { let verifying_key_binary = Binary::from(verifying_key_bytes.to_vec()); println!("verifying key: {}", hex::encode(verifying_key_bytes)); - assert_eq!( - true, - verify( - &test_value.to_vec(), - signature_bytes.as_slice(), - &verifying_key_binary, - ) - .unwrap() - ); + assert!(verify( + test_value, + signature_bytes.as_slice(), + &verifying_key_binary, + ) + .unwrap()); // test with invalid msg let bad_value = "invalid starting msg".as_bytes(); - let result = verify( - &bad_value.to_vec(), - signature_bytes.as_slice(), - &verifying_key_binary, - ); + let result = verify(bad_value, signature_bytes.as_slice(), &verifying_key_binary); assert!(result.is_err()) } } diff --git a/contracts/treasury/examples/schema.rs b/contracts/treasury/examples/schema.rs new file mode 100644 index 0000000..f1b7400 --- /dev/null +++ b/contracts/treasury/examples/schema.rs @@ -0,0 +1,10 @@ +use ::treasury::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use cosmwasm_schema::write_api; + +fn main() { + write_api! { + instantiate: InstantiateMsg, + query: QueryMsg, + execute: ExecuteMsg, + } +} diff --git a/contracts/treasury/src/lib.rs b/contracts/treasury/src/lib.rs index b7f80b0..2f24467 100644 --- a/contracts/treasury/src/lib.rs +++ b/contracts/treasury/src/lib.rs @@ -4,7 +4,7 @@ extern crate core; pub mod contract; mod error; mod execute; -mod msg; +pub mod msg; mod state; mod grant; diff --git a/scripts/schema.sh b/scripts/schema.sh new file mode 100644 index 0000000..65db05e --- /dev/null +++ b/scripts/schema.sh @@ -0,0 +1,20 @@ +START_DIR=$(pwd) + +# ${f <-- from variable f +# ## <-- greedy front trim +# * <-- matches anything +# / <-- until the last '/' +# } +# + +echo "generating schema for account contract" +cd contracts/account +cargo run --example schema > /dev/null +rm -rf ./schema/raw +cd "$START_DIR" + +echo "generating schema for treasury contract" +cd contracts/treasury +cargo run --example schema > /dev/null +rm -rf ./schema/raw +cd "$START_DIR" \ No newline at end of file From b9e897be85fb62529ff5f7ddeb65e5874de75671 Mon Sep 17 00:00:00 2001 From: peartes Date: Fri, 23 Aug 2024 01:28:19 +0100 Subject: [PATCH 2/7] chore: testing workflow --- .github/workflows/artifacts.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 1f4e9af..1152f2a 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -6,8 +6,6 @@ permissions: on: push: - tags: - - "v*" branches: - main - workflow From 7b5b572a6255b057dc3f1a911ed1812d2ce88489 Mon Sep 17 00:00:00 2001 From: peartes Date: Fri, 23 Aug 2024 01:34:55 +0100 Subject: [PATCH 3/7] chore: only run the workflow on tag push --- .github/workflows/artifacts.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 1152f2a..1f4e9af 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -6,6 +6,8 @@ permissions: on: push: + tags: + - "v*" branches: - main - workflow From e9cd3595243179f8731e736dc4442503c4d93969 Mon Sep 17 00:00:00 2001 From: peartes Date: Fri, 23 Aug 2024 01:54:38 +0100 Subject: [PATCH 4/7] chore: make script executable --- .github/workflows/artifacts.yml | 1 - scripts/schema.sh | 0 2 files changed, 1 deletion(-) mode change 100644 => 100755 scripts/schema.sh diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 1f4e9af..6ec95f0 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -10,7 +10,6 @@ on: - "v*" branches: - main - - workflow jobs: release-artifacts: diff --git a/scripts/schema.sh b/scripts/schema.sh old mode 100644 new mode 100755 From 53b49b2ca3b4a7478b027402c694acbc4b16a1dd Mon Sep 17 00:00:00 2001 From: peartes Date: Fri, 23 Aug 2024 02:35:08 +0100 Subject: [PATCH 5/7] fix: permission issue on script --- .github/workflows/Basic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Basic.yml b/.github/workflows/Basic.yml index a81635d..ec345f8 100644 --- a/.github/workflows/Basic.yml +++ b/.github/workflows/Basic.yml @@ -71,4 +71,4 @@ jobs: - name: Schema Changes # fails if any changes not committed - run: test -z "$(git status --porcelain)" + run: chmod +x ./scripts/check-schema.sh && test -z "$(git status --porcelain)" From ddb5f365be5b3c022e0de0f8e06b232cdd7871d2 Mon Sep 17 00:00:00 2001 From: peartes Date: Fri, 23 Aug 2024 02:42:48 +0100 Subject: [PATCH 6/7] fix: wrong file name --- .github/workflows/Basic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Basic.yml b/.github/workflows/Basic.yml index ec345f8..964ab0b 100644 --- a/.github/workflows/Basic.yml +++ b/.github/workflows/Basic.yml @@ -71,4 +71,4 @@ jobs: - name: Schema Changes # fails if any changes not committed - run: chmod +x ./scripts/check-schema.sh && test -z "$(git status --porcelain)" + run: chmod +x ./scripts/schema.sh && test -z "$(git status --porcelain)" From 8ddfcc0e8a4775500d082f2bc7de0487276ae47c Mon Sep 17 00:00:00 2001 From: Kehinde Faleye Date: Fri, 23 Aug 2024 10:58:20 +0100 Subject: [PATCH 7/7] Update Cargo.toml Signed-off-by: Kehinde Faleye --- Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e50e5f..c486e37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,5 +29,4 @@ rsa = { version = "0.9.2" } getrandom = { version = "0.2.10", features = ["custom"] } p256 = {version = "0.13.2", features = ["ecdsa-core", "arithmetic", "serde"]} prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]} -cosmos-sdk-proto = {git = "https://github.com/burnt-labs/cosmos-rust.git", rev = "75e72f446629f98330e209e2f6268250d325cccb", default-features = false, features = ["std", "cosmwasm", "xion", "serde"]} -osmosis-std-derive = "0.13.2" \ No newline at end of file +cosmos-sdk-proto = {git = "https://github.com/burnt-labs/cosmos-rust.git", rev = "75e72f446629f98330e209e2f6268250d325cccb", default-features = false, features = ["std", "cosmwasm", "xion", "serde"]} \ No newline at end of file