Skip to content

Bouqute/godwoken-tests

 
 

Repository files navigation

Godwoken Tests

This repository contains integration tests that test Godwoken. You can trigger a test workflow here or run tests locally.

Key Env

In a Github workflow, the GW_PREBUILDS_IMAGE env will replace the DOCKER_PREBUILD_IMAGE_NAME env in kicker/docker/.build.mode.env. You could change this image as you like, such as nervos/godwoken-prebuilds:latest.

# .github/workflows/test.yml

env:
  # Image built from https://github.com/Flouse/godwoken-docker-prebuilds/tree/develop
  GW_PREBUILDS_IMAGE_NAME: ghcr.io/flouse/godwoken-prebuilds
  GW_PREBUILD_IMAGE_TAG: develop

Test cases in test.yml

# .github/workflows/test.yml

- 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/multi-sign-wallet.ts
    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/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: 6

- 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: 6

- name: Testcase - LendingContracts
    working-directory: testcases/lending-contracts
    run: |
    yarn
    echo "The configs should have been updated:"
    cat config.json
    yarn deploy
    timeout-minutes: 12

More cases could be added into .github/workflows/test.yml.

How to create a godwoken integration-test workflow

Prerequisites

Admin rights(actions:write permission) to this repository is required.

2 Methods

  • Use the Run workflow button on the Action tab to easily trigger a run

    run workflow

    We can specify the inputs of a workflow dispatch:

    a. The prebuild image including Godwoken related bins (* required). Pick the right tag from:
      
     - https://hub.docker.com/r/nervos/godwoken-prebuilds
     - https://github.com/Flouse/godwoken-docker-prebuilds/pkgs/container/godwoken-prebuilds
    
    b. The special versions of Godwoken, Godwoken-scripts, or Polyjuice we want to test with (optional)
    
  • Use the dispatches REST API endpoint to manually trigger a GitHub Action workflow run

    post /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches

    See also: GitHub Doc - Create a workflow dispatch event

    Example:

    curl -u {username}:{$token} \
        -X POST \
        -H "Accept: application/vnd.github.v3+json" \
        https://api.github.com/repos/nervosnetwork/godwoken-tests/actions/workflows/test.yml/dispatches \
        -d '{"ref":"develop","inputs":{"gw_prebuild_image_name":"ghcr.io/flouse/godwoken-prebuilds","gw_prebuild_image_tag":"v0.6.5-rc3"}}'

    Set up a variable for token to avoid leaving your token in shell history, which should be avoided.

Running tests locally

Prerequisites

Steps

  1. Fetch the source code:

    git clone --recursive https://github.com/nervosnetwork/godwoken-tests.git
    cd godwoken-tests
  2. Update nervos/godwoken-prebuilds docker image to the version you expected.

    # edit this line in `kicker/docker/.build.mode.env`
    DOCKER_PREBUILD_IMAGE_TAG=<the tag you expected>
  3. Start Godwoken-Kicker

    cd kicker
    make init && make start
  4. Generate a devnet envfile from godwoken-config.toml

    cd tools
    yarn install
    cd packages/tools
    yarn generate-envfile
  5. Run test cases using devnet.env

    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.

About

Integration tests for Godwoken

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 54.0%
  • Solidity 26.9%
  • JavaScript 8.8%
  • TypeScript 7.3%
  • Shell 3.0%