Skip to content

Commit

Permalink
fix: update e2e test path
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Jan 12, 2024
1 parent 088f784 commit ed469ca
Show file tree
Hide file tree
Showing 36 changed files with 12,909 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
docker image ls -a
- name: Run Tests
working-directory: ./thor-e2e-tests
working-directory: ./tests/thor-e2e-tests
run: |
export THOR_IMAGE=vechain/thor:${{ github.sha }}
yarn install
Expand All @@ -84,7 +84,7 @@ jobs:
fail-on-error: 'true'
reporter: 'mocha-json'
path: |
./thor-e2e-results/results.json
./tests/thor-e2e-results/results.json
# TODO: Add PR Comment
- name: Add PR Comment
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "thor-e2e-tests"]
path = thor-e2e-tests
path = tests/thor-e2e-tests
url = [email protected]:vechain/thor-e2e-tests.git
47 changes: 47 additions & 0 deletions tests/thor-e2e-tests/.github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Integration Tests

on: [push, pull_request]

permissions:
checks: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
integration_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Run Tests
run: |
yarn install
yarn test:report
- name: Publish Results
uses: dorny/test-reporter@v1
id: test-reporter
if: success() || failure() # run this step even if previous step failed
with:
name: Integration Tests
only-summary: "false"
list-suites: "all"
list-tests: "all"
fail-on-error: "true"
reporter: "mocha-json"
path: |
results.json
# TODO: Add PR Comment
- name: Add PR Comment
run: |
echo ${{steps.test-reporter.outputs.url_html}}
21 changes: 21 additions & 0 deletions tests/thor-e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
node_modules
.env

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

results.json

.vscode
.idea
.DS_Store

7 changes: 7 additions & 0 deletions tests/thor-e2e-tests/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": "hardhat/register",
"timeout": 40000,
"slow": 25000,
"parallel": true,
"_": ["test/**/*.ts"]
}
56 changes: 56 additions & 0 deletions tests/thor-e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# VechainThor E2E Tests

## Prerequisites

