Add working tests for send_bsc and send

This commit is contained in:
pscott
2021-06-17 17:20:52 +02:00
parent 225a6788c5
commit e5fafae176
38 changed files with 360 additions and 261 deletions

View File

@@ -18,5 +18,5 @@ export const sim_options_x = {
};
export const Resolve = require("path").resolve;
export const NANOS_PATH = Resolve("elfs/ethereum_nanos.elf");
export const NANOX_PATH = Resolve("elfs/ethereum_nanox.elf");
export const NANOS_ELF_PATH = Resolve("elfs/ethereum_nanos.elf");
export const NANOX_ELF_PATH = Resolve("elfs/ethereum_nanox.elf");

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

1
tests/snapshots/tmp/nanos/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.png

1
tests/snapshots/tmp/nanox/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.png

View File

@@ -1,60 +0,0 @@
import "core-js/stable";
import "regenerator-runtime/runtime";
import Eth from "@ledgerhq/hw-app-eth";
import { byContractAddress } from "@ledgerhq/hw-app-eth/erc20";
import Zemu from "@zondax/zemu";
import { TransportStatusError } from "@ledgerhq/errors";
const {NANOS_PATH, sim_options_nanos} = require("generic.js");
test("Check chunk-size edge case", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOS_PATH);
try {
await sim.start(sim_options_nanos);
let transport = await sim.getTransport();
const eth = new Eth(transport);
// Send transaction
// Couldn't find the transaction, but this is a special raw tx that checks that what was fixed by https://github.com/LedgerHQ/ledgerjs/pull/606 still works.
let tx = eth.signTransaction(
"44'/60'/0'/0/0",
"f8c282abcd8609184e72a00082271094aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa820300b858bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb25a0eb7170e671a8dd4607248d4850ac3daec22f6acea72cd0e4fe26adb0e8e08095a02f36ae65347b134cdfc0809292a34fa59c3e3e2eda0283b65d190fe8823a35d3"
);
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
await sim.clickRight();
// Data Present
await sim.clickRight();
// Amount 1/3
await sim.clickRight();
// Amount 2/3
await sim.clickRight();
// Amount 3/3
await sim.clickRight();
// Address 1/3
await sim.clickRight();
// Address 2/3
await sim.clickRight();
// Address 3/3
await sim.clickRight();
// Chain ID
await sim.clickRight();
// Max Fees
await sim.clickRight();
// Accept
await sim.clickBoth();
await expect(tx).resolves.toEqual({
r: "99ef8e0ff0f1755571c8c00ca18483ae97b907e5c90780333d474930fb7d68ee",
s: "707dfc5d5ae47dba7fd7d6afe84c4a3c5a5a649630963a04dc1b88304327ba2a",
v: "6d",
});
} finally {
await sim.close();
}
});

View File

