Skip to content

Commit

Permalink
Merge pull request #6 from LedgerHQ/develop
Browse files Browse the repository at this point in the history
Align master with P1
  • Loading branch information
fbeutin-ledger authored May 23, 2024
2 parents 972fe55 + c75553d commit 40e76d4
Show file tree
Hide file tree
Showing 666 changed files with 4,323 additions and 2,824 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ IndentWidth: 4
ColumnLimit: 78
UseTab: Never
IndentCaseLabels: false
InsertBraces: false
InsertBraces: true
PointerAlignment: Right

AlwaysBreakAfterReturnType: TopLevelDefinitions
Expand Down Expand Up @@ -36,4 +36,5 @@ AlignArrayOfStructures: Left
SortIncludes: Never
SpaceAfterCStyleCast: false
AllowShortEnumsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
...
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Checklist
<!-- Put an `x` in each box when you have completed the items. -->
- [ ] App update process has been followed <!-- See comment below -->
- [ ] Target branch is `develop` <!-- unless you have a very good reason -->
- [ ] Application version has been bumped <!-- required if your changes are to be deployed -->

<!-- Make sure you followed the process described in https://developers.ledger.com/docs/device-app/deliver/maintenance before opening your Pull Request.
Don't hesitate to contact us directly on Discord if you have any questions ! https://developers.ledger.com/discord -->
53 changes: 31 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
device: [nanos, nanosp, nanox, stax]
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:3.11.0
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -43,32 +43,25 @@ jobs:
path: app_${{ matrix.device }}_dbg.tgz
name: app_${{ matrix.device }}_dbg.tgz

build_docker_integration_tests:
uses: ./.github/workflows/docker.yml
secrets: inherit
with:
dockerfile: docker/Dockerfile.integration-tests
image_name: integration_tests

build_docker_tezos_ocaml:
if: github.repository == 'trilitech/ledger-app-tezos-wallet'
uses: ./.github/workflows/docker.yml
secrets: inherit
with:
dockerfile: docker/Dockerfile.ocaml
image_name: tezos_ocaml

integration_tests_basic:
needs: [build_app, build_docker_integration_tests]
needs: [build_app]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
device: [nanos, nanosp, nanox, stax]
container:
image: ${{ needs.build_docker_integration_tests.outputs.image }}
credentials:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest

steps:
- name: Set Git Safe Directory
run: |
Expand All @@ -93,17 +86,31 @@ jobs:
./tests/integration/run_test_local.sh -F -m ${{ matrix.device }} \
./tests/integration/${{ matrix.device }}
else
./tests/integration/run_test_local.sh -F -m ${{ matrix.device }} \
./tests/integration/nano ./tests/integration/nano/${{ matrix.device }}
apk add gmp-dev curl jq libsodium-dev git xxd procps
python3 -m venv tezos_test_env --system-site-package
source ./tezos_test_env/bin/activate
python3 -m pip install -r ./tests/requirements.txt -q
TMP_DIR=$(mktemp -d /tmp/foo-XXXXXX)
tar xfz app_${{ matrix.device }}_dbg.tgz -C $TMP_DIR
python3 -m pytest -n 32 tests/integration/nano/ --tb=no \
--device ${{ matrix.device }} --app $TMP_DIR/app.elf \
--log-dir integration_tests_log
fi
- name: Upload results
- name: Upload Stax results
uses: actions/upload-artifact@v3
if: always()
if: always() && matrix.device == 'stax'
with:
name: integration_tests_${{ matrix.device }}.json
path: ./integration_tests.json

- name: Upload Nano results
uses: actions/upload-artifact@v3
if: always() && matrix.device != 'stax'
with:
name: integration_tests_log_${{ matrix.device }}
path: ./integration_tests_log

generate_samples_unit_tests:
needs: [build_docker_tezos_ocaml]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -151,18 +158,15 @@ jobs:
path: tests/samples/operations/nano

integration_tests_samples:
needs: [build_app, generate_samples_unit_tests, build_docker_integration_tests]
needs: [build_app, generate_samples_unit_tests]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
device: [nanos, nanosp, nanox]
type: [micheline, operations]
container:
image: ${{ needs.build_docker_integration_tests.outputs.image }}
credentials:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -184,7 +188,12 @@ jobs:
path: tests

- name: Test
run: ./tests/integration/run_test_local.sh -T100 -F -m ${{ matrix.device }} tests
run: |
apk add gmp-dev curl jq libsodium-dev git xxd procps
python3 -m venv tezos_test_env --system-site-package
source ./tezos_test_env/bin/activate
python3 -m pip install -r ./tests/requirements.txt -q
./tests/integration/run_test_local.sh -T100 -F -m ${{ matrix.device }} tests
- name: Upload results
uses: actions/upload-artifact@v3
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/swap.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Swap feature tests
name: Swap functional tests

