From 58a57ab2aa464fb0bac5cfef926a9be69378cf77 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Sun, 22 Dec 2024 19:19:59 +0700 Subject: [PATCH 1/4] Create tests.yml run tests --- .github/workflows/tests.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..14d770d19 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,15 @@ +on: [push, pull_request] +name: Test +jobs: + test: + strategy: + matrix: + go-version: [1.23.x] + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - run: go test ./... From 81ce279a98d64bdf89929c1da26370b917ce8238 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Sat, 11 Jan 2025 13:31:07 +0700 Subject: [PATCH 2/4] add 2 new github actions --- .github/workflows/clippy.yml | 39 +++++++++++++++++++++++++++++++++++ .github/workflows/windows.yml | 23 +++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 .github/workflows/clippy.yml create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 000000000..ec7fdd6fa --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,39 @@ +# .github/workflows/clippy.yml +name: Clippy Checks + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + libwasmvm_clippy_msrv: + runs-on: ubuntu-latest + container: + image: rust:1.83.0 + steps: + - uses: actions/checkout@v4 + - name: Version information + run: rustc --version && cargo --version + - name: Add clippy component + run: rustup component add clippy + - name: Run clippy + working-directory: libwasmvm + run: cargo clippy --all-targets -- -D warnings + + libwasmvm_clippy_stable: + runs-on: ubuntu-latest + container: + image: rust:1.83.0 + steps: + - uses: actions/checkout@v4 + - name: Version information + run: rustc --version && cargo --version + - name: Add clippy component + run: rustup component add clippy + - name: Run clippy + working-directory: libwasmvm + run: cargo clippy --all-targets -- -D warnings diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 000000000..ed7719bf9 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,23 @@ +# .github/workflows/windows.yml +name: Windows Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + libwasmvm_sanity_windows: + runs-on: windows-latest + container: + image: rust:1.83.0 + steps: + - uses: actions/checkout@v4 + - name: Show Rust version information + run: rustc --version && cargo --version && rustup --version + - name: Run unit tests + working-directory: libwasmvm + run: cargo test From 6e78fbacd5188116b19f253236b3eba79276a3c8 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Sat, 11 Jan 2025 14:39:02 +0700 Subject: [PATCH 3/4] gci --- .golangci.yml | 6 +----- ibc_test.go | 5 ++--- internal/api/api_test.go | 3 +-- internal/api/iterator_test.go | 5 ++--- internal/api/lib.go | 3 +-- internal/api/lib_test.go | 3 +-- internal/api/mocks.go | 5 ++--- lib_libwasmvm_test.go | 5 ++--- lib_test.go | 3 +-- 9 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3af894222..09aa3a1f8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,8 +3,4 @@ linters: # https://golangci-lint.run/usage/linters/#enabled-by-default enable: - gofumpt - - goimports - -linters-settings: - goimports: - local-prefixes: github.com/CosmWasm/wasmvm + - gci diff --git a/ibc_test.go b/ibc_test.go index 2da754d14..f6aecfdc1 100644 --- a/ibc_test.go +++ b/ibc_test.go @@ -7,11 +7,10 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/CosmWasm/wasmvm/v2/internal/api" "github.com/CosmWasm/wasmvm/v2/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) const IBC_TEST_CONTRACT = "./testdata/ibc_reflect.wasm" diff --git a/internal/api/api_test.go b/internal/api/api_test.go index 1d8109857..7b6c6eec1 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -5,9 +5,8 @@ import ( "os" "testing" - "github.com/stretchr/testify/require" - "github.com/CosmWasm/wasmvm/v2/types" + "github.com/stretchr/testify/require" ) func TestValidateAddressFailure(t *testing.T) { diff --git a/internal/api/iterator_test.go b/internal/api/iterator_test.go index 0c81db775..b67088e10 100644 --- a/internal/api/iterator_test.go +++ b/internal/api/iterator_test.go @@ -6,11 +6,10 @@ import ( "sync" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/CosmWasm/wasmvm/v2/internal/api/testdb" "github.com/CosmWasm/wasmvm/v2/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type queueData struct { diff --git a/internal/api/lib.go b/internal/api/lib.go index 2b71adc1c..73a922930 100644 --- a/internal/api/lib.go +++ b/internal/api/lib.go @@ -13,9 +13,8 @@ import ( "strings" "syscall" - "golang.org/x/sys/unix" - "github.com/CosmWasm/wasmvm/v2/types" + "golang.org/x/sys/unix" ) // Value types diff --git a/internal/api/lib_test.go b/internal/api/lib_test.go index 90c55a8c2..4d8a9add8 100644 --- a/internal/api/lib_test.go +++ b/internal/api/lib_test.go @@ -13,10 +13,9 @@ import ( "testing" "time" + "github.com/CosmWasm/wasmvm/v2/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/CosmWasm/wasmvm/v2/types" ) const ( diff --git a/internal/api/mocks.go b/internal/api/mocks.go index ac8500dd8..fb6be293c 100644 --- a/internal/api/mocks.go +++ b/internal/api/mocks.go @@ -8,11 +8,10 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/CosmWasm/wasmvm/v2/internal/api/testdb" "github.com/CosmWasm/wasmvm/v2/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) /** helper constructors **/ diff --git a/lib_libwasmvm_test.go b/lib_libwasmvm_test.go index 4c25f69a0..b12bd7bd9 100644 --- a/lib_libwasmvm_test.go +++ b/lib_libwasmvm_test.go @@ -9,11 +9,10 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/CosmWasm/wasmvm/v2/internal/api" "github.com/CosmWasm/wasmvm/v2/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) const ( diff --git a/lib_test.go b/lib_test.go index 35094e7df..54b2d3293 100644 --- a/lib_test.go +++ b/lib_test.go @@ -3,9 +3,8 @@ package cosmwasm import ( "testing" - "github.com/stretchr/testify/require" - "github.com/CosmWasm/wasmvm/v2/types" + "github.com/stretchr/testify/require" ) func TestCreateChecksum(t *testing.T) { From f62005682f08c027ec81025c790fe653bbfc69b9 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Sat, 11 Jan 2025 14:43:29 +0700 Subject: [PATCH 4/4] add new jobs and lint rust --- .github/workflows/audity.yml | 29 ++++++++++++++ .github/workflows/libwasmvm-sanity.yml | 51 ++++++++++++++++++++++++ libwasmvm/bindings.h | 54 +++++++++++++------------- libwasmvm/src/cache.rs | 26 ++++++------- libwasmvm/src/calls.rs | 36 ++++++++--------- libwasmvm/src/lib.rs | 2 +- 6 files changed, 139 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/audity.yml create mode 100644 .github/workflows/libwasmvm-sanity.yml diff --git a/.github/workflows/audity.yml b/.github/workflows/audity.yml new file mode 100644 index 000000000..14828a7f3 --- /dev/null +++ b/.github/workflows/audity.yml @@ -0,0 +1,29 @@ +# .github/workflows/libwasmvm_audit.yml +name: libwasmvm_audit + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + libwasmvm_audit: + runs-on: ubuntu-latest + container: + image: rust:1.83.0 + steps: + - uses: actions/checkout@v4 + - name: Install OpenSSL + run: | + sudo apt update + sudo apt install libssl-dev + - name: Show Rust version information + run: rustc --version && cargo --version && rustup --version + - name: Install cargo-audit + run: cargo install --debug cargo-audit --version 0.21.0 + - name: Run cargo-audit + working-directory: libwasmvm + run: cargo audit diff --git a/.github/workflows/libwasmvm-sanity.yml b/.github/workflows/libwasmvm-sanity.yml new file mode 100644 index 000000000..ce8a4f60e --- /dev/null +++ b/.github/workflows/libwasmvm-sanity.yml @@ -0,0 +1,51 @@ +# .github/workflows/libwasmvm_sanity.yml +name: libwasmvm_sanity + +on: + push: + branches: + - main + - 0.14-dev + - GoIter-creation + - release/* + pull_request: + branches: + - main + +jobs: + libwasmvm_sanity: + runs-on: ubuntu-latest + container: + image: rust:1.83.0 + steps: + - uses: actions/checkout@v4 + - name: Show Rust version information + run: rustc --version && cargo --version && rustup --version + - name: Add Rust components + run: rustup component add rustfmt + - name: Ensure libwasmvm/bindings.h is up-to-date + working-directory: libwasmvm + run: | + cargo check + CHANGES_IN_REPO=$(git status --porcelain bindings.h) + if [[ -n "$CHANGES_IN_REPO" ]]; then + echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:" + git status && git --no-pager diff + exit 1 + fi + - name: Ensure internal/api/bindings.h is up to date + run: diff libwasmvm/bindings.h internal/api/bindings.h + - name: Check Rust formatting + working-directory: libwasmvm + run: cargo fmt -- --check + - name: Run unit tests + working-directory: libwasmvm + run: cargo test + - name: Build docs + working-directory: libwasmvm + run: cargo doc --no-deps + - name: Test docs + working-directory: libwasmvm + run: | + sed -i '/^crate-type = \["cdylib"\]/d' Cargo.toml + cargo test --doc diff --git a/libwasmvm/bindings.h b/libwasmvm/bindings.h index 1f356a7fc..1032e17af 100644 --- a/libwasmvm/bindings.h +++ b/libwasmvm/bindings.h @@ -53,9 +53,9 @@ enum GoError { }; typedef int32_t GoError; -typedef struct cache_t { +typedef struct CacheT { -} cache_t; +} CacheT; /** * A view into an externally owned byte slice (Go `[]byte`). @@ -412,33 +412,33 @@ typedef struct GasReport { uint64_t used_internally; } GasReport; -struct cache_t *init_cache(struct ByteSliceView config, struct UnmanagedVector *error_msg); +struct CacheT *init_cache(struct ByteSliceView config, struct UnmanagedVector *error_msg); -struct UnmanagedVector store_code(struct cache_t *cache, +struct UnmanagedVector store_code(struct CacheT *cache, struct ByteSliceView wasm, bool checked, bool persist, struct UnmanagedVector *error_msg); -void remove_wasm(struct cache_t *cache, +void remove_wasm(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -struct UnmanagedVector load_wasm(struct cache_t *cache, +struct UnmanagedVector load_wasm(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -void pin(struct cache_t *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); +void pin(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -void unpin(struct cache_t *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); +void unpin(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -struct AnalysisReport analyze_code(struct cache_t *cache, +struct AnalysisReport analyze_code(struct CacheT *cache, struct ByteSliceView checksum, struct UnmanagedVector *error_msg); -struct Metrics get_metrics(struct cache_t *cache, struct UnmanagedVector *error_msg); +struct Metrics get_metrics(struct CacheT *cache, struct UnmanagedVector *error_msg); -struct UnmanagedVector get_pinned_metrics(struct cache_t *cache, struct UnmanagedVector *error_msg); +struct UnmanagedVector get_pinned_metrics(struct CacheT *cache, struct UnmanagedVector *error_msg); /** * frees a cache reference @@ -448,9 +448,9 @@ struct UnmanagedVector get_pinned_metrics(struct cache_t *cache, struct Unmanage * This must be called exactly once for any `*cache_t` returned by `init_cache` * and cannot be called on any other pointer. */ -void release_cache(struct cache_t *cache); +void release_cache(struct CacheT *cache); -struct UnmanagedVector instantiate(struct cache_t *cache, +struct UnmanagedVector instantiate(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView info, @@ -463,7 +463,7 @@ struct UnmanagedVector instantiate(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector execute(struct cache_t *cache, +struct UnmanagedVector execute(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView info, @@ -476,7 +476,7 @@ struct UnmanagedVector execute(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector migrate(struct cache_t *cache, +struct UnmanagedVector migrate(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -488,7 +488,7 @@ struct UnmanagedVector migrate(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector migrate_with_info(struct cache_t *cache, +struct UnmanagedVector migrate_with_info(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -501,7 +501,7 @@ struct UnmanagedVector migrate_with_info(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector sudo(struct cache_t *cache, +struct UnmanagedVector sudo(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -513,7 +513,7 @@ struct UnmanagedVector sudo(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector reply(struct cache_t *cache, +struct UnmanagedVector reply(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -525,7 +525,7 @@ struct UnmanagedVector reply(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector query(struct cache_t *cache, +struct UnmanagedVector query(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -537,7 +537,7 @@ struct UnmanagedVector query(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_channel_open(struct cache_t *cache, +struct UnmanagedVector ibc_channel_open(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -549,7 +549,7 @@ struct UnmanagedVector ibc_channel_open(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_channel_connect(struct cache_t *cache, +struct UnmanagedVector ibc_channel_connect(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -561,7 +561,7 @@ struct UnmanagedVector ibc_channel_connect(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_channel_close(struct cache_t *cache, +struct UnmanagedVector ibc_channel_close(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -573,7 +573,7 @@ struct UnmanagedVector ibc_channel_close(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_packet_receive(struct cache_t *cache, +struct UnmanagedVector ibc_packet_receive(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -585,7 +585,7 @@ struct UnmanagedVector ibc_packet_receive(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_packet_ack(struct cache_t *cache, +struct UnmanagedVector ibc_packet_ack(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -597,7 +597,7 @@ struct UnmanagedVector ibc_packet_ack(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache, +struct UnmanagedVector ibc_packet_timeout(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -609,7 +609,7 @@ struct UnmanagedVector ibc_packet_timeout(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_source_callback(struct cache_t *cache, +struct UnmanagedVector ibc_source_callback(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, @@ -621,7 +621,7 @@ struct UnmanagedVector ibc_source_callback(struct cache_t *cache, struct GasReport *gas_report, struct UnmanagedVector *error_msg); -struct UnmanagedVector ibc_destination_callback(struct cache_t *cache, +struct UnmanagedVector ibc_destination_callback(struct CacheT *cache, struct ByteSliceView checksum, struct ByteSliceView env, struct ByteSliceView msg, diff --git a/libwasmvm/src/cache.rs b/libwasmvm/src/cache.rs index 064abcd5b..2e77dd6a8 100644 --- a/libwasmvm/src/cache.rs +++ b/libwasmvm/src/cache.rs @@ -15,9 +15,9 @@ use crate::querier::GoQuerier; use crate::storage::GoStorage; #[repr(C)] -pub struct cache_t {} +pub struct CacheT {} -pub fn to_cache(ptr: *mut cache_t) -> Option<&'static mut Cache> { +pub fn to_cache(ptr: *mut CacheT) -> Option<&'static mut Cache> { if ptr.is_null() { None } else { @@ -30,12 +30,12 @@ pub fn to_cache(ptr: *mut cache_t) -> Option<&'static mut Cache, -) -> *mut cache_t { +) -> *mut CacheT { let r = catch_unwind(|| do_init_cache(config)).unwrap_or_else(|err| { handle_vm_panic("do_init_cache", err); Err(Error::panic()) }); - handle_c_error_ptr(r, error_msg) as *mut cache_t + handle_c_error_ptr(r, error_msg) as *mut CacheT } fn do_init_cache(config: ByteSliceView) -> Result<*mut Cache, Error> { @@ -49,7 +49,7 @@ fn do_init_cache(config: ByteSliceView) -> Result<*mut Cache, ) { @@ -110,7 +110,7 @@ fn do_remove_wasm( #[no_mangle] pub extern "C" fn load_wasm( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) -> UnmanagedVector { @@ -140,7 +140,7 @@ fn do_load_wasm( #[no_mangle] pub extern "C" fn pin( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) { @@ -170,7 +170,7 @@ fn do_pin( #[no_mangle] pub extern "C" fn unpin( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) { @@ -278,7 +278,7 @@ fn set_to_csv(set: BTreeSet>) -> String { #[no_mangle] pub extern "C" fn analyze_code( - cache: *mut cache_t, + cache: *mut CacheT, checksum: ByteSliceView, error_msg: Option<&mut UnmanagedVector>, ) -> AnalysisReport { @@ -357,7 +357,7 @@ impl From for Metrics { #[no_mangle] pub extern "C" fn get_metrics( - cache: *mut cache_t, + cache: *mut CacheT, error_msg: Option<&mut UnmanagedVector>, ) -> Metrics { let r = match to_cache(cache) { @@ -412,7 +412,7 @@ impl From for PinnedMetrics { #[no_mangle] pub extern "C" fn get_pinned_metrics( - cache: *mut cache_t, + cache: *mut CacheT, error_msg: Option<&mut UnmanagedVector>, ) -> UnmanagedVector { let r = match to_cache(cache) { @@ -442,7 +442,7 @@ fn do_get_pinned_metrics( /// This must be called exactly once for any `*cache_t` returned by `init_cache` /// and cannot be called on any other pointer. #[no_mangle] -pub extern "C" fn release_cache(cache: *mut cache_t) { +pub extern "C" fn release_cache(cache: *mut CacheT) { if !cache.is_null() { // this will free cache when it goes out of scope let _ = unsafe { Box::from_raw(cache as *mut Cache) }; diff --git a/libwasmvm/src/calls.rs b/libwasmvm/src/calls.rs index b49ac142a..8fcb3b289 100644 --- a/libwasmvm/src/calls.rs +++ b/libwasmvm/src/calls.rs @@ -16,7 +16,7 @@ use cosmwasm_vm::{ use crate::api::GoApi; use crate::args::{ARG1, ARG2, ARG3, CACHE_ARG, CHECKSUM_ARG, GAS_REPORT_ARG}; -use crate::cache::{cache_t, to_cache}; +use crate::cache::{to_cache, CacheT}; use crate::db::Db; use crate::error::{handle_c_error_binary, Error}; use crate::handle_vm_panic::handle_vm_panic; @@ -35,7 +35,7 @@ fn into_backend(db: Db, api: GoApi, querier: GoQuerier) -> Backend