Skip to content

Commit

Permalink
Merge pull request #7 from nervosnetwork/CI
Browse files Browse the repository at this point in the history
Godwoken integration tests in CI
  • Loading branch information
Flouse authored Sep 26, 2021
2 parents 2f6917c + a893c46 commit b78e615
Show file tree
Hide file tree
Showing 40 changed files with 9,226 additions and 125 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/rust.yml

This file was deleted.

162 changes: 143 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,160 @@
name: Test
name: Integration Test

on:
push:
branches:
# - main
- CI
# - dependabot/**
pull_request:
branches:
- develop

jobs:
docker:
timeout-minutes: 10
readonly-testnet-node-sync-to-tip:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: readonly-testnet-node-sync-to-tip
env:
IMAGE_TAG: v0.6.4-rc5
run: |
cd configs
docker run --rm -i -w /deploy \
-v `pwd`/gw-testnet-config.toml:/deploy/gw-testnet-config.toml \
-v `pwd`/pk:/deploy/pk \
nervos/godwoken-prebuilds:${{ env.IMAGE_TAG }} bash -c "RUST_LOG=gw=debug godwoken run -c gw-testnet-config.toml"
- name: Setup tmate session for debugging if something failed
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 30

devnet:
timeout-minutes: 60
runs-on: ubuntu-latest

- name: Start containers
run: docker-compose --version
# run: docker-compose -f "docker-compose.yml" up -d --build
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'

# set up buildx/BuildKit runner in the context,
# make the Docker cache exportable and thus properly cacheable
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# In this step, this action saves a list of existing images,
# the cache is created without them in the post run.
# It also restores the cache if it exists.
- uses: satackey/[email protected]
continue-on-error: true # Ignore the failure of a step and avoid terminating the job.

# - name: Install node
# uses: actions/setup-node@v1
# - name: Cache Docker layers
# uses: actions/cache@v2
# with:
# node-version: 14.x
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-

- name: Rust Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry
~/.cargo/git
target
kicker/cache/build
# kicker/packages/godwoken/target
# kicker/packages
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
- name: Install moleculec
run: |
test "$(moleculec --version)" = "Moleculec 0.6.1" \
|| CARGO_TARGET_DIR=target/ cargo install moleculec --version 0.6.1
- name: Install Capsule
run: |
test "$(capsule -V)" = "Capsule 0.4.6 36d59e0" \
|| CARGO_TARGET_DIR=target/ cargo install ckb-capsule \
--git https://github.com/nervosnetwork/capsule.git \
--tag v0.4.6
- name: Start Godwoken-Kicker services
working-directory: kicker
run: |
docker system df -v
docker-compose --version
make init
make start
docker-compose --file docker/docker-compose.yml logs --tail 6
# FIXME: Godwoken service is not running - https://github.com/Flouse/godwoken/runs/3639382192?check_suite_focus=true#step:8:667
- name: Make sure the services of Kicker are OK
working-directory: kicker
run: |
make start
docker-compose --file docker/docker-compose.yml logs --tail 6
sudo chown -R `whoami` cache/build
# sudo chown -R `whoami` packages/godwoken/target
# TODO: check servics

- uses: actions/setup-node@v2
with:
node-version: '14'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Node Cache
uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Generate devnet envfile from godwoken-config.toml
working-directory: tools
run: |
yarn install
cd packages/tools
yarn generate-envfile
- name: Testcase - Godwoken Polyjuice Compatibility Examples
working-directory: testcases/godwoken-polyjuice-compatibility-examples
run: |
yarn install && yarn compile
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/box-proxy.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/multi-sign-wallet.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/multicall.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/create2.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/stable-swap-3-pool.ts
timeout-minutes: 10

- name: Testcase - Pancakeswap
working-directory: testcases/pancakeswap-contracts-godwoken
run: |
yarn && yarn compile
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/deploy.ts
timeout-minutes: 2

- name: Save logs
if: always()
working-directory: kicker/docker
run: docker-compose logs --tail 60000 > /tmp/kicker.log
- name: Archive logs
if: always()
uses: actions/upload-artifact@v2
with:
name: kicker-logs
path: |
/tmp/kicker.log
# - name: Run tests
# run:
- name: Stop containers of Kicker
if: always()
working-directory: kicker
run: make stop

