Skip to content

Commit

Permalink
feat: enabling e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Jan 15, 2024
1 parent 872ba93 commit 3a467c0
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests
README.md
thorest.png
CODE_OF_CONDUCT.md
54 changes: 53 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -57,3 +58,54 @@ current development landscape.

- We follow the [Effective Go](https://golang.org/doc/effective_go) guidelines. Please make sure your code is idiomatic
and follows the guidelines.

### Code Linting

- 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
```
31 changes: 31 additions & 0 deletions .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

on:
push:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
# use the default if on main branch, otherwise use the pull request config
args: --timeout=30m --config=${{ github.event_name == 'pull_request' && '.golangci.pull-request.yml' || '.golangci.yml' }}
only-new-issues: true
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
91 changes: 91 additions & 0 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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
- name: Publish Results
uses: dorny/test-reporter@v1
id: test-reporter
if: success() || failure()
with:
name: E2E Test Results
only-summary: 'false'
list-suites: 'all'
list-tests: 'failed'
fail-on-error: 'true'
reporter: "jest-junit"
path: |
./tests/thor-e2e-tests/junit.xml
- name: Echo Report URL
run: |
echo ${{steps.test-reporter.outputs.url_html}}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests/thor-e2e-tests"]
path = tests/thor-e2e-tests
url = https://github.com/vechain/thor-e2e-tests.git
13 changes: 13 additions & 0 deletions .golangci.pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Please refer to the official golangci-lint config documentation for more details:
# https://golangci-lint.run/usage/configuration/
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml

linters:
enable-all: true

run:
timeout: 10m
tests: false

issues:
max-issues-per-linter: 1000
15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Please refer to the official golangci-lint config documentation for more details:
# https://golangci-lint.run/usage/configuration/
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml

linters:
disable:
- unused
- errcheck

run:
timeout: 10m
tests: false

issues:
max-issues-per-linter: 1000
26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ export GO111MODULE=on

.PHONY: thor disco all clean test

thor:| go_version_check
help:
@egrep -h '\s#@\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?#@ "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}'

thor:| go_version_check #@ Build the `thor` executable
@echo "building $@..."
@go build -v -o $(CURDIR)/bin/$@ -ldflags "-X main.version=$(THOR_VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.gitTag=$(GIT_TAG)" ./cmd/thor
@echo "done. executable created at 'bin/$@'"

disco:| go_version_check
disco:| go_version_check #@ Build the `disco` executable
@echo "building $@..."
@go build -v -o $(CURDIR)/bin/$@ -ldflags "-X main.version=$(DISCO_VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.gitTag=$(GIT_TAG)" ./cmd/disco
@echo "done. executable created at 'bin/$@'"
Expand All @@ -37,16 +40,25 @@ go_version_check:
fi \
fi

all: thor disco
all: thor disco #@ Build the `thor` and `disco` executables

clean:
clean: #@ Clean the build artifacts
-rm -rf \
$(CURDIR)/bin/thor \
$(CURDIR)/bin/disco
$(CURDIR)/bin/disco

test:| go_version_check
test:| go_version_check #@ Run the tests
@go test -cover $(PACKAGES)

test-coverage:| go_version_check
test-coverage:| go_version_check #@ Run the tests with coverage
@go test -race -coverprofile=coverage.out -covermode=atomic $(PACKAGES)
@go tool cover -html=coverage.out

lint_command_check:
@command -v golangci-lint || (echo "golangci-lint not found, please install it from https://golangci-lint.run/usage/install/" && exit 1)

lint: | go_version_check lint_command_check #@ Run 'golangci-lint' on new code changes
@golangci-lint run --new --config .golangci.pull-request.yml

lint-all: | go_version_check lint_command_check #@ Run 'golangci-lint' on the entire codebase
@golangci-lint run --config .golangci.yml
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ git clone https://github.com/vechain/thor.git
cd thor
```

To see a list of all available commands, run `make help`

### Building

To build the main app `thor`, just run
Expand Down Expand Up @@ -209,3 +211,5 @@ A special shout out to following projects:
Vechain Thor is licensed under the
[GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.html), also included
in *LICENSE* file in repository.


4 changes: 1 addition & 3 deletions api/accounts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ func convertCallResultWithInputGas(vo *runtime.Output, inputGas uint64) *CallRes
Data: hexutil.Encode(txEvent.Data),
}
event.Topics = make([]thor.Bytes32, len(txEvent.Topics))
for k, topic := range txEvent.Topics {
event.Topics[k] = topic
}
copy(event.Topics, txEvent.Topics)
events[j] = event
}
for j, txTransfer := range vo.Transfers {
Expand Down
4 changes: 1 addition & 3 deletions api/transactions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ func convertReceipt(txReceipt *tx.Receipt, header *block.Header, tx *tx.Transact
Data: hexutil.Encode(txEvent.Data),
}
event.Topics = make([]thor.Bytes32, len(txEvent.Topics))
for k, topic := range txEvent.Topics {
event.Topics[k] = topic
}
copy(event.Topics, txEvent.Topics)
otp.Events[j] = event

}
Expand Down
8 changes: 4 additions & 4 deletions cmd/thor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"time"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/crypto"
"github.com/inconshreveable/log15"
isatty "github.com/mattn/go-isatty"
"github.com/mattn/go-isatty"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"github.com/vechain/thor/v2/api"
Expand All @@ -30,7 +30,7 @@ import (
"github.com/vechain/thor/v2/state"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/txpool"
cli "gopkg.in/urfave/cli.v1"
"gopkg.in/urfave/cli.v1"

// Force-load the tracer engines to trigger registration
_ "github.com/vechain/thor/v2/tracers/js"
Expand Down Expand Up @@ -355,7 +355,7 @@ func masterKeyAction(ctx *cli.Context) error {
if isatty.IsTerminal(os.Stdin.Fd()) {
fmt.Println("Input JSON keystore (end with ^d):")
}
keyjson, err := ioutil.ReadAll(os.Stdin)
keyjson, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 3a467c0

Please sign in to comment.