@@ -1,195 +0,0 @@
import "core-js/stable";
import "regenerator-runtime/runtime";
import Eth from "@ledgerhq/hw-app-eth";
import { byContractAddress } from "@ledgerhq/hw-app-eth/erc20";
import Zemu from "@zondax/zemu";
import { TransportStatusError } from "@ledgerhq/errors";
const {NANOS_PATH, NANOX_PATH, sim_options_nanos, sim_options_nanox} = require("generic.js");
test("Transfer nanos", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOS_PATH);
try {
await sim.start(sim_options_nanos);
let transport = await sim.getTransport();
const eth = new Eth(transport);
// Send transaction
// https://etherscan.io/tx/0xa0f067369c92d240e253ac3bcb7b7aa56952f7e6feb4c2d93239713fb4e2c40e
let tx = eth.signTransaction(
"44'/60'/0'/0/0",
"F8A95F850684EE180082CA2D944297394C20800E8A38A619A243E9BBE7681FF24E80B844A9059CBB000000000000000000000000D99A9739CF8B0BF66A7C99D9E14510C3146358C60000000000000000000000000000000000000000000002F0DEB79238F100000025A04CABB0BD9DFDC55605915450F9C7E0E3311996071D9F722BFA12E09C9EF8A23FA03DD645E1DA9B19448A327CC5ADCF89FA228C3642528D60258D9AE32A5B07F7A2"
);
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
await sim.clickRight();
// Data Present
await sim.clickRight();
// Amount
await sim.clickRight();
// Address 1/3
await sim.clickRight();
// Address 2/3
await sim.clickRight();
// Address 3/3
await sim.clickRight();
// Chain ID
await sim.clickRight();
// Max Fees
await sim.clickRight();
// Accept
await sim.clickBoth();
await expect(tx).resolves.toEqual({
r: "610f4e866a960467e139387d21a922e836c6ae09af548940aa8ceaa04f720ab4",
s: "1e9f5e10bf4667c3a8b094856af1d1a98faa544331f654158255fe87cbb55737",
v: "6d",
});
} finally {
await sim.close();
}
});
test("Transfer nanox", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOX_PATH);
try {
await sim.start(sim_options_nanox);
let transport = await sim.getTransport();
const eth = new Eth(transport);
// Send transaction
// https://etherscan.io/tx/0xa0f067369c92d240e253ac3bcb7b7aa56952f7e6feb4c2d93239713fb4e2c40e
let tx = eth.signTransaction(
"44'/60'/0'/0/0",
"F8A95F850684EE180082CA2D944297394C20800E8A38A619A243E9BBE7681FF24E80B844A9059CBB000000000000000000000000D99A9739CF8B0BF66A7C99D9E14510C3146358C60000000000000000000000000000000000000000000002F0DEB79238F100000025A04CABB0BD9DFDC55605915450F9C7E0E3311996071D9F722BFA12E09C9EF8A23FA03DD645E1DA9B19448A327CC5ADCF89FA228C3642528D60258D9AE32A5B07F7A2"
);
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
await sim.clickRight();
// Data Present
await sim.clickRight();
// Amount
await sim.clickRight();
// Address 1
await sim.clickRight();
// Chain ID
await sim.clickRight();
// Max Fees
await sim.clickRight();
// Accept
await sim.clickBoth();
await expect(tx).resolves.toEqual({
r: "610f4e866a960467e139387d21a922e836c6ae09af548940aa8ceaa04f720ab4",
s: "1e9f5e10bf4667c3a8b094856af1d1a98faa544331f654158255fe87cbb55737",
v: "6d",
});
} finally {
await sim.close();
}
});
test("Deposit nanos", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOS_PATH);
try {
await sim.start(sim_options_nanos);
let transport = await sim.getTransport();
const eth = new Eth(transport);
// Deposit transaction
// https://etherscan.io/tx/0xf2ff5519baafdc46c3b300e03e189a5b45f48552969fd6bc45ed6e3adb0ecb5f
let tx = eth.signTransaction(
"44'/60'/0'/0/0",
"f8eb81958508e534039d8302177594d54f502e184b6b739d7d27a6410a67dc462d69c880b8842505c3d903f33191df6561f0409b39172d41aafe1edef210994ef40957a0a2afc4d9d1ec02893294412a4c8f915f75892b395ebbf6859ec246ec365c3b1f56f47c3a0a5d00000000000000000000000000000000000000000000000000000000000045c90000000000000000000000000000000000000000000000000000000041be71c025a0dd2ca8adf62d74dd023a35695281e9859737fecf3597409915e63bf4297ebf20a022e73752616372ce3cf2e473d951f4063227df1a2ace5a2320314803f6993b72"
);
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
await sim.clickRight();
// Data Present
await sim.clickRight();
// Amount
await sim.clickRight();
// Address 1
await sim.clickRight();
// Address 2
await sim.clickRight();
// Address 3
await sim.clickRight();
// Chain ID
await sim.clickRight();
// Max Fees 1
await sim.clickRight();
// Max Fees 2
await sim.clickRight();
// Max Fees 3
await sim.clickRight();
// Accept
await sim.clickBoth();
await expect(tx).resolves.toEqual({
r: "760c0d133c1095830614736e24c5741dcfcf1c46aeb301c3f213d92eac66c7b8",
s: "0e19d23ef82e04d2a3e77bc24ad036a381a2a12333b8d9228776bedf08092472",
v: "6e"
});
} finally {
await sim.close();
}
});
test("Deposit nanox", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOX_PATH);
try {
await sim.start(sim_options_nanox);
let transport = await sim.getTransport();
const eth = new Eth(transport);
// Deposit transaction
// https://etherscan.io/tx/0xf2ff5519baafdc46c3b300e03e189a5b45f48552969fd6bc45ed6e3adb0ecb5f
let tx = eth.signTransaction(
"44'/60'/0'/0/0",
"f8eb81958508e534039d8302177594d54f502e184b6b739d7d27a6410a67dc462d69c880b8842505c3d903f33191df6561f0409b39172d41aafe1edef210994ef40957a0a2afc4d9d1ec02893294412a4c8f915f75892b395ebbf6859ec246ec365c3b1f56f47c3a0a5d00000000000000000000000000000000000000000000000000000000000045c90000000000000000000000000000000000000000000000000000000041be71c025a0dd2ca8adf62d74dd023a35695281e9859737fecf3597409915e63bf4297ebf20a022e73752616372ce3cf2e473d951f4063227df1a2ace5a2320314803f6993b72"
);
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
await sim.clickRight();
// Data Present
await sim.clickRight();
// Amount
await sim.clickRight();
// Address 1
await sim.clickRight();
// Chain ID
await sim.clickRight();
// Max Fees 1/2
await sim.clickRight();
// Accept
await sim.clickBoth();
await expect(tx).resolves.toEqual({
r: "760c0d133c1095830614736e24c5741dcfcf1c46aeb301c3f213d92eac66c7b8",
s: "0e19d23ef82e04d2a3e77bc24ad036a381a2a12333b8d9228776bedf08092472",
v: "6e",
});
} finally {
await sim.close();
}
});

