forked from wl-buildingtools/nightfall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nightfall-test
executable file
·121 lines (93 loc) · 3.71 KB
/
nightfall-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
set -e
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
declare isTestFailed=false
launchContainersAndRunIntegrationTest(){
printf "${GREEN}*** Docker Compose Build ***${NC}\n"
docker-compose build --build-arg NPM_TOKEN=${NPM_TOKEN}
printf "${GREEN}*** Launching containerized ganache ***${NC}\n"
docker-compose up -d ganache
printf "${GREEN}*** Deploying all contracts ***${NC}\n"
docker-compose run --rm truffle-offchain migrate --reset --network=default
docker-compose run --rm truffle-zkp migrate --reset --network=default
docker-compose run --rm truffle-nightlite migrate --reset --network=default
printf "${GREEN}*** Launching independent containers ***${NC}\n"
# these container take time to setup
# starting them first to avoid ECONNREFUSED error
# as other containers depends on them
docker-compose up -d mongo-merkle-tree
docker-compose up -d mongo-nightfall
# check to avoid `docker-compose exec` in github actions workflow
if [[ ! $GITHUB_ACTION ]]
then
while ! docker-compose exec mongo-nightfall mongo nightfall --host=localhost -u admin -p admin is-mongo-ready.js; do
sleep 3
done
fi
printf "${GREEN}*** Launching containerized microservices ***${NC}\n"
if [[ -f docker-compose.override.yml ]]
then
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f ./integration-test/docker-compose.test.yml up -d api-gateway
else
docker-compose -f docker-compose.yml -f ./integration-test/docker-compose.test.yml up -d api-gateway
fi
# save all test logs to a file in background
printf "${GREEN}*** Saving the test logs to nightfall_test.log file ***${NC}\n"
docker-compose logs -f &> nightfall_test.log &disown
# delay needed to ensure all container are in running state.
sleep 30
printf "${GREEN}*** Run Integration test ***${NC}\n"
npm run $1 || isTestFailed=true
}
cleanup(){
printf "${GREEN}*** Cleaning up all containers ***${NC}\n"
docker-compose down -v || {
# delay need as waiting time so all container are properly done
# nightfall_default network have no dependency left.
sleep 3
printf "${GREEN}*** Remove nightfall network ***${NC}\n"
docker network rm nightfall_network
printf "${GREEN}*** Remove nightfall's mongo volume ***${NC}\n"
docker volume rm nightfall_mongo-nightfall-volume
printf "${GREEN}*** Remove zkp-code volume ***${NC}\n"
docker volume rm nightfall_zkp-code-volume
printf "${GREEN}*** Remove the merkle tree's mongo volume ***${NC}\n"
docker volume rm nightfall_mongo-merkle-tree-volume
}
printf "${GREEN}*** Delete files created by previous run ***${NC}\n"
rm -dr zkp/build/ || true
rm -dr offchain/build/ || true
rm docker-compose.override.yml || true
}
cleanup
if [[ -z "$NPM_TOKEN" ]]; then
printf "${RED}*** ENV variable NPM_TOKEN is not set ***${NC}\n"
printf "Please set a valid (permission required :repo and :read-packages) github personal access token to the ENV - 'NPM_TOKEN'\n"
exit 1
fi
printf "${GREEN}*** Pull zokrates docker image ***${NC}\n"
docker pull zokrates/zokrates:0.5.1
printf "${GREEN}*** Install node modules dependencies of nightfall ***${NC}\n"
npm ci
printf "${GREEN}*** Installing zkp dependencies ***${NC}\n"
pushd zkp
npm i
popd
if [[ "$1" == "compliance" || "$1" == "mimc" ]]
then
cp docker-compose.override.$1.yml docker-compose.override.yml
launchContainersAndRunIntegrationTest test-$1
else
launchContainersAndRunIntegrationTest test
fi
df -h
printf "${GREEN}*** List all containers with their Ips ***${NC}\n"
docker inspect -f '{{.Name}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker-compose ps -q)
cleanup
if $isTestFailed
then
printf "${RED}*** Integration test failed ***${NC}\n"
exit 1
fi