Skip to content

Commit

Permalink
tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Apr 16, 2024
1 parent a44985f commit e5fb3d0
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
51 changes: 51 additions & 0 deletions tests_zemu/tests/amino.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
setWithdrawAddress,
cliGovDeposit,
example_tx_str_msgMultiSend,
testTx,
} from './common'

// @ts-ignore
Expand Down Expand Up @@ -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()
}
})
})
46 changes: 43 additions & 3 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
]

Expand Down Expand Up @@ -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"
}
File renamed without changes.
File renamed without changes.

0 comments on commit e5fb3d0

Please sign in to comment.