Merge pull request #160 from LedgerHQ/add_tests

Add tests
This commit is contained in:
pscott
2021-06-18 15:12:45 +02:00
committed by GitHub
81 changed files with 8063 additions and 12 deletions

View File

@@ -1,6 +1,12 @@
name: Compilation & tests
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
job_build_debug:
@@ -8,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: docker://ledgerhq/ledger-app-builder:2.0.0-1
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:2.0.0-1
steps:
- name: Clone

35
.github/workflows/e2e-tests.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: End-to-end tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
e2e-tests:
runs-on: ubuntu-latest
steps:
- name: Test
run: |
id
echo $HOME
echo $DISPLAY
- name: Checkout
uses: actions/checkout@v2
- run: sudo apt-get update -y && sudo apt-get install -y libusb-1.0.0 libudev-dev
- name: Install node
uses: actions/setup-node@v2
with:
node-version: '14.4.0'
- name: Install yarn
run: |
npm install -g yarn
- name: Build/Install build js deps
run: |
cd tests && yarn install
- name: Run zemu tests
run: |
cd tests && yarn test

View File

@@ -1,6 +1,12 @@
name: Code style check
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
job_lint:

18
.gitignore vendored
View File

@@ -1,7 +1,17 @@
bin
debug
dep
obj
# Compilation of Ledger's app
src/glyphs.c
src/glyphs.h
bin/
debug/
dep/
obj/
# Python
*.pyc
# JS
tests/node_modules
tests/lib
tests/yarn-error.log

View File

@@ -306,7 +306,7 @@ endif
CC := $(CLANGPATH)clang
#CFLAGS += -O0
CFLAGS += -O3 -Os -I/usr/include -Wno-format-invalid-specifier -Wno-format-extra-args -Wno-main
CFLAGS += -O3 -Os -Wno-format-invalid-specifier -Wno-format-extra-args -Wno-main
AS := $(GCCPATH)arm-none-eabi-gcc
@@ -351,6 +351,14 @@ load: all
delete:
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)
install_tests:
cd tests && (yarn install || sudo yarn install)
run_tests:
cd tests && (yarn test || sudo yarn test)
test: install_tests run_tests
# import generic rules from the sdk
include $(BOLOS_SDK)/Makefile.rules

View File

