Skip to content

Commit 9a85b1b

Browse files
committed
add travis ci with regtest tests
1 parent 5fbce51 commit 9a85b1b

29 files changed

+954
-939
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
- docker
3+
sudo: false
4+
script:
5+
- sh -c 'cd ./regtest && ./test.sh'

npm-shrinkwrap.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "slpdb",
3+
"private": true,
34
"version": "1.0.0",
45
"description": "Indexer for the Simple Ledger Protocol with real-time validation notifications.",
56
"main": "index.js",

regtest/.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ node_modules
33
.idea
44
.DS_STORE
55
log
6+
7+
regtest
8+
test

regtest/Dockerfile.nodejs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Start from a Debian image with the latest version of Go installed
2+
# and a workspace (GOPATH) configured at /go.
3+
FROM node:14.16.0-slim
4+
5+
RUN apt-get update && apt-get install -y build-essential
6+
7+
# Copy the local package files to the container's workspace.
8+
ADD . /usr/src/SLPDB
9+
10+
# Switch to the correct working directory.
11+
WORKDIR /usr/src/SLPDB/regtest
12+
13+
# Create the data volume.
14+
VOLUME ["/data"]

regtest/README.md

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
1-
## Regtest Network for End-to-End testing
1+
# Regtest tests
22

3-
To get started with unit tests you need to startup the sandboxed bitcoin regtest network described in `docker-compose.yml`. This will creates a network of bitcoin nodes which will connect to a locally running SLPDB instance outside of the docker container.
3+
Tests are provided for SLPDB using a docker compose network that has two bitcoin node containers, one mongo db container, and one SLPDB container. Tests are run using mocha and cover the expected data written to MongoDB for various scenarios that would be expected in a live network. Continuous integration tests have been setup using Travis CI (see `../.travis.yml`).
44

5-
Start the regtest network and SLPDB:
6-
```
7-
$ git apply ./patches/*
8-
$ cp .env.regtest .env
9-
$ cd regtest
10-
$ docker-compose up -d
11-
$ npm start
5+
## Run the tests
126

13-
```
14-
15-
Next, in a new terminal run the e2e tests using:
16-
17-
```
18-
$ npm test
19-
```
20-
21-
22-
23-
### Optional: Setting up mongoDB replica set for testing
24-
1. Uncomment mongo entrypoint/volume lines in `docker-compose.yml`
25-
2. Delete `regtest/mongo/db` and `regtest/mongo/configdb` directories
26-
3. Run `docker-compose up -d`
27-
4. Run `docker exec -it regtest_mongo_1 mongo`
28-
5. Run `rs.initiate()`
29-
6. Run `rs.status()` to make sure `ok: 1`
30-
7. Run `cfg = rs.config()`
31-
8. Run `cfg.members[0].host = "localhost:27017"`
32-
9. Run `cfg.reconfig(cfg, {force:true})`
7+
`$ cd ./regtest && ./test.sh`

