forked from aptos-labs/ledger-app-aptos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_wrapper.sh
executable file
·105 lines (92 loc) · 3.47 KB
/
make_wrapper.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
#!/bin/bash
validate_model_arg() {
if [[ "$1" != "nanos" && "$1" != "nanosp" && "$1" != "nanox" ]]; then
echo -e "Unexpected model name passed \nPassed model name: $1\nExpected model names: nanos, nanosp, nanox"
exit 0
fi
}
handle_build_app() {
validate_model_arg "$1"
sudo docker run -d --rm -ti -v "$(realpath .):/app" --user "$(id -u $USER)":"$(id -g $USER)" \
ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest \
/bin/bash -c "BOLOS_SDK=\$$(echo "$1" | tr '[:lower:]' '[:upper:]')_SDK make build"
}
handle_start_emulator() {
validate_model_arg "$1"
speculos "$(pwd)"/bin/app.elf --model "$1" --display headless --seed "shoot"
}
handle_load_app() {
validate_model_arg "$1"
if [[ "$1" == "nanox" ]]; then
echo "App loading and removal is not supported in nanox"
exit 1
fi
# We need to add the appropriate udev rules
wget -q -O - https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/add_udev_rules.sh | sudo bash
sudo docker run --rm -ti -v "/dev/bus/usb:/dev/bus/usb" -v "$(realpath .):/app" --privileged \
ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest \
/bin/bash -c "BOLOS_SDK=\$$(echo "$1" | tr '[:lower:]' '[:upper:]')_SDK make load"
}
handle_delete_app() {
validate_model_arg "$1"
if [[ "$1" == "nanox" ]]; then
echo "App loading and removal is not supported in nanox"
exit 1
fi
# We need to add the appropriate udev rules
wget -q -O - https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/add_udev_rules.sh | sudo bash
sudo docker run --rm -ti -v "/dev/bus/usb:/dev/bus/usb" -v "$(realpath .):/app" --privileged \
ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest \
/bin/bash -c "BOLOS_SDK=\$$(echo "$1" | tr '[:lower:]' '[:upper:]')_SDK make delete"
}
handle_run_tests() {
validate_model_arg "$1"
project_root_dir=$(pwd)
export PYTHONPATH=$project_root_dir/tests
echo "Executing app unit testcases"
cd unit-tests || exit 1
cmake -Bbuild -H. && make -C build && CTEST_OUTPUT_ON_FAILURE=1 make -C build test
echo "Executing speculos based function testcases"
cd ../tests/speculos || exit 1
pip install --extra-index-url https://test.pypi.org/simple/ -r requirements.txt
pytest --model "$1" -v
echo "Executing ledgercomm based function testcases with speculos"
cd ../ledgercomm || exit 1
pip install -r requirements.txt
speculos "$project_root_dir"/bin/app.elf --button-port 42000 --model "$1" --display headless &
echo "Waiting for 10 5 seconds to start speculos"
sleep 5
speculos_process_id=$!
pytest --model "$1" --headless -v
kill $speculos_process_id
cd "$project_root_dir" || exit 1
}
handle_choice() {
case $1 in
1) handle_build_app "$2" ;;
2) handle_start_emulator "$2" ;;
3) handle_load_app "$2" ;;
4) handle_delete_app "$2" ;;
5) handle_run_tests "$2" ;;
*)
echo "Invalid choice. Please use a valid option (1-5)."
;;
esac
}
show_menu() {
echo "========== MENU =========="
echo "1. Build App"
echo "2. Start Emulator"
echo "3. Load app"
echo "4. Delete app"
echo "5. Run tests"
echo "=========================="
}
if [ $# -lt 2 ]; then
echo "Expected number of args are not provided!"
show_menu
echo "Usage: $0 <option> <wallet-model>"
echo "Example: $0 1 nanos (to build app for nanos wallet)"
exit 1
fi
handle_choice "$@"