From 5d44ae52ef7de6bafcdd4efa5fb0f3979a68242b Mon Sep 17 00:00:00 2001 From: neithanmo Date: Fri, 26 Jul 2024 13:45:50 -0600 Subject: [PATCH] Fix approval for stax target --- tests_zemu/tests/_config.ts | 25 +++++++++---- tests_zemu/tests/addresses.test.ts | 41 ++++++++------------- tests_zemu/tests/basic.test.ts | 27 ++++---------- tests_zemu/tests/keys.test.ts | 53 +++++++-------------------- tests_zemu/tests/txs_advanced.test.ts | 35 +++++++++--------- tests_zemu/tests/txs_basic.test.ts | 27 ++++---------- 6 files changed, 79 insertions(+), 129 deletions(-) diff --git a/tests_zemu/tests/_config.ts b/tests_zemu/tests/_config.ts index 22b402e5..effcc2a7 100644 --- a/tests_zemu/tests/_config.ts +++ b/tests_zemu/tests/_config.ts @@ -1,4 +1,4 @@ -import { IDeviceModel, DEFAULT_START_OPTIONS } from '@zondax/zemu' +import { IDeviceModel, DEFAULT_START_OPTIONS, ButtonKind } from '@zondax/zemu' import { resolve } from 'path' @@ -16,10 +16,21 @@ export const models: IDeviceModel[] = [ { name: 'stax', prefix: 'ST', path: APP_PATH_ST }, ] -export const defaultOptions = { - ...DEFAULT_START_OPTIONS, - // startText: "DO NOT USE", - logging: true, - custom: `-s "${APP_SEED}"`, - X11: false, +export const defaultOptions = (m: IDeviceModel, is_address = false) => { + let approveAction = ButtonKind.ApproveHoldButton + let approveKeyword = '' + + if (m.name == 'stax' && is_address) { + approveKeyword = 'Show as QR' + approveAction = ButtonKind.ApproveTapButton + } + + return { + ...DEFAULT_START_OPTIONS, + logging: true, + custom: `-s "${APP_SEED}"`, + approveAction, + approveKeyword, + model: m.name, + } } diff --git a/tests_zemu/tests/addresses.test.ts b/tests_zemu/tests/addresses.test.ts index e4f9d9d9..39f09b81 100644 --- a/tests_zemu/tests/addresses.test.ts +++ b/tests_zemu/tests/addresses.test.ts @@ -15,16 +15,20 @@ ******************************************************************************* */ import Zemu, { ButtonKind } from '@zondax/zemu' -import { defaultOptions, models } from './_config' +import { defaultOptions as commonOpts, models } from './_config' import ZCashApp from '@zondax/ledger-zcash' jest.setTimeout(60000) +const defaultOptions = (model: any, is_address = false) => { + let opts = commonOpts(model, is_address) + return opts +} describe('Addresses', function () { - test.each(models)('get unshielded address', async function (m) { + test.each(models)('get_unshielded_address', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) const expectedAddrRaw = '031f6d238009787c20d5d7becb6b6ad54529fc0a3fd35088e85c2c3966bfec050e' const expectedAddr = 't1KHG39uhsssPkYcAXkzZ5Bk2w1rnFukZvx' @@ -39,15 +43,10 @@ describe('Addresses', function () { } }) - test.each(models)('show unshielded address', async function (m) { + test.each(models)('show_unshielded_address', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const expectedAddrRaw = '026f27818e7426a10773226b3553d0afe50a3697bd02652f1b57d67bf648577d11' @@ -65,10 +64,10 @@ describe('Addresses', function () { } }) - test.each(models)('get shielded address', async function (m) { + test.each(models)('get_shielded_address', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 + 0x80000000 @@ -87,7 +86,7 @@ describe('Addresses', function () { test.each(models)('get invalid shielded address', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 @@ -100,12 +99,7 @@ describe('Addresses', function () { test.each(models)('show shielded address', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 + 0x80000000 @@ -126,15 +120,10 @@ describe('Addresses', function () { } }) - test.each(models)('get shielded address with div', async function (m) { + test.each(models)('show_shielded_address_with_div', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 + 0x80000000 diff --git a/tests_zemu/tests/basic.test.ts b/tests_zemu/tests/basic.test.ts index 52f77a3d..64c6c9af 100644 --- a/tests_zemu/tests/basic.test.ts +++ b/tests_zemu/tests/basic.test.ts @@ -15,21 +15,20 @@ ******************************************************************************* */ import Zemu, { ButtonKind, zondaxMainmenuNavigation } from '@zondax/zemu' -import { defaultOptions, models } from './_config' +import { defaultOptions as commonOpts, models } from './_config' import ZCashApp from '@zondax/ledger-zcash' jest.setTimeout(60000) +const defaultOptions = (model: any) => { + let opts = commonOpts(model, false) + return opts +} describe('Basic', function () { test.each(models)('can start and stop container', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m)) } finally { await sim.close() } @@ -38,12 +37,7 @@ describe('Basic', function () { test.each(models)('main menu', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m)) const nav = zondaxMainmenuNavigation(m.name, [1, 0, 0, 4, -5]) await sim.navigateAndCompareSnapshots('.', `${m.prefix.toLowerCase()}-mainmenu`, nav.schedule) } finally { @@ -54,12 +48,7 @@ describe('Basic', function () { test.each(models)('get app version', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) const resp = await app.getVersion() diff --git a/tests_zemu/tests/keys.test.ts b/tests_zemu/tests/keys.test.ts index 3aced372..7e6b0d54 100644 --- a/tests_zemu/tests/keys.test.ts +++ b/tests_zemu/tests/keys.test.ts @@ -16,26 +16,19 @@ import Zemu, { ButtonKind, DEFAULT_START_OPTIONS } from '@zondax/zemu' import ZCashApp from '@zondax/ledger-zcash' -import { APP_SEED, models } from './_config' - -const defaultOptions = { - ...DEFAULT_START_OPTIONS, - logging: true, - custom: `-s "${APP_SEED}"`, -} +import { APP_SEED, defaultOptions as commonOpts, models } from './_config' jest.setTimeout(600000) +const defaultOptions = (model: any, is_address = false) => { + let opts = commonOpts(model, is_address) + return opts +} describe('Nullifier', function () { test.each(models)('get nullifier account 0x01', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 0x01 + 0x80000000 @@ -57,15 +50,10 @@ describe('Nullifier', function () { } }) - test.each(models)('get nullifier account 0xFF', async function (m) { + test.each(models)('get_nullifier_account_0xFF', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const path = 0xff + 0x80000000 @@ -88,16 +76,11 @@ describe('Nullifier', function () { }) }) -describe('Get keys', function () { +describe('Get_keys', function () { test.each(models)('get ivk', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 + 0x80000000 @@ -125,12 +108,7 @@ describe('Get keys', function () { test.each(models)('get ovk', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 + 0x80000000 @@ -153,12 +131,7 @@ describe('Get keys', function () { test.each(models)('Get fvk', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m, true)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 + 0x80000000 @@ -192,7 +165,7 @@ describe('Diversifiers', function () { test.each(models)('Div list with startindex', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) const zip32Account = 1000 + 0x80000000 diff --git a/tests_zemu/tests/txs_advanced.test.ts b/tests_zemu/tests/txs_advanced.test.ts index e1213a42..18c4d695 100644 --- a/tests_zemu/tests/txs_advanced.test.ts +++ b/tests_zemu/tests/txs_advanced.test.ts @@ -16,7 +16,7 @@ import Zemu, { ButtonKind, DEFAULT_START_OPTIONS } from '@zondax/zemu' import ZCashApp from '@zondax/ledger-zcash' -import { APP_SEED, models } from './_config' +import { APP_SEED, defaultOptions as commonOpts, models } from './_config' import { get_inittx_data, ZcashBuilderBridge, SPEND_PATH, OUTPUT_PATH } from '@zondax/zcashtools' import { fee_for, TX_INPUT_DATA } from './_vectors' import crypto from 'crypto' @@ -25,10 +25,9 @@ import { LedgerError } from '@zondax/ledger-js' const tx_version = 0x05 -const defaultOptions = { - ...DEFAULT_START_OPTIONS, - logging: true, - custom: `-s "${APP_SEED}"`, +const defaultOptions = (model: any) => { + let opts = commonOpts(model, false) + return opts } jest.setTimeout(600000) @@ -37,7 +36,7 @@ describe('End to end transactions', function () { test.each(models)('tx_1transparent_input_1spend_input_2sapling_outputs', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -251,7 +250,7 @@ describe('End to end transactions', function () { test.each(models)('tx_2_transparent_output_1_spend_2_shielded_outputs', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -498,7 +497,7 @@ describe('End to end transactions', function () { test.each(models)('make_transaction_with_2_transparent_input_1transparent_output_1spend_2shielded_outputs', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -722,7 +721,7 @@ describe('End to end transactions', function () { test.each(models)('make_transaction_with_2transparent_input_2transparent_output', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -839,7 +838,7 @@ describe('End to end transactions', function () { test.each(models)('ExtractingSignaturesWithoutCheckandsign', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -892,7 +891,7 @@ describe('Failing transactions', function () { test.each(models)('try_to_extract_spend_data_without_calling_inittx', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) await expect(app.extractSpendData()).rejects.toThrow('Data is invalid') @@ -904,7 +903,7 @@ describe('Failing transactions', function () { test.each(models)('extractingOutputNoSpendData', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -935,7 +934,7 @@ describe('Failing transactions', function () { test.each(models)('extracting_more_signatures_than_needed', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -1139,7 +1138,7 @@ describe('Failing transactions', function () { test.each(models)('not_using_ledger_rand_for_tx', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -1315,7 +1314,7 @@ describe('Failing transactions', function () { test.each(models)('use_other_address_in_builder_than_inittx', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -1494,7 +1493,7 @@ describe('Failing transactions', function () { test.each(models)('tryNonZIP0317Fee', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) //use stringify+parse for deep copy @@ -1520,7 +1519,7 @@ describe('Failing transactions', function () { test.skip.each(models)('extract_data_after_tx_reject', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ ...defaultOptions, model: m.name, rejectKeyword: m.name === 'stax' ? 'Hold' : '' }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -1559,7 +1558,7 @@ describe('Failing transactions', function () { const sim = new Zemu(m.path) const bad_tx_version = 7 try { - await sim.start({ ...defaultOptions, model: m.name }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) diff --git a/tests_zemu/tests/txs_basic.test.ts b/tests_zemu/tests/txs_basic.test.ts index 421b2597..21fd7974 100644 --- a/tests_zemu/tests/txs_basic.test.ts +++ b/tests_zemu/tests/txs_basic.test.ts @@ -15,7 +15,7 @@ ******************************************************************************* */ import Zemu, { ButtonKind } from '@zondax/zemu' -import { defaultOptions, models } from './_config' +import { defaultOptions as commonOpts, models } from './_config' import ZCashApp from '@zondax/ledger-zcash' import { get_inittx_data, OUTPUT_PATH, SPEND_PATH, ZcashBuilderBridge } from '@zondax/zcashtools' import { fee_for, TX_INPUT_DATA } from './_vectors' @@ -25,17 +25,16 @@ import { Signatures } from '@zondax/zcashtools/build/native' jest.setTimeout(600000) const tx_version = 0x05 +const defaultOptions = (model: any) => { + let opts = commonOpts(model, false) + return opts +} describe('tx methods', function () { test.each(models)('txinit', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) const tx_input_data = TX_INPUT_DATA[0] @@ -59,12 +58,7 @@ describe('tx methods', function () { test.each(models)('PARTIAL1 - make a transaction with 2 spend 2 outputs', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH) @@ -169,12 +163,7 @@ describe('tx methods', function () { test.each(models)('PARTIAL2 - make a transaction with 2 spend 2 outputs', async function (m) { const sim = new Zemu(m.path) try { - await sim.start({ - ...defaultOptions, - model: m.name, - approveKeyword: m.name === 'stax' ? 'QR' : '', - approveAction: ButtonKind.ApproveTapButton, - }) + await sim.start(defaultOptions(m)) const app = new ZCashApp(sim.getTransport()) console.log(SPEND_PATH)