forked from LedgerHQ/app-algorand
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add zemu tests for shorcut mode (#34)
* feat: add zemu tests for shorcut mode * fix: dummy commit
- Loading branch information
1 parent
191ca98
commit 46e7e06
Showing
70 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters