Skip to content

Commit

Permalink
feat: add zemu tests for shorcut mode
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelm41 committed Oct 15, 2024
1 parent 191ca98 commit 76a02f3
Show file tree
Hide file tree
Showing 69 changed files with 110 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@zondax/ledger-algorand": "../js",
"@zondax/zemu": "^0.50.2"
"@zondax/zemu": "^0.51.0"
},
"devDependencies": {
"@types/jest": "^29.4.0",
Expand Down
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.
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.
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.
98 changes: 98 additions & 0 deletions tests_zemu/tests/big_transactions_shortchut.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/** ******************************************************************************
* (c) 2018 - 2022 Zondax AG
*
* 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, { DEFAULT_START_OPTIONS, ClickNavigation } from '@zondax/zemu'
import { zondaxToggleBlindSigning } from '@zondax/zemu/dist/zondax'
// @ts-ignore
import AlgorandApp from '@zondax/ledger-algorand'
import {APP_SEED, clickableModels, txApplicationLong} from './common'

// @ts-ignore
import ed25519 from 'ed25519-supercop'

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

const accountId = 123

jest.setTimeout(300000)

describe('BigTransactions - Shortcut', function () {
test.concurrent.each(clickableModels)('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(clickableModels)('sign application big', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new AlgorandApp(sim.getTransport())

const txBlob = Buffer.from(txApplicationLong, 'hex')
console.log(sim.getMainMenuSnapshot())

// Enable expert mode
await sim.toggleExpertMode(`${m.prefix.toLowerCase()}-sign_application_big_shortcut`, true, 0);

// Toggle shortcut mode on nano s, s+ and x devices, and compare
const snapshotsDelta = m.name == "nanos" ? 3 : 0
let nav = new ClickNavigation([2, 0, 5 + snapshotsDelta, 0])
await sim.navigateAndCompareSnapshots(".", `${m.prefix.toLowerCase()}-sign_application_big_shortcut`, nav.schedule, true, 3);

// Take snapshots of the shortcut mode and compare
nav = new ClickNavigation([2, -2])
await sim.navigateAndCompareSnapshots(".", `${m.prefix.toLowerCase()}-sign_application_big_shortcut`, nav.schedule, true, 12 + snapshotsDelta);

console.log(sim.getMainMenuSnapshot())
const responseAddr = await app.getAddressAndPubKey(accountId)
const pubKey = responseAddr.publicKey

await sim.deleteEvents()

// do not wait here.. we need to navigate
const signatureRequest = app.sign(accountId, txBlob)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())

// Click on "skip fields" and approve
nav = new ClickNavigation([1, 0, 0])
await sim.navigateAndCompareSnapshots(".", `${m.prefix.toLowerCase()}-sign_application_big_shortcut`, nav.schedule, true, 17 + snapshotsDelta);

const signatureResponse = await signatureRequest
console.log(signatureResponse)

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

// Now verify the signature
const prehash = Buffer.concat([Buffer.from('TX'), txBlob])
const valid = ed25519.verify(signatureResponse.signature, prehash, pubKey)
expect(valid).toEqual(true)
} finally {
await sim.close()
}
})
})
14 changes: 11 additions & 3 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ const APP_PATH_SP = resolve('../app/output/app_s2.elf')
const APP_PATH_ST = resolve('../app/output/app_stax.elf')
const APP_PATH_FL = resolve('../app/output/app_flex.elf')

export const models: IDeviceModel[] = [
export const touchableModels: IDeviceModel[] = [
{ name: 'stax', prefix: 'ST', path: APP_PATH_ST },
{ name: 'flex', prefix: 'FL', path: APP_PATH_FL },
]

export const clickableModels: IDeviceModel[] = [
{ name: 'nanos', prefix: 'S', path: APP_PATH_S },
{ name: 'nanox', prefix: 'X', path: APP_PATH_X },
{ name: 'nanosp', prefix: 'SP', path: APP_PATH_SP },
{ name: 'stax', prefix: 'ST', path: APP_PATH_ST },
{ name: 'flex', prefix: 'FL', path: APP_PATH_FL },
]

export const models: IDeviceModel[] = [
...clickableModels,
...touchableModels,
]

export const txAssetFreeze = [
Expand Down

0 comments on commit 76a02f3

Please sign in to comment.