forked from trustlines-protocol/end2end
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-e2e.sh
executable file
·145 lines (125 loc) · 3.49 KB
/
run-e2e.sh
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#! /bin/bash
NYC_OUTPUT_DIR=.nyc_output
set -u
function die() {
echo "$1"
exit 1
}
OPTIND=1 # Reset in case getopts has been used previously in the shell.
cwd=$(pwd)
# Initialize our own variables:
use_local_yarn=0
pull=0
coverage=0
only_backend=0
while getopts "lpcb" opt; do
case "$opt" in
l)
use_local_yarn=1
[[ -e src/Trustline.ts ]] || die "run-e2e.sh: local test runs must be started from the clientlib repository"
;;
p)
pull=1
;;
c)
coverage=1
;;
b)
only_backend=1
;;
esac
done
# Makes the bash script to print out every command before it is executed except echo
# this is a replacement for 'set -x'
function preexec() {
[[ ${BASH_COMMAND} != echo* ]] && echo >&2 "+ ${BASH_COMMAND}"
}
set -o functrace # run DEBUG trap in subshells
trap preexec DEBUG
function cleanup() {
cd "${E2E_DIR}" || die "cd failed"
docker-compose down -v
rm -r "${mydir}"
}
E2E_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
cd "${E2E_DIR}" || die "cd failed"
if [[ ${pull} -eq 1 ]]; then
docker-compose pull
fi
mydir=$(mktemp -td end2end.XXXXXX)
trap "cleanup" EXIT
trap "exit 1" SIGINT SIGTERM
# unset environment variables set in .env, otherwise we overwrite .env
unset PGHOST PGUSER POSTGRES_USER PGDATABASE PGPASSWORD POSTGRES_PASSWORD
docker-compose up --no-start
docker-compose up helper
docker cp parity-dev-pw e2e-helper:/shared
docker-compose up -d postgres parity
sleep 5
docker-compose up contracts
# copies the addresses.json file out to get a contract's address in the relay's config.toml
docker cp e2e-helper:/shared/addresses.json .
relay_config=config.toml
address_file=addresses.json
first_network_address=$(sed --regexp-extended 's/\{"networks": \["(0x[0-9,a-f,A-F]+)".*/\1/' $address_file)
cat >${relay_config} <<EOF
[relay]
syncInterval = 300
updateNetworksInterval = 5
enableEtherFaucet = true
enableRelayMetaTransaction = true
enableDeployIdentity = true
[relay.rpc]
host = "node"
port = 8545
ssl = false
[[relay.delegationFees]]
value = 1
currencyNetwork = "${first_network_address}"
EOF
rm -f $address_file
docker cp config.toml e2e-helper:/shared
docker-compose up createtables
docker-compose up init
docker-compose up -d index relay
if [[ ${only_backend} -eq 0 ]]; then
sleep 3
docker-compose logs -t -f parity index relay e2e &
if [[ ${use_local_yarn} -eq 0 ]]; then
docker-compose up -d e2e
docker_wait_output=$(docker wait e2e)
case ${docker_wait_output} in
[0-9]*)
result=${docker_wait_output}
;;
*)
result=1
;;
esac
docker-compose logs -t e2e >"${mydir}/output.txt"
cd "${cwd}" || die "cd failed"
if [[ ${coverage} -eq 1 ]]; then
rm -rf "${NYC_OUTPUT_DIR}"
docker cp e2e:/clientlib/"${NYC_OUTPUT_DIR}"/. "${NYC_OUTPUT_DIR}"
fi
else
cd "${cwd}" || die "cd failed"
# Copies the file addresses.json in the shared volume to the local directory cwd/tests/e2e-config
docker run --rm -v "$PWD"/tests/e2e-config:/dest -v end2end_shared:/source -w /source alpine cp addresses.json /dest
yarn run test:e2e | tee "${mydir}/output.txt"
result="${PIPESTATUS[0]}"
fi
cat "${mydir}/output.txt"
exit "${result}"
else
echo
echo "====================================================="
echo "Initialization is complete."
echo "You've started the script with the -b flag."
echo "You can now run your tests manually."
echo "Hit Ctrl-C when done."
echo "====================================================="
echo
sleep 5
docker-compose logs -t -f parity index relay
fi