Skip to content

Commit

Permalink
add API avail recovery app
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Dec 17, 2024
1 parent 83d501b commit e98b1d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/src/substrate/substrate_coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C" {

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

#define INS_SIGN_RAW 0x03

Expand Down
38 changes: 22 additions & 16 deletions tests_zemu/tests/recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
******************************************************************************* */

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

const defaultOptions = {
Expand All @@ -25,9 +25,6 @@ const defaultOptions = {
X11: false,
}

export const PATH = "m/44'/354'/0'/0'/0'"
export const DOT_SS58_PREFIX = 0

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

Expand All @@ -43,15 +40,19 @@ describe('Standard', function () {
}
})

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

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

const resp = await app.getAddress(PATH, DOT_SS58_PREFIX)
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 {
Expand All @@ -68,9 +69,9 @@ describe('Standard', function () {
approveKeyword: isTouchDevice(m.name) ? 'Confirm' : '',
approveAction: ButtonKind.ApproveTapButton,
})
const app = new PolkadotGenericApp(sim.getTransport(), 'dot')
const app = newSubstrateApp(sim.getTransport(), 'AvailRecovery')

const respRequest = app.getAddress(PATH, DOT_SS58_PREFIX, true)
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`)
Expand All @@ -79,33 +80,38 @@ describe('Standard', function () {

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.only.each(models)('show address recovery - reject', async function (m) {
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 = new PolkadotGenericApp(sim.getTransport(), 'dot')
const app = newSubstrateApp(sim.getTransport(), 'AvailRecovery')

const respRequest = app.getAddress(PATH, DOT_SS58_PREFIX, true)
expect(respRequest).rejects.toMatchObject({
returnCode: 0x6986,
errorMessage: 'Transaction rejected'
})
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()
}
Expand Down

0 comments on commit e98b1d5

Please sign in to comment.