Skip to content

Commit

Permalink
improve zemu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Mar 25, 2022
1 parent 9ccfaf3 commit 280707e
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions tests_zemu/tests/standard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ describe('Standard', function () {
const respRequest = app.showAddressAndPubKey(path, 'cosmos')
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())

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

const resp = await respRequest
console.log(resp)
Expand Down Expand Up @@ -161,9 +160,7 @@ describe('Standard', function () {

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

// Now navigate the address / path
await sim.compareSnapshotsAndAccept('.', `${m.prefix.toLowerCase()}-show_address_huge`, 3)
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-show_address_huge`)

const resp = await respRequest
console.log(resp)
Expand Down Expand Up @@ -201,9 +198,7 @@ describe('Standard', function () {

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

// Now navigate the address / path
await sim.compareSnapshotsAndAccept('.', `${m.prefix.toLowerCase()}-sign_basic`, m.prefix == 'S' ? 6 : 5)
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic`)

const resp = await signatureRequest
console.log(resp)
Expand Down Expand Up @@ -248,15 +243,58 @@ describe('Standard', function () {

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic2`)

const resp = await signatureRequest
console.log(resp)

// Now navigate the address / path
await sim.compareSnapshotsAndAccept('.', `${m.prefix.toLowerCase()}-sign_basic2`, m.prefix == 'S' ? 7 : 6)
expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')

// Now verify the signature
const hash = crypto.createHash('sha256')
const msgHash = Uint8Array.from(hash.update(tx).digest())

const signatureDER = resp.signature
const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER))

const pk = Uint8Array.from(respPk.compressed_pk)

const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk)
expect(signatureOk).toEqual(true)
} finally {
await sim.close()
}
})

test.each(DEVICE_MODELS)('sign basic with extra fields', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...DEFAULT_OPTIONS, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 118, 0, 0, 0]
const tx = JSON.stringify(example_tx_str_basic)

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, 'cosmos')
expect(respPk.return_code).toEqual(0x9000)
expect(respPk.error_message).toEqual('No errors')
console.log(respPk)

// do not wait here..
const signatureRequest = app.sign(path, tx)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_basic_extra_fields`)

const resp = await signatureRequest
console.log(resp)

expect(resp.return_code).toEqual(0x9000)
expect(resp.error_message).toEqual('No errors')
expect(resp).toHaveProperty('signature')

// Now verify the signature
const hash = crypto.createHash('sha256')
Expand Down

0 comments on commit 280707e

Please sign in to comment.