From e5fb3d0d47703148943c45fb882cc0e13c9c742a Mon Sep 17 00:00:00 2001 From: Carlos Medeiros Date: Tue, 16 Apr 2024 18:21:27 +0100 Subject: [PATCH] tests wip --- tests_zemu/tests/amino.test.ts | 51 +++++++++++++++++++ tests_zemu/tests/common.ts | 46 +++++++++++++++-- .../{standard.test.ts => standard.test.ts_} | 0 .../{textual.test.ts => textual.test.ts_} | 0 4 files changed, 94 insertions(+), 3 deletions(-) rename tests_zemu/tests/{standard.test.ts => standard.test.ts_} (100%) rename tests_zemu/tests/{textual.test.ts => textual.test.ts_} (100%) diff --git a/tests_zemu/tests/amino.test.ts b/tests_zemu/tests/amino.test.ts index 9bc28d0f..99eb63f8 100644 --- a/tests_zemu/tests/amino.test.ts +++ b/tests_zemu/tests/amino.test.ts @@ -27,6 +27,7 @@ import { setWithdrawAddress, cliGovDeposit, example_tx_str_msgMultiSend, + testTx, } from './common' // @ts-ignore @@ -519,4 +520,54 @@ describe('Amino', function () { await sim.close() } }) + + + test.only.each(DEVICE_MODELS)('TextTx', async function (m) { + const sim = new Zemu(m.path) + try { + await sim.start({ ...defaultOptions, model: m.name }) + const app = new CosmosApp(sim.getTransport()) + + // Activate expert mode + await sim.toggleExpertMode(); + + const path = [44, 118, 0, 0, 0] + const tx = Buffer.from(JSON.stringify(testTx)) + 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, AMINO_JSON_TX) + + // Wait until we are not in the main menu + await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) + await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-testTx`) + + 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() + } + }) }) diff --git a/tests_zemu/tests/common.ts b/tests_zemu/tests/common.ts index 722cae2a..e6314d7c 100644 --- a/tests_zemu/tests/common.ts +++ b/tests_zemu/tests/common.ts @@ -34,9 +34,9 @@ export const defaultOptions = { } export const DEVICE_MODELS: IDeviceModel[] = [ - { name: 'nanos', prefix: 'S', path: APP_PATH_S }, - { name: 'nanox', prefix: 'X', path: APP_PATH_X }, - { name: 'nanosp', prefix: 'SP', path: APP_PATH_SP }, + //{ name: 'nanos', prefix: 'S', path: APP_PATH_S }, + //{ name: 'nanox', prefix: 'X', path: APP_PATH_X }, + //{ name: 'nanosp', prefix: 'SP', path: APP_PATH_SP }, { name: 'stax', prefix: 'ST', path: APP_PATH_ST }, ] @@ -358,3 +358,43 @@ export const setWithdrawAddress = { ], sequence: '2' } + + export const testTx = { + "account_number": "2008470", + "chain_id": "osmosis-1", + "fee": { + "amount": [ + { + "amount": "4496", + "denom": "uosmo" + } + ], + "gas": "1198689", + }, + "memo": "FE", + "msgs": [ + { + "type": "osmosis/poolmanager/swap-exact-amount-in", + "value": { + "routes": [ + { + "pool_id": "1247", + "token_out_denom": "ibc/D79E7D83AB399BFFF93433E54FAA480C191248FC556924A2A8351AE2638B3877" + }, + { + "pool_id": "1428", + "token_out_denom": "ibc/698350B8A61D575025F3ED13E9AC9C0F45C89DEFE92F76D5838F1D3C1A7FF7C9" + } + ], + "sender": "osmo1ml9mtk6mhuhmvkvvr7pcfrfjy0z9y9avqaawsm", + "token_in": { + "amount": "301772", + "denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4" + }, + "token_out_min_amount": "25036" + } + } + ], + "sequence": "2", + "timeout_height": "14761501" +} diff --git a/tests_zemu/tests/standard.test.ts b/tests_zemu/tests/standard.test.ts_ similarity index 100% rename from tests_zemu/tests/standard.test.ts rename to tests_zemu/tests/standard.test.ts_ diff --git a/tests_zemu/tests/textual.test.ts b/tests_zemu/tests/textual.test.ts_ similarity index 100% rename from tests_zemu/tests/textual.test.ts rename to tests_zemu/tests/textual.test.ts_