View File

@@ -15,12 +15,12 @@ const sim_options_nanox = {
};
const Resolve = require("path").resolve;
const NANOS_PATH = Resolve("elfs/ethereum_nanos.elf");
const NANOX_PATH = Resolve("elfs/ethereum_nanox.elf");
const NANOS_ELF_PATH = Resolve("elfs/ethereum_nanos.elf");
const NANOX_ELF_PATH = Resolve("elfs/ethereum_nanox.elf");
module.exports = {
NANOS_PATH,
NANOX_PATH,
NANOS_ELF_PATH,
NANOX_ELF_PATH,
sim_options_nanos,
sim_options_nanox
}

168
tests/src/send.test.js Normal file
View File

@@ -0,0 +1,168 @@
import "core-js/stable";
import "regenerator-runtime/runtime";
import Eth from "@ledgerhq/hw-app-eth";
import { byContractAddress } from "@ledgerhq/hw-app-eth/erc20";
import Zemu from "@zondax/zemu";
import { TransportStatusError } from "@ledgerhq/errors";
import { expect } from "../jest";
const {NANOS_ELF_PATH, NANOX_ELF_PATH, sim_options_nanos, sim_options_nanox} = require("generic.js");
const ORIGINAL_SNAPSHOT_PATH_PREFIX = "snapshots/send/";
const SNAPSHOT_PATH_PREFIX = "snapshots/tmp/";
const ORIGINAL_SNAPSHOT_PATH_NANOS = ORIGINAL_SNAPSHOT_PATH_PREFIX + "nanos/";
const ORIGINAL_SNAPSHOT_PATH_NANOX = ORIGINAL_SNAPSHOT_PATH_PREFIX + "nanox/";
const SNAPSHOT_PATH_NANOS = SNAPSHOT_PATH_PREFIX + "nanos/";
const SNAPSHOT_PATH_NANOX = SNAPSHOT_PATH_PREFIX + "nanox/";
test("Transfer nanos", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOS_ELF_PATH);
try {
await sim.start(sim_options_nanos);
let transport = await sim.getTransport();
let buffer = Buffer.from("058000002C8000003C800000010000000000000000EB44850306DC4200825208945A321744667052AFFA8386ED49E00EF223CBFFC3876F9C9E7BF6181880018080", "hex");
// Send transaction
let tx = transport.send(0xe0, 0x04, 0x00, 0x00, buffer);
let filename;
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
filename = "review.png";
await sim.snapshot(SNAPSHOT_PATH_NANOS + filename);
const review = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_review = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(review).toEqual(expected_review);
// Amount 1/3
filename = "amount_1.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount_1 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount_1 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount_1).toEqual(expected_amount_1);
// Amount 2/3
filename = "amount_2.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount_2 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount_2 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount_2).toEqual(expected_amount_2);
// Amount 3/3
filename = "amount_3.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount_3 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount_3 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount_3).toEqual(expected_amount_3);
// Address 1/3
filename = "address_1.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const address_1 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_address_1 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(address_1).toEqual(expected_address_1);
// Address 2/3
filename = "address_2.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const address_2 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_address_2 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(address_2).toEqual(expected_address_2);
// Address 3/3
filename = "address_3.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const address_3 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_address_3 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(address_3).toEqual(expected_address_3);
// Max Fees
filename = "fees.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const fees = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_fees = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(fees).toEqual(expected_fees);
// Accept
filename = "accept.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const accept = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_accept = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(accept).toEqual(expected_accept);
await sim.clickBoth();
await expect(tx).resolves.toEqual(
Buffer.from([ 38, 111, 56, 157, 21, 50, 15, 5, 1, 56, 53, 38, 237, 3, 222, 145, 124, 20, 33, 39, 22, 240, 154, 38, 45, 188, 152, 67, 16, 134, 165, 219, 73, 13, 201, 148, 183, 185, 114, 48, 187, 53, 253, 246, 254, 194, 244, 216, 255, 76, 251, 139, 254, 178, 166, 82, 195, 100, 199, 56, 255, 3, 60, 5, 221, 144, 0])
);
} finally {
await sim.close();
}
});
test("Transfer nanox", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOX_ELF_PATH);
try {
await sim.start(sim_options_nanox);
let transport = await sim.getTransport();
let buffer = Buffer.from("058000002C8000003C800000010000000000000000EB44850306DC4200825208945A321744667052AFFA8386ED49E00EF223CBFFC3876F9C9E7BF6181880018080", "hex");
// Send transaction
let tx = transport.send(0xe0, 0x04, 0x00, 0x00, buffer);
let filename;
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
filename = "review.png";
await sim.snapshot(SNAPSHOT_PATH_NANOX + filename);
const review = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_review = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(review).toEqual(expected_review);
// Amount
filename = "amount.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const amount = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_amount = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(amount).toEqual(expected_amount);
// Address
filename = "address.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const address = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_address = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(address).toEqual(expected_address);
// Max Fees
filename = "fees.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const fees = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_fees = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(fees).toEqual(expected_fees);
// Accept
filename = "accept.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const accept = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_accept = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(accept).toEqual(expected_accept);
await sim.clickBoth();
await expect(tx).resolves.toEqual(
Buffer.from([ 38, 111, 56, 157, 21, 50, 15, 5, 1, 56, 53, 38, 237, 3, 222, 145, 124, 20, 33, 39, 22, 240, 154, 38, 45, 188, 152, 67, 16, 134, 165, 219, 73, 13, 201, 148, 183, 185, 114, 48, 187, 53, 253, 246, 254, 194, 244, 216, 255, 76, 251, 139, 254, 178, 166, 82, 195, 100, 199, 56, 255, 3, 60, 5, 221, 144, 0])
);
} finally {
await sim.close();
}
});

