Skip to content

Commit

Permalink
ci: added a justfile (#102)
Browse files Browse the repository at this point in the history
* imp: added a Makefile

* imp: using just now

* ci: simplified the test command

* docs: updated docs

* ci: using just in ci now
  • Loading branch information
srdtrk committed May 10, 2024
1 parent d4ef6df commit a9f503b
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 88 deletions.
64 changes: 22 additions & 42 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,32 @@ jobs:
fail-fast: false
matrix:
test:
- TestIcaContractChannelHandshake_Ordered_Protobuf
- TestIcaContractChannelHandshake_Unordered_Protobuf
- TestIcaRelayerInstantiatedChannelHandshake
- TestRecoveredIcaContractInstantiatedChannelHandshake
- TestIcaContractExecution_Ordered_Protobuf
- TestIcaContractExecution_Unordered_Protobuf
- TestIcaContractTimeoutPacket_Ordered_Protobuf
- TestIcaContractTimeoutPacket_Unordered_Protobuf
- TestOwnerCreateIcaContract
- TestOwnerPredefinedAction
- TestSendCosmosMsgs_Ordered_Protobuf
- TestSendCosmosMsgs_Unordered_Protobuf
- TestSendWasmMsgsProtobufEncoding
- TestMigrateOrderedToUnordered
- TestCloseChannel_Protobuf_Unordered
- TestWithContractTestSuite/TestIcaContractChannelHandshake_Ordered_Protobuf
- TestWithContractTestSuite/TestIcaContractChannelHandshake_Unordered_Protobuf
- TestWithContractTestSuite/TestIcaRelayerInstantiatedChannelHandshake
- TestWithContractTestSuite/TestRecoveredIcaContractInstantiatedChannelHandshake
- TestWithContractTestSuite/TestIcaContractExecution_Ordered_Protobuf
- TestWithContractTestSuite/TestIcaContractExecution_Unordered_Protobuf
- TestWithContractTestSuite/TestIcaContractTimeoutPacket_Ordered_Protobuf
- TestWithContractTestSuite/TestIcaContractTimeoutPacket_Unordered_Protobuf
- TestWithOwnerTestSuite/TestOwnerCreateIcaContract
- TestWithOwnerTestSuite/TestOwnerPredefinedAction
- TestWithContractTestSuite/TestSendCosmosMsgs_Ordered_Protobuf
- TestWithContractTestSuite/TestSendCosmosMsgs_Unordered_Protobuf
- TestWithContractTestSuite/TestSendWasmMsgsProtobufEncoding
- TestWithContractTestSuite/TestMigrateOrderedToUnordered
- TestWithContractTestSuite/TestCloseChannel_Protobuf_Unordered
name: ${{ matrix.test }}
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Build Owner Contract with Docker
run: |
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="devcontract_cache_burner",target=/code/contracts/burner/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.15.0 ./testing/contracts/cw-ica-owner
- name: Build Callback Contract with Docker
run: |
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="devcontract_cache_burner",target=/code/contracts/burner/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.15.0 ./testing/contracts/callback-counter
- name: Install cargo-run-script
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-run-script
uses: actions/checkout@v4
- name: Install just
uses: extractions/setup-just@v2
- name: Build Test Contracts with Docker
run: just build-test-contracts
- name: Build Optimized Contract
uses: actions-rs/cargo@v1
with:
command: run-script
args: optimize
run: just build-optimize
- name: Setup Go
uses: actions/setup-go@v4
with:
Expand All @@ -83,11 +67,7 @@ jobs:
- name: TestContract
run: |
cd e2e/interchaintest
if [[ ${{ matrix.test }} == TestOwner* ]]; then
go test -v . -run TestWithOwnerTestSuite -testify.m ${{ matrix.test }}
else
go test -v . -run TestWithContractTestSuite -testify.m ${{ matrix.test }}
fi
go test -v . -run=${{ matrix.test }}
- name: Upload Diagnostics on Failure
uses: actions/upload-artifact@v4
if: ${{ failure() }}
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,31 @@ Buying and selling and NFT from Xion on Injective using Nomos SDK and ICA contro
</div>


## Building

We use [cosmwasm/optimizer](https://github.com/CosmWasm/optimizer) docker image to build the contract. This project uses `just` as the task runner. To install `just`, run the following command:

```sh
cargo install just
```

To build the contract, run the following command:

```sh
just build-optimize
```

## Testing

There are two kinds of tests in this repository: unit tests and end to end tests. The unit tests are located inside the rust files in the `src` directory. The end to end tests are located in the `e2e` directory.

### Unit tests

In general, the unit tests are for testing the verification functions for the handshake, and for testing that the serializers and deserializers are working correctly. To run the unit tests, run `cargo test`.
In general, the unit tests are for testing the verification functions for the handshake, and for testing that the serializers and deserializers are working correctly. To run the unit tests, run:

```sh
just unit-tests
```

### End to end tests

Expand Down
72 changes: 27 additions & 45 deletions e2e/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,41 @@ These tests are designed to test the ICA contract itself and its interaction wit

All contract tests are located in `interchaintest/contract_test.go` file. Currently, there are four tests in this file:

- `TestIcaContractChannelHandshake_Ordered_Protobuf`
- `TestIcaContractChannelHandshake_Unordered_Protobuf`
- `TestIcaRelayerInstantiatedChannelHandshake`
- `TestRecoveredIcaContractInstantiatedChannelHandshake`
- `TestIcaContractExecution_Ordered_Protobuf`
- `TestIcaContractExecution_Unordered_Protobuf`
- `TestIcaContractTimeoutPacket_Ordered_Protobuf`
- `TestIcaContractTimeoutPacket_Unordered_Protobuf`
- `TestSendCosmosMsgs_Ordered_Protobuf`
- `TestSendCosmosMsgs_Unordered_Protobuf`
- `TestSendWasmMsgsProtobufEncoding`
- `TestMigrateOrderedToUnordered`
- `TestCloseChannel_Protobuf_Unordered`

(These three tests used to be one monolithic test, but they were split into three in order to run them in parallel in the CI.)

To run the tests locally, run the following commands from this directory:

```text
cd interchaintest/
go test -v . -run TestWithContractTestSuite -testify.m $TEST_NAME
- TestWithContractTestSuite/TestIcaContractChannelHandshake_Ordered_Protobuf
- TestWithContractTestSuite/TestIcaContractChannelHandshake_Unordered_Protobuf
- TestWithContractTestSuite/TestIcaRelayerInstantiatedChannelHandshake
- TestWithContractTestSuite/TestRecoveredIcaContractInstantiatedChannelHandshake
- TestWithContractTestSuite/TestIcaContractExecution_Ordered_Protobuf
- TestWithContractTestSuite/TestIcaContractExecution_Unordered_Protobuf
- TestWithContractTestSuite/TestIcaContractTimeoutPacket_Ordered_Protobuf
- TestWithContractTestSuite/TestIcaContractTimeoutPacket_Unordered_Protobuf
- TestWithOwnerTestSuite/TestOwnerCreateIcaContract
- TestWithOwnerTestSuite/TestOwnerPredefinedAction
- TestWithContractTestSuite/TestSendCosmosMsgs_Ordered_Protobuf
- TestWithContractTestSuite/TestSendCosmosMsgs_Unordered_Protobuf
- TestWithContractTestSuite/TestSendWasmMsgsProtobufEncoding
- TestWithContractTestSuite/TestMigrateOrderedToUnordered
- TestWithContractTestSuite/TestCloseChannel_Protobuf_Unordered

To run the tests locally, run the following command in the root of the repository:

```sh
just e2e-test $TEST_NAME
```

where `$TEST_NAME` is one of the four tests listed above.
where `$TEST_NAME` is one of the tests listed above.

Before running the tests, you must have built the optimized contract in the `/artifacts` directory. To do this, run the following command from the root of the repository:
Before running the tests, you must have built the optimized contract in the `/artifacts` directory. To do this, run the following commands from the root of the repository:

```text
cargo run-script optimize
```sh
just build-optimized
just build-test-contracts
```

### Owner Contract Tests

These tests are designed to test the ICA contract's interaction with external contracts such as callbacks. For this, a mock owner contract is used.

All owner contract tests are located in `interchaintest/owner_test.go` file. Currently, there are two tests in this file:

- `TestOwnerCreateIcaContract`
- `TestOwnerPredefinedAction`

```text
cd interchaintest/
go test -v . -run TestWithOwnerTestSuite -testify.m $TEST_NAME
```

where `$TEST_NAME` is one of the two tests listed above.

## In the CI

The tests are run in the github CI after every push to the `main` branch. See the [github actions workflow](https://github.com/srdtrk/cw-ica-controller/blob/main/.github/workflows/e2e.yml) for more details.

For some unknown reason, the timeout test sometimes fails in the CI (I'd say about 20-25% of the time). In this case, feel free to rerun the CI job.
The tests are run in the github CI after every push to the `main` branch and in every PR. See the [github actions workflow](https://github.com/srdtrk/cw-ica-controller/blob/main/.github/workflows/e2e.yml) for more details.

## About the tests

The tests are currently run on wasmd `v0.41.0` and ibc-go `v7.3.0`'s simd which implements json encoding feature for the interchain accounts module.
The tests are currently run on wasmd `v0.50.0` and ibc-go `v8.1.0`.
37 changes: 37 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build optimized wasm using the cosmwasm/optimizer:0.15.1 docker image
build-optimize:
echo "Compiling optimized wasm..."
docker run --rm -t -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.15.1
echo "Optimized wasm file created at 'artifacts/cw-ica-controller.wasm'"

# Run cargo fmt and clippy
lint:
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings

# Build the test contracts using the cosmwasm/optimizer:0.15.1 docker image
build-test-contracts:
echo "Building test contracts..."
echo "Building cw-ica-owner..."
docker run --rm -t -v "$(pwd)":/code \
--mount type=volume,source="devcontract_cache_burner",target=/code/contracts/burner/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.15.1 ./testing/contracts/cw-ica-owner
echo "Building callback-counter..."
docker run --rm -t -v "$(pwd)":/code \
--mount type=volume,source="devcontract_cache_burner",target=/code/contracts/burner/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.15.1 ./testing/contracts/callback-counter
echo "Optimized wasm files created at 'artifacts/cw-ica-owner.wasm' and 'artifacts/callback-counter.wasm'"

# Run the unit tests
unit-tests:
RUST_BACKTRACE=1 cargo test --locked --all-features

# Run the e2e tests
e2e-test testname:
echo "Running {{testname}} test..."
cd e2e/interchaintest && go test -v -run={{testname}}

0 comments on commit a9f503b

Please sign in to comment.