Skip to content

Commit

Permalink
upgrade zemu
Browse files Browse the repository at this point in the history
  • Loading branch information
jleni committed Feb 23, 2021
1 parent 18d9697 commit f2021d5
Show file tree
Hide file tree
Showing 71 changed files with 3,242 additions and 1,584 deletions.
1 change: 1 addition & 0 deletions tests_zemu/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/yarn-error.log
/snapshots-tmp
34 changes: 17 additions & 17 deletions tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
"zondax"
],
"dependencies": {
"ledger-cosmos-js": "^2",
"@zondax/zemu": "^0.2.4"
"@zondax/zemu": "^0.7.0",
"ledger-cosmos-js": "^2.1.8"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/node": "^7.12.6",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"babel-eslint": "^10.1.0",
"babel-jest": "24",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.3",
"jest": "24",
"babel-jest": "26.6.3",
"crypto-js": "4.0.0",
"eslint": "^7.13.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.1.4",
"jest": "26.6.3",
"jest-serial-runner": "^1.1.0 ",
"secp256k1": "^4.0.1",
"crypto-js": "4.0.0"
"secp256k1": "^4.0.2"
}
}
1 change: 0 additions & 1 deletion tests_zemu/snapshots-tmp/.gitignore

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests_zemu/snapshots-tmp/show-address-huge/.gitkeep

This file was deleted.

1 change: 0 additions & 1 deletion tests_zemu/snapshots-tmp/show-address/.gitkeep

This file was deleted.

1 change: 0 additions & 1 deletion tests_zemu/snapshots-tmp/sign-basic-combined/.gitkeep

This file was deleted.

1 change: 0 additions & 1 deletion tests_zemu/snapshots-tmp/sign-basic/.gitkeep

This file was deleted.

1 change: 0 additions & 1 deletion tests_zemu/snapshots-tmp/sign-expert/.gitkeep

This file was deleted.

Binary file removed tests_zemu/snapshots/show-address-huge/1.png
Binary file not shown.
Binary file removed tests_zemu/snapshots/show-address-huge/9.png
Binary file not shown.
Binary file removed tests_zemu/snapshots/show-address/4.png
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
147 changes: 47 additions & 100 deletions tests_zemu/tests/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import {expect, test} from "jest";
/** ******************************************************************************
* (c) 2020 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************* */

import jest, {expect} from "jest";
import Zemu from "@zondax/zemu";
import CosmosApp from "ledger-cosmos-js";
import secp256k1 from "secp256k1/elliptic";
Expand All @@ -10,7 +26,7 @@ const APP_PATH = Resolve("../app/bin/app.elf");
const APP_SEED = "equip will roof matter pink blind book anxiety banner elbow sun young"
const sim_options = {
logging: true,
start_delay: 4000,
start_delay: 3000,
custom: `-s "${APP_SEED}"`
, X11: true
};
Expand Down Expand Up @@ -127,7 +143,7 @@ describe('Basic checks', function () {
}
});