- [Docker](https://docs.docker.com/install/)
- [Yarn](https://yarnpkg.com/en/docs/install)
- [Node.js](https://nodejs.org/en/download/)

## Running the tests

```shell
yarn install
yarn test
```

## Debugging the tests

- These steps are useful if you want to debug

```bash
yarn docker:up
yarn test:fast
```

## Scripts

---

### Generate Open API Specification

- These scripts will output the Open API Spec to `./src/open-api-types.ts`


#### **Option 1** - By local file:

```bash
yarn generate:openapi ./thor.yaml
```

#### **Option 2** - By URL:

```bash
yarn generate:openapi https://darrenvechain.github.io/thor-docs/thor.yaml
```

---

### Generate test accounts

- This command will add 5 new accounts to the genesis with balances, and add the details to `./src/wallet.ts` so you can
easily access their addresses and private keys.

```bash
yarn generate:accounts
```

26 changes: 26 additions & 0 deletions tests/thor-e2e-tests/contracts/VIP180.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

interface VIP180 {
function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint8);

function totalSupply() external view returns (uint256);

function balanceOf(address _owner) external view returns (uint256);

function transfer(address _to, uint256 _value) external;

function transferFrom(address _from, address _to, uint256 _value) external;

function approve(address _spender, uint256 _value) external;

function allowance(address _owner, address _spender) external view returns (uint256);

event Transfer(address indexed _from, address indexed _to, uint256 _value);

event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
30 changes: 30 additions & 0 deletions tests/thor-e2e-tests/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

import "@nomiclabs/hardhat-truffle5";
import "@vechain/hardhat-vechain";
import "@vechain/hardhat-ethers";

// use mocha config from .mocharc.json so we have common config between hardhat and mocha
const mochaConfig = require("./.mocharc.json");
delete mochaConfig.require;

const config: HardhatUserConfig = {
defaultNetwork: "vechain",
solidity: "0.8.19",
mocha: mochaConfig,
networks: {
hardhat: {},
vechain: {
url: "http://127.0.0.1:8669",
accounts: {
mnemonic:
"denial kitchen pet squirrel other broom bar gas better priority spoil cross",
count: 100,
},
gas: 10000000,
},
},
};

export default config;
72 changes: 72 additions & 0 deletions tests/thor-e2e-tests/network/config/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"launchTime": 1703180212,
"gasLimit": 10000000,
"extraData": "My custom VeChain",
"accounts": [
{
"address": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed",
"balance": "0x14ADF4B7320334B9000000",
"energy": 0,
"code": "0x6060604052600256",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000000000000000000000000000002"
}
},
{
"address": "0x435933c8064b4ae76be665428e0307ef2ccfbd68",
"balance": "0x14ADF4B7320334B9000000",
"energy": "0x14ADF4B7320334B9000000"
},
{
"address": "0x0f872421dc479f3c11edd89512731814d0598db5",
"balance": "0x14ADF4B7320334B9000000",
"energy": "0x14ADF4B7320334B9000000"
},
{
"address": "0xf370940abdbd2583bc80bfc19d19bc216c88ccf0",
"balance": "0x14ADF4B7320334B9000000",
"energy": "0x14ADF4B7320334B9000000"
},
{
"address": "0x99602e4bbc0503b8ff4432bb1857f916c3653b85",
"balance": "0x14ADF4B7320334B9000000",
"energy": "0x14ADF4B7320334B9000000"
},
{
"address": "0x61e7d0c2b25706be3485980f39a3a994a8207acf",
"balance": "0x14ADF4B7320334B9000000",
"energy": "0x14ADF4B7320334B9000000"
}
],
"authority": [
{
"masterAddress": "0x435933c8064b4ae76be665428e0307ef2ccfbd68",
"endorsorAddress": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed",
"identity": "0x000000000000000068747470733a2f2f636f6e6e65782e76656368612e696e2f"
},
{
"masterAddress": "0xf370940abdbd2583bc80bfc19d19bc216c88ccf0",
"endorsorAddress": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed",
"identity": "0x000000000000000068747470733a2f2f656e762e7665636861696e2e6f72672f"
},
{
"masterAddress": "0x0f872421dc479f3c11edd89512731814d0598db5",
"endorsorAddress": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed",
"identity": "0x0000000000000068747470733a2f2f617070732e7665636861696e2e6f72672f"
}
],
"params": {
"rewardRatio": 300000000000000000,
"baseGasPrice": 1000000000000000,
"proposerEndorsement": "0x14ADF4B7320334B9000000",
"executorAddress": "0x0000000000000000000000004578656375746f72"
},
"executor": {
"approvers": [
{
"address": "0x199b836d8a57365baccd4f371c1fabb7be77d389",
"identity": "0x00000000000067656e6572616c20707572706f736520626c6f636b636861696e"
}
]
}
}
22 changes: 22 additions & 0 deletions tests/thor-e2e-tests/network/config/health_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

# Set the URL
url="http://localhost:8669/blocks/best"

# Make the HTTP request and store the response in a variable
response=$(wget -qO- $url)

echo $response

# Extract the value of "number" from the JSON response using grep
number=$(echo $response | grep -o '"number":[^,}]*' | awk -F: '{print $2}' | tr -d '[:space:]')

# Check if the number is greater than 0
if [ $number -gt 0 ]; then
echo "Health check passed! Number is greater than 0."
exit 0
else
echo "Health check failed! Unexpected response or number is not greater than 0:"
echo $response
exit 1
fi
14 changes: 14 additions & 0 deletions tests/thor-e2e-tests/network/config/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

if [ -z "$MASTER_KEY" ]; then
echo "MASTER_KEY is not set"
exit 1
fi

echo "$MASTER_KEY" > /tmp/master.key

BOOTNODE_IP=$(ping -c 1 thor-disco | awk -F'[()]' '/PING/{print $2}')
echo $BOOTNODE_IP
thor --config-dir=/tmp --network /node/config/genesis.json --api-addr="0.0.0.0:8669" --api-cors="*" --bootnode "enode://e32e5960781ce0b43d8c2952eeea4b95e286b1bb5f8c1f0c9f09983ba7141d2fdd7dfbec798aefb30dcd8c3b9b7cda8e9a94396a0192bfa54ab285c2cec515ab@$BOOTNODE_IP:55555"
15 changes: 15 additions & 0 deletions tests/thor-e2e-tests/network/docker-compose-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.8"

services:
base-authority-node:
image: ${THOR_IMAGE:-vechain/thor:latest}
entrypoint: "/node/config/start.sh"
volumes:
- type: bind
source: ./config
target: /node/config
healthcheck:
test: ["CMD", "/node/config/health_check.sh"]
interval: 1s
timeout: 5s
retries: 120
37 changes: 37 additions & 0 deletions tests/thor-e2e-tests/network/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.8"

services:
thor-disco:
image: ${THOR_IMAGE:-vechain/thor:latest}
container_name: thor-disco
entrypoint: "disco --keyhex=99f0500549792796c14fed62011a51081dc5b5e68fe8bd8a13b86be829c4fd36"

authority-node-1:
extends:
file: docker-compose-base.yaml
service: base-authority-node
container_name: authority-node-1
environment:
MASTER_KEY: "7b067f53d350f1cf20ec13df416b7b73e88a1dc7331bc904b92108b1e76a08b1"
ports:
- "8669:8669"

authority-node-2:
extends:
file: docker-compose-base.yaml
service: base-authority-node
container_name: authority-node-2
environment:
MASTER_KEY: "35b5cc144faca7d7f220fca7ad3420090861d5231d80eb23e1013426847371c4"
ports:
- "8679:8669"

authority-node-3:
extends:
file: docker-compose-base.yaml
service: base-authority-node
container_name: authority-node-3
environment:
MASTER_KEY: "f4a1a17039216f535d42ec23732c79943ffb45a089fbb78a14daad0dae93e991"
ports:
- "8689:8669"
Loading

0 comments on commit ed469ca

Please sign in to comment.