Skip to content

Commit

Permalink
Fix approval for stax target
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo committed Jul 26, 2024
1 parent 25c3b9e commit 5d44ae5
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 129 deletions.
25 changes: 18 additions & 7 deletions tests_zemu/tests/_config.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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,
}
}
41 changes: 15 additions & 26 deletions tests_zemu/tests/addresses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
27 changes: 8 additions & 19 deletions tests_zemu/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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 {
Expand All @@ -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()
Expand Down
53 changes: 13 additions & 40 deletions tests_zemu/tests/keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5d44ae5

Please sign in to comment.