diff --git a/Makefile b/Makefile index a3d64ef1e..7d5ee0123 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ all: app_nanos.tgz app_nanosp.tgz app_nanox.tgz debug: app_nanos_dbg.tgz app_nanosp_dbg.tgz app_nanox_dbg.tgz -.PHONY: clean all debug integration_tests unit_tests scan-build% \ +.PHONY: clean all debug format integration_tests unit_tests scan-build% \ integration_tests_basic integration_tests_basic_% docker_% DOCKER = docker @@ -130,6 +130,10 @@ load_%: app_%.tgz # # Dash vs under aliases: +format: + @find ./app/src -name '*.c' -exec clang-format -i "{}" \; + @find ./app/src -name '*.h' -exec clang-format -i "{}" \; + docker-images: docker_images integration-tests: integration_tests unit-tests: unit_tests diff --git a/README.md b/README.md index 36f7d75c3..16cc82d6e 100644 --- a/README.md +++ b/README.md @@ -136,20 +136,22 @@ To generate/reset the snapshots, you can do so for individual tests. First, start a container for running individual tests: ```sh -docker run --rm -it --entrypoint /bin/bash -v $(pwd)/tests/integration:/tests --network host \ +docker run --rm -it --entrypoint /bin/bash -v $(pwd):/app --network host \ ledger-app-tezos-integration-tests -cd /tests/stax +cd /app/tests/integration/stax export PORT=5000 + +git config --global --add safe.directory /app +. ../app_vars.sh ``` Before running the test, start the app in a separate container (as each test will quit the app): ```sh make app_stax_dbg.tgz -seed="zebra`for i in $(seq 1 23) ; do echo -n ' zebra' ; done`" -docker run --rm -it -v $(pwd)/app/bin:/speculos/apps -v $(pwd)/tests/integration:/tests --network host \ - ledger-app-tezos-integration-tests --display=headless --vnc-port 41000 --seed "$seed" -m stax apps/app.elf + +TARGET=stax ./scripts/run_app.sh ``` You can view/interact with the app using a vnc client on port `41000`. diff --git a/scripts/run_app.sh b/scripts/run_app.sh new file mode 100755 index 000000000..eeee3708c --- /dev/null +++ b/scripts/run_app.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Copyright 2023 Nomadic Labs +# Copyright 2023 TriliTech +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +seed="zebra`for i in $(seq 1 23) ; do echo -n ' zebra' ; done`" + +docker run --rm -it -v $(pwd)/app/bin:/speculos/apps \ + -v $(pwd)/tests/integration:/tests --network host \ + ledger-app-tezos-integration-tests --display=headless --vnc-port 41000 \ + --seed "$seed" -m $TARGET apps/app.elf diff --git a/tests/integration/app_vars.sh b/tests/integration/app_vars.sh new file mode 100644 index 000000000..e3e286eca --- /dev/null +++ b/tests/integration/app_vars.sh @@ -0,0 +1,42 @@ +# Copyright 2023 Nomadic Labs +# Copyright 2023 Trilitech +# Copyright 2023 Functori +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +COMMIT=$(git describe --tags --abbrev=8 --always --long --dirty 2>/dev/null | sed 's/-dirty/*/') +export COMMIT_BYTES=$(printf '%s' "$COMMIT" | xxd -p -c 256) + +VERSION_WALLET_TAG="00" +APPVERSION_M=3 +APPVERSION_N=0 +APPVERSION_P=0 +export VERSION_BYTES=$(printf "%02x%02x%02x%02x" "$VERSION_WALLET_TAG" "$APPVERSION_M" "$APPVERSION_N" "$APPVERSION_P") + +## Error code +ERR_WRONG_PARAM=6b00 +ERR_WRONG_LENGTH=6c00 +ERR_INVALID_INS=6d00 +ERR_WRONG_LENGTH_FOR_INS=917e +ERR_REJECT=6985 +ERR_PARSE_ERROR=9405 +ERR_REFERENCED_DATA_NOT_FOUND=6a88 +ERR_WRONG_VALUES=6a80 +ERR_SECURITY=6982 +ERR_HID_REQUIRED=6983 +ERR_CLASS=6e00 +ERR_MEMORY_ERROR=9200 +ERR_UNEXPECTED_STATE=9001 +ERR_UNEXPECTED_SIGN_STATE=9002 +ERR_UNKNOWN_CX_ERR=9003 +ERR_UNKNOWN=90ff diff --git a/tests/integration/test_runtime.sh b/tests/integration/test_runtime.sh index eb96484d7..9b11d4a31 100644 --- a/tests/integration/test_runtime.sh +++ b/tests/integration/test_runtime.sh @@ -1,5 +1,6 @@ # Copyright 2023 Nomadic Labs # Copyright 2023 Trilitech +# Copyright 2023 Functori # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -47,32 +48,7 @@ seed="zebra`for i in $(seq 1 23) ; do echo -n ' zebra' ; done`" OUTPUT_BARS=$(for i in $(seq 1 $((COLUMNS-18))); do echo -n =; done) -COMMIT=$(git describe --tags --abbrev=8 --always --long --dirty 2>/dev/null | sed 's/-dirty/*/') -COMMIT_BYTES=$(printf '%s' "$COMMIT" | xxd -p -c 256) - -VERSION_WALLET_TAG="00" -APPVERSION_M=3 -APPVERSION_N=0 -APPVERSION_P=0 -VERSION_BYTES=$(printf "%02x%02x%02x%02x" "$VERSION_WALLET_TAG" "$APPVERSION_M" "$APPVERSION_N" "$APPVERSION_P") - -## Error code -ERR_WRONG_PARAM=6b00 -ERR_WRONG_LENGTH=6c00 -ERR_INVALID_INS=6d00 -ERR_WRONG_LENGTH_FOR_INS=917e -ERR_REJECT=6985 -ERR_PARSE_ERROR=9405 -ERR_REFERENCED_DATA_NOT_FOUND=6a88 -ERR_WRONG_VALUES=6a80 -ERR_SECURITY=6982 -ERR_HID_REQUIRED=6983 -ERR_CLASS=6e00 -ERR_MEMORY_ERROR=9200 -ERR_UNEXPECTED_STATE=9001 -ERR_UNEXPECTED_SIGN_STATE=9002 -ERR_UNKNOWN_CX_ERR=9003 -ERR_UNKNOWN=90ff +. "`dirname $0`/app_vars.sh" attempts() { nb=$(( $TIMEOUT * 20 )) # We use multiplication to avoid floats