Skip to content

Commit

Permalink
Sync upstream (#8)
Browse files Browse the repository at this point in the history
* Sync many-things/main

---------

Co-authored-by: nambrot <nambrot@googlemail.com>
Co-authored-by: ByeongSu Hong <hong@byeongsu.dev>
  • Loading branch information
3 people authored Feb 1, 2024
1 parent 94fed0f commit c4485e0
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 66 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 20 additions & 27 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,43 @@ 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:
CARGO_TERM_COLOR: always
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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
32 changes: 24 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions contracts/core/mailbox/src/execute.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
14 changes: 12 additions & 2 deletions contracts/core/va/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ fn replay_hash(validator: &HexBinary, storage_location: &str) -> StdResult<HexBi
fn domain_hash(local_domain: u32, mailbox: HexBinary) -> StdResult<HexBinary> {
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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")]
Expand Down
1 change: 0 additions & 1 deletion contracts/igps/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod contract;
mod error;
mod event;
pub mod execute;
mod proto;
pub mod query;

#[cfg(test)]
Expand Down
24 changes: 0 additions & 24 deletions contracts/igps/core/src/proto.rs

This file was deleted.

0 comments on commit c4485e0

Please sign in to comment.