Skip to content

Commit

Permalink
test(e2e): simplify e2e init & network launch (#3333)
Browse files Browse the repository at this point in the history
  • Loading branch information
air1one authored and faustbrian committed Dec 11, 2019
1 parent 33256db commit 4c1797d
Show file tree
Hide file tree
Showing 99 changed files with 809 additions and 930 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/test.yml
Expand Up @@ -104,26 +104,20 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Docker swarm init
run: docker swarm init
- name: Install and build packages
run: yarn setup && cd __tests__/e2e && ../../node_modules/.bin/tsc && yarn cache clean && yarn install --frozen-lockfile
- name: Generate files
run: node --version && cd __tests__/e2e && yarn generate -c 3 -v ${{ matrix.node-version }}
- name: Make scripts executable
run: sudo chmod +x __tests__/e2e/dist/docker* && sudo chmod +x __tests__/e2e/dist/node0/docker/testnet-e2e/entrypoint.sh && sudo chmod +x __tests__/e2e/dist/node1/docker/testnet-e2e/entrypoint.sh && sudo chmod +x __tests__/e2e/dist/node2/docker/testnet-e2e/entrypoint.sh && sudo chmod +x __tests__/e2e/dist/node0/ark.sh && sudo chmod +x __tests__/e2e/dist/node1/ark.sh && sudo chmod +x __tests__/e2e/dist/node2/ark.sh
- name: Docker init and start
run: cd __tests__/e2e/dist && ./docker-init.sh && ./docker-start.sh
- name: Wait 10 sec for docker containers to be up
run: sleep 10
- name: Docker compose up
run: cd __tests__/e2e/lib/config && docker-compose up -d
- name: Wait 20 sec for docker containers to be up and nodes be running
run: sleep 20
- name: Run tests
run: cd __tests__/e2e && sudo chown -R $USER:$USER ./dist/ && yarn run-tests -s scenario1
run: cd __tests__/e2e && yarn run-tests -s scenario1
- name: Output results - node0
if: always()
run: cat __tests__/e2e/dist/node0/output.log && cat __tests__/e2e/dist/node0/errors.log
run: docker logs config_core0_1
- name: Output results - node1
if: always()
run: cat __tests__/e2e/dist/node1/output.log && cat __tests__/e2e/dist/node1/errors.log
run: docker logs config_core1_1
- name: Output results - node2
if: always()
run: cat __tests__/e2e/dist/node2/output.log && cat __tests__/e2e/dist/node2/errors.log
run: docker logs config_core2_1
37 changes: 23 additions & 14 deletions __tests__/e2e/README.md
Expand Up @@ -12,23 +12,31 @@ This project enables writing and running end-to-end tests on Ark core (v2).

## Install and run

Install the project dependencies :
First you need to have core setup and built :

`yarn install`
`yarn setup`

Now to run the tests locally, you need to have Docker installed. Then, run this command to initialize docker swarm feature :
Then you can go to the e2e folder and install the project dependencies :

`docker swarm init`
`cd __tests__/e2e && yarn install`

Now to run the tests locally, you need to have Docker (and docker-compose) installed.

You can now run the configured tests like this :

```bash
bin/e2e generate -c 3 # 3 nodes, you can generate up to 10
bin/e2e docker # or to see output: cd dist && ./docker-init.sh && ./docker-start.sh && cd ..
cd lib/config && docker-compose up -d && cd ../.. # launches the network
bin/e2e run-tests # by default the main "scenario1" is run, see -s option for custom scenario
cd lib/config && docker-compose down -v && cd ../.. # shuts down the network
```

This will generate the 3 nodes on testnet and run the tests defined in `scenario1`. (it can take some time depending on your machine resources)
This will launch a network of 5 nodes on testnet and run the tests defined in `scenario1`. (it can take some time depending on your machine resources)

You can see the live output of the nodes by using the docker logs command :

```bash
docker logs config_core0_1 -f # for the first node (core0)
```

## Create new tests

Expand Down Expand Up @@ -91,10 +99,11 @@ You can have a look at `doublespend1` folder to have examples of actions and tes

To perform some actions (like creating a new transaction), we want to send requests to one node's API.

The nodes between themselves interact through classic 4000 / 4003 ports. But externally their ports are mapped so in our test we interact with them differently :
The nodes between themselves interact through classic 4000 / 4003 ports. But to access the API externally there is a specific nginx server than will help us. It listens on port 4900 and you can access the nodes API through it this way :

- For API calls we request localhost on port ( 4300 + node number ) to access a specific node (node numbers start from zero, so node0 will be requested on port 4300, node1 on port 4301...)
- For P2P calls we request localhost on port ( 4000 + node number )
```bash
curl 127.0.0.1:4900/core0/api/v2/blocks # use core1 for the 2nd node, etc
```

### Guidelines for writing tests

Expand All @@ -104,13 +113,13 @@ Here are some tips :
- Initialize what you need in your test case, don't re-use something from another test case : create your own wallets (transfer coins from genesis), your own transactions etc.
- Use an `utils.js` file if you need, also have a look at `utils.js` in the `networks` folder and in the `lib` folder

## CircleCI
## Github

The end-to-end tests are configured to run on CircleCI for each commit.
The end-to-end tests are configured to run on Github for each commit.

## Technical details about this project
## More details about the e2e docker architecture

To understand how this end-to-end testing framework works behind the scenes, have a look at [TechnicalDetails.md](TechnicalDetails.md).
You can have a look to the `lib/config` folder to understand how the network is working on docker, and you can for example increase the number of nodes you want to run by tweaking the docker-compose file and related core config folders.

## Suggestions, improvements

Expand Down
113 changes: 0 additions & 113 deletions __tests__/e2e/TechnicalDetails.md

This file was deleted.

14 changes: 0 additions & 14 deletions __tests__/e2e/bin/e2e
Expand Up @@ -4,20 +4,6 @@ const app = require('commander')

app.version(require('../package.json').version)

app
.command('generate')
.description('generate the file structure for e2e testing')
.option('-c, --nodes <number of nodes>', 'number of nodes to generate', 3)
.option('-v, --version <node version>', 'node version to use', "12.x")
.option('-n, --network <network>', 'network to use as a base (testnet / devnet / mainnet)', "testnet")
.option('-r, --relay', 'relay only mode : generate files for relay use', false)
.action((options) => require('../lib/generate')(options))

app
.command('docker')
.description('Run the docker initialization scripts')
.action(() => require('../lib/docker')())

app
.command('run-tests')
.description('Run the tests')
Expand Down
85 changes: 85 additions & 0 deletions __tests__/e2e/lib/config/docker-compose.yml
@@ -0,0 +1,85 @@
version: '2.2'
services:
peerdiscovery:
build: ./peer-discovery
image: peerdiscovery
nginx:
image: nginx:latest
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- 4900:4900

postgres0: &postgresServiceDefinition
image: "postgres:alpine"
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: ark_testnet
POSTGRES_USER: ark
postgres1: *postgresServiceDefinition
postgres2: *postgresServiceDefinition
postgres3: *postgresServiceDefinition
postgres4: *postgresServiceDefinition

core0: &coreServiceDefinition
build: ./nodes
image: core
volumes:
- ./../../../../:/core
depends_on:
- postgres1
- peerdiscovery
command:
- /bin/sh
- -c
- /core/packages/core/bin/run core:run --network=testnet
environment: &coreEnvironment
CORE_DB_HOST: postgres0
CORE_DB_DATABASE: ark_testnet
CORE_DB_USERNAME: ark
CORE_PATH_CONFIG: /core/__tests__/e2e/lib/config/nodes/core0
CORE_PATH_DATA: /core/__tests__/e2e/lib/config/nodes/core0

core1:
<<: *coreServiceDefinition
depends_on:
- postgres1
- peerdiscovery
environment:
<<: *coreEnvironment
CORE_DB_HOST: postgres1
CORE_PATH_CONFIG: /core/__tests__/e2e/lib/config/nodes/core1
CORE_PATH_DATA: /core/__tests__/e2e/lib/config/nodes/core1

core2:
<<: *coreServiceDefinition
depends_on:
- postgres2
- peerdiscovery
environment:
<<: *coreEnvironment
CORE_DB_HOST: postgres2
CORE_PATH_CONFIG: /core/__tests__/e2e/lib/config/nodes/core2
CORE_PATH_DATA: /core/__tests__/e2e/lib/config/nodes/core2

core3:
<<: *coreServiceDefinition
depends_on:
- postgres3
- peerdiscovery
environment:
<<: *coreEnvironment
CORE_DB_HOST: postgres3
CORE_PATH_CONFIG: /core/__tests__/e2e/lib/config/nodes/core3
CORE_PATH_DATA: /core/__tests__/e2e/lib/config/nodes/core3

core4:
<<: *coreServiceDefinition
depends_on:
- postgres4
- peerdiscovery
environment:
<<: *coreEnvironment
CORE_DB_HOST: postgres4
CORE_PATH_CONFIG: /core/__tests__/e2e/lib/config/nodes/core4
CORE_PATH_DATA: /core/__tests__/e2e/lib/config/nodes/core4
17 changes: 0 additions & 17 deletions __tests__/e2e/lib/config/docker/Dockerfile-10.x

This file was deleted.

17 changes: 0 additions & 17 deletions __tests__/e2e/lib/config/docker/Dockerfile-12.x

This file was deleted.

3 changes: 0 additions & 3 deletions __tests__/e2e/lib/config/docker/ark-network-start.sh

This file was deleted.

6 changes: 0 additions & 6 deletions __tests__/e2e/lib/config/docker/ark.sh

This file was deleted.

0 comments on commit 4c1797d

Please sign in to comment.