diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..85376b5eb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +tests +README.md +thorest.png +CODE_OF_CONDUCT.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 653615891..32efeebf9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -34,7 +34,8 @@ current development landscape. ```bash make test ``` - - **Note:**: Please refer to the [README](https://github.com/vechain/thor/blob/master/README.md) for information on how to start the node and interact with the + - **Note:**: Please refer to the [README](https://github.com/vechain/thor/blob/master/README.md) for information on + how to start the node and interact with the API. 5. Make your changes and commit them with a clear and concise commit message. 6. Push your changes to your forked repository: @@ -62,3 +63,49 @@ current development landscape. - We employ `golangci-lint` for code linting in our development process. It ensures that code adheres to established standards, and any changes that do not pass the linting checks will trigger an error during the Continuous Integration (CI) process. - You can run it locally by installing the `golangci-lint` binary and running `make lint` in the root directory of the repository. + +## Testing + +### Unit Tests + +```bash +make test +``` + +### Unit Tests with Coverage + +```bash +make test-coverage +``` + +### E2E Tests + +Our E2E tests are written in TypeScript, utilizing hardhat contract solidity development tools. Before running the E2E +tests, ensure you have the following prerequisites installed: + +- [Docker](https://docs.docker.com/get-docker/) +- [Node.js](https://nodejs.org/en/download/) +- [Yarn](https://classic.yarnpkg.com/en/docs/install/) +- [Git](https://git-scm.com/downloads) + +The E2E tests are located in the tests/thor-e2e-tests directory as a submodule. If you haven't initialized the submodule +yet, run: + +```bash +git submodule update --init --recursive +``` + +To run the E2E tests, build the Docker image first: + +```bash +docker build -t vechain/thor-e2e . +export THOR_IMAGE=vechain/thor-e2e +``` + +Then, you can run the tests: + +```bash +cd tests/thor-e2e-tests +yarn install +yarn test +``` diff --git a/.github/workflows/test-docker-build.yaml b/.github/workflows/test-docker-build.yaml index b80be30d5..87d09678f 100644 --- a/.github/workflows/test-docker-build.yaml +++ b/.github/workflows/test-docker-build.yaml @@ -22,7 +22,7 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Build and push + - name: Test Build uses: docker/build-push-action@v4 with: context: . diff --git a/.github/workflows/test-e2e-results.yaml b/.github/workflows/test-e2e-results.yaml new file mode 100644 index 000000000..a7166cfea --- /dev/null +++ b/.github/workflows/test-e2e-results.yaml @@ -0,0 +1,28 @@ +name: 'E2E Test Report' + +on: + workflow_run: + workflows: ['E2E Tests'] + types: + - completed + +permissions: + contents: read + actions: read + checks: write + +jobs: + report: + runs-on: ubuntu-latest + steps: + - uses: dorny/test-reporter@v1 + id: test-reporter + with: + artifact: test-results + name: E2E Test Report + path: '*.xml' + reporter: jest-junit + + - name: Echo Report URL + run: | + echo ${{steps.test-reporter.outputs.url_html}} diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml new file mode 100644 index 000000000..f1c8fd956 --- /dev/null +++ b/.github/workflows/test-e2e.yaml @@ -0,0 +1,79 @@ +name: E2E Tests + +on: + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + build-docker-image: + name: Build Docker image + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and export + uses: docker/build-push-action@v5 + with: + context: . + tags: vechain/thor:${{ github.sha }} + outputs: type=docker,dest=/tmp/vechain-thor.tar + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: vechain-thor-image + path: /tmp/vechain-thor.tar + retention-days: 7 + + run-tests: + runs-on: ubuntu-latest + needs: build-docker-image + env: + THOR_IMAGE: vechain/thor:${{ github.sha }} + name: Run E2E Tests + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: vechain-thor-image + path: /tmp + + - name: Setup Node JS + uses: actions/setup-node@v4 + with: + node-version: '18.x' + + - name: Load image + run: | + docker load --input /tmp/vechain-thor.tar + docker image ls -a + + - name: Run Tests + working-directory: ./tests/thor-e2e-tests + run: | + export THOR_IMAGE=vechain/thor:${{ github.sha }} + yarn install + yarn test + + - uses: actions/upload-artifact@v3 + if: success() || failure() + with: + name: e2e-test-results + path: ./tests/thor-e2e-tests/junit.xml diff --git a/.gitmodules b/.gitmodules index e69de29bb..3441a15eb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tests/thor-e2e-tests"] + path = tests/thor-e2e-tests + url = https://github.com/vechain/thor-e2e-tests.git diff --git a/tests/thor-e2e-tests b/tests/thor-e2e-tests new file mode 160000 index 000000000..c33c98529 --- /dev/null +++ b/tests/thor-e2e-tests @@ -0,0 +1 @@ +Subproject commit c33c985298bb70406cdacbd51fce80e6dd50c3d7