Skip to content

Commit 546f755

Browse files
committed
feat: add testing in ci
1 parent 27b9d90 commit 546f755

File tree

4 files changed

+142
-27
lines changed

4 files changed

+142
-27
lines changed

.gitlab-ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
stages:
2+
- build
3+
- test
4+
5+
build:
6+
stage: build
7+
image: node:20.18.1
8+
before_script:
9+
- yarn install --frozen-lockfile
10+
script:
11+
- yarn build
12+
13+
e2e_test:
14+
stage: test
15+
image: node:20.18.1
16+
variables:
17+
POSTGRES_DB: db
18+
POSTGRES_USER: user
19+
POSTGRES_PASSWORD: pass
20+
PGPASSWORD: ${POSTGRES_PASSWORD}
21+
services:
22+
- name: postgres:17
23+
alias: postgres
24+
before_script:
25+
- yarn install --frozen-lockfile
26+
- apt update && apt install -y postgresql-common
27+
- YES=1 /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
28+
- apt -y install postgresql-client-17
29+
- curl -o test/e2e_tests/db/db_btc_testnet https://githubstatic.flare.center/db_btc_testnet
30+
- curl -o test/e2e_tests/db/db_doge_testnet https://githubstatic.flare.center/db_doge_testnet
31+
- curl -o test/e2e_tests/db/db_xrp_testnet https://githubstatic.flare.center/db_xrp_testnet
32+
script:
33+
- yarn test ci
34+
35+
lint:
36+
stage: test
37+
image: node:20.18.1
38+
before_script:
39+
- yarn install --frozen-lockfile
40+
script:
41+
- yarn lint:check
42+
- yarn format:check

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"format:fix": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
2323
"-----Testing-----": "echo \"Testing scripts\"",
2424
"makeE2Eexecutable": "chmod +x test/e2e_tests/run_tests.sh",
25-
"test:btc": "./test/e2e_tests/run_tests.sh all btc",
25+
"test": "./test/e2e_tests/run_tests.sh ",
2626
"test:make_db:btc": "./test/e2e_tests/run_tests.sh make_db btc",
2727
"test:run_tests:btc": "./test/e2e_tests/run_tests.sh run_tests btc",
2828
"test:doge": "./test/e2e_tests/run_tests.sh all doge",

test/e2e_tests/db/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ services:
77
POSTGRES_USER: user
88
POSTGRES_PASSWORD: pass
99
ports:
10-
- "127.0.0.1:8080:5432"
10+
- "127.0.0.1:8081:5432"

test/e2e_tests/run_tests.sh

Lines changed: 98 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ export DB_DATABASE=db
44
export DB_USERNAME=user
55
export DB_PASSWORD=pass
66
export DB_HOST=127.0.0.1
7-
export DB_PORT=8080
7+
export DB_PORT=8081
88

9-
export VERIFIER_TYPE=$2
109
export TESTNET=true
1110

1211
export NUMBER_OF_CONFIRMATIONS=6
@@ -19,45 +18,119 @@ export API_KEYS=12345
1918

2019

2120
wait_for_pg_ready() {
22-
until docker compose -f test/e2e_tests/db/docker-compose.yaml exec postgres_testing_db pg_isready -h 127.0.0.1 -p 5432 -U db 1> /dev/null; do
21+
until $DOCKER_CMD pg_isready -h $DB_HOST -p 5432 -U db 1> /dev/null; do
2322
sleep 1
2423
done
2524
}
2625

26+
_make_db(){
27+
$DOCKER_CMD dropdb -h $DB_HOST -U user db
28+
wait_for_pg_ready
29+
$DOCKER_CMD createdb -h $DB_HOST -U user -E utf8 -T template0 db
30+
wait_for_pg_ready
31+
$DOCKER_CMD pg_restore -h $DB_HOST --no-owner --role=user -U user --dbname=db /tmp/dbdump
32+
wait_for_pg_ready
33+
}
34+
35+
make_db(){
36+
export VERIFIER_TYPE=$1
37+
DOCKER_CMD="docker compose -f test/e2e_tests/db/docker-compose.yaml exec postgres_testing_db"
2738

28-
if [ "$1" = "all" ] || [ "$1" = "make_db" ]; then
2939
echo ""
30-
echo Making mock DB
40+
echo Making mock DB for $VERIFIER_TYPE
41+
3142
docker compose -f test/e2e_tests/db/docker-compose.yaml up -d
3243
wait_for_pg_ready
44+
docker compose -f test/e2e_tests/db/docker-compose.yaml cp test/e2e_tests/db/db_${VERIFIER_TYPE}_testnet postgres_testing_db:/tmp/dbdump
45+
echo "Copying dump to DB"
46+
wait_for_pg_ready
47+
48+
_make_db
49+
}
3350

