Skip to content

Commit

Permalink
Fix HDPath validation and CLA in recovery app (Zondax#10)
Browse files Browse the repository at this point in the history
* fix hdpath validation

* bump version

* fix cla for generic

* add API avail recovery app

* update zxlib and js
  • Loading branch information
abenso authored Dec 17, 2024
1 parent 0a064c6 commit 5cbe512
Show file tree
Hide file tree
Showing 198 changed files with 152 additions and 12 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ zemu_install: tests_tools_build

test_all:
make zemu_install

echo "Testing recovery"
make clean
SUBSTRATE_PARSER_FULL=1 COIN=AVAIL_RECOVERY make
cd tests_zemu && yarn test_recovery && cd ..

echo "Testing standard"
make clean
SUBSTRATE_PARSER_FULL=1 make
make clean_build
SUBSTRATE_PARSER_FULL=1 SUPPORT_SR25519=1 make buildS
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=1
# This is the `spec_version` field of `Runtime`
APPVERSION_N=39
# This is the patch version of this release
APPVERSION_P=0
APPVERSION_P=1
11 changes: 11 additions & 0 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ void extractHDPath(uint32_t rx, uint32_t offset) {

memcpy(hdPath, G_io_apdu_buffer + offset, sizeof(uint32_t) * HDPATH_LEN_DEFAULT);

#ifdef RECOVERY_APP
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT &&
hdPath[1] == HDPATH_1_RECOVERY;
#else
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT &&
hdPath[1] == HDPATH_1_DEFAULT;
#endif

if (!mainnet) {
THROW(APDU_CODE_DATA_INVALID);
Expand Down Expand Up @@ -249,9 +254,15 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
{
TRY
{
#ifdef RECOVERY_APP
if (G_io_apdu_buffer[OFFSET_CLA] != CLA_RECOVERY) {
THROW(APDU_CODE_CLA_NOT_SUPPORTED);
}
#else
if (G_io_apdu_buffer[OFFSET_CLA] != CLA) {
THROW(APDU_CODE_CLA_NOT_SUPPORTED);
}
#endif

if (rx < APDU_MIN_LENGTH) {
THROW(APDU_CODE_WRONG_LENGTH);
Expand Down
3 changes: 2 additions & 1 deletion app/src/substrate/substrate_coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ extern "C" {

#define COIN_ADDR_TYPE 42
#define CLA 0xbc
#define CLA_RECOVERY 0xbe

#define INS_SIGN_RAW 0x03

#define HDPATH_LEN_DEFAULT 5
#define HDPATH_0_DEFAULT (0x80000000 | 0x2c)
#define HDPATH_1_DEFAULT (0x80000000 | 0x2c5)
#define HDPATH_1_RECOVERY (0x80000000 | 0x2c5)
#define HDPATH_1_RECOVERY (0x80000000 | 0x162)

#define HDPATH_2_DEFAULT (0x80000000u | 0u)
#define HDPATH_3_DEFAULT (0u)
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib
Submodule ledger-zxlib updated 59 files
+34 −39 app/common/app_main.c
+31 −30 app/common/app_main.h
+37 −26 app/ui/view.c
+9 −2 app/ui/view.h
+35 −37 app/ui/view_inspect_s.c
+42 −1 app/ui/view_internal.h
+97 −89 app/ui/view_nano.c
+1 −1 app/ui/view_nano.h
+15 −14 app/ui/view_nano_inspect.h
+12 −12 app/ui/view_nbgl.c
+107 −7 app/ui/view_s.c
+306 −148 app/ui/view_x.c
+1 −1 dockerized_build.mk
+32 −33 include/apdu_codes.h
+19 −16 include/app_mode.h
+19 −21 include/base58.h
+1 −1 include/base64.h
+1 −1 include/bech32.h
+1 −1 include/bignum.h
+1 −6 include/bittools.h
+17 −20 include/buffering.h
+15 −15 include/hexutils.h
+8 −35 include/segwit_addr.h
+15 −18 include/sigutils.h
+17 −16 include/timeutils.h
+318 −415 include/utf8.h
+145 −149 include/view_templates.h
+14 −14 include/zxcanary.h
+51 −49 include/zxerror.h
+74 −79 include/zxformat.h
+14 −14 include/zxtypes.h
+2 −3 include/zxutils_ledger.h
+4 −4 include/zxversion.h
+1 −1 scripts/install_deps.sh
+1 −1 scripts/template.sh
+27 −3 src/app_mode.c
+40 −48 src/base58.c
+20 −20 src/base64.c
+20 −23 src/bech32.c
+24 −27 src/bignum.c
+20 −26 src/buffering.c
+24 −25 src/hexutils.c
+14 −22 src/segwit_addr.c
+17 −21 src/sigutils.c
+76 −686 src/timeutils.c
+19 −17 src/zxcanary.c
+30 −30 src/zxformat.c
+133 −134 src/zxutils_ledger.c
+1 −1 templates/Makefile.root
+1 −1 tests/asciify.cpp
+1 −1 tests/base64.cpp
+1 −1 tests/bech32.cpp
+1 −1 tests/bip44path.cpp
+1 −1 tests/buffering_tests.cpp
+1 −1 tests/doubledabble.cpp
+1 −1 tests/hexutils.cpp
+1 −1 tests/macros.cpp
+1 −1 tests/sigutils.cpp
+1 −1 tests/zxformat.cpp
19 changes: 10 additions & 9 deletions tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@
],
"scripts": {
"clean": "ts-node tests/pullImageKillOld.ts",
"test": "yarn clean && jest --maxConcurrency 3"
"test": "yarn clean && jest --maxConcurrency 3 --testPathIgnorePatterns recovery.test.ts",
"test_recovery": "yarn clean && jest --maxConcurrency 3 recovery.test.ts"
},
"dependencies": {
"@zondax/ledger-substrate": "^1.0.0",
"@zondax/zemu": "^0.51.0"
"@zondax/ledger-substrate": "^1.0.1",
"@zondax/zemu": "^0.53.0"
},
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/ledgerhq__hw-transport": "^4.21.8",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"blakejs": "^1.2.1",
"crypto-js": "4.2.0",
"ed25519-supercop": "^2.0.1",
"eslint": "^9.13.0",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-jest": "^28.9.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "29.7.0",
"jssha": "^3.3.1",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
"typescript": "^5.7.2"
}
}
Binary file modified tests_zemu/snapshots/fl-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer/00009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00002.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00003.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00004.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00005.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00008.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00009.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00012.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00013.png
Binary file modified tests_zemu/snapshots/sp-balances_transfer_expert/00015.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00000.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00001.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00002.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00003.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00005.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00009.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00011.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00012.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00001.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00002.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00003.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00004.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00006.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00009.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00010.png
Binary file modified tests_zemu/snapshots/sp-proxy_proxy/00012.png
Binary file modified tests_zemu/snapshots/sp-raw_sign/00001.png
Binary file modified tests_zemu/snapshots/sp-raw_sign/00002.png
Binary file modified tests_zemu/snapshots/sp-raw_sign/00004.png
Binary file modified tests_zemu/snapshots/sp-raw_sign_hex/00001.png
Binary file modified tests_zemu/snapshots/sp-raw_sign_hex/00002.png
Binary file modified tests_zemu/snapshots/sp-raw_sign_hex/00003.png
Binary file modified tests_zemu/snapshots/sp-raw_sign_hex/00004.png
Binary file modified tests_zemu/snapshots/sp-raw_sign_hex/00006.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00001.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00002.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00003.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00004.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00005.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00006.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00007.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00009.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00010.png
Binary file modified tests_zemu/snapshots/sp-session_setkeys/00012.png
Binary file modified tests_zemu/snapshots/sp-show_address/00001.png
Binary file modified tests_zemu/snapshots/sp-show_address/00003.png
Binary file modified tests_zemu/snapshots/sp-show_address_reject/00001.png
Binary file modified tests_zemu/snapshots/sp-show_address_reject/00003.png
Binary file modified tests_zemu/snapshots/sp-show_address_reject/00004.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00002.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00003.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00004.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00005.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00006.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00007.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00008.png
Binary file modified tests_zemu/snapshots/sp-staking_nominate/00010.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00001.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00002.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00003.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00004.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00005.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00006.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00007.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00008.png
Binary file modified tests_zemu/snapshots/sp-utility_batch/00010.png
Binary file modified tests_zemu/snapshots/st-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/x-balances_transfer/00002.png
Binary file modified tests_zemu/snapshots/x-balances_transfer/00003.png
Binary file modified tests_zemu/snapshots/x-balances_transfer/00004.png
Binary file modified tests_zemu/snapshots/x-balances_transfer/00005.png
Binary file modified tests_zemu/snapshots/x-balances_transfer/00006.png
Binary file modified tests_zemu/snapshots/x-balances_transfer/00007.png
Binary file modified tests_zemu/snapshots/x-balances_transfer/00009.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00002.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00003.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00004.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00005.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00008.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00009.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00012.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00013.png
Binary file modified tests_zemu/snapshots/x-balances_transfer_expert/00015.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00000.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00001.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00002.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00003.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00005.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00009.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00011.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00012.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00001.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00002.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00003.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00004.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00006.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00009.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00010.png
Binary file modified tests_zemu/snapshots/x-proxy_proxy/00012.png
Binary file modified tests_zemu/snapshots/x-raw_sign/00001.png
Binary file modified tests_zemu/snapshots/x-raw_sign/00002.png
Binary file modified tests_zemu/snapshots/x-raw_sign/00004.png
Binary file modified tests_zemu/snapshots/x-raw_sign_hex/00001.png
Binary file modified tests_zemu/snapshots/x-raw_sign_hex/00002.png
Binary file modified tests_zemu/snapshots/x-raw_sign_hex/00003.png
Binary file modified tests_zemu/snapshots/x-raw_sign_hex/00004.png
Binary file modified tests_zemu/snapshots/x-raw_sign_hex/00006.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00001.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00002.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00003.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00004.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00005.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00006.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00007.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00009.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00010.png
Binary file modified tests_zemu/snapshots/x-session_setkeys/00012.png
Binary file modified tests_zemu/snapshots/x-show_address/00001.png
Binary file modified tests_zemu/snapshots/x-show_address/00003.png
Binary file modified tests_zemu/snapshots/x-show_address_reject/00001.png
Binary file modified tests_zemu/snapshots/x-show_address_reject/00003.png
Binary file modified tests_zemu/snapshots/x-show_address_reject/00004.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00002.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00003.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00004.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00005.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00006.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00007.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00008.png
Binary file modified tests_zemu/snapshots/x-staking_nominate/00010.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00001.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00002.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00003.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00004.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00005.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00006.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00007.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00008.png
Binary file modified tests_zemu/snapshots/x-utility_batch/00010.png
119 changes: 119 additions & 0 deletions tests_zemu/tests/recovery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/** ******************************************************************************
* (c) 2020 Zondax GmbH
*
* 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.
******************************************************************************* */

import Zemu, { ButtonKind, DEFAULT_START_OPTIONS, isTouchDevice } from '@zondax/zemu'
import { newSubstrateApp } from '@zondax/ledger-substrate'
import { APP_SEED, models } from './common'

const defaultOptions = {
...DEFAULT_START_OPTIONS,
logging: true,
custom: `-s "${APP_SEED}"`,
X11: false,
}

const expected_address_recovery = '5HAeMNeM1XzB9ab742XyV8rM4u1wsAUiQQod61n9cjMTrKbn'
const expected_pk_recovery = 'e1b4d72d27b3e91b9b6116555b4ea17138ddc12ca7cdbab30e2e0509bd848419'

jest.setTimeout(180000)

describe('Standard', function () {
test.concurrent.each(models)('can start and stop container', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
} finally {
await sim.close()
}
})

test.concurrent.each(models)('get address recovery', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = newSubstrateApp(sim.getTransport(), 'AvailRecovery')

const resp = await app.getAddress(0x80000000, 0x80000000, 0x80000000)

console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')

expect(resp.address).toEqual(expected_address_recovery)
expect(resp.pubKey).toEqual(expected_pk_recovery)
} finally {
await sim.close()
}
})

test.concurrent.each(models)('show address recovery', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({
...defaultOptions,
model: m.name,
approveKeyword: isTouchDevice(m.name) ? 'Confirm' : '',
approveAction: ButtonKind.ApproveTapButton,
})
const app = newSubstrateApp(sim.getTransport(), 'AvailRecovery')

const respRequest = app.getAddress(0x80000000, 0x80000000, 0x80000000, true)
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-recovery_show_address`)

const resp = await respRequest

console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')

expect(resp.address).toEqual(expected_address_recovery)
expect(resp.pubKey).toEqual(expected_pk_recovery)
} finally {
await sim.close()
}
})

test.concurrent.each(models)('show address recovery - reject', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({
...defaultOptions,
model: m.name,
approveKeyword: isTouchDevice(m.name) ? 'Confirm' : '',
})
const app = newSubstrateApp(sim.getTransport(), 'AvailRecovery')

const respRequest = app.getAddress(0x80000000, 0x80000000, 0x80000000, true)
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())

await sim.compareSnapshotsAndReject('.', `${m.prefix.toLowerCase()}-recovery_show_address_reject`)

const resp = await respRequest
console.log(resp)

expect(resp.return_code).toEqual(0x6986)
expect(resp.error_message).toEqual('Transaction rejected')

} finally {
await sim.close()
}
})
})

0 comments on commit 5cbe512

Please sign in to comment.