diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 00000000..76dcd7b9 --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,47 @@ +name: pr + +on: + pull_request: + branches: + - "main" + +jobs: + artifact: + permissions: + contents: write + pull-requests: write + + name: artifact + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + run: | + rustup toolchain install 1.72 \ + --profile minimal \ + --target wasm32-unknown-unknown \ + --no-self-update + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + + - name: Install Deps + run: make install-prod + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build wasm + run: | + cargo generate-lockfile + make ci-build + + - name: Pull request artifacts + uses: gavv/pull-request-artifacts@v2 + with: + commit: ${{ github.event.pull_request.head.sha }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + artifacts-branch: artifacts + artifacts: | + wasm_codes.zip diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1cbe220c..358bd4de 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,38 +16,23 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Cache dependencies - uses: actions/cache@v3 + - uses: actions/setup-go@v4 with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + go-version: '1.21' - name: Install Rust - run: rustup update 1.72 - - - name: Install rename - run: sudo apt-get install -y rename + run: | + rustup toolchain install 1.72 \ + --profile minimal \ + --target wasm32-unknown-unknown \ + --no-self-update - - name: Install rust deps - run: make install + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 - name: Run tests run: cargo test --workspace --exclude hpl-tests - - name: Build wasm - run: make ci-build - - - name: Upload wasm archive - uses: actions/upload-artifact@v2 - with: - name: wasm_codes - path: wasm_codes.zip - coverage: runs-on: ubuntu-latest env: @@ -55,11 +40,19 @@ jobs: steps: - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: '1.21' + - name: Install Rust - run: rustup update nightly + run: | + rustup toolchain install 1.72 \ + --profile minimal \ + --target wasm32-unknown-unknown \ + --no-self-update - - name: Install target - run: rustup target add wasm32-unknown-unknown + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov diff --git a/Cargo.toml b/Cargo.toml index 9ef3ffa3..7fa7f06c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,8 +82,8 @@ digest = { version = "0.10.7" } # testing cw-multi-test = "0.20.0" rstest = "0.18.2" -test-tube = { version = "0.3.0" } -osmosis-test-tube = { version = "21.0.0" } +test-tube = { version = "0.5.0" } +osmosis-test-tube = { version = "22.1.0" } ibcx-test-utils = { version = "0.1.2" } tokio = { version = "1", features = ["full"] } diff --git a/Makefile b/Makefile index a7b1cf3e..b1864dc3 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,38 @@ +PWD:=$(shell pwd) +BASE:=$(shell basename "$(PWD)") + clean: @cargo clean @rm -rf ./artifacts -install: - cargo install --force cw-optimizoor cosmwasm-check beaker +install: install-dev + +install-dev: install-prod + cargo install --force cw-optimizoor beaker + +install-prod: + cargo install --force cosmwasm-check rustup target add wasm32-unknown-unknown schema: ls ./contracts | xargs -n 1 -t beaker wasm ts-gen -build: - cargo build - cargo wasm +check: + ls -d ./artifacts/*.wasm | xargs -I x cosmwasm-check x + +optimize: + docker run --rm -v "$(PWD)":/code \ + --mount type=volume,source="$(BASE)_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/optimizer:0.15.0 + +optimize-fast: cargo cw-optimizoor rename --force 's/(.*)-(.*)\.wasm/$$1\.wasm/d' artifacts/* -check: build - ls -d ./artifacts/*.wasm | xargs -I x cosmwasm-check x +build: optimize-fast check + cargo build + cargo wasm -ci-build: check +ci-build: optimize check zip -jr wasm_codes.zip artifacts diff --git a/contracts/core/mailbox/src/execute.rs b/contracts/core/mailbox/src/execute.rs index c8b1dff5..5f06e026 100644 --- a/contracts/core/mailbox/src/execute.rs +++ b/contracts/core/mailbox/src/execute.rs @@ -1,7 +1,8 @@ use cosmwasm_std::{ - ensure, ensure_eq, to_json_binary, wasm_execute, Coin, Coins, DepsMut, Env, HexBinary, - MessageInfo, Response + ensure, ensure_eq, to_json_binary, wasm_execute, Coin, Coins, DepsMut, Env, + HexBinary, MessageInfo, Response, }; +use cw_utils::PaymentError::MissingDenom; use hpl_interface::{ core::{ mailbox::{DispatchMsg, DispatchResponse}, diff --git a/contracts/core/va/src/contract.rs b/contracts/core/va/src/contract.rs index 69bd6eb5..dd77b473 100644 --- a/contracts/core/va/src/contract.rs +++ b/contracts/core/va/src/contract.rs @@ -131,7 +131,10 @@ fn replay_hash(validator: &HexBinary, storage_location: &str) -> StdResult StdResult { let mut bz = vec![]; bz.append(&mut local_domain.to_be_bytes().to_vec()); - bz.append(&mut mailbox.to_vec()); + // left pad with zeroes + let mut addr = [0u8; 32]; + addr[32 - mailbox.len()..].copy_from_slice(&mailbox); + bz.append(&mut addr.to_vec()); bz.append(&mut "HYPERLANE_ANNOUNCEMENT".as_bytes().to_vec()); let hash = keccak256_hash(&bz); @@ -272,6 +275,12 @@ mod test { ) } + fn preset_20_byte_address() -> Self { + let mut p = Announcement::preset(); + p.mailbox = "49cfd6ef774acab14814d699e3f7ee36fdfba932".into(); + return p; + } + fn rand() -> Self { // prepare test data let mailbox = gen_bz(32); @@ -387,7 +396,8 @@ mod test { #[rstest] #[case::rand(Announcement::rand(), false)] - #[case::actual_data_1(Announcement::preset(), false)] + #[case::actual_data(Announcement::preset(), false)] + #[case::actual_data_20_bytes(Announcement::preset_20_byte_address(), false)] #[should_panic(expected = "unauthorized")] #[case::replay(Announcement::rand(), true)] #[should_panic(expected = "verify failed")] diff --git a/contracts/igps/core/src/lib.rs b/contracts/igps/core/src/lib.rs index c45aa050..6085f7f3 100644 --- a/contracts/igps/core/src/lib.rs +++ b/contracts/igps/core/src/lib.rs @@ -2,7 +2,6 @@ pub mod contract; mod error; mod event; pub mod execute; -mod proto; pub mod query; #[cfg(test)] diff --git a/contracts/igps/core/src/proto.rs b/contracts/igps/core/src/proto.rs deleted file mode 100644 index 13bd68d0..00000000 --- a/contracts/igps/core/src/proto.rs +++ /dev/null @@ -1,24 +0,0 @@ -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(::prost::Message, ::serde::Serialize, ::serde::Deserialize)] -pub struct QuerySupplyOfRequest { - /// denom is the coin denom to query balances for. - #[prost(string, tag = "1")] - pub denom: ::prost::alloc::string::String, -} - -/// QuerySupplyOfResponse is the response type for the Query/SupplyOf RPC method. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(::prost::Message, ::serde::Serialize, ::serde::Deserialize)] -pub struct QuerySupplyOfResponse { - /// amount is the supply of the coin. - #[prost(message, optional, tag = "1")] - pub amount: ::core::option::Option, -} - -#[derive(serde::Serialize, serde::Deserialize, ::prost::Message)] -pub struct Coin { - #[prost(string, tag = "1")] - pub denom: ::prost::alloc::string::String, - #[prost(string, tag = "2")] - pub amount: ::prost::alloc::string::String, -}