34-
commands=(
35-
"docker compose -f test/e2e_tests/db/docker-compose.yaml cp test/e2e_tests/db/db_$2_testnet postgres_testing_db:/tmp/dbdump"
36-
"docker compose -f test/e2e_tests/db/docker-compose.yaml exec postgres_testing_db dropdb -U user db"
37-
"docker compose -f test/e2e_tests/db/docker-compose.yaml exec postgres_testing_db createdb -U user -E utf8 -T template0 db"
38-
"docker compose -f test/e2e_tests/db/docker-compose.yaml exec postgres_testing_db pg_restore --no-owner --role=user -U user --dbname=db /tmp/dbdump"
39-
)
40-
51+
make_db_ci(){
52+
export VERIFIER_TYPE=$1
53+
export DB_HOST=postgres
54+
export DB_PORT=5432
55+
DOCKER_CMD=""
56+
4157
echo ""
42-
echo Copying db_$2_testnet to DB
43-
for command in "${commands[@]}"; do
44-
eval "$command"
45-
wait_for_pg_ready
46-
done
47-
fi
58+
echo Copying dumb to DB
4859

60+
cp test/e2e_tests/db/db_${VERIFIER_TYPE}_testnet /tmp/dbdump
61+
62+
_make_db
63+
}
4964

50-
if [ "$1" = "all" ] || [ "$1" = "run_tests" ]; then
65+
run_tests(){
66+
export VERIFIER_TYPE=$1
5167
echo ""
52-
echo Runing $2 tests
53-
mocha -r ts-node/register --require source-map-support/register "test/e2e_tests/$2/**/*.e2e-spec.ts"
54-
fi
55-
68+
echo Runing $VERIFIER_TYPE tests
69+
mocha -r ts-node/register --require source-map-support/register "test/e2e_tests/${VERIFIER_TYPE}/**/*.e2e-spec.ts"
70+
}
5671

57-
if [ "$1" = "all" ] || [ "$1" = "delete_db" ]; then
72+
delete_db(){
5873
echo ""
5974
echo Stoping and removing DB
6075
docker compose -f test/e2e_tests/db/docker-compose.yaml down
61-
fi
76+
}
77+
78+
show_help() {
79+
echo "
80+
Usage: yarn test COMMAND ARGUMENT
81+
82+
Commands:
83+
run Run e2e tests (create db, run tests, delete db) (needs verifier type as argument, e.g. yarn test run btc)
84+
make_db Create mock DB (needs verifier type as argument, e.g. yarn test make_db btc)
85+
run_tests Run e2e tests (existing db needed) (needs verifier type as argument, e.g. yarn test run_tests btc)
86+
delete_db Delete mock DB
87+
ci Run tests in gitlab ci
88+
89+
Arguments:
90+
btc Bitcoin verifier
91+
doge Dogecoin verifier
92+
xrp Ripple verifier
93+
"
94+
}
95+
96+
main() {
97+
if [ $# -eq 0 ]; then
98+
show_help
99+
exit 1
100+
fi
101+
102+
CMD="$1"
103+
shift
104+
case "$CMD" in
105+
run)
106+
# TODO:(andraz) add validtion (only one argument)
107+
make_db "$@"
108+
run_tests "$@"
109+
delete_db
110+
;;
111+
make_db)
112+
make_db "$@"
113+
;;
114+
run_tests)
115+
run_tests "$@"
116+
;;
117+
delete_db)
118+
delete_db
119+
;;
120+
ci)
121+
# TODO:(andraz) can be improved that it doesn't crash at first error but runs all tests
122+
make_db_ci btc &&
123+
run_tests btc &&
124+
make_db_ci doge &&
125+
run_tests doge &&
126+
make_db_ci xrp &&
127+
run_tests xrp
128+
;;
129+
*)
130+
show_help
131+
;;
132+
esac
133+
}
62134

135+
main "$@"
63136

0 commit comments

Comments
 (0)