Skip to content

Commit

Permalink
update tests & snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Sep 18, 2023
1 parent bc67593 commit 28fcc5d
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 154 deletions.
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/00010.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/sp-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/sp-mainmenu/00010.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/st-mainmenu/00001.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/x-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/x-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
363 changes: 209 additions & 154 deletions tests_zemu/tests/textual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,122 +28,217 @@ jest.setTimeout(90000)

describe('Textual', function () {
// eslint-disable-next-line jest/expect-expect
test.concurrent.each(DEVICE_MODELS)('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(DEVICE_MODELS)('sign basic textual', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 118, 0, 0, 0]
const tx = Buffer.from(tx_sign_textual, 'hex')
const hrp = 'cosmos'

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, hrp)
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, hrp, TEXTUAL_TX)

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

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')
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.concurrent.each(DEVICE_MODELS)('sign basic textual expert', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new CosmosApp(sim.getTransport())

// Change to expert mode so we can skip fields
await sim.toggleExpertMode()

const path = [44, 118, 0, 0, 0]
const tx = Buffer.from(tx_sign_textual, 'hex')
const hrp = 'cosmos'

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, hrp)
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, hrp, TEXTUAL_TX)

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

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')
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.concurrent.each(DEVICE_MODELS)('sign basic textual eth ', async function (m) {
// test.concurrent.each(DEVICE_MODELS)('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(DEVICE_MODELS)('sign basic textual', async function (m) {
// const sim = new Zemu(m.path)
// try {
// await sim.start({ ...defaultOptions, model: m.name })
// const app = new CosmosApp(sim.getTransport())

// const path = [44, 118, 0, 0, 0]
// const tx = Buffer.from(tx_sign_textual, 'hex')
// const hrp = 'cosmos'

// // get address / publickey
// const respPk = await app.getAddressAndPubKey(path, hrp)
// 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, hrp, TEXTUAL_TX)

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

// 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')
// 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.concurrent.each(DEVICE_MODELS)('sign basic textual expert', async function (m) {
// const sim = new Zemu(m.path)
// try {
// await sim.start({ ...defaultOptions, model: m.name })
// const app = new CosmosApp(sim.getTransport())

// // Change to expert mode so we can skip fields
// await sim.toggleExpertMode()

// const path = [44, 118, 0, 0, 0]
// const tx = Buffer.from(tx_sign_textual, 'hex')
// const hrp = 'cosmos'

// // get address / publickey
// const respPk = await app.getAddressAndPubKey(path, hrp)
// 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, hrp, TEXTUAL_TX)

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

// 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')
// 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.concurrent.each(DEVICE_MODELS)('sign basic textual eth ', async function (m) {
// const sim = new Zemu(m.path)
// try {
// await sim.start({ ...defaultOptions, model: m.name })
// const app = new CosmosApp(sim.getTransport())

// // Enable expert to allow sign with eth path
// await sim.toggleExpertMode();

// const path = [44, 60, 0, 0, 0]
// const tx = Buffer.from(tx_sign_textual, 'hex')
// const hrp = 'inj'

// // get address / publickey
// const respPk = await app.getAddressAndPubKey(path, hrp)
// 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, hrp, TEXTUAL_TX)

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

// 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 sha3 = require('js-sha3')
// const msgHash = Buffer.from(sha3.keccak256(tx), 'hex')

// 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.concurrent.each(DEVICE_MODELS)('sign basic textual eth warning ', async function (m) {
// const sim = new Zemu(m.path)
// try {
// await sim.start({ ...defaultOptions, model: m.name })
// const app = new CosmosApp(sim.getTransport())

// const path = [44, 60, 0, 0, 0]
// const tx = Buffer.from(tx_sign_textual, 'hex')
// const hrp = 'inj'

// // get address / publickey
// const respPk = await app.getAddressAndPubKey(path, hrp)
// 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, hrp, TEXTUAL_TX)

// // Wait until we are not in the main menu
// await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
// let nav = undefined;
// if (m.name === 'stax') {
// const okButton: IButton = {
// x: 200,
// y: 540,
// delay: 0.25,
// };
// nav = new TouchNavigation([
// ButtonKind.ConfirmYesButton,
// ]);
// nav.schedule[0].button = okButton;
// } else {
// nav = new ClickNavigation([1, 0]);
// }
// await sim.navigate('.', `${m.prefix.toLowerCase()}-textual-sign_basic_eth_warning`, nav.schedule);

// const resp = await signatureRequest
// console.log(resp)

// expect(resp.return_code).toEqual(0x6984)
// } finally {
// await sim.close()
// }
// })

test.concurrent.each(DEVICE_MODELS)('sign basic textual evmos ', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new CosmosApp(sim.getTransport())

// Enable expert to allow sign with eth path
await sim.toggleExpertMode();
await sim.toggleExpertMode()

const path = [44, 60, 0, 0, 0]
const tx = Buffer.from(tx_sign_textual, 'hex')
const hrp = 'inj'
const hrp = 'evmos'

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, hrp)
Expand All @@ -156,7 +251,13 @@ describe('Textual', function () {

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-textual-sign_basic_eth`)
const last_index = await sim.navigateUntilText(
'.',
`${m.prefix.toLowerCase()}-textual-sign_basic_evmos`,
sim.startOptions.approveKeyword,
false,
false,
)

const resp = await signatureRequest
console.log(resp)
Expand All @@ -180,50 +281,4 @@ describe('Textual', function () {
await sim.close()
}
})

test.concurrent.each(DEVICE_MODELS)('sign basic textual eth warning ', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new CosmosApp(sim.getTransport())

const path = [44, 60, 0, 0, 0]
const tx = Buffer.from(tx_sign_textual, 'hex')
const hrp = 'inj'

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, hrp)
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, hrp, TEXTUAL_TX)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
let nav = undefined;
if (m.name === 'stax') {
const okButton: IButton = {
x: 200,
y: 540,
delay: 0.25,
};
nav = new TouchNavigation([
ButtonKind.ConfirmYesButton,
]);
nav.schedule[0].button = okButton;
} else {
nav = new ClickNavigation([1, 0]);
}
await sim.navigate('.', `${m.prefix.toLowerCase()}-textual-sign_basic_eth_warning`, nav.schedule);

const resp = await signatureRequest
console.log(resp)

expect(resp.return_code).toEqual(0x6984)
} finally {
await sim.close()
}
})
})

0 comments on commit 28fcc5d

Please sign in to comment.