From 3b588d3b815991f4e3d330bc4dad776a5399932c Mon Sep 17 00:00:00 2001 From: Charles-Edouard de la Vergne Date: Tue, 19 Mar 2024 16:30:42 +0100 Subject: [PATCH] Fix various Linter issues --- .github/ISSUE_TEMPLATE/bug_report.md | 7 ++- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/ISSUE_TEMPLATE/network_request.md | 15 ++--- .github/pull_request_template.md | 4 +- .gitignore | 2 +- README.md | 62 ++++++++++--------- client/pyproject.toml | 2 +- doc/eth_contract_support_embedded.adoc | 1 - examples/signMessageEIP711v0.py | 2 +- makefile_conf/chain/akroma.mk | 2 +- makefile_conf/chain/artis_sigma1.mk | 2 +- makefile_conf/chain/artis_tau1.mk | 2 +- makefile_conf/chain/atheios.mk | 2 +- makefile_conf/chain/bsc.mk | 2 +- makefile_conf/chain/bttc.mk | 2 +- makefile_conf/chain/callisto.mk | 2 +- makefile_conf/chain/conflux_espace.mk | 2 +- makefile_conf/chain/cube.mk | 2 +- makefile_conf/chain/dexon.mk | 2 +- makefile_conf/chain/ellaism.mk | 2 +- makefile_conf/chain/ether1.mk | 2 +- makefile_conf/chain/ethereum_classic.mk | 2 +- makefile_conf/chain/ethergem.mk | 2 +- makefile_conf/chain/ethersocial.mk | 2 +- makefile_conf/chain/expanse.mk | 2 +- makefile_conf/chain/flare.mk | 2 +- makefile_conf/chain/flare_coston.mk | 2 +- makefile_conf/chain/gochain.mk | 2 +- makefile_conf/chain/hpb.mk | 2 +- makefile_conf/chain/kardiachain.mk | 2 +- makefile_conf/chain/meter.mk | 2 +- makefile_conf/chain/mix.mk | 2 +- makefile_conf/chain/moonbeam.mk | 2 +- makefile_conf/chain/moonriver.mk | 2 +- makefile_conf/chain/musicoin.mk | 2 +- makefile_conf/chain/okc.mk | 2 +- makefile_conf/chain/pirl.mk | 2 +- makefile_conf/chain/poa.mk | 2 +- makefile_conf/chain/polygon.mk | 2 +- makefile_conf/chain/reosc.mk | 2 +- makefile_conf/chain/rsk.mk | 2 +- makefile_conf/chain/rsk_testnet.mk | 2 +- makefile_conf/chain/shyft.mk | 2 +- makefile_conf/chain/songbird.mk | 2 +- makefile_conf/chain/tecracoin.mk | 2 +- makefile_conf/chain/tecratestnet.mk | 2 +- makefile_conf/chain/thundercore.mk | 2 +- makefile_conf/chain/tomochain.mk | 2 +- makefile_conf/chain/ubiq.mk | 2 +- makefile_conf/chain/volta.mk | 2 +- makefile_conf/chain/webchain.mk | 2 +- makefile_conf/chain/wethio.mk | 2 +- src/plugins.c | 2 +- src/plugins.h | 2 +- src_bagl/ui_flow_performPrivacyOperation.c | 10 +-- src_bagl/ui_plugin.c | 2 +- src_nbgl/ui_get_eth2_public_key.c | 2 +- tests/speculos/.gitignore | 2 +- tests/speculos/README.md | 6 +- tests/speculos/docs/README.md | 21 ++++--- .../speculos/ethereum_client/ethereum_cmd.py | 31 +++++----- .../ethereum_client/ethereum_cmd_builder.py | 16 ++--- tests/speculos/ethereum_client/plugin.py | 4 +- tests/speculos/ethereum_client/transaction.py | 4 +- tests/speculos/ethereum_client/utils.py | 2 +- tests/speculos/old_test_eip191.py | 8 +-- tests/speculos/test_eip1559.py | 4 +- tests/speculos/test_eip712.py | 2 +- tests/speculos/test_erc1155.py | 10 +-- tests/speculos/test_erc20information.py | 2 +- tests/speculos/test_erc721.py | 12 ++-- tests/speculos/test_pubkey_cmd.py | 4 +- tests/speculos/test_sign_cmd.py | 16 ++--- tests/unit/.gitignore | 2 +- tests/unit/CMakeLists.txt | 2 +- tests/unit/Makefile | 2 +- tests/unit/README.md | 16 +++-- tests/unit/demo_tu.c | 2 +- tests/unit/tests/demo.c | 2 +- tests/zemu/.gitignore | 2 +- tests/zemu/Makefile | 2 +- tests/zemu/globalsetup.js | 2 +- tests/zemu/jest.js | 2 +- tests/zemu/setupTests.js | 2 +- 84 files changed, 197 insertions(+), 184 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index a141a2d83..2bbff6061 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -19,8 +19,8 @@ Describe your issue in as much detail as possible here. ## Steps to reproduce -* Tell us how to reproduce this issue
-* Where the issue is, if you know
+* Tell us how to reproduce this issue +* Where the issue is, if you know * Which commands triggered the issue, if any ## Expected behaviour @@ -37,4 +37,5 @@ Please paste any logs here that demonstrate the issue, if they exist ## Proposed solution -If you have an idea of how to fix this issue, please write it down here, so we can begin discussing it \ No newline at end of file +If you have an idea of how to fix this issue, please write it down here, +so we can begin discussing it diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 031ba337d..af1481d66 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,6 +1,6 @@ --- name: Feature report -about: Suggest an idea for this project +about: Suggest an idea for this project title: 'Add [Subject of the issue]' labels: 'enhancement' assignees: '' diff --git a/.github/ISSUE_TEMPLATE/network_request.md b/.github/ISSUE_TEMPLATE/network_request.md index 369f21e29..ee5115ae3 100644 --- a/.github/ISSUE_TEMPLATE/network_request.md +++ b/.github/ISSUE_TEMPLATE/network_request.md @@ -1,6 +1,6 @@ --- name: Network request -about: Request of new chain or network +about: Request of new chain or network title: 'Add {NameChain} network ({SYMBOL})' labels: 'enhancement, chain/network' assignees: '' @@ -8,12 +8,13 @@ assignees: '' --- ## Description -- [ ] Symbol: -- [ ] ChainId: -- [ ] Website: -- [ ] Block-Explorer: -- [ ] [slip-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) type: + +- [ ] Symbol: +- [ ] ChainId: +- [ ] Website: +- [ ] Block-Explorer: +- [ ] [slip-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) type: ## Additional comments -Please post additional comments in this section if you have them, otherwise delete it. \ No newline at end of file +Please post additional comments in this section if you have them, otherwise delete it. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 40246410a..b17d6952b 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,6 @@ ## Description -Please provide a detailed description of what was done in this PR. +Please provide a detailed description of what was done in this PR. (And mentioned if linked to an issue [docs](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)) ## Changes include @@ -18,4 +18,4 @@ Please complete this section if any breaking changes have been made, otherwise d ## Additional comments -Please post additional comments in this section if you have them, otherwise delete it. \ No newline at end of file +Please post additional comments in this section if you have them, otherwise delete it. diff --git a/.gitignore b/.gitignore index 0f19b97e3..9562cd315 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ tests/elfs/* tests/snapshots-tmp .vscode -.idea \ No newline at end of file +.idea diff --git a/README.md b/README.md index a18f9d794..592f0b499 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,11 @@ - [Update binaries](#update-binaries) - [Contributing](#contributing) - ## About the project -Ethereum wallet application framework for Nano S, Nano S Plus and Nano X. +Ethereum wallet application framework for Nano S, Nano S Plus and Nano X. Ledger Blue is not maintained anymore, but the app can still be compiled for this target using the branch [`blue-final-release`](https://github.com/LedgerHQ/app-ethereum/tree/blue-final-release). ## Documentation @@ -53,8 +52,9 @@ To compile it and load it on a device, please check out our [developer portal](h ### Plugins -We have the concept of plugins in the ETH app. -Find the documentations here: +We have the concept of plugins in the ETH app. +Find the documentations here: + - [Blog Ethereum plugins](https://blog.ledger.com/ethereum-plugins/) - [Ethereum application Plugins : Technical Specifications](https://github.com/LedgerHQ/app-ethereum/blob/master/doc/ethapp_plugins.asc) - [Plugin guide](https://hackmd.io/300Ukv5gSbCbVcp3cZuwRQ) @@ -70,46 +70,53 @@ Testing is done via the open-source framework [zemu](https://github.com/Zondax/z - [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#debian-stable) - [build environment](https://github.com/LedgerHQ/ledger-app-builder/blob/master/Dockerfile) -#### Build the applications required by the test suite +#### Build the applications required by the test suite 1. Add your BOLOS SDKs path to: - - `NANOS_SDK` and `NANOX_SDK` + + `NANOS_SDK` and `NANOX_SDK` 2. Go to the `tests` folder and run `./build_local_test_elfs.sh` - - ```sh - cd tests - # This helper script will build the applications required by the test suite and move them at the right place. - yarn install - ./build_local_test_elfs.sh - ``` + + ```sh + cd tests + # This helper script will build the applications required by the test suite and move them at the right place. + yarn install + ./build_local_test_elfs.sh + ``` ### Running all tests + #### With Makefile 1. Then you can install and run tests by simply running on the `root` of the repo: - - ```sh - make test - ``` - - This will run `make install_tests` and `make run_tests` + + ```sh + make test + # This will run `make install_tests` and `make run_tests` + ``` #### With yarn 1. Go to the `tests` folder and run: - - ```sh - yarn test - ``` + + ```sh + yarn test + ``` ### Running a specific tests -1. Go to the `tests` folder and run: - - ```sh - yarn jest --runInBand --detectOpenHandles {YourTestFile} - ``` -2. For example with the `send test`: - - ```sh - yarn jest --runInBand --detectOpenHandles src/send.test.js - ``` +1. Go to the `tests` folder and run: + + ```sh + yarn jest --runInBand --detectOpenHandles {YourTestFile} + ``` +2. For example with the `send test`: + + ```sh + yarn jest --runInBand --detectOpenHandles src/send.test.js + ``` ### Adding tests @@ -142,7 +149,6 @@ cp bin/app.elf tests/elfs/ethereum_nanos.elf Repeat the operation for a binary compiled with nanoX SDK and change for `ethereum_nanox.elf`. - ## Contributing Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. diff --git a/client/pyproject.toml b/client/pyproject.toml index 3a91961d1..e68d1a34d 100644 --- a/client/pyproject.toml +++ b/client/pyproject.toml @@ -48,4 +48,4 @@ Home = "https://github.com/LedgerHQ/app-ethereum" ignore_missing_imports = true [tool.flake8] -max-line-length = 120 \ No newline at end of file +max-line-length = 120 diff --git a/doc/eth_contract_support_embedded.adoc b/doc/eth_contract_support_embedded.adoc index 36a582c98..24c5dea5a 100644 --- a/doc/eth_contract_support_embedded.adoc +++ b/doc/eth_contract_support_embedded.adoc @@ -45,4 +45,3 @@ A UI implementation might want to convert an ERC 20 token contract address to a 2 tickers can be temporarily provisioned to the application by using the PROVIDE ERC 20 TOKEN INFORMATION APDU, described in *src_features/provideErc20TokenInformation* - the UI can then iterate on the provisioned tickers to display relevant information to the user The same mechanism will be extended to support well known contract addresses in the future - diff --git a/examples/signMessageEIP711v0.py b/examples/signMessageEIP711v0.py index 97b8ef1b8..cbe6595a9 100755 --- a/examples/signMessageEIP711v0.py +++ b/examples/signMessageEIP711v0.py @@ -59,7 +59,7 @@ def parse_bip32_path(path): domainHash = binascii.unhexlify(args.domainHash) messageHash = binascii.unhexlify(args.messageHash) -encodedTx = domainHash + messageHash +encodedTx = domainHash + messageHash donglePath = parse_bip32_path(args.path) apdu = bytearray.fromhex("e00c0000") diff --git a/makefile_conf/chain/akroma.mk b/makefile_conf/chain/akroma.mk index 68c935fa4..0426bdb52 100644 --- a/makefile_conf/chain/akroma.mk +++ b/makefile_conf/chain/akroma.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/200625'" TICKER = "AKA" CHAIN_ID = 200625 -APPNAME = "Akroma" \ No newline at end of file +APPNAME = "Akroma" diff --git a/makefile_conf/chain/artis_sigma1.mk b/makefile_conf/chain/artis_sigma1.mk index 766bd321c..1539ccc2a 100644 --- a/makefile_conf/chain/artis_sigma1.mk +++ b/makefile_conf/chain/artis_sigma1.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/246529'" TICKER = "ATS" CHAIN_ID = 246529 -APPNAME = "ARTIS sigma1" \ No newline at end of file +APPNAME = "ARTIS sigma1" diff --git a/makefile_conf/chain/artis_tau1.mk b/makefile_conf/chain/artis_tau1.mk index dd0d981ae..720f50625 100644 --- a/makefile_conf/chain/artis_tau1.mk +++ b/makefile_conf/chain/artis_tau1.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/246785'" TICKER = "ATS" CHAIN_ID = 246785 -APPNAME = "ARTIS tau1" \ No newline at end of file +APPNAME = "ARTIS tau1" diff --git a/makefile_conf/chain/atheios.mk b/makefile_conf/chain/atheios.mk index e7e9ef555..77a73d731 100644 --- a/makefile_conf/chain/atheios.mk +++ b/makefile_conf/chain/atheios.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/1620'" TICKER = "ATH" CHAIN_ID = 1620 -APPNAME = "Atheios" \ No newline at end of file +APPNAME = "Atheios" diff --git a/makefile_conf/chain/bsc.mk b/makefile_conf/chain/bsc.mk index dc70e0bcc..e3c9f6a71 100644 --- a/makefile_conf/chain/bsc.mk +++ b/makefile_conf/chain/bsc.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "BNB" CHAIN_ID = 56 -APPNAME = "Binance Smart Chain" \ No newline at end of file +APPNAME = "Binance Smart Chain" diff --git a/makefile_conf/chain/bttc.mk b/makefile_conf/chain/bttc.mk index 9e82b675e..64513371a 100644 --- a/makefile_conf/chain/bttc.mk +++ b/makefile_conf/chain/bttc.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "BTT" CHAIN_ID = 199 -APPNAME = "BTTC" \ No newline at end of file +APPNAME = "BTTC" diff --git a/makefile_conf/chain/callisto.mk b/makefile_conf/chain/callisto.mk index 1147dc9c8..5919f3fbd 100644 --- a/makefile_conf/chain/callisto.mk +++ b/makefile_conf/chain/callisto.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/820'" TICKER = "CLO" CHAIN_ID = 820 -APPNAME = "Callisto" \ No newline at end of file +APPNAME = "Callisto" diff --git a/makefile_conf/chain/conflux_espace.mk b/makefile_conf/chain/conflux_espace.mk index 6efc293af..8bc8c9abb 100644 --- a/makefile_conf/chain/conflux_espace.mk +++ b/makefile_conf/chain/conflux_espace.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "CFX" CHAIN_ID = 1030 -APPNAME = "Conflux eSpace" \ No newline at end of file +APPNAME = "Conflux eSpace" diff --git a/makefile_conf/chain/cube.mk b/makefile_conf/chain/cube.mk index 7ac424cf6..614036d7f 100644 --- a/makefile_conf/chain/cube.mk +++ b/makefile_conf/chain/cube.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "CUBE" CHAIN_ID = 1818 -APPNAME = "Cube" \ No newline at end of file +APPNAME = "Cube" diff --git a/makefile_conf/chain/dexon.mk b/makefile_conf/chain/dexon.mk index c892e3533..7cd36b73a 100644 --- a/makefile_conf/chain/dexon.mk +++ b/makefile_conf/chain/dexon.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/237'" TICKER = "DXN" CHAIN_ID = 237 -APPNAME = "DEXON" \ No newline at end of file +APPNAME = "DEXON" diff --git a/makefile_conf/chain/ellaism.mk b/makefile_conf/chain/ellaism.mk index 1bd55896d..27df5db75 100644 --- a/makefile_conf/chain/ellaism.mk +++ b/makefile_conf/chain/ellaism.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/163'" TICKER = "ELLA" CHAIN_ID = 64 -APPNAME = "Ellaism" \ No newline at end of file +APPNAME = "Ellaism" diff --git a/makefile_conf/chain/ether1.mk b/makefile_conf/chain/ether1.mk index 9efc01588..188558632 100644 --- a/makefile_conf/chain/ether1.mk +++ b/makefile_conf/chain/ether1.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/1313114'" TICKER = "ETHO" CHAIN_ID = 1313114 -APPNAME = "Ether-1" \ No newline at end of file +APPNAME = "Ether-1" diff --git a/makefile_conf/chain/ethereum_classic.mk b/makefile_conf/chain/ethereum_classic.mk index ac44b6ab5..5cc1760c7 100644 --- a/makefile_conf/chain/ethereum_classic.mk +++ b/makefile_conf/chain/ethereum_classic.mk @@ -2,4 +2,4 @@ APP_LOAD_PARAMS += --path "44'/61'" --path "44'/60'" TICKER = "ETC" CHAIN_ID = 61 -APPNAME = "Ethereum Classic" \ No newline at end of file +APPNAME = "Ethereum Classic" diff --git a/makefile_conf/chain/ethergem.mk b/makefile_conf/chain/ethergem.mk index 6c819762b..09d3855a4 100644 --- a/makefile_conf/chain/ethergem.mk +++ b/makefile_conf/chain/ethergem.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/1987'" TICKER = "EGEM" CHAIN_ID = 1987 -APPNAME = "EtherGem" \ No newline at end of file +APPNAME = "EtherGem" diff --git a/makefile_conf/chain/ethersocial.mk b/makefile_conf/chain/ethersocial.mk index bbf512c76..95e153c8e 100644 --- a/makefile_conf/chain/ethersocial.mk +++ b/makefile_conf/chain/ethersocial.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/31102'" TICKER = "ESN" CHAIN_ID = 31102 -APPNAME = "Ethersocial" \ No newline at end of file +APPNAME = "Ethersocial" diff --git a/makefile_conf/chain/expanse.mk b/makefile_conf/chain/expanse.mk index f2ee9952e..737ec439f 100644 --- a/makefile_conf/chain/expanse.mk +++ b/makefile_conf/chain/expanse.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/40'" TICKER = "EXP" CHAIN_ID = 2 -APPNAME = "Expanse" \ No newline at end of file +APPNAME = "Expanse" diff --git a/makefile_conf/chain/flare.mk b/makefile_conf/chain/flare.mk index 36339eea1..e8ecf3b82 100644 --- a/makefile_conf/chain/flare.mk +++ b/makefile_conf/chain/flare.mk @@ -6,4 +6,4 @@ CHAIN_ID = 14 APP_LOAD_PARAMS += --tlvraw 9F:01 DEFINES += HAVE_PENDING_REVIEW_SCREEN -APPNAME = "Flare" \ No newline at end of file +APPNAME = "Flare" diff --git a/makefile_conf/chain/flare_coston.mk b/makefile_conf/chain/flare_coston.mk index 0d6bddf5d..f8f5ed229 100644 --- a/makefile_conf/chain/flare_coston.mk +++ b/makefile_conf/chain/flare_coston.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/554'" --path "44'/60'" TICKER = "FLR" CHAIN_ID = 16 -APPNAME = "Flare Coston" \ No newline at end of file +APPNAME = "Flare Coston" diff --git a/makefile_conf/chain/gochain.mk b/makefile_conf/chain/gochain.mk index 180b2fd67..b24e64e6a 100644 --- a/makefile_conf/chain/gochain.mk +++ b/makefile_conf/chain/gochain.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/6060'" TICKER = "GO" CHAIN_ID = 60 -APPNAME = "GoChain" \ No newline at end of file +APPNAME = "GoChain" diff --git a/makefile_conf/chain/hpb.mk b/makefile_conf/chain/hpb.mk index 60fb3c137..03fc0056e 100644 --- a/makefile_conf/chain/hpb.mk +++ b/makefile_conf/chain/hpb.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/269'" TICKER = "HPB" CHAIN_ID = 269 -APPNAME = "HPB" \ No newline at end of file +APPNAME = "HPB" diff --git a/makefile_conf/chain/kardiachain.mk b/makefile_conf/chain/kardiachain.mk index cc76d38d6..8ee40becf 100644 --- a/makefile_conf/chain/kardiachain.mk +++ b/makefile_conf/chain/kardiachain.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "KAI" CHAIN_ID = 24 -APPNAME = "KardiaChain" \ No newline at end of file +APPNAME = "KardiaChain" diff --git a/makefile_conf/chain/meter.mk b/makefile_conf/chain/meter.mk index 2a7412013..cb4554b0d 100644 --- a/makefile_conf/chain/meter.mk +++ b/makefile_conf/chain/meter.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "MTR" CHAIN_ID = 82 -APPNAME = "Meter" \ No newline at end of file +APPNAME = "Meter" diff --git a/makefile_conf/chain/mix.mk b/makefile_conf/chain/mix.mk index c180cc90b..6d96ce796 100644 --- a/makefile_conf/chain/mix.mk +++ b/makefile_conf/chain/mix.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/76'" TICKER = "MIX" CHAIN_ID = 76 -APPNAME = "Mix" \ No newline at end of file +APPNAME = "Mix" diff --git a/makefile_conf/chain/moonbeam.mk b/makefile_conf/chain/moonbeam.mk index 5822f8f1f..963ee6377 100644 --- a/makefile_conf/chain/moonbeam.mk +++ b/makefile_conf/chain/moonbeam.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" --path "44'/1284'" TICKER = "GLMR" CHAIN_ID = 1284 -APPNAME = "Moonbeam" \ No newline at end of file +APPNAME = "Moonbeam" diff --git a/makefile_conf/chain/moonriver.mk b/makefile_conf/chain/moonriver.mk index 441371573..5c9391e5b 100644 --- a/makefile_conf/chain/moonriver.mk +++ b/makefile_conf/chain/moonriver.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" --path "44'/1285'" TICKER = "MOVR" CHAIN_ID = 1285 -APPNAME = "Moonriver" \ No newline at end of file +APPNAME = "Moonriver" diff --git a/makefile_conf/chain/musicoin.mk b/makefile_conf/chain/musicoin.mk index 188bebb6e..0c530d762 100644 --- a/makefile_conf/chain/musicoin.mk +++ b/makefile_conf/chain/musicoin.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/184'" TICKER = "MUSIC" CHAIN_ID = 7762959 -APPNAME = "Musicoin" \ No newline at end of file +APPNAME = "Musicoin" diff --git a/makefile_conf/chain/okc.mk b/makefile_conf/chain/okc.mk index 6ed8042b3..9fdd4aa24 100644 --- a/makefile_conf/chain/okc.mk +++ b/makefile_conf/chain/okc.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "OKT" CHAIN_ID = 66 -APPNAME = "OKXChain" \ No newline at end of file +APPNAME = "OKXChain" diff --git a/makefile_conf/chain/pirl.mk b/makefile_conf/chain/pirl.mk index 3f30261cb..fec941e3f 100644 --- a/makefile_conf/chain/pirl.mk +++ b/makefile_conf/chain/pirl.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/164'" TICKER = "PIRL" CHAIN_ID = 3125659152 -APPNAME = "Pirl" \ No newline at end of file +APPNAME = "Pirl" diff --git a/makefile_conf/chain/poa.mk b/makefile_conf/chain/poa.mk index c415c2640..dd9f32e93 100644 --- a/makefile_conf/chain/poa.mk +++ b/makefile_conf/chain/poa.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "POA" CHAIN_ID = 99 -APPNAME = "POA" \ No newline at end of file +APPNAME = "POA" diff --git a/makefile_conf/chain/polygon.mk b/makefile_conf/chain/polygon.mk index 9bdf2dc60..0348401ee 100644 --- a/makefile_conf/chain/polygon.mk +++ b/makefile_conf/chain/polygon.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "MATIC" CHAIN_ID = 137 -APPNAME = "Polygon" \ No newline at end of file +APPNAME = "Polygon" diff --git a/makefile_conf/chain/reosc.mk b/makefile_conf/chain/reosc.mk index 9f9cedfbd..662e8a282 100644 --- a/makefile_conf/chain/reosc.mk +++ b/makefile_conf/chain/reosc.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/2894'" TICKER = "REOSC" CHAIN_ID = 2894 -APPNAME = "REOSC" \ No newline at end of file +APPNAME = "REOSC" diff --git a/makefile_conf/chain/rsk.mk b/makefile_conf/chain/rsk.mk index dad8f56fb..bdbef873a 100644 --- a/makefile_conf/chain/rsk.mk +++ b/makefile_conf/chain/rsk.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/137'" --path "44'/00'" TICKER = "RBTC" CHAIN_ID = 30 -APPNAME = "RSK" \ No newline at end of file +APPNAME = "RSK" diff --git a/makefile_conf/chain/rsk_testnet.mk b/makefile_conf/chain/rsk_testnet.mk index 2142f7cdf..8caa3a7f6 100644 --- a/makefile_conf/chain/rsk_testnet.mk +++ b/makefile_conf/chain/rsk_testnet.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/37310'" TICKER = "RBTC" CHAIN_ID = 31 -APPNAME = "RSK Test" \ No newline at end of file +APPNAME = "RSK Test" diff --git a/makefile_conf/chain/shyft.mk b/makefile_conf/chain/shyft.mk index b578933a6..71ead2b20 100644 --- a/makefile_conf/chain/shyft.mk +++ b/makefile_conf/chain/shyft.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/60'" TICKER = "SHFT" CHAIN_ID = 7341 -APPNAME = "Shyft" \ No newline at end of file +APPNAME = "Shyft" diff --git a/makefile_conf/chain/songbird.mk b/makefile_conf/chain/songbird.mk index bc11a41a7..4c767ee0f 100644 --- a/makefile_conf/chain/songbird.mk +++ b/makefile_conf/chain/songbird.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/554'" --path "44'/60'" TICKER = "SGB" CHAIN_ID = 19 -APPNAME = "Songbird" \ No newline at end of file +APPNAME = "Songbird" diff --git a/makefile_conf/chain/tecracoin.mk b/makefile_conf/chain/tecracoin.mk index eabc8261f..87a94ffdb 100644 --- a/makefile_conf/chain/tecracoin.mk +++ b/makefile_conf/chain/tecracoin.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/554'" --path "44'/60'" TICKER = "TCR" CHAIN_ID = 20531812 -APPNAME = "TecraCoin" \ No newline at end of file +APPNAME = "TecraCoin" diff --git a/makefile_conf/chain/tecratestnet.mk b/makefile_conf/chain/tecratestnet.mk index d97ab8198..1be7c068b 100644 --- a/makefile_conf/chain/tecratestnet.mk +++ b/makefile_conf/chain/tecratestnet.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/554'" --path "44'/60'" TICKER = "TCR" CHAIN_ID = 20531811 -APPNAME = "TecraTestnet" \ No newline at end of file +APPNAME = "TecraTestnet" diff --git a/makefile_conf/chain/thundercore.mk b/makefile_conf/chain/thundercore.mk index a7a4dddd3..ea63c1af5 100644 --- a/makefile_conf/chain/thundercore.mk +++ b/makefile_conf/chain/thundercore.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/1001'" TICKER = "TT" CHAIN_ID = 108 -APPNAME = "ThunderCore" \ No newline at end of file +APPNAME = "ThunderCore" diff --git a/makefile_conf/chain/tomochain.mk b/makefile_conf/chain/tomochain.mk index 953830836..19e2f4be0 100644 --- a/makefile_conf/chain/tomochain.mk +++ b/makefile_conf/chain/tomochain.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/889'" TICKER = "TOMO" CHAIN_ID = 88 -APPNAME = "TomoChain" \ No newline at end of file +APPNAME = "TomoChain" diff --git a/makefile_conf/chain/ubiq.mk b/makefile_conf/chain/ubiq.mk index 62a4ba127..840d30401 100644 --- a/makefile_conf/chain/ubiq.mk +++ b/makefile_conf/chain/ubiq.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/108'" TICKER = "UBQ" CHAIN_ID = 8 -APPNAME = "Ubiq" \ No newline at end of file +APPNAME = "Ubiq" diff --git a/makefile_conf/chain/volta.mk b/makefile_conf/chain/volta.mk index 28f7c5610..9230cbc30 100644 --- a/makefile_conf/chain/volta.mk +++ b/makefile_conf/chain/volta.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/73799'" --path "44'/60'" TICKER = "VOLTA" CHAIN_ID = 73799 -APPNAME = "Volta" \ No newline at end of file +APPNAME = "Volta" diff --git a/makefile_conf/chain/webchain.mk b/makefile_conf/chain/webchain.mk index 3a7da247c..f2bb36496 100644 --- a/makefile_conf/chain/webchain.mk +++ b/makefile_conf/chain/webchain.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/227'" TICKER = "WEB" CHAIN_ID = 24484 -APPNAME = "Webchain" \ No newline at end of file +APPNAME = "Webchain" diff --git a/makefile_conf/chain/wethio.mk b/makefile_conf/chain/wethio.mk index fc491dffa..11b29d70a 100644 --- a/makefile_conf/chain/wethio.mk +++ b/makefile_conf/chain/wethio.mk @@ -1,4 +1,4 @@ APP_LOAD_PARAMS += --path "44'/77777'" TICKER = "ZYN" CHAIN_ID = 78 -APPNAME = "Wethio" \ No newline at end of file +APPNAME = "Wethio" diff --git a/src/plugins.c b/src/plugins.c index 42c17a9c2..025697963 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -37,4 +37,4 @@ void plugin_ui_get_item(void) { sizeof(strings.common.fullAddress), strings.common.fullAmount, sizeof(strings.common.fullAmount)); -} \ No newline at end of file +} diff --git a/src/plugins.h b/src/plugins.h index 1ccc123d4..df406c00b 100644 --- a/src/plugins.h +++ b/src/plugins.h @@ -8,4 +8,4 @@ void plugin_ui_get_item_internal(uint8_t *title_buffer, uint8_t *msg_buffer, size_t msg_buffer_size); -#endif // _PLUGIN_H_ \ No newline at end of file +#endif // _PLUGIN_H_ diff --git a/src_bagl/ui_flow_performPrivacyOperation.c b/src_bagl/ui_flow_performPrivacyOperation.c index 5c181eff9..8c870c06a 100644 --- a/src_bagl/ui_flow_performPrivacyOperation.c +++ b/src_bagl/ui_flow_performPrivacyOperation.c @@ -3,7 +3,7 @@ // clang-format off UX_STEP_NOCB( - ux_display_privacy_public_key_flow_1_step, + ux_display_privacy_public_key_flow_1_step, pnn, { &C_icon_eye, @@ -11,21 +11,21 @@ UX_STEP_NOCB( "privacy key", }); UX_STEP_NOCB( - ux_display_privacy_public_key_flow_2_step, + ux_display_privacy_public_key_flow_2_step, bnnn_paging, { .title = "Address", .text = strings.common.fullAddress, }); UX_STEP_NOCB( - ux_display_privacy_public_key_flow_3_step, + ux_display_privacy_public_key_flow_3_step, bnnn_paging, { .title = "Key", .text = strings.common.fullAmount, }); UX_STEP_CB( - ux_display_privacy_public_key_flow_4_step, + ux_display_privacy_public_key_flow_4_step, pb, io_seproxyhal_touch_privacy_ok(NULL), { @@ -33,7 +33,7 @@ UX_STEP_CB( "Approve", }); UX_STEP_CB( - ux_display_privacy_public_key_flow_5_step, + ux_display_privacy_public_key_flow_5_step, pb, io_seproxyhal_touch_privacy_cancel(NULL), { diff --git a/src_bagl/ui_plugin.c b/src_bagl/ui_plugin.c index c3743fa62..e493bd903 100644 --- a/src_bagl/ui_plugin.c +++ b/src_bagl/ui_plugin.c @@ -46,4 +46,4 @@ void display_next_plugin_item(bool entering) { } } } -} \ No newline at end of file +} diff --git a/src_nbgl/ui_get_eth2_public_key.c b/src_nbgl/ui_get_eth2_public_key.c index 9f388df27..3f6a3e70c 100644 --- a/src_nbgl/ui_get_eth2_public_key.c +++ b/src_nbgl/ui_get_eth2_public_key.c @@ -27,4 +27,4 @@ static void buildScreen(void) { void ui_display_public_eth2(void) { buildScreen(); -} \ No newline at end of file +} diff --git a/tests/speculos/.gitignore b/tests/speculos/.gitignore index 94026aa28..a6d415f89 100644 --- a/tests/speculos/.gitignore +++ b/tests/speculos/.gitignore @@ -22,4 +22,4 @@ pytestdebug.log .mypy_cache .coverage .coverage.* -coverage.xml \ No newline at end of file +coverage.xml diff --git a/tests/speculos/README.md b/tests/speculos/README.md index 68d146878..3cc7fd3c4 100644 --- a/tests/speculos/README.md +++ b/tests/speculos/README.md @@ -8,6 +8,7 @@ These tests are implemented in Python with the `SpeculosClient` interface which - [pip](https://pip.pypa.io/en/stable/installation/) ### Dependencies + Python dependencies are listed in [requirements.txt](requirements.txt) ```shell @@ -19,6 +20,7 @@ python3 -m pip install -r requirements.txt ### Compilation app Go to the root of the repository: + ```sh make DEBUG=1 NFT_TESTING_KEY=1 BOLOS_SDK=$NANOX_SDK mv bin/app.elf tests/speculos/.elf @@ -26,12 +28,13 @@ mv bin/app.elf tests/speculos/.elf Given the requirements are installed, just do (by default command): -``` +```shell cd tests/speculos/ pytest ``` ### Custom options + - **--model:** "nanos", "nanox", "nanosp" | default: "nanos" - **--display:** "qt", "headless" | default: "qt" - **--path:** the path of the binary app | default: path of makefile compilation @@ -39,6 +42,7 @@ pytest ## Example With `nanox` binary app: + ```sh # the --path is variable to where you put your binary diff --git a/tests/speculos/docs/README.md b/tests/speculos/docs/README.md index eb6df7138..8a10e58a0 100644 --- a/tests/speculos/docs/README.md +++ b/tests/speculos/docs/README.md @@ -32,6 +32,7 @@ ## Ethereum_client ### Ethereum_cmd_builder + ```py def chunked(size, source) @@ -49,6 +50,7 @@ class EthereumCommandBuilder: ``` ### Ethereum_cmd + ```py class EthereumCommand: # Sending apdu and parsing the response in the right form @@ -61,16 +63,14 @@ class EthereumCommand: def simple_sign_tx(self, bip32_path: str, transaction: Transaction, result: List = list()) -> None: def sign_eip712(self, bip32_path: str, transaction: EIP712, result: List = list()) -> None: def personal_sign_tx(self, bip32_path: str, transaction: PersonalTransaction, result: List = list()) -> None: - - # Allows to send an apdu without return of speculos def send_apdu(self, apdu: bytes) -> bytes: # Allows to send an apdu with return of speculos def send_apdu_context(self, apdu: bytes, result: List = list()) -> bytes: - ``` ### Utils + ```py def save_screenshot(cmd, path: str): def compare_screenshot(cmd, path: str): @@ -80,21 +80,23 @@ def packed_bip32_path_from_string(path: str) -> bytes: def write_varint(n: int) -> bytes: def read_varint(buf: BytesIO, prefix: Optional[bytes] = None) -> int: def read(buf: BytesIO, size: int) -> bytes: -def read_uint(buf: BytesIO, +def read_uint(buf: BytesIO, bit_len: int, byteorder: Literal['big', 'little'] = 'little') -> int: ``` ## Tests new apdu -If a new instruction is programmed it will be necessary to create 2 new functions. -one in `ethereum_cmd_builder` : +If a new instruction is programmed it will be necessary to create 2 new functions. +one in `ethereum_cmd_builder`: + - Creation of the raw apdu you can find some examples in this same file - -and one in `ethereum_cmd`: + +and one in `ethereum_cmd`: + - Send the apdu to speculos and parse the answer in a `list` named result you can find some examples in this same file ## Example for write new tests -To send several apdu and get the return +To send several apdu and get the return ```py FIRST = bytes.fromhex("{YourAPDU}") @@ -130,4 +132,3 @@ def test_some_error(cmd): pass assert error.args[0] == '0x6a80' ``` - diff --git a/tests/speculos/ethereum_client/ethereum_cmd.py b/tests/speculos/ethereum_client/ethereum_cmd.py index a13a817cf..8c575af6b 100644 --- a/tests/speculos/ethereum_client/ethereum_cmd.py +++ b/tests/speculos/ethereum_client/ethereum_cmd.py @@ -22,7 +22,7 @@ def __init__(self, self.builder = EthereumCommandBuilder(debug=debug) self.debug = debug self.model = model - + def get_configuration(self) -> Tuple[int, int, int, int]: try: response = self.client._apdu_exchange( @@ -46,7 +46,7 @@ def set_plugin(self, plugin: Plugin): self.client._apdu_exchange( self.builder.set_plugin(plugin=plugin) ) - + except ApduException as error: raise DeviceException(error_code=error.sw, ins=InsType.INS_SET_PLUGIN) @@ -79,7 +79,7 @@ def get_public_key(self, bip32_path: str, result: List, display: bool = False) - data=chunk[5:]) as exchange: yield exchange response: bytes = exchange.receive() - + except ApduException as error: raise DeviceException(error_code=error.sw, ins=InsType.INS_GET_PUBLIC_KEY) @@ -94,17 +94,17 @@ def get_public_key(self, bip32_path: str, result: List, display: bool = False) - uncompressed_addr_len: bytes = response[offset:offset + pub_key_len] offset += pub_key_len - + eth_addr_len: int = response[offset] offset += 1 - + eth_addr: bytes = response[offset:offset + eth_addr_len] offset += eth_addr_len chain_code: bytes = response[offset:] assert len(response) == 1 + pub_key_len + 1 + eth_addr_len + 32 # 32 -> chain_code_len - + result.append(uncompressed_addr_len) result.append(eth_addr) result.append(chain_code) @@ -120,7 +120,7 @@ def perform_privacy_operation(self, bip32_path: str, result: List, display: bool data=chunk[5:]) as exchange: yield exchange response: bytes = exchange.receive() - + except ApduException as error: raise DeviceException(error_code=error.sw, ins=InsType.INS_PERFORM_PRIVACY_OPERATION) @@ -146,7 +146,7 @@ def send_apdu_context(self, apdu: bytes, result: List = list()) -> bytes: data=apdu[5:]) as exchange: yield exchange result.append(exchange.receive()) - + except ApduException as error: raise DeviceException(error_code=error.sw, ins=InsType.INS_SIGN_TX) @@ -162,14 +162,14 @@ def simple_sign_tx(self, bip32_path: str, transaction: Transaction, result: List data=chunk[5:]) as exchange: yield exchange response: bytes = exchange.receive() - + except ApduException as error: raise DeviceException(error_code=error.sw, ins=InsType.INS_SIGN_TX) # response = V (1) || R (32) || S (32) assert len(response) == 65 v, r, s = parse_sign_response(response) - + result.append(v) result.append(r) result.append(s) @@ -185,14 +185,14 @@ def sign_eip712(self, bip32_path: str, transaction: EIP712, result: List = list( data=chunk[5:]) as exchange: yield exchange response: bytes = exchange.receive() - + except ApduException as error: raise DeviceException(error_code=error.sw, ins=InsType.INS_SIGN_EIP712) # response = V (1) || R (32) || S (32) assert len(response) == 65 v, r, s = parse_sign_response(response) - + result.append(v) result.append(r) result.append(s) @@ -211,16 +211,13 @@ def personal_sign_tx(self, bip32_path: str, transaction: PersonalTransaction, re response: bytes = exchange.receive() else: self.send_apdu(apdu) - + except ApduException as error: raise DeviceException(error_code=error.sw, ins=InsType.INS_SIGN_TX) # response = V (1) || R (32) || S (32) v, r, s = parse_sign_response(response) - + result.append(v) result.append(r) result.append(s) - - - diff --git a/tests/speculos/ethereum_client/ethereum_cmd_builder.py b/tests/speculos/ethereum_client/ethereum_cmd_builder.py index 2cb224e0e..dd516d415 100644 --- a/tests/speculos/ethereum_client/ethereum_cmd_builder.py +++ b/tests/speculos/ethereum_client/ethereum_cmd_builder.py @@ -156,7 +156,7 @@ def get_public_key(self, bip32_path: str, display: bool = False) -> bytes: """ cdata = packed_bip32_path_from_string(bip32_path) - + return self.serialize(cla=self.CLA, ins=InsType.INS_GET_PUBLIC_KEY, p1=0x01 if display else 0x00, @@ -172,10 +172,10 @@ def perform_privacy_operation(self, bip32_path: str, display: bool, shared_secre String representation of BIP32 path. Third party public key on Curve25519 : 32 bytes Optional if returning the shared secret - + """ cdata = packed_bip32_path_from_string(bip32_path) - + return self.serialize(cla=self.CLA, ins=InsType.INS_PERFORM_PRIVACY_OPERATION, p1=0x01 if display else 0x00, @@ -200,7 +200,7 @@ def simple_sign_tx(self, bip32_path: str, transaction: Transaction) -> bytes: """ cdata = packed_bip32_path_from_string(bip32_path) - + tx: bytes = transaction.serialize() cdata = cdata + tx @@ -230,7 +230,7 @@ def sign_eip712(self, bip32_path: str, transaction: EIP712) -> bytes: """ cdata = packed_bip32_path_from_string(bip32_path) - + tx: bytes = transaction.serialize() cdata = cdata + tx @@ -259,12 +259,12 @@ def personal_sign_tx(self, bip32_path: str, transaction: PersonalTransaction) -> """ cdata = packed_bip32_path_from_string(bip32_path) - + tx: bytes = transaction.serialize() cdata = cdata + tx last_chunk = len(cdata) // MAX_APDU_LEN - + # The generator allows to send apdu frames because we can't send an apdu > 255 for i, (chunk) in enumerate(chunked(MAX_APDU_LEN, cdata)): if i == 0 and i == last_chunk: @@ -290,4 +290,4 @@ def personal_sign_tx(self, bip32_path: str, transaction: PersonalTransaction) -> ins=InsType.INS_SIGN_PERSONAL_TX, p1=0x80, p2=0x00, - cdata=chunk) \ No newline at end of file + cdata=chunk) diff --git a/tests/speculos/ethereum_client/plugin.py b/tests/speculos/ethereum_client/plugin.py index 9274fdecd..88e7892c1 100644 --- a/tests/speculos/ethereum_client/plugin.py +++ b/tests/speculos/ethereum_client/plugin.py @@ -10,7 +10,7 @@ def __init__(self, erc20_ticker: string , addr: Union[str, bytes], nb_decimals: self.nb_decimals: int = nb_decimals self.chainID: int = chainID self.sign: bytes = bytes.fromhex(sign) - + def serialize(self) -> bytes: return b"".join([ write_varint(len(self.erc20_ticker)), @@ -67,4 +67,4 @@ def serialize(self) -> bytes: write_varint(len(self.sign)), self.sign, - ]) \ No newline at end of file + ]) diff --git a/tests/speculos/ethereum_client/transaction.py b/tests/speculos/ethereum_client/transaction.py index 4c9fe2395..64b261b36 100644 --- a/tests/speculos/ethereum_client/transaction.py +++ b/tests/speculos/ethereum_client/transaction.py @@ -88,9 +88,9 @@ class EIP712: def __init__(self, domain_hash: str, msg_hash: str) -> None: self.domain_hash = bytes.fromhex(domain_hash) self.msg_hash = bytes.fromhex(msg_hash) - + def serialize(self) -> bytes: return b"".join([ self.domain_hash, self.msg_hash - ]) \ No newline at end of file + ]) diff --git a/tests/speculos/ethereum_client/utils.py b/tests/speculos/ethereum_client/utils.py index 6b0eb6022..de03b782a 100644 --- a/tests/speculos/ethereum_client/utils.py +++ b/tests/speculos/ethereum_client/utils.py @@ -54,7 +54,7 @@ def bip32_path_from_string(path: str) -> List[bytes]: def packed_bip32_path_from_string(path: str) -> bytes: bip32_paths = bip32_path_from_string(path) - + return b"".join([ len(bip32_paths).to_bytes(1, byteorder="big"), *bip32_paths diff --git a/tests/speculos/old_test_eip191.py b/tests/speculos/old_test_eip191.py index d24ad0b7c..423bd2377 100644 --- a/tests/speculos/old_test_eip191.py +++ b/tests/speculos/old_test_eip191.py @@ -16,7 +16,7 @@ def test_personal_sign_metamask(cmd): with cmd.personal_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Sign message compare_screenshot(cmd, f"screenshots/eip191/{PATH_IMG[cmd.model]}/personal_sign_metamask/00000.png") @@ -49,7 +49,7 @@ def test_personal_sign_metamask(cmd): assert v == 0x1c # 28 assert r.hex() == "916099cf0d9c21911c85f0770a47a9696a8189e78c259cf099749748c507baae" assert s.hex() == "0d72234bc0ac2e94c5f7a5f4f9cd8610a52be4ea55515a85b9703f1bb158415c" - + def test_personal_sign_reject(cmd): result: list = [] @@ -109,7 +109,7 @@ def test_personal_sign_non_ascii(cmd): with cmd.personal_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Sign message compare_screenshot(cmd, f"screenshots/eip191/{PATH_IMG[cmd.model]}/personal_sign_non_ascii/00000.png") @@ -159,7 +159,7 @@ def test_personal_sign_opensea(cmd): with cmd.personal_sign_tx(bip32_path, transaction, result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Sign message compare_screenshot(cmd, f"screenshots/eip191/{PATH_IMG[cmd.model]}/personal_sign_opensea/00000.png") diff --git a/tests/speculos/test_eip1559.py b/tests/speculos/test_eip1559.py index f834df36c..62cb43a70 100644 --- a/tests/speculos/test_eip1559.py +++ b/tests/speculos/test_eip1559.py @@ -9,7 +9,7 @@ def test_sign_eip_1559(cmd): with cmd.send_apdu_context(apdu_sign_eip_1559, result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Review transaction compare_screenshot(cmd, f"screenshots/eip1559/{PATH_IMG[cmd.model]}/sign_eip_1559/00000.png") @@ -47,7 +47,7 @@ def test_sign_eip_1559(cmd): # Address compare_screenshot(cmd, f"screenshots/eip1559/{PATH_IMG[cmd.model]}/sign_eip_1559/00002.png") cmd.client.press_and_release('right') - + # Max Fees compare_screenshot(cmd, f"screenshots/eip1559/{PATH_IMG[cmd.model]}/sign_eip_1559/00003.png") cmd.client.press_and_release('right') diff --git a/tests/speculos/test_eip712.py b/tests/speculos/test_eip712.py index 6a72aa477..161e6eee3 100644 --- a/tests/speculos/test_eip712.py +++ b/tests/speculos/test_eip712.py @@ -176,4 +176,4 @@ def test_sign_eip_712_bad_msg(cmd): with cmd.sign_eip712(bip32_path=bip32_path, transaction=transaction, result=result) as ex: pass - assert error.args[0] == '0x6a80' \ No newline at end of file + assert error.args[0] == '0x6a80' diff --git a/tests/speculos/test_erc1155.py b/tests/speculos/test_erc1155.py index c20fe2e10..f3948a4a7 100644 --- a/tests/speculos/test_erc1155.py +++ b/tests/speculos/test_erc1155.py @@ -38,7 +38,7 @@ def test_transfer_erc1155(cmd): if cmd.model == "nanox" or cmd.model == "nanosp": cmd.set_plugin(plugin=PLUGIN) cmd.provide_nft_information(plugin=PROVIDE_NFT_INFORMATION) - + cmd.send_apdu(SIGN_FIRST) with cmd.send_apdu_context(SIGN_MORE, result) as ex: @@ -46,7 +46,7 @@ def test_transfer_erc1155(cmd): # Review transaction compare_screenshot(cmd, f"screenshots/erc1155/{PATH_IMG[cmd.model]}/transfer_erc1155/00000.png") cmd.client.press_and_release('right') - + # NFT Transfer compare_screenshot(cmd, f"screenshots/erc1155/{PATH_IMG[cmd.model]}/transfer_erc1155/00001.png") cmd.client.press_and_release('right') @@ -98,7 +98,7 @@ def test_transfer_erc1155_without_nft_provide_info(cmd): cmd.set_plugin(plugin=PLUGIN) - + cmd.send_apdu(SIGN_FIRST) with cmd.send_apdu_context(SIGN_MORE, result) as ex: @@ -114,7 +114,7 @@ def test_transfer_erc1155_without_set_plugin(cmd): with pytest.raises(ethereum_client.exception.errors.DenyError) as error: cmd.provide_nft_information(plugin=PROVIDE_NFT_INFORMATION) - + cmd.send_apdu(SIGN_FIRST) with cmd.send_apdu_context(SIGN_MORE, result) as ex: @@ -161,7 +161,7 @@ def test_transfer_batch_erc1155(cmd): if cmd.model == "nanox" or cmd.model == "nanosp": cmd.set_plugin(plugin=PLUGIN_BATCH) cmd.provide_nft_information(plugin=PROVIDE_NFT_INFORMATION_BATCH) - + cmd.send_apdu(SIGN_FIRST_BATCH) cmd.send_apdu(SIGN_MORE_1_BATCH) cmd.send_apdu(SIGN_MORE_2_BATCH) diff --git a/tests/speculos/test_erc20information.py b/tests/speculos/test_erc20information.py index 9af2c7b3d..de01c638c 100644 --- a/tests/speculos/test_erc20information.py +++ b/tests/speculos/test_erc20information.py @@ -28,4 +28,4 @@ def test_provide_erc20_token_error(cmd): with pytest.raises(ethereum_client.exception.errors.UnknownDeviceError) as error: cmd.provide_erc20_token_information(info=erc20_info) - assert error.args[0] == '0x6a80' \ No newline at end of file + assert error.args[0] == '0x6a80' diff --git a/tests/speculos/test_erc721.py b/tests/speculos/test_erc721.py index 865250144..c492f65a4 100644 --- a/tests/speculos/test_erc721.py +++ b/tests/speculos/test_erc721.py @@ -38,7 +38,7 @@ def test_transfer_erc721(cmd): if cmd.model == "nanox" or cmd.model == "nanosp": cmd.set_plugin(plugin=PLUGIN) cmd.provide_nft_information(plugin=PROVIDE_NFT_INFORMATION) - + cmd.send_apdu(SIGN_FIRST) with cmd.send_apdu_context(SIGN_MORE, result) as ex: @@ -46,7 +46,7 @@ def test_transfer_erc721(cmd): # Review transaction compare_screenshot(cmd, f"screenshots/erc721/{PATH_IMG[cmd.model]}/transfer_erc721/00000.png") cmd.client.press_and_release('right') - + # NFT Transfer compare_screenshot(cmd, f"screenshots/erc721/{PATH_IMG[cmd.model]}/transfer_erc721/00001.png") cmd.client.press_and_release('right') @@ -97,7 +97,7 @@ def test_transfer_erc721_without_nft_provide_info(cmd): pass assert error.args[0] == '0x6a80' - + def test_transfer_erc721_without_set_plugin(cmd): @@ -106,10 +106,10 @@ def test_transfer_erc721_without_set_plugin(cmd): if cmd.model == "nanox" or cmd.model == "nanosp": with pytest.raises(ethereum_client.exception.errors.DenyError) as error: cmd.provide_nft_information(plugin=PROVIDE_NFT_INFORMATION) - + cmd.send_apdu(SIGN_FIRST) with cmd.send_apdu_context(SIGN_MORE, result) as ex: pass - - assert error.args[0] == '0x6985' \ No newline at end of file + + assert error.args[0] == '0x6985' diff --git a/tests/speculos/test_pubkey_cmd.py b/tests/speculos/test_pubkey_cmd.py index 17f1d78b4..451bbf9aa 100644 --- a/tests/speculos/test_pubkey_cmd.py +++ b/tests/speculos/test_pubkey_cmd.py @@ -92,11 +92,11 @@ def test_reject_get_public_key(cmd): # Approve compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00004.png") cmd.client.press_and_release('right') - + # Reject compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00005.png") cmd.client.press_and_release('both') - + if cmd.model == "nanox" or cmd.model == "nanosp": # Verify address compare_screenshot(cmd, f"screenshots/pubkey/{PATH_IMG[cmd.model]}/reject_get_public_key/00000.png") diff --git a/tests/speculos/test_sign_cmd.py b/tests/speculos/test_sign_cmd.py index 90879acd3..5da7ef6ec 100644 --- a/tests/speculos/test_sign_cmd.py +++ b/tests/speculos/test_sign_cmd.py @@ -27,7 +27,7 @@ def test_sign_simple(cmd): with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Review transaction compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/simple/00000.png") @@ -87,7 +87,7 @@ def test_sign_simple(cmd): def test_sign_reject(cmd): result: list = [] - + # Ether coin type bip32_path="44'/60'/1'/0/0" @@ -134,7 +134,7 @@ def test_sign_reject(cmd): # Accept and send compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/reject/00008.png") cmd.client.press_and_release('right') - + # Reject compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/reject/00009.png") cmd.client.press_and_release('both') @@ -169,7 +169,7 @@ def test_sign_reject(cmd): def test_sign_limit_nonce(cmd): result: list = [] - + # Ether coin type bip32_path="44'/60'/1'/0/0" @@ -246,7 +246,7 @@ def test_sign_limit_nonce(cmd): def test_sign_error_transaction_type(cmd): result: list = [] - + # Ether coin type bip32_path="44'/60'/1'/0/0" @@ -311,7 +311,7 @@ def test_sign_nonce_display(cmd): with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Review transaction compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/nonce_display/00000.png") @@ -413,7 +413,7 @@ def test_sign_blind_simple(cmd): with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Review transaction compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/blind_simple/00000.png") @@ -546,7 +546,7 @@ def test_sign_blind_and_nonce_display(cmd): with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex: sleep(0.5) - + if cmd.model == "nanos": # Review transaction compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/blind_and_nonce_display/00000.png") diff --git a/tests/unit/.gitignore b/tests/unit/.gitignore index 2cbee4ed1..c77e954dc 100644 --- a/tests/unit/.gitignore +++ b/tests/unit/.gitignore @@ -19,4 +19,4 @@ build/ # Coverage file coverage.info -coverage \ No newline at end of file +coverage diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 93605b2df..3683680a9 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -62,4 +62,4 @@ add_library(demo SHARED ./demo_tu.c) target_link_libraries(test_demo PUBLIC cmocka gcov demo) -add_test(test_demo test_demo) \ No newline at end of file +add_test(test_demo test_demo) diff --git a/tests/unit/Makefile b/tests/unit/Makefile index 71d8a14fc..91d1bfd1b 100644 --- a/tests/unit/Makefile +++ b/tests/unit/Makefile @@ -39,4 +39,4 @@ clean: @if [ -d coverage ]; then $(ECHO) -e "${RED}[ RM ]${RESET}" coverage && $(RM) -r coverage ; fi; @if [ -f coverage.info ]; then $(ECHO) -e "${RED}[ RM ]${RESET}" coverage.info && $(RM) -r coverage.info ; fi; -.PHONY: all coverage clean \ No newline at end of file +.PHONY: all coverage clean diff --git a/tests/unit/README.md b/tests/unit/README.md index 68a98f28b..bb2ab7f29 100644 --- a/tests/unit/README.md +++ b/tests/unit/README.md @@ -1,7 +1,7 @@ # Unit tests -It is important to unit test your functions. -This also allows you to document how your functions work. +It is important to unit test your functions. +This also allows you to document how your functions work. We use the library [**cmocka**](https://cmocka.org/#features) ## Requirement @@ -9,11 +9,12 @@ We use the library [**cmocka**](https://cmocka.org/#features) - [CMake >= 3.10](https://cmake.org/download/) - [lcov >= 1.14](http://ltp.sourceforge.net/coverage/lcov.php) -Don't worry, you don't necessarily need to install the `cmocka library` because the **cmakelist automatically fetches** the library +Don't worry, you don't necessarily need to install the `cmocka library` +because the **cmakelist automatically fetches** the library ## Add new test -Create new file into `tests` folder and follow [this initiation](https://cmocka.org/talks/cmocka_unit_testing_and_mocking.pdf) +Create new file into `tests` folder and follow [this initiation](https://cmocka.org/talks/cmocka_unit_testing_and_mocking.pdf) Now go to the `CMakeLists.txt` file and add your test with the specific file you want to test. @@ -27,12 +28,15 @@ The `default rules` of makefile will compile the tests and run them. make ``` -The `coverage rule` will launch the default rules and generate the coverage and you will be **automatically redirected** to the generated .html +The `coverage rule` will launch the default rules and generate the coverage +and you will be **automatically redirected** to the generated .html + ```sh make coverage ``` The `clean rule` will delete the folders and files generated + ```sh make clean -``` \ No newline at end of file +``` diff --git a/tests/unit/demo_tu.c b/tests/unit/demo_tu.c index c4f450cad..1287e7c69 100644 --- a/tests/unit/demo_tu.c +++ b/tests/unit/demo_tu.c @@ -9,4 +9,4 @@ int local_strchr_demo(char *string, char ch) { } } return -1; -} \ No newline at end of file +} diff --git a/tests/unit/tests/demo.c b/tests/unit/tests/demo.c index 1da227dc9..cdc9d9a65 100644 --- a/tests/unit/tests/demo.c +++ b/tests/unit/tests/demo.c @@ -15,4 +15,4 @@ int main(void) { cmocka_unit_test(null_test_success), }; return cmocka_run_group_tests(tests, NULL, NULL); -} \ No newline at end of file +} diff --git a/tests/zemu/.gitignore b/tests/zemu/.gitignore index 826d3f011..fedc35235 100644 --- a/tests/zemu/.gitignore +++ b/tests/zemu/.gitignore @@ -1,4 +1,4 @@ /node_modules /snapshots-tmp /elfs -/lib \ No newline at end of file +/lib diff --git a/tests/zemu/Makefile b/tests/zemu/Makefile index 82d770661..0ff9a8419 100644 --- a/tests/zemu/Makefile +++ b/tests/zemu/Makefile @@ -5,4 +5,4 @@ all: yarn install yarn test -.PHONY: all \ No newline at end of file +.PHONY: all diff --git a/tests/zemu/globalsetup.js b/tests/zemu/globalsetup.js index e83523342..ce41bc60d 100644 --- a/tests/zemu/globalsetup.js +++ b/tests/zemu/globalsetup.js @@ -14,4 +14,4 @@ module.exports = async () => { await Zemu.checkAndPullImage(); await Zemu.stopAllEmuContainers(); fsExtra.emptyDirSync("snapshots/tmp") -}; \ No newline at end of file +}; diff --git a/tests/zemu/jest.js b/tests/zemu/jest.js index 521ecbe62..c5156ab7f 100644 --- a/tests/zemu/jest.js +++ b/tests/zemu/jest.js @@ -19,4 +19,4 @@ export const sim_options_x = { export const Resolve = require("path").resolve; export const NANOS_ELF_PATH = Resolve("elfs/ethereum_nanos.elf"); -export const NANOX_ELF_PATH = Resolve("elfs/ethereum_nanox.elf"); \ No newline at end of file +export const NANOX_ELF_PATH = Resolve("elfs/ethereum_nanox.elf"); diff --git a/tests/zemu/setupTests.js b/tests/zemu/setupTests.js index cbd02302e..a9a9f827b 100644 --- a/tests/zemu/setupTests.js +++ b/tests/zemu/setupTests.js @@ -16,4 +16,4 @@ expect.extend({ } } }, - }); \ No newline at end of file + });