Skip to content

Commit e5e664d

Browse files
committed
Add Docker-based test runner
1 parent 13b4098 commit e5e664d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "esplora-tests",
33
"scripts": {
44
"test": "cypress run",
5-
"test:runner": "cypress open"
5+
"test:runner": "cypress open",
6+
"test:docker": "./run-docker.sh"
67
},
78
"dependencies": {
89
"bitcoin-core": "^3.0.0",

tests/run-docker.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# Cleanup on exit
5+
trap 'docker stop esplora-tests-explorer || true; [ -n "$datadir" ] && rm -rf "$datadir" || true' EXIT
6+
7+
# Build the Esplora docker image
8+
(
9+
cd ..
10+
[ -n "$SKIP_BUILD_BASE" ] || docker build -t blockstream/esplora-base:latest -f Dockerfile.deps .
11+
[ -n "$SKIP_BUILD_IMAGE" ] || docker build -t esplora .
12+
)
13+
14+
# Run Esplora/Electrs in regtest mode
15+
datadir=$(mktemp -d /tmp/esplora-tests.XXXXX)
16+
docker run -v $datadir:/data --rm -t --name esplora-tests-explorer \
17+
-v $HOME/workspace/blockstream/esplora/run.sh:/srv/explorer/run.sh \
18+
-e EXPOSE_BITCOIND_RPC=1 \
19+
esplora bash -c "/srv/explorer/run.sh bitcoin-regtest explorer" \
20+
&
21+
sleep 1
22+
23+
cont_ip=$(docker inspect esplora-tests-explorer | jq -r '.[0].NetworkSettings.IPAddress')
24+
export BASE_URL=http://$cont_ip/regtest
25+
26+
# Wait for the HTTP REST API to become available
27+
while ! curl $BASE_URL/api/blocks/tip/height; do
28+
sleep 0.5
29+
done
30+
31+
# Load the default wallet (needed for the Cypress tests)
32+
docker exec esplora-tests-explorer cli -rpcwait loadwallet default
33+
34+
# Grab the bitcoin cookie
35+
bitcoind_cookie=$(docker exec esplora-tests-explorer cat /data/bitcoin/regtest/.cookie)
36+
export BITCOIND_URL=http://$bitcoind_cookie@$cont_ip:18443/
37+
38+
# Build Cypress and run the tests
39+
docker build -t esplora-tests-cypress .
40+
docker run -it --rm \
41+
-v $PWD/cypress/videos:/tests/cypress/videos -v $PWD/cypress/screenshots:/tests/cypress/screenshots \
42+
-e BASE_URL -e BITCOIND_URL \
43+
esplora-tests-cypress
44+
45+
# TODO exit with an error code if the tests fail

0 commit comments

Comments
 (0)