regtest/_test.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
git apply ./patches/*
4+
5+
export RPC1_HOST="bitcoin1"
6+
export RPC1_PORT="18443"
7+
export RPC2_HOST="bitcoin2"
8+
export RPC2_PORT="18443"
9+
export MONGO_HOST="mongo"
10+
export MONGO_PORT="27017"
11+
12+
npm test

regtest/bitcoin-abc/Dockerfile regtest/bitcoind/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ RUN set -ex \
77
&& apt-get install -qq --no-install-recommends ca-certificates dirmngr gosu gpg wget \
88
&& rm -rf /var/lib/apt/lists/*
99

10-
ENV BITCOIN_VERSION 0.21.2
11-
ENV BITCOIN_URL https://github.com/bitcoin-cash-node/bitcoin-cash-node/releases/download/v0.21.2/bitcoin-cash-node-0.21.2-x86_64-linux-gnu.tar.gz
12-
ENV BITCOIN_SHA256 f22df3e37beff99651dd2a0902d9627642464502a6d017f5b4494a44a6159177
10+
ENV BITCOIN_VERSION 23.0.0
11+
ENV BITCOIN_URL https://github.com/bitcoin-cash-node/bitcoin-cash-node/releases/download/v23.0.0/bitcoin-cash-node-23.0.0-x86_64-linux-gnu.tar.gz
12+
ENV BITCOIN_SHA256 474d53ba3dc10cee20da4c1e8d77e31a6b3c54c805f72eab7d705c9211c879bd
1313

1414
# install bitcoin binaries
1515
RUN set -ex \
File renamed without changes.
File renamed without changes.

regtest/docker-compose.yml

+30-37
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
11
version: "3.5"
22
services:
3-
bitcoin1: # the node not connected to SLPDB
4-
image: "bitcoin-abc"
3+
bitcoin1: # the node connected to SLPDB via RPC and zmq
4+
image: "bchn"
55
restart: always
66
build:
7-
context: "./bitcoin-abc"
7+
context: "./bitcoind"
88
command: "bitcoind"
99
healthcheck:
1010
test: ["CMD", "/entrypoint.sh", "bitcoin-cli", "getblockchaininfo"]
1111
expose:
1212
- "18333"
1313
ports:
14-
- "18444:18443"
14+
- "18443:18443"
15+
- "28332:28332"
1516
volumes:
16-
- ./bitcoin-abc/bitcoin.conf:/data/bitcoin.conf
17-
networks:
18-
- regnet
19-
bitcoin2: # the node connected to SLPDB via RPC and zmq
20-
image: "bitcoin-abc"
17+
- ./bitcoind/bitcoin.conf:/data/bitcoin.conf
18+
bitcoin2: # the node not connected to SLPDB
19+
image: "bchn"
2120
restart: always
2221
build:
23-
context: "./bitcoin-abc"
22+
context: "./bitcoind"
2423
command: "bitcoind"
2524
healthcheck:
2625
test: ["CMD", "/entrypoint.sh", "bitcoin-cli", "getblockchaininfo"]
2726
expose:
2827
- "18333"
29-
- "28332"
3028
ports:
31-
- "18443:18443"
32-
- "29332:28332"
29+
- "18444:18443"
3330
volumes:
34-
- ./bitcoin-abc/bitcoin.conf:/data/bitcoin.conf
35-
networks:
36-
- regnet
31+
- ./bitcoind/bitcoin.conf:/data/bitcoin.conf
32+
depends_on:
33+
- bitcoin1
3734
mongo:
38-
image: mongo:4.2
35+
image: mongo:4.4
3936
restart: always
40-
networks:
41-
- regnet
4237
# entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "devrs" ]
4338
healthcheck:
4439
test: echo 'db.runCommand("ping").ok' | mongo --quiet 1
@@ -48,21 +43,19 @@ services:
4843
start_period: 40s
4944
ports:
5045
- "26017:27017"
51-
# volumes:
52-
# - ./mongo/db:/data/db
53-
# - ./mongo/configdb:/data/configdb
54-
# slpdb:
55-
# build:
56-
# context: "./slpdb"
57-
# image: slpdb
58-
# restart: always
59-
# networks:
60-
# - regnet
61-
# depends_on:
62-
# - mongo
63-
# - bitcoin2
64-
# ports:
65-
# - "27339:28339"
66-
67-
networks:
68-
regnet:
46+
depends_on:
47+
- bitcoin1
48+
- bitcoin2
49+
slpdb:
50+
build:
51+
context: ".."
52+
dockerfile: "./regtest/slpdb/Dockerfile"
53+
image: slpdb
54+
restart: always
55+
depends_on:
56+
- mongo
57+
ports:
58+
- "27339:27339"
59+
volumes:
60+
- .:/usr/src/SLPDB/regtest
61+
- ..:/usr/src/SLPDB/test
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
rpc_protocol='http'
22
rpc_user='bitcoin'
33
rpc_pass='password'
4-
rpc_host='localhost'
4+
rpc_host='bitcoin1'
55
rpc_port='18443'
66
rpc_limit='150'
77
db_name='slpdb'
8-
db_url='mongodb://localhost:26017'
8+
db_url='mongodb://mongo:26017'
99
core_from='543375'
1010
core_from_testnet='0'
1111
core_slp_mempool_ignore_length='1000000'
12-
zmq_incoming_host='0.0.0.0'
13-
zmq_incoming_port='29332'
12+
zmq_incoming_host='bitcoin1'
13+
zmq_incoming_port='28332'
1414
zmq_outgoing_host='0.0.0.0'
1515
zmq_outgoing_port='27339'
1616
zmq_outgoing_enable=1
1717
telemetry_host='status.slpdb.io'
1818
telemetry_advertised_host="James' MBP"
1919
telemetry_advertised_graph_search_host=''
2020
telemetry_advertised_slp_socket_host=''
21-
telemetry_secret='7da8a6ac0a1f03f24ae852d6769ac27e9c411ff3ba7d8ec1feae81f81924e0ac'
21+
telemetry_secret='7da8a6ac0a1f03f24ae852d6769ac27e9c411ff3ba7d8ec1feae81f81924e0ac'

regtest/slpdb/Dockerfile

+6-9
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ RUN apk update && apk upgrade && \
55

66
RUN apk add --no-cache --virtual build-dependencies python --update py-pip \
77
build-base python-dev make automake autoconf libtool \
8-
&& pip install --upgrade pip \
9-
&& rm -rf /var/cache/apk/*
8+
&& pip install --upgrade pip
109

1110
RUN mkdir -p /usr/src/SLPDB
1211

1312
WORKDIR /usr/src
1413

15-
RUN git clone https://github.com/simpleledger/SLPDB.git && cd SLPDB
14+
ADD . /usr/src/SLPDB
1615
WORKDIR /usr/src/SLPDB
17-
RUN npm install
18-
RUN git fetch --all && git checkout c2f6763ab9c1a80d68b1c8bd37fee0180e143758
19-
RUN npm install
16+
RUN npm i
2017

21-
COPY regtest.env .env
22-
COPY filters.regtest.yml filters.yml
23-
COPY ./docker-entrypoint.sh ./entrypoint.sh
18+
COPY ./regtest/slpdb/.env.regtest .env
19+
COPY ./regtest/slpdb/filters.regtest.yml filters.yml
20+
COPY ./regtest/slpdb/docker-entrypoint.sh ./entrypoint.sh
2421

2522
ENTRYPOINT [ "./entrypoint.sh" ]
2623
CMD [ "run" ]

regtest/slpdb/regtest.env

-19
This file was deleted.

regtest/test.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
echo "INFO: Cleaning up from previous runs..."
4+
docker-compose down
5+
6+
echo "INFO: Creating regtest network from source"
7+
docker-compose up -d
8+
9+
echo "INFO: Running mocha tests in docker"
10+
docker-compose exec slpdb ./regtest/_test.sh
11+
exit_code=$?
12+
13+
if [ $exit_code -eq 0 ]; then
14+
echo "INFO: All regtest network tests pass (code: $exit_code)"
15+
else
16+
echo "ERROR: One or more regtest network tests failed (code: $exit_code)"
17+
fi
18+
19+
echo "INFO: Cleaning up."
20+
docker-compose down
21+
22+
exit $exit_code

0 commit comments

Comments
 (0)