# - name: Stop containers
# if: always()
# run: docker-compose -f "docker-compose.yml" down
- name: Setup tmate session for debugging if something failed
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 30
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target/
build/
/cache/*.json
error.log

.env
Expand All @@ -13,3 +14,5 @@ error.log
.vscode/dryrun.log
.vscode/targets.log
.vscode/settings.json

contracts/node_modules/
13 changes: 11 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
[submodule "godwoken-examples"]
path = tools
url = https://github.com/Flouse/godwoken-examples
branch = for-godwoken-integration-tests

branch = contracts
[submodule "godwoken-kicker"]
path = kicker
url = https://github.com/RetricSu/godwoken-kicker
branch = develop
[submodule "testcases/godwoken-polyjuice-compatibility-examples"]
path = testcases/godwoken-polyjuice-compatibility-examples
url = https://github.com/honestgoing/godwoken-polyjuice-compatibility-examples.git
[submodule "testcases/pancakeswap-contracts-godwoken"]
path = testcases/pancakeswap-contracts-godwoken
url = https://github.com/honestgoing/pancakeswap-contracts-godwoken.git
27 changes: 21 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "multi-sign-wallet",
"env": {
"ENV_PATH": "devnet.env"
},
"runtimeExecutable": "yarn",
"runtimeArgs": [
"test:multi-sign-wallet",
"debug"
],
"port": 9229,
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "lldb",
"request": "launch",
Expand All @@ -15,12 +32,10 @@
],
"env": {
"RUST_LOG": "godwoken_tests=debug",
"CKB_RPC": "http://localhost:8114",
"GODWOKEN_RPC": "http://localhost:8119",
"MINER_PRIVATE_KEY": "0xdd50cac37ec6dd12539a968c1a2cbedda75bd8724f7bcad486548eaabb87fc8b",
"MINER_CKB_ADDR": "ckt1qyqy84gfm9ljvqr69p0njfqullx5zy2hr9kq0pd3n5",
"USER1_PRIVATE_KEY": "0x6cd5e7be2f6504aa5ae7c0c04178d8f47b7cfc63b71d95d9e6282f5b090431bf",
"USER1_CKB_ADDR": "ckt1qyqf22qfzaer95xm5d2m5km0f6k288x9warqnhsf4m"
"CKB_RPC": "https://testnet.ckb.dev/rpc",
// "GODWOKEN_RPC": "http://localhost:8119",
"MINER_PRIVATE_KEY": "0xf5e9bac200a2eca0b0eead8a327ef3dc148ba10e192d07badad2d195f2488b94",
"USER1_PRIVATE_KEY": "0xa443ed1e456f0f23bcdf4f302f599cf77530d594ad896e84b549a04b0ea40c10",
},
"cwd": "${workspaceFolder}"
},
Expand Down
86 changes: 40 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,55 @@

This repository contains integration tests that test [Godwoken](https://github.com/nervosnetwork/godwoken).

## Running tests locally
## Prerequisites

1. Before tests can be run locally, a godwoken dev chain should be runing.
* [Docker](https://docs.docker.com/get-docker/), [docker-compose](https://docs.docker.com/compose/install/), [`Node.js` v14+](https://nodejs.org) and [`Yarn`](https://yarnpkg.com) are required.
* Before tests can be run locally, a godwoken dev chain should be runing.
[Godwoken-Kicker](https://github.com/RetricSu/godwoken-kicker) would be a good choice to start godwoken-polyjuice chain with one line command.

2. Update your godwoken configs into `configs/`, including `godwoken-config.toml`, `scripts-deploy-result.json` and `lumos-config.json`.
## Running tests locally

3. Build tools
```bash
chmod +x init.sh && ./init.sh # build tools for testing
1. Fetch the source code:
```sh
git clone --recursive https://github.com/nervosnetwork/godwoken-tests.git
cd godwoken-tests
```

4. `cp example.env .env` and then update environment variables in `.env` such as `CKB_RPC`, `GODWOKEN_RPC`, `MINER_PRIVATE_KEY`, `MINER_CKB_ADDR`, `USER1_PRIVATE_KEY` and `USER1_CKB_ADDR`.

5. Run tests with your own environment variables.
```bash
source .env # use your own env file
RUST_LOG=info cargo run # run all test cases
2. Update [`nervos/godwoken-prebuilds`](https://hub.docker.com/r/nervos/godwoken-prebuilds/tags?page=1&ordering=last_updated) docker image to the version you expected.
```sh
# edit this line in `kicker/docker/.build.mode.env`
DOCKER_PREBUILD_IMAGE_TAG=<the tag you expected>
```

**Note**: If you boot a new godwoken chain, you should update the config files in `configs/` and run `./init.sh` again.

## Test cases

The test cases are managed in `src/specs/`, such as `scr/specs/ckb_asset.rs`.

Remember to add new specs into `all_specs()` function in `src/main.rs`.

You can run specified specs:
3. Start Godwoken-Kicker
```sh
cd kicker
make init && make start
```

```bash
RUST_LOG=godwoken_tests=debug cargo run -- [CkbAsset] [SudtAsset] [Polyjuice] [OtherSpecStructName]
4. Generate a devnet envfile from [godwoken-config.toml](kicker/workspace/config.toml)
```sh
cd tools
yarn install
cd packages/tools
yarn generate-envfile
```

See all available options:

```bash
cargo run -- --help
#
# godwoken-tests 0.1.0
#
# USAGE:
# godwoken-tests [FLAGS] [OPTIONS] [specs]...
#
# FLAGS:
# -h, --help Prints help information
# --no-report [TODO]Do not show integration test report
# -V, --version Prints version information
# --verbose [TODO]Show verbose log
#
# OPTIONS:
# -c, --concurrent <concurrent> The number of specs can running concurrently [default: 1]
# --log-file <log-file> [TODO]Write log outputs into file.
# --max-time <SECONDS> Exit when total running time exceeds this limit

# ARGS:
# <specs>...
5. Run test cases using `devnet.env`
```sh
cd testcases/godwoken-polyjuice-compatibility-examples
yarn install && yarn compile
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/box-proxy.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/multi-sign-wallet.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/multicall.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/create2.ts
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/stable-swap-3-pool.ts

cd testcases/pancakeswap-contracts-godwoken
yarn && yarn compile
ENV_PATH=../../tools/packages/tools/configs/devnet.env yarn ts-node ./scripts/deploy.ts
```

New test cases could be added into `testcases` directory

**Note**: If you boot a new godwoken chain, you should `generate-envfile` again.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add Godwoken Kicker as a submodule
Empty file added cache/.gitkeep
Empty file.
Loading

0 comments on commit b78e615

Please sign in to comment.