Add prototype for tests
This commit is contained in:
18
tests/.babelrc
Normal file
18
tests/.babelrc
Normal 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
13
tests/.flowconfig
Normal file
@@ -0,0 +1,13 @@
|
||||
[ignore]
|
||||
<PROJECT_ROOT>/lib
|
||||
|
||||
[include]
|
||||
|
||||
[libs]
|
||||
flow-typed
|
||||
|
||||
[lints]
|
||||
|
||||
[options]
|
||||
|
||||
[strict]
|
||||
BIN
tests/elfs/ethereum_nanos.elf
Executable file
BIN
tests/elfs/ethereum_nanos.elf
Executable file
Binary file not shown.
BIN
tests/elfs/ethereum_nanox.elf
Executable file
BIN
tests/elfs/ethereum_nanox.elf
Executable file
Binary file not shown.
15
tests/globalsetup.js
Normal file
15
tests/globalsetup.js
Normal 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
33
tests/jest.config.js
Normal 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
22
tests/jest.js
Normal 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_PATH = Resolve("elfs/ethereum_nanos.elf");
|
||||
export const NANOX_PATH = Resolve("elfs/ethereum_nanox.elf");
|
||||
42
tests/lib/ethereum.test.js
Normal file
42
tests/lib/ethereum.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
require("core-js/stable");
|
||||
|
||||
require("regenerator-runtime/runtime");
|
||||
|
||||
var _hwAppEth = _interopRequireDefault(require("@ledgerhq/hw-app-eth"));
|
||||
|
||||
var _erc = require("@ledgerhq/hw-app-eth/erc20");
|
||||
|
||||
var _zemu = _interopRequireDefault(require("@zondax/zemu"));
|
||||
|
||||
var _errors = require("@ledgerhq/errors");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
test("Test USDT Lend on Compound", async () => {
|
||||
jest.setTimeout(100000);
|
||||
const sim = new _zemu.default(NANOS_PATH);
|
||||
|
||||
try {
|
||||
await sim.start(sim_options);
|
||||
let transport = await sim.getTransport();
|
||||
const eth = new _hwAppEth.default(transport); // Send transaction
|
||||
// https://etherscan.io/tx/0xa0f067369c92d240e253ac3bcb7b7aa56952f7e6feb4c2d93239713fb4e2c40e
|
||||
|
||||
let tx = eth.signTransaction("44'/60'/0'/0/0", "F8A95F850684EE180082CA2D944297394C20800E8A38A619A243E9BBE7681FF24E80B844A9059CBB000000000000000000000000D99A9739CF8B0BF66A7C99D9E14510C3146358C60000000000000000000000000000000000000000000002F0DEB79238F100000025A04CABB0BD9DFDC55605915450F9C7E0E3311996071D9F722BFA12E09C9EF8A23FA03DD645E1DA9B19448A327CC5ADCF89FA228C3642528D60258D9AE32A5B07F7A2");
|
||||
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());
|
||||
await sim.clickRight();
|
||||
await sim.clickRight();
|
||||
await sim.clickRight();
|
||||
await sim.clickRight();
|
||||
await sim.clickBoth();
|
||||
await expect(tx).resolves.toEqual({
|
||||
r: "e8c2b5b956b34386e68c5cc5bfc76aac158706430fcf1c71c9f6eb7d9dd690c8",
|
||||
s: "064005410a778b047fdd4afcb1e712217c297e5b0a2190f88b9e56ac745fae69",
|
||||
v: "26"
|
||||
});
|
||||
} finally {
|
||||
await sim.close();
|
||||
}
|
||||
});
|
||||
39
tests/package.json
Normal file
39
tests/package.json
Normal 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.30.0",
|
||||
"@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"
|
||||
}
|
||||
}
|
||||
42
tests/src/ethereum.test.js
Normal file
42
tests/src/ethereum.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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("Test 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.clickRight();
|
||||
await sim.clickRight();
|
||||
await sim.clickRight();
|
||||
await sim.clickRight();
|
||||
await sim.clickBoth();
|
||||
|
||||
await expect(tx).resolves.toEqual({
|
||||
r: "e8c2b5b956b34386e68c5cc5bfc76aac158706430fcf1c71c9f6eb7d9dd690c8",
|
||||
s: "064005410a778b047fdd4afcb1e712217c297e5b0a2190f88b9e56ac745fae69",
|
||||
v: "26",
|
||||
});
|
||||
|
||||
} finally {
|
||||
await sim.close();
|
||||
}
|
||||
});
|
||||
26
tests/src/generic.js
Normal file
26
tests/src/generic.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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_PATH = Resolve("elfs/ethereum_nanos.elf");
|
||||
const NANOX_PATH = Resolve("elfs/ethereum_nanox.elf");
|
||||
|
||||
module.exports = {
|
||||
NANOS_PATH,
|
||||
NANOX_PATH,
|
||||
sim_options_nanos,
|
||||
sim_options_nanox
|
||||
}
|
||||
7067
tests/yarn.lock
Normal file
7067
tests/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user