it('get app version', async function () {
it('app version', async function () {
const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
Expand Down Expand Up @@ -206,19 +222,7 @@ describe('Basic checks', function () {
}
});

function compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount) {
for (let i = 0; i < snapshotCount; i++) {
const img1 = Zemu.LoadPng2RGB(`${snapshotPrefixTmp}${i}.png`);
const img2 = Zemu.LoadPng2RGB(`${snapshotPrefixGolden}${i}.png`);
expect(img1).toEqual(img2);
}
}

it('show address', async function () {
const snapshotPrefixGolden = "snapshots/show-address/";
const snapshotPrefixTmp = "snapshots-tmp/show-address/";
let snapshotCount = 0;

const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
Expand All @@ -227,22 +231,15 @@ describe('Basic checks', function () {
// Derivation path. First 3 items are automatically hardened!
const path = [44, 118, 5, 0, 3];
const respRequest = app.showAddressAndPubKey(path, "cosmos");

// We need to wait until the app responds to the APDU
await Zemu.sleep(2000);
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());

// Now navigate the address / path
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickBoth(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.compareSnapshotsAndAccept(".", "show_address", 4);

const resp = await respRequest;
console.log(resp);

compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");

Expand Down Expand Up @@ -275,41 +272,29 @@ describe('Basic checks', function () {
});

it('show address - HUGE - expert', async function () {
const snapshotPrefixGolden = "snapshots/show-address-huge/";
const snapshotPrefixTmp = "snapshots-tmp/show-address-huge/";
let snapshotCount = 0;

const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
const app = new CosmosApp(sim.getTransport());

// Activate expert mode
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickBoth(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight();
await sim.clickBoth();
await sim.clickLeft();

// Derivation path. First 3 items are automatically hardened!
const path = [44, 118, 2147483647, 0, 4294967295];
const respRequest = app.showAddressAndPubKey(path, "cosmos");

// We need to wait until the app responds to the APDU
await Zemu.sleep(2000);
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());

// Now navigate the address / path
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickBoth(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.compareSnapshotsAndAccept(".", "show_address_huge", 7);

const resp = await respRequest;
console.log(resp);

compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");

Expand All @@ -324,10 +309,6 @@ describe('Basic checks', function () {
});

it('sign basic', async function () {
const snapshotPrefixGolden = "snapshots/sign-basic/";
const snapshotPrefixTmp = "snapshots-tmp/sign-basic/";
let snapshotCount = 0;

const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
Expand All @@ -345,20 +326,15 @@ describe('Basic checks', function () {
// do not wait here..
const signatureRequest = app.sign(path, tx);

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

// Reference window
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
for (let i = 0; i < 6; i++) {
await sim.clickRight(Resolve(`${snapshotPrefixTmp}${snapshotCount++}.png`));
}
await sim.clickBoth();
// Now navigate the address / path
await sim.compareSnapshotsAndAccept(".", "sign_basic", 7);

let resp = await signatureRequest;
console.log(resp);

compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");

Expand Down Expand Up @@ -401,20 +377,15 @@ describe('Basic checks', function () {
// do not wait here..
const signatureRequest = app.sign(path, tx);

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

// Reference window
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
for (let i = 0; i < 8; i++) {
await sim.clickRight(Resolve(`${snapshotPrefixTmp}${snapshotCount++}.png`));
}
await sim.clickBoth();
// Now navigate the address / path
await sim.compareSnapshotsAndAccept(".", "sign_basic_combined", 9);

let resp = await signatureRequest;
console.log(resp);

compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");

Expand All @@ -436,10 +407,6 @@ describe('Basic checks', function () {
});

it('show address and sign basic', async function () {
const snapshotPrefixGolden = "snapshots/show-address-and-sign-basic/";
const snapshotPrefixTmp = "snapshots-tmp/show-address-and-sign-basic/";
let snapshotCount = 0;

const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
Expand All @@ -451,15 +418,11 @@ describe('Basic checks', function () {
// get address / publickey
const respRequest = app.showAddressAndPubKey(path, "cosmos");

// We need to wait until the app responds to the APDU
await Zemu.sleep(3000);
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());

// Now navigate the address / path
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickRight(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.clickBoth(`${snapshotPrefixTmp}${snapshotCount++}.png`);
await sim.compareSnapshotsAndAccept(".", "show_address_and_sign_basic_1", 4);

const respPk = await respRequest;
console.log(respPk);
Expand All @@ -471,20 +434,15 @@ describe('Basic checks', function () {
// do not wait here..
const signatureRequest = app.sign(path, tx);

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

// Reference window
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
for (let i = 0; i < 6; i++) {
await sim.clickRight(Resolve(`${snapshotPrefixTmp}${snapshotCount++}.png`));
}
await sim.clickBoth();
// Now navigate the address / path
await sim.compareSnapshotsAndAccept(".", "show_address_and_sign_basic_2", 7);

let resp = await signatureRequest;
console.log(resp);

compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");

Expand All @@ -506,10 +464,6 @@ describe('Basic checks', function () {
});

it('sign expert', async function () {
const snapshotPrefixGolden = "snapshots/sign-expert/";
const snapshotPrefixTmp = "snapshots-tmp/sign-expert/";
let snapshotCount = 0;

const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
Expand All @@ -527,22 +481,15 @@ describe('Basic checks', function () {
// do not wait here..
const signatureRequest = app.sign(path, tx);

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

// Reference window
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
for (let i = 0; i < 14; i++) {
await sim.clickRight(Resolve(`${snapshotPrefixTmp}${snapshotCount++}.png`));
}
await sim.clickBoth();
await sim.clickBoth();
await sim.clickBoth();
// Now navigate the address / path
await sim.compareSnapshotsAndAccept(".", "sign_expert", 15);

let resp = await signatureRequest;
console.log(resp);

compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");

Expand Down
Loading

0 comments on commit f2021d5

Please sign in to comment.