@@ -4,4 +4,56 @@ Ledger Blue is not maintained anymore, but the app can still be compiled for thi
This app follows the specification available in the `doc/` folder
To compile it and load it on a device, have a look here: https://ledger.readthedocs.io/en/latest/userspace/getting_started.html
To compile it and load it on a device, have a look here: https://ledger.readthedocs.io/en/latest/userspace/getting_started.html
# Testing
Testing is done via the open-source framework [zemu](https://github.com/Zondax/zemu).
## Running tests
First [install yarn](https://classic.yarnpkg.com/en/docs/install/#debian-stable).
Then you can install the project by simply running:
```
make test
```
This will run `make install_tests` and `make run_tests`
To run a specific tests (here the send test):
```
cd tests
sudo jest --runInBand --detectOpenHandles src/send.test.js
```
Make sure you're in the `tests` folder before running `jest` or `yarn test`.
## Adding tests
### Zemu
To add tests, copy one of the already existing test files in `tests/src/`.
You then need to adapt the `buffer` and `tx` variables to adapt to the APDU you wish to send.
- Adapt the expected screen flow. Please create a folder under `tests/snapshots` with the name of the test you're performing.
- Then adapt the `ORIGINAL_SNAPSHOT_PATH_PREFIX` with the name of the folder you just created.
- To create the snapshots, modify the `SNAPSHOT_PATH_PREFIX` and set it to be equal to `ORIGINAL_SNAPSHOT_PATH_PREFIX`.
- Run the tests once, this will create all the snapshots in the folder you created.
- Put back your `SNAPSHOT_PATH_PREFIX` to `snapshots/tmp/`.
Finally make sure you adapt the expected signature!
### Update binaries
Don't forget to update the binaries in the test folder. To do so, compile with those environement variables:
```
make DEBUG=1 ALLOW_DATA=1
```
Then copy the binary to the `tests/elfs` folder (in this case, compiled with SDK for nanoS):
```
cp bin/app.elf tests/elfs/ethereum_nanos.elf
```
Repeat the operation for a binary compiled with nanoX SDK and change for `ethereum_nanox.elf`.

View File

@@ -365,9 +365,8 @@ tokenDefinition_t *getKnownToken(uint8_t *contractAddress) {
break;
case CHAIN_KIND_FLARE:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_FLARE[i]);
break
case CHAIN_KIND_THETA:
currentToken = (tokenDefinition_t *) PIC(&TOKENS_THETA[i]);
break case CHAIN_KIND_THETA : currentToken =
(tokenDefinition_t *) PIC(&TOKENS_THETA[i]);
break;
}
if (memcmp(currentToken->address, tmpContent.txContent.destination, ADDRESS_LENGTH) == 0) {

18
tests/.babelrc Normal file
View File

@@ -0,0 +1,18 @@
{
"plugins": [
[
"@babel/plugin-proposal-class-properties"
]
],
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-flow"
],
}

13
tests/.flowconfig Normal file
View File

@@ -0,0 +1,13 @@
[ignore]
<PROJECT_ROOT>/lib
[include]
[libs]
flow-typed
[lints]
[options]
[strict]

BIN
tests/elfs/ethereum_nanos.elf Executable file

Binary file not shown.

BIN
tests/elfs/ethereum_nanox.elf Executable file

Binary file not shown.

15
tests/globalsetup.js Normal file
View File

@@ -0,0 +1,15 @@
import Zemu from "@zondax/zemu";
const catchExit = async () => {
process.on("SIGINT", () => {
Zemu.stopAllEmuContainers(function () {
process.exit();
});
});
};
module.exports = async () => {
await catchExit();
await Zemu.checkAndPullImage();
await Zemu.stopAllEmuContainers();
};

33
tests/jest.config.js Normal file
View File

@@ -0,0 +1,33 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html
module.exports = {
modulePaths: ["<rootDir>/src", "<rootDir>/tests"],
moduleNameMapper: {
"^jest$": "<rootDir>/jest.js",
},
// Automatically clear mock calls and instances between every test
clearMocks: true,
// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
globalSetup: "<rootDir>/globalsetup.js",
// A list of paths to directories that Jest should use to search for files in
roots: ["<rootDir>"],
runner: "jest-serial-runner",
// The test environment that will be used for testing
testEnvironment: "node",
// The glob patterns Jest uses to detect test files
testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)",
"**/?(*.)+(ispec|test).[tj]s?(x)",
],
};

22
tests/jest.js Normal file
View File

@@ -0,0 +1,22 @@
export default jest;
export const { expect, test } = global;
export const sim_options_s = {
model: "nanos",
logging: true,
start_delay: 2000,
X11: true,
custom: "",
};
export const sim_options_x = {
model: "nanox",
logging: true,
start_delay: 2000,
X11: true,
custom: "",
};
export const Resolve = require("path").resolve;
export const NANOS_ELF_PATH = Resolve("elfs/ethereum_nanos.elf");
export const NANOX_ELF_PATH = Resolve("elfs/ethereum_nanox.elf");

39
tests/package.json Normal file
View File

@@ -0,0 +1,39 @@
{
"name": "swap-test",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"build": "babel src/ -d lib/",
"prepublish": "yarn run build",
"test": "jest src --verbose --runInBand --detectOpenHandles"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@ledgerhq/hw-app-eth": "^5.52.1",
"@ledgerhq/hw-transport-http": "^4.74.2",
"@ledgerhq/logs": "^5.50.0",
"@zondax/zemu": "0.13.0",
"bignumber.js": "^9.0.0",
"bip32-path": "^0.4.2",
"core-js": "^3.7.0",
"ethereum-tx-decoder": "^3.0.0",
"google-protobuf": "^3.11.0",
"jest-serial-runner": "^1.1.0",
"js-sha256": "^0.9.0",
"regenerator-runtime": "^0.13.7",
"secp256k1": "^3.7.1"
},
"devDependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/preset-env": "^7.7.1",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-stage-0": "^7.0.0",
"@babel/register": "^7.7.0",
"flow-bin": "^0.112.0",
"jest": "^26.6.3"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 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: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 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.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 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: 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

176
tests/src/approve.test.js Normal file
View File

