Skip to content

Commit

Permalink
Merge pull request #53 from cosmos/add_testcases
Browse files Browse the repository at this point in the history
Add testcases
  • Loading branch information
jleni authored Mar 31, 2022
2 parents 0909aeb + cad3e2b commit 114e3b1
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=34
# This is the patch version of this release
APPVERSION_P=1
APPVERSION_P=2
38 changes: 38 additions & 0 deletions tests/testcases/manual.json
Original file line number Diff line number Diff line change
Expand Up @@ -1840,5 +1840,43 @@
"7 | Gas : 200000"
],
"expert": true
},
{
"name": "minimal_extra_field",
"tx": {
"account_number": "V1",
"chain_id": "V2",
"fee": {
"amount": [
{
"amount": "b"
},
{
"c": "d"
},
{
"x": "y"
}
],
"gas": "V3"
},
"foo": "bar",
"memo": "V4",
"msgs": [],
"sequence": "V5",
"unknown_param": "123456"
},
"foo": "bar",
"parsingErr": "No error",
"validationErr": "Unexpected field",
"expected": [
"0 | Chain ID : V2",
"1 | Account : V1",
"2 | Sequence : V5",
"3 | Memo : V4",
"4 | fee/amount : Unexpected field",
"5 | Gas : V3"
],
"expert": true
}
]
2 changes: 1 addition & 1 deletion tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"testSR25519": "jest --detectOpenHandles --runInBand tests/sr25519.test.ts"
},
"dependencies": {
"@zondax/zemu": "^0.27.0-rc2",
"@zondax/zemu": "^0.27.4",
"ledger-cosmos-js": "^2.1.8"
},
"devDependencies": {
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/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,38 @@ export const example_tx_str_basic2 = {
],
sequence: '6',
}

export const example_tx_str_basic_extra_fields = {
account_number: '108',
chain_id: 'cosmoshub-4',
extra_field: 'empty',
fee: {
amount: [
{
amount: '600',
denom: 'uatom',
},
],
gas: '200000',
},
foo: 'bar',
memo: '',
msgs: [
{
type: 'cosmos-sdk/MsgWithdrawDelegationReward',
value: {
delegator_address: 'cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h',
validator_address: 'cosmosvaloper1kn3wugetjuy4zetlq6wadchfhvu3x740ae6z6x',
},
},
{
type: 'cosmos-sdk/MsgWithdrawDelegationReward',
value: {
delegator_address: 'cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h',
validator_address: 'cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0',
},
},
],
sequence: '106',
unknown_field: 123456
}
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 114e3b1

Please sign in to comment.