Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala committed May 10, 2023
1 parent 9f677b1 commit 3982ca9
Show file tree
Hide file tree
Showing 248 changed files with 84,890 additions and 76,214 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ zemu_install: tests_tools_build
test_all:
make zemu_install
SUBSTRATE_PARSER_FULL=1 make
make clean_glyphs
SUBSTRATE_PARSER_FULL=1 SUPPORT_SR25519=1 make buildS
make zemu_test
85,754 changes: 40,793 additions & 44,961 deletions tests/testcases_current.json

Large diffs are not rendered by default.

74,873 changes: 43,926 additions & 30,947 deletions tests/testcases_previous.json

Large diffs are not rendered by default.

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-substrate": "^0.40.5",
"@zondax/zemu": "^0.36.2"
"@zondax/zemu": "^0.42.0"
},
"devDependencies": {
"@types/jest": "^29.2.1",
Expand Down
Binary file modified tests_zemu/snapshots/s-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/s-mainmenu/00007.png
Binary file modified tests_zemu/snapshots/s-mainmenu/00010.png
Diff not rendered.
Binary file added tests_zemu/snapshots/s-proxy_proxy/00004.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file added tests_zemu/snapshots/s-txUtility_batch/00000.png
Binary file added tests_zemu/snapshots/s-txUtility_batch/00001.png
Binary file added tests_zemu/snapshots/s-txUtility_batch/00002.png
Binary file added tests_zemu/snapshots/s-txUtility_batch/00003.png
Binary file added tests_zemu/snapshots/s-txUtility_batch/00004.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00007.png
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Diff not rendered.
Binary file added tests_zemu/snapshots/sp-proxy_proxy/00004.png
Binary file added tests_zemu/snapshots/sp-txUtility_batch/00001.png
Binary file added tests_zemu/snapshots/sp-txUtility_batch/00002.png
Binary file added tests_zemu/snapshots/sp-txUtility_batch/00003.png
Binary file added tests_zemu/snapshots/sp-txUtility_batch/00004.png
Binary file added tests_zemu/snapshots/sp-txUtility_batch/00005.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00007.png
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Diff not rendered.
Binary file added tests_zemu/snapshots/x-proxy_proxy/00004.png
Binary file added tests_zemu/snapshots/x-staking_nominate/00000.png
Binary file added tests_zemu/snapshots/x-staking_nominate/00006.png
Binary file added tests_zemu/snapshots/x-staking_nominate/00007.png
Binary file added tests_zemu/snapshots/x-staking_nominate/00008.png
Binary file added tests_zemu/snapshots/x-staking_nominate/00009.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00000.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00001.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00002.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00003.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00004.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00005.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00006.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00007.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00008.png
Binary file added tests_zemu/snapshots/x-txUtility_batch/00009.png
8 changes: 4 additions & 4 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { IDeviceModel } from '@zondax/zemu'

const Resolve = require('path').resolve
import { resolve } from 'path'

export const APP_SEED = 'equip will roof matter pink blind book anxiety banner elbow sun young'

const APP_PATH_S = Resolve('../app/output/app_s.elf')
const APP_PATH_X = Resolve('../app/output/app_x.elf')
const APP_PATH_SP = Resolve('../app/output/app_s2.elf')
const APP_PATH_S = resolve('../app/output/app_s.elf')
const APP_PATH_X = resolve('../app/output/app_x.elf')
const APP_PATH_SP = resolve('../app/output/app_s2.elf')

export const models: IDeviceModel[] = [
{ name: 'nanos', prefix: 'S', path: APP_PATH_S },
Expand Down
144 changes: 144 additions & 0 deletions tests_zemu/tests/custom.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/** ******************************************************************************
* (c) 2020 Zondax GmbH
*
* 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 } from '@zondax/zemu'
import { newKusamaApp } from '@zondax/ledger-substrate'
import { APP_SEED, models } from './common'

// @ts-expect-error missing typings
import ed25519 from 'ed25519-supercop'
import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs'
import { txBalances_transfer, txSession_setKeys, txStaking_nominate, txProxy_proxy, txUtility_batch } from './zemu_blobs'

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

jest.setTimeout(180000)

const TXNS = [
{
name: 'balances_transfer',
blob: txBalances_transfer,
},
{
name: 'session_setkeys',
blob: txSession_setKeys,
},
{
name: 'staking_nominate',
blob: txStaking_nominate,
},
{
name: 'proxy_proxy',
blob: txProxy_proxy,
},
{
name: 'txUtility_batch',
blob: txUtility_batch,
},
]

describe.each(TXNS)('Transactions', function (data) {
test.concurrent.each(models)(`Test: ${data.name}`, async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = newKusamaApp(sim.getTransport())
const pathAccount = 0x80000000
const pathChange = 0x80000000
const pathIndex = 0x80000000

const txBlob = Buffer.from(data.blob, 'hex')

const responseAddr = await app.getAddress(pathAccount, pathChange, pathIndex)
const pubKey = Buffer.from(responseAddr.pubKey, 'hex')

// do not wait here.. we need to navigate
const signatureRequest = app.sign(pathAccount, pathChange, pathIndex, txBlob)
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())

await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-${data.name}`)

const signatureResponse = await signatureRequest
console.log(signatureResponse)

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

// Now verify the signature
let prehash = txBlob
if (txBlob.length > 256) {
const context = blake2bInit(32)
blake2bUpdate(context, txBlob)
prehash = Buffer.from(blake2bFinal(context))
}
const valid = ed25519.verify(signatureResponse.signature.subarray(1), prehash, pubKey)
expect(valid).toEqual(true)
} finally {
await sim.close()
}
})
})

test.concurrent.each(models)('balances transfer expert', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = newKusamaApp(sim.getTransport())
const pathAccount = 0x80000000
const pathChange = 0x80000000
const pathIndex = 0x80000000

// Change to expert mode
await sim.toggleExpertMode()

const txBlob = Buffer.from(txBalances_transfer, 'hex')

const responseAddr = await app.getAddress(pathAccount, pathChange, pathIndex)
const pubKey = Buffer.from(responseAddr.pubKey, 'hex')

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

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

await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-balances_transfer_expert`)

const signatureResponse = await signatureRequest
console.log(signatureResponse)

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

// Now verify the signature
let prehash = txBlob
if (txBlob.length > 256) {
const context = blake2bInit(32)
blake2bUpdate(context, txBlob)
prehash = Buffer.from(blake2bFinal(context))
}
const valid = ed25519.verify(signatureResponse.signature.subarray(1), prehash, pubKey)
expect(valid).toEqual(true)
} finally {
await sim.close()
}
})
27 changes: 1 addition & 26 deletions tests_zemu/tests/recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,6 @@ const defaultOptions = {

jest.setTimeout(60000)

async function activateSecretMode(sim: any) {
// Get to Zondax.ch menu
for (let i = 0; i < 3; i += 1) {
await sim.clickRight()
}

// Activate secret features
for (let i = 0; i < 10; i += 1) {
await sim.clickBoth('', false)
}

let reviewSteps = 6
if (sim.startOptions.model === 'nanos') {
reviewSteps = 7
}

// Review warning message
for (let i = 0; i < reviewSteps; i += 1) {
await sim.clickRight()
}

// Accept
await sim.clickBoth()
}

describe('Recovery', function () {
test.concurrent.each(models)('main secret menu (%s)', async function (m) {
const sim = new Zemu(m.path)
Expand All @@ -74,7 +49,7 @@ describe('Recovery', function () {
expect(resp.address).toEqual(kusama_expected_address)
expect(resp.pubKey).toEqual(kusama_expected_pk)

await activateSecretMode(sim)
await sim.enableSpecialMode('Zondax', true)

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

Expand Down
57 changes: 7 additions & 50 deletions tests_zemu/tests/sr25519.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Zemu, { DEFAULT_START_OPTIONS } from '@zondax/zemu'
import { newKusamaApp } from '@zondax/ledger-substrate'
import { APP_SEED } from './common'
import { txBalances_transfer, txStaking_nominate } from './zemu_blobs'
import { txBalances_transfer } from './zemu_blobs'

// @ts-ignore
import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs'
Expand All @@ -34,6 +34,9 @@ const defaultOptions = {
X11: false,
}

const expected_address = 'Cz4vu6J2NHP977ZYZcMCdjmmLgmddKvXRi5TxecuTgFfKww'
const expected_pk = '121cc87d316d311fe3e3b9c34b1083a29c55f6ebd214b60f59578b0a37007424'

jest.setTimeout(180000)

describe('SR25519', function () {
Expand All @@ -50,9 +53,6 @@ describe('SR25519', function () {
expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')

const expected_address = 'Cz4vu6J2NHP977ZYZcMCdjmmLgmddKvXRi5TxecuTgFfKww'
const expected_pk = '121cc87d316d311fe3e3b9c34b1083a29c55f6ebd214b60f59578b0a37007424'

expect(resp.address).toEqual(expected_address)
expect(resp.pubKey).toEqual(expected_pk)
} finally {
Expand All @@ -77,9 +77,6 @@ describe('SR25519', function () {
expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')

const expected_address = 'Cz4vu6J2NHP977ZYZcMCdjmmLgmddKvXRi5TxecuTgFfKww'
const expected_pk = '121cc87d316d311fe3e3b9c34b1083a29c55f6ebd214b60f59578b0a37007424'

expect(resp.address).toEqual(expected_address)
expect(resp.pubKey).toEqual(expected_pk)
} finally {
Expand Down Expand Up @@ -142,7 +139,7 @@ describe('SR25519', function () {
prehash = Buffer.from(blake2bFinal(context))
}
const signingcontext = Buffer.from([])
const valid = addon.schnorrkel_verify(pubKey, signingcontext, prehash, signatureResponse.signature.slice(1))
const valid = addon.schnorrkel_verify(pubKey, signingcontext, prehash, signatureResponse.signature.subarray(1))
expect(valid).toEqual(true)
} finally {
await sim.close()
Expand Down Expand Up @@ -189,7 +186,7 @@ describe('SR25519', function () {
prehash = Buffer.from(blake2bFinal(context))
}
const signingcontext = Buffer.from([])
const valid = addon.schnorrkel_verify(pubKey, signingcontext, prehash, signatureResponse.signature.slice(1))
const valid = addon.schnorrkel_verify(pubKey, signingcontext, prehash, signatureResponse.signature.subarray(1))
expect(valid).toEqual(true)
} finally {
await sim.close()
Expand Down Expand Up @@ -241,51 +238,11 @@ describe('SR25519', function () {
prehash = Buffer.from(blake2bFinal(context))
}
const signingcontext = Buffer.from([])
const valid = addon.schnorrkel_verify(pubKey, signingcontext, prehash, signatureResponse.signature.slice(1))
const valid = addon.schnorrkel_verify(pubKey, signingcontext, prehash, signatureResponse.signature.subarray(1))
expect(valid).toEqual(true)
} finally {
await sim.close()
}
})

test.concurrent('sign large nomination', async function () {
const sim = new Zemu(APP_PATH)
try {
await sim.start({ ...defaultOptions })
const app = newKusamaApp(sim.getTransport())
const pathAccount = 0x80000000
const pathChange = 0x80000000
const pathIndex = 0x80000000

const txBlob = Buffer.from(txStaking_nominate, 'hex')

const responseAddr = await app.getAddress(pathAccount, pathChange, pathIndex, false, 1)
const pubKey = Buffer.from(responseAddr.pubKey, 'hex')

// do not wait here.. we need to navigate
const signatureRequest = app.sign(pathAccount, pathChange, pathIndex, txBlob, 1)
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', 's-sign_large_nomination_sr25519')

const signatureResponse = await signatureRequest
console.log(signatureResponse)

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

// Now verify the signature
let prehash = txBlob
if (txBlob.length > 256) {
const context = blake2bInit(32)
blake2bUpdate(context, txBlob)
prehash = Buffer.from(blake2bFinal(context))
}
const signingcontext = Buffer.from([])
const valid = addon.schnorrkel_verify(pubKey, signingcontext, prehash, signatureResponse.signature.slice(1))
expect(valid).toEqual(true)
} finally {
await sim.close()
}
})
})
Loading

0 comments on commit 3982ca9

Please sign in to comment.