forked from trezor/connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·154 lines (133 loc) · 4.01 KB
/
run.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
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
# This script runs trezor-connect tests.
# It spins up trezor-user-env and sets required evironment variables.
set -euo pipefail
USER_ENV_IMAGE="registry.gitlab.com/satoshilabs/trezor/trezor-user-env/trezor-user-env"
cleanup() {
if [ -n "${dockerID-}" ]; then
echo "Stopping container with an ID $dockerID"
"$DOCKER_PATH" stop "$dockerID" && echo "trezor-user-env stopped"
fi
}
trap cleanup EXIT
# Running standalone instance of trezor-user-env
# docker run -it -e SDL_VIDEODRIVER="dummy" -p "9001:9001" -p "21326:21326" -p "21325:21326" registry.gitlab.com/satoshilabs/trezor/trezor-user-env/trezor-user-env
# Tweaking trezor-user-env locally
# docker run -it -e SDL_VIDEODRIVER="dummy" -p "9001:9001" -p "21326:21326" -p "21325:21326" registry.gitlab.com/satoshilabs/trezor/trezor-user-env/trezor-user-env nix-shell
# do your changes using `vi` and run:
# [nix-shell:/trezor-user-env]# ./run.sh
# Ports
# 9001 - websocket server, communication test case > user-env (setup etc...)
# 21326 - trezord proxy. beacuse of trezord CORS check
# 21325 - original trezord port redirected to trezor-user-env proxy
runDocker() {
echo "Pulling latest trezor-user-env"
"$DOCKER_PATH" pull "$USER_ENV_IMAGE"
# `--rm` flag will automatically delete container when done
dockerID=$(
"$DOCKER_PATH" run -d --rm \
-e SDL_VIDEODRIVER="dummy" \
-p "9001:9001" \
-p "21326:21326" \
-p "21325:21326" \
"$USER_ENV_IMAGE"
)
"$DOCKER_PATH" logs -f "$dockerID" &
echo "Running docker container with ID $dockerID"
}
waitForEnv() {
echo "Waiting for trezor-user-env to load up..."
counter=0
max_attempts=60
# there is no official support for websockets in curl
# trezor-user-env websocket server will return HTTP/1.1 426 Upgrade Required error with "Upgrade: websocket" header
until (curl -i -s -I http://localhost:9001 | grep 'websocket'); do
if [ ${counter} -eq ${max_attempts} ]; then
echo "trezor-user-env is not running. exiting"
exit 1
fi
counter=$(($counter+1))
printf "."
sleep 1
done
echo "trezor-user-env loaded up"
}
show_usage() {
echo "Usage: run [OPTIONS] [ARGS]"
echo ""
echo "Options:"
echo " -c Disable backend cache. default: enabled"
echo " -d Disable docker. Useful when running own instance of trezor-user-env. default: enabled"
echo " -D PATH Set path to docker executable. Can be replaced with `podman`. default: docker"
echo " -e All methods except excluded, example: applySettings,signTransaction"
echo " -f Use specific firmware version, example: 2.1.4, 1.8.0 default: 2-master"
echo " -i Included methods only, example: applySettings,signTransaction"
echo " -s actual test script. default: 'yarn test:integration'"
}
# default options
FIRMWARE=""
INCLUDED_METHODS=""
EXCLUDED_METHODS=""
DOCKER=true
DOCKER_PATH="docker"
TEST_SCRIPT="yarn test:integration"
USE_TX_CACHE=true
USE_WS_CACHE=true
# user options
OPTIND=1
while getopts ":i:e:f:s:D:hdc" opt; do
case $opt in
d)
DOCKER=false
;;
D)
DOCKER_PATH="$OPTARG"
;;
c)
USE_TX_CACHE=false
USE_WS_CACHE=false
;;
s)
TEST_SCRIPT=$OPTARG
;;
f)
FIRMWARE=$OPTARG
;;
i)
INCLUDED_METHODS=$OPTARG
;;
e)
EXCLUDED_METHODS=$OPTARG
;;
h) # Script usage
show_usage
exit 0
;;
\?)
echo "invalid option $OPTARG"
exit 1
;;
esac
done
shift $((OPTIND - 1))
# export essential process.env variables
export TESTS_FIRMWARE=$FIRMWARE
export TESTS_INCLUDED_METHODS=$INCLUDED_METHODS
export TESTS_EXCLUDED_METHODS=$EXCLUDED_METHODS
export TESTS_USE_TX_CACHE=$USE_TX_CACHE
export TESTS_USE_WS_CACHE=$USE_WS_CACHE
run() {
if [ $DOCKER = true ]; then
runDocker
fi
waitForEnv
echo "Running ${TEST_SCRIPT}"
echo " Firmware: ${FIRMWARE}"
echo " Included methods: ${INCLUDED_METHODS}"
echo " Excluded methods: ${EXCLUDED_METHODS}"
echo " TxCache: ${USE_TX_CACHE}"
echo " WsCache: ${USE_WS_CACHE}"
# run actual test script
${TEST_SCRIPT}
}
run