@@ -0,0 +1,176 @@
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, TIMEOUT} = require("generic.js");
const ORIGINAL_SNAPSHOT_PATH_PREFIX = "snapshots/approve/";
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("Approve DAI tokens nanos", async () => {
jest.setTimeout(TIMEOUT);
const sim = new Zemu(NANOS_ELF_PATH);
try {
await sim.start(sim_options_nanos);
let transport = await sim.getTransport();
// Token provisioning
let buffer = Buffer.from("034441496B175474E89094C44DA98B954EEDEAC495271D0F00000012000000013045022100B3AA979633284EB0F55459099333AB92CF06FDD58DC90E9C070000C8E968864C02207B10EC7D6609F51DDA53D083A6E165A0ABF3A77E13250E6F260772809B49AFF5", "hex");
let tx = transport.send(0xe0, 0x0a, 0x00, 0x00, buffer);
// Send transaction
buffer = Buffer.from("058000002C8000003C800000010000000000000000F869468506A8B15E0082EBEB946B175474E89094C44DA98B954EEDEAC495271D0F80B844095EA7B30000000000000000000000007D2768DE32B0B80B7A3454C06BDAC94A69DDC7A9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF018080", "hex");
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);
// Type
filename = "type.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const type = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_type = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(type).toEqual(expected_type);
// Amount
filename = "amount.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount).toEqual(expected_amount);
// 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([37, 146, 36, 53, 17, 57, 107, 101, 164, 250, 167, 53, 165, 71, 46, 169, 155, 60, 224, 247, 242, 51, 142, 171, 66, 98, 6, 115, 11, 192, 221, 197, 127, 22, 27, 192, 248, 97, 6, 77, 132, 13, 228, 244, 48, 76, 253, 25, 165, 113, 1, 126, 98, 223, 125, 143, 112, 207, 96, 92, 15, 2, 85, 147, 182, 144, 0])
);
} finally {
await sim.close();
}
});
test("Approve DAI token nanox", async () => {
jest.setTimeout(TIMEOUT);
const sim = new Zemu(NANOX_ELF_PATH);
try {
await sim.start(sim_options_nanox);
let transport = await sim.getTransport();
// Token provisioning
let buffer = Buffer.from("034441496B175474E89094C44DA98B954EEDEAC495271D0F00000012000000013045022100B3AA979633284EB0F55459099333AB92CF06FDD58DC90E9C070000C8E968864C02207B10EC7D6609F51DDA53D083A6E165A0ABF3A77E13250E6F260772809B49AFF5", "hex");
let tx = transport.send(0xe0, 0x0a, 0x00, 0x00, buffer);
// Send transaction
buffer = Buffer.from("058000002C8000003C800000010000000000000000F869468506A8B15E0082EBEB946B175474E89094C44DA98B954EEDEAC495271D0F80B844095EA7B30000000000000000000000007D2768DE32B0B80B7A3454C06BDAC94A69DDC7A9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF018080", "hex");
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);
// Type
filename = "type.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const type = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_type = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(type).toEqual(expected_type);
// 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([37, 146, 36, 53, 17, 57, 107, 101, 164, 250, 167, 53, 165, 71, 46, 169, 155, 60, 224, 247, 242, 51, 142, 171, 66, 98, 6, 115, 11, 192, 221, 197, 127, 22, 27, 192, 248, 97, 6, 77, 132, 13, 228, 244, 48, 76, 253, 25, 165, 113, 1, 126, 98, 223, 125, 143, 112, 207, 96, 92, 15, 2, 85, 147, 182, 144, 0])
);
} finally {
await sim.close();
}
});

174
tests/src/deposit.test.js Normal file
View File