184
tests/src/send_bsc.test.js Normal file
View File

@@ -0,0 +1,184 @@
import "core-js/stable";
import "regenerator-runtime/runtime";
import Eth from "@ledgerhq/hw-app-eth";
import { byContractAddress } from "@ledgerhq/hw-app-eth/erc20";
import Zemu from "@zondax/zemu";
import { TransportStatusError } from "@ledgerhq/errors";
import { expect } from "../jest";
const {NANOS_ELF_PATH, NANOX_ELF_PATH, sim_options_nanos, sim_options_nanox} = require("generic.js");
const ORIGINAL_SNAPSHOT_PATH_PREFIX = "snapshots/send_bsc/";
const SNAPSHOT_PATH_PREFIX = "snapshots/tmp/";
const ORIGINAL_SNAPSHOT_PATH_NANOS = ORIGINAL_SNAPSHOT_PATH_PREFIX + "nanos/";
const ORIGINAL_SNAPSHOT_PATH_NANOX = ORIGINAL_SNAPSHOT_PATH_PREFIX + "nanox/";
const SNAPSHOT_PATH_NANOS = SNAPSHOT_PATH_PREFIX + "nanos/";
const SNAPSHOT_PATH_NANOX = SNAPSHOT_PATH_PREFIX + "nanox/";
test("Transfer bsc nanos", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOS_ELF_PATH);
try {
await sim.start(sim_options_nanos);
let transport = await sim.getTransport();
let buffer = Buffer.from("058000002C8000003C800000010000000000000000EB0185012A05F200825208945A321744667052AFFA8386ED49E00EF223CBFFC3876F9C9E7BF6181880388080", "hex");
// Send transaction
let tx = transport.send(0xe0, 0x04, 0x00, 0x00, buffer);
let filename;
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
filename = "review.png";
await sim.snapshot(SNAPSHOT_PATH_NANOS + filename);
const review = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_review = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(review).toEqual(expected_review);
// Amount 1/3
filename = "amount_1.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount_1 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount_1 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount_1).toEqual(expected_amount_1);
// Amount 2/3
filename = "amount_2.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount_2 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount_2 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount_2).toEqual(expected_amount_2);
// Amount 3/3
filename = "amount_3.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount_3 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount_3 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount_3).toEqual(expected_amount_3);
// Address 1/3
filename = "address_1.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const address_1 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_address_1 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(address_1).toEqual(expected_address_1);
// Address 2/3
filename = "address_2.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const address_2 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_address_2 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(address_2).toEqual(expected_address_2);
// Address 3/3
filename = "address_3.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const address_3 = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_address_3 = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(address_3).toEqual(expected_address_3);
// Chain ID
filename = "chainid.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const chainid = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_chainid = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(chainid).toEqual(expected_chainid);
// Max Fees
filename = "fees.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const fees = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_fees = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(fees).toEqual(expected_fees);
// Accept
filename = "accept.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const accept = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_accept = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(accept).toEqual(expected_accept);
await sim.clickBoth();
await expect(tx).resolves.toEqual(
Buffer.from([147, 246, 103, 204, 52, 233, 129, 93, 244, 240, 82, 251, 52, 99, 205, 190, 53, 95, 255, 92, 26, 207, 78, 145, 155, 53, 57, 128, 101, 33, 160, 89, 173, 107, 53, 73, 43, 113, 8, 217, 217, 225, 204, 122, 237, 229, 54, 237, 107, 49, 115, 25, 123, 86, 221, 135, 60, 188, 59, 67, 224, 65, 214, 244, 7, 144, 0]),
);
} finally {
await sim.close();
}
});
test("Transfer bsc nanox", async () => {
jest.setTimeout(100000);
const sim = new Zemu(NANOX_ELF_PATH);
try {
await sim.start(sim_options_nanox);
let transport = await sim.getTransport();
let buffer = Buffer.from("058000002C8000003C800000010000000000000000EB0185012A05F200825208945A321744667052AFFA8386ED49E00EF223CBFFC3876F9C9E7BF6181880388080", "hex");
// Send transaction
let tx = transport.send(0xe0, 0x04, 0x00, 0x00, buffer);
let filename;
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
// Review tx
filename = "review.png";
await sim.snapshot(SNAPSHOT_PATH_NANOX + filename);
const review = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_review = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(review).toEqual(expected_review);
// Amount
filename = "amount.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const amount = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_amount = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(amount).toEqual(expected_amount);
// Address
filename = "address.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const address = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_address = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(address).toEqual(expected_address);
// Chain ID
filename = "chainid.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const chainid = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_chainid = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(chainid).toEqual(expected_chainid);
// Max Fees
filename = "fees.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const fees = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_fees = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(fees).toEqual(expected_fees);
// Accept
filename = "accept.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const accept = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_accept = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(accept).toEqual(expected_accept);
await sim.clickBoth();
await expect(tx).resolves.toEqual(
Buffer.from([147, 246, 103, 204, 52, 233, 129, 93, 244, 240, 82, 251, 52, 99, 205, 190, 53, 95, 255, 92, 26, 207, 78, 145, 155, 53, 57, 128, 101, 33, 160, 89, 173, 107, 53, 73, 43, 113, 8, 217, 217, 225, 204, 122, 237, 229, 54, 237, 107, 49, 115, 25, 123, 86, 221, 135, 60, 188, 59, 67, 224, 65, 214, 244, 7, 144, 0]),
);
} finally {
await sim.close();
}
});