on:
workflow_dispatch:
push:
branches:
- main
- develop
pull_request:

jobs:
job_functional_tests:
uses: functori/app-exchange/.github/workflows/reusable_swap_functional_tests.yml@ebc5932d939e2bad5eaf3d5e316626169da6ff23
uses: LedgerHQ/app-exchange/.github/workflows/reusable_swap_functional_tests.yml@develop
with:
repo_for_exchange: 'functori/app-exchange'
branch_for_exchange: 'ajinkyaraj-23@display-source-field'
branch_for_exchange: 'develop'
branch_for_tezos: ${{ github.ref }}
run_for_devices: '["nanos", "nanosp", "stax"]'
test_filter: '"tezos_new"'
repo_for_tezos: ${{ github.repository }}
test_filter: '"tezos"'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
/app/src/glyphs.h
/app_*.tgz
/integration_tests.json
/integration_tests_log
/pattern_registry
/tests/samples
/*env/

tags
__pycache__
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ docker_speculos:
$(DOCKER) image tag $(LEDGERHQ)/speculos speculos

docker_ledger_app_builder:
$(DOCKER) pull $(LEDGERHQ)/ledger-app-builder/ledger-app-builder:3.11.0
$(DOCKER) image tag $(LEDGERHQ)/ledger-app-builder/ledger-app-builder:3.11.0 \
$(DOCKER) pull $(LEDGERHQ)/ledger-app-builder/ledger-app-dev-tools:latest
$(DOCKER) image tag $(LEDGERHQ)/ledger-app-builder/ledger-app-dev-tools:latest \
ledger-app-builder

docker_ledger_app_ocaml:
$(DOCKER) build -t ledger-app-tezos-ocaml \
-f docker/Dockerfile.ocaml docker --platform linux/$(CPU)

docker_ledger_app_integration_tests:
$(DOCKER) build -t ledger-app-tezos-integration-tests \
-f docker/Dockerfile.integration-tests docker --platform linux/$(CPU)
$(DOCKER) pull $(LEDGERHQ)/ledger-app-builder/ledger-app-dev-tools:latest
$(DOCKER) image tag $(LEDGERHQ)/ledger-app-builder/ledger-app-dev-tools:latest \
ledger-app-tezos-integration-tests

docker_images: docker_speculos \
docker_ledger_app_builder \
Expand Down Expand Up @@ -94,12 +95,23 @@ integration_tests_basic_stax: app_stax.tgz \
tests/integration/stax/*
$(RUN_TEST_DOCKER) stax tests/integration/stax

integration_tests_basic_%: app_%.tgz \
integration_tests_basic_%: app_%.tgz \
app_%_dbg.tgz \
tests/integration/* \
tests/integration/nano/* \
tests/integration/nano/%/*
$(RUN_TEST_DOCKER) $* tests/integration/nano tests/integration/nano/$*
docker run --rm -i -v "$(realpath .):/app" \
--entrypoint=/bin/sh ledger-app-tezos-integration-tests -c " \
TMP_DIR=\$$(mktemp -d /tmp/foo-XXXXXX); \
cd /app; \
tar xfz app_$*_dbg.tgz -C \$$TMP_DIR; \
apk add gmp-dev curl jq libsodium-dev git xxd procps; \
python3 -m venv tezos_test_env --system-site-package; \
source ./tezos_test_env/bin/activate; \
python3 -m pip install -r tests/requirements.txt -q ; \
python3 -m pytest -n 32 tests/integration/nano/ --tb=no \
--device $* --app \$$TMP_DIR/app.elf \
--log-dir integration_tests_log"

integration_tests_basic: integration_tests_basic_nanos \
integration_tests_basic_nanosp \
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ The docker images can be built using the provided Makefile:
:; make docker-images
```

This pulls down two images, `ghcr.io/ledgerhq/speculos` and
`ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest`. It
This pulls down following image, `ghcr.io/ledgerhq/ledger-app-dev-tools`. It
also builds an image via `docker/Dockerfile.ocaml`.

We do not make the builds of the software conditional on these docker
Expand Down Expand Up @@ -157,11 +156,10 @@ make app_nanox_dbg.tgz
You can run an individual test from the test container. You should see the app progress on the vnc viewer.

```sh
./tests/integration/nano/<test_name>.py \
pytest tests/integration/nano/<test_name>.py \
--device $DEVICE \
--port $PORT \
--display headless \
--vnc-port 41000 \
--speculos-args="--vnc-port 41000" \
--app app/bin/app.elf
```

Expand All @@ -177,43 +175,36 @@ re-run the test normally afterwards, to ensure the snapshots have been set corre

#### Preparation

First, start a container for running individual tests:
First start the app in a terminal using following command:

```sh
docker run --rm -it --entrypoint /bin/bash -v $(pwd):/app --network host \
ledger-app-tezos-integration-tests

cd /app/tests/integration/stax
export PORT=5000

git config --global --add safe.directory /app
. ../app_vars.sh
make app_stax_dbg.tgz
TARGET=stax ./scripts/run_app.sh
```
You should be able to see the stax display on your screen.

Before running the test, start the app in a separate container (as each test will quit the app):
Open a new terminal for running tests, run following commands to setup test environment

```sh
make app_stax_dbg.tgz

TARGET=stax ./scripts/run_app.sh
$ docker exec -it ledger-app-tezos-integration-tests bash;
<docker>$ export PORT=5000
<docker>$ . tests/integration/app_vars.sh
```

You can view/interact with the app using a vnc client on port `41000`.

#### Running

You can run an individual test from the test container. You should see the app progress on the vnc viewer.
You can run an individual test from the test container. You should see the app progress on the display.

```sh
./<test_name>.py
./tests/integration/stax/<test_name>.py
```

#### Setting goldimages

You can reset/set goldimages using the following:

```sh
GOLDEN=1 ./<test_name>.py
GOLDEN=1 ./tests/integration/stax/<test_name>.py
```

If you are resetting goldimages for multiple tests, you can also use `export NOQUIT=1` to keep the app
Expand Down Expand Up @@ -265,3 +256,12 @@ You can run :
./scripts/test_swap.sh update $DEVICE
```
to perform all snapshot update steps based on your current Tezos repository.

## Contributing

The version of the app must be updated after every change. Following files need to be updated
with a new version
1. app/Makefile
2. tests/integration/app_vars.sh
3. tests/integration/nano/utils/app.py
4. the snapshots (nano and stax)
6 changes: 1 addition & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ APPNAME = "Tezos Wallet"
# Application version
APPVERSION_M=3
APPVERSION_N=0
APPVERSION_P=0
APPVERSION_P=3
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

# COMMIT
Expand Down Expand Up @@ -135,10 +135,6 @@ CFLAGS += -Wwrite-strings
########################################
# See SDK `include/appflags.h` for the purpose of each permission
#HAVE_APPLICATION_FLAG_DERIVE_MASTER = 1
ifneq ($(TARGET_NAME), TARGET_NANOS)
HAVE_APPLICATION_FLAG_GLOBAL_PIN = 1
HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1
endif
HAVE_APPLICATION_FLAG_LIBRARY = 1

########################################
Expand Down
2 changes: 0 additions & 2 deletions app/src/apdu.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Tezos Ledger application - Some common primitives and some command handlers
TODO: split this file (apdu primitives and apdu handlers)
Copyright 2023 Nomadic Labs <[email protected]>
Copyright 2023 Trilitech <[email protected]>
Expand Down
24 changes: 18 additions & 6 deletions app/src/apdu.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Tezos Ledger application - Some common primitives and some command handlers
TODO: split this file (apdu primitives and apdu handlers)
Copyright 2023 Nomadic Labs <[email protected]>
With code excerpts from:
Expand Down Expand Up @@ -82,11 +80,25 @@
*
*/

typedef void(tz_handler)(command_t *);
typedef void(tz_handler)(command_t *cmd);
typedef tz_handler *tz_handler_t;

tz_handler handle_unimplemented;
tz_handler handle_apdu_version;
tz_handler handle_apdu_git;
tz_handler handle_unimplemented; /// handler for unknown commands
tz_handler handle_apdu_version; /// handle version enquiry apdu
tz_handler handle_apdu_git; /// handle git commit enquiry apdu
/**
* @brief Function to handle apdu request for public key. The public key is
* derived only once and stored in the RAM, in order to avoid repeated
* derivation calculations. This function can be called with or without
* prompt.
*
*/
tz_handler handle_apdu_get_public_key;
/**
* @brief Parse the received command and prompt user for appropriate action.
* Triggers blindsigning and/or expert mode workflows based on transaction
* involved. Stream based parser helps decode arbitararily large transaction,
* screen by screen.
*
*/
tz_handler handle_apdu_sign;
Loading

0 comments on commit 40e76d4

Please sign in to comment.