@@ -0,0 +1,174 @@
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, TIMEOUT} = require("generic.js");
// Adapt this prefix.
const ORIGINAL_SNAPSHOT_PATH_PREFIX = "snapshots/deposit/";
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("Deposit ETH nanos", async () => {
jest.setTimeout(TIMEOUT);
const sim = new Zemu(NANOS_ELF_PATH);
try {
await sim.start(sim_options_nanos);
let transport = await sim.getTransport();
let buffer = Buffer.from("058000002c8000003c800000010000000000000000f8924685028fa6ae008306599594cc9a0b7c43dc2a5f023bb9b738e45b0ef6b06e0488016345785d8a0000b864474cf53d0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a900000000000000000000000070bc641723fad48be2df6cf63dc6270ee2f8974300000000000000000000000000000000", "hex");
let tx = transport.send(0xe0, 0x04, 0x00, 0x00, buffer);
buffer = Buffer.from("00000000000000000000000000000000018080", "hex");
tx = transport.send(0xe0, 0x04, 0x80, 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);
// Data present
filename = "data_present.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const data_present = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_data_present = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(data_present).toEqual(expected_data_present);
// Amount
filename = "amount.png";
await sim.clickRight(SNAPSHOT_PATH_NANOS + filename);
const amount = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOS + filename);
const expected_amount = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOS + filename);
expect(amount).toEqual(expected_amount);
// 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, 181, 174, 58, 1, 30, 181, 14, 125, 31, 233, 245, 230, 246, 217, 28, 169, 244, 223, 202, 95, 115, 128, 95, 196, 134, 109, 73, 231, 46, 173, 47, 92, 60, 110, 85, 219, 89, 37, 88, 107, 181, 142, 67, 75, 88, 178, 192, 71, 86, 246, 98, 19, 21, 151, 249, 140, 26, 162, 65, 139, 22, 153, 43, 129, 144, 0])
);
} finally {
await sim.close();
}
});
test("Deposit ETH nanox", async () => {
jest.setTimeout(TIMEOUT);
const sim = new Zemu(NANOX_ELF_PATH);
try {
await sim.start(sim_options_nanox);
let transport = await sim.getTransport();
let buffer = Buffer.from("058000002c8000003c800000010000000000000000f8924685028fa6ae008306599594cc9a0b7c43dc2a5f023bb9b738e45b0ef6b06e0488016345785d8a0000b864474cf53d0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a900000000000000000000000070bc641723fad48be2df6cf63dc6270ee2f8974300000000000000000000000000000000", "hex");
let tx = transport.send(0xe0, 0x04, 0x00, 0x00, buffer);
buffer = Buffer.from("00000000000000000000000000000000018080", "hex");
tx = transport.send(0xe0, 0x04, 0x80, 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);
// Data present
filename = "data_present.png";
await sim.clickRight(SNAPSHOT_PATH_NANOX + filename);
const data_present = Zemu.LoadPng2RGB(SNAPSHOT_PATH_NANOX + filename);
const expected_data_present = Zemu.LoadPng2RGB(ORIGINAL_SNAPSHOT_PATH_NANOX + filename);
expect(data_present).toEqual(expected_data_present);
// 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, 181, 174, 58, 1, 30, 181, 14, 125, 31, 233, 245, 230, 246, 217, 28, 169, 244, 223, 202, 95, 115, 128, 95, 196, 134, 109, 73, 231, 46, 173, 47, 92, 60, 110, 85, 219, 89, 37, 88, 107, 181, 142, 67, 75, 88, 178, 192, 71, 86, 246, 98, 19, 21, 151, 249, 140, 26, 162, 65, 139, 22, 153, 43, 129, 144, 0])
);
} finally {
await sim.close();
}
});

29
tests/src/generic.js Normal file
View File

@@ -0,0 +1,29 @@
const sim_options_nanos = {
model: "nanos",
logging: true,
start_delay: 2000,
X11: true,
custom: "",
};
const sim_options_nanox = {
model: "nanox",
logging: true,
start_delay: 2000,
X11: true,
custom: "",
};
const Resolve = require("path").resolve;
const NANOS_ELF_PATH = Resolve("elfs/ethereum_nanos.elf");
const NANOX_ELF_PATH = Resolve("elfs/ethereum_nanox.elf");
const TIMEOUT = 1000000;
module.exports = {
NANOS_ELF_PATH,
NANOX_ELF_PATH,
sim_options_nanos,
sim_options_nanox,
TIMEOUT,
}

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

@@ -0,0 +1,167 @@
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, TIMEOUT} = 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(TIMEOUT);
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(TIMEOUT);
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, TIMEOUT} = 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(TIMEOUT);
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(TIMEOUT);
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();
}
});

7063
tests/yarn.lock Normal file

File diff suppressed because it is too large Load Diff