Remove 'zemu' tests

This commit is contained in:
Charles-Edouard de la Vergne
2024-04-08 14:15:04 +02:00
parent d4b6e5ca35
commit 5f7d312eca
34 changed files with 0 additions and 7935 deletions

View File

@@ -1,73 +0,0 @@
---
name: Tests (Zemu)
on:
workflow_dispatch:
push:
branches:
- master
- develop
pull_request:
jobs:
# =====================================================
# ZEMU TESTS
# =====================================================
building_for_e2e_zemu_tests:
name: Building binaries for E2E Zemu tests
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest
steps:
- uses: actions/checkout@v4
- name: Build testing binaries
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
cd tests/zemu/ && ./build_local_test_elfs.sh
- name: Upload app binaries
uses: actions/upload-artifact@v4
with:
name: e2e_zemu_elfs
path: ./tests/zemu/elfs/
jobs-e2e-zemu-tests:
name: E2E Zemu tests
needs: [building_for_e2e_zemu_tests]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install additional tools
run: sudo apt-get update -y && sudo apt-get install -y libusb-1.0.0 libudev-dev
- name: Install NodeJS
uses: actions/setup-node@v3
with:
node-version: "16"
- name: Install yarn
run: npm install -g yarn
- name: Build/Install build js deps
run: cd tests/zemu/ && yarn install
- name: Create tmp folder for artifacts
run: mkdir tests/zemu/elfs
- name: Download app binaries
uses: actions/download-artifact@v4
with:
path: tmp/
- name: Gather elfs
run: cp tmp/e2e_zemu_elfs/*.elf tests/zemu/elfs/
- name: Run zemu tests
run: cd tests/zemu/ && yarn test

View File

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

View File

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

View File

@@ -1,4 +0,0 @@
/node_modules
/snapshots-tmp
/elfs
/lib

View File

@@ -1,8 +0,0 @@
MAKEFLAGS += --no-print-directory
all:
./build_local_test_elfs.sh
yarn install
yarn test
.PHONY: all

View File

@@ -1,45 +0,0 @@
#!/usr/bin/env bash
set -e
TESTS_PATH=$(dirname "$(realpath "$0")")
# FILL THESE WITH YOUR OWN SDKs PATHS
# NANOS_SDK=
# NANOX_SDK=
# list of apps required by tests that we want to build here
APPS=("ethereum" "ethereum_classic")
# list of SDKS
NANO_SDKS=("$NANOS_SDK" "$NANOX_SDK")
# list of target elf file name suffix
FILE_SUFFIXES=("nanos" "nanox")
# move to the tests directory
cd "$TESTS_PATH" || exit 1
# Do it only now since before the cd command, we might not have been inside the repository
GIT_REPO_ROOT=$(git rev-parse --show-toplevel)
# create elfs directory if it doesn't exist
mkdir -p elfs
# move to repo's root to build apps
cd "$GIT_REPO_ROOT" || exit 1
for ((sdk_idx=0; sdk_idx < "${#NANO_SDKS[@]}"; sdk_idx++))
do
nano_sdk="${NANO_SDKS[$sdk_idx]}"
elf_suffix="${FILE_SUFFIXES[$sdk_idx]}"
echo "* Building elfs for $(basename "$nano_sdk")..."
for appname in "${APPS[@]}"
do
echo "** Building app $appname..."
make clean BOLOS_SDK="$nano_sdk"
make -j DEBUG=1 NFT_TESTING_KEY=1 BOLOS_SDK="$nano_sdk" CHAIN="$appname"
cp bin/app.elf "$TESTS_PATH/elfs/${appname}_${elf_suffix}.elf"
done
done
echo "done"

View File

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

View File

@@ -1,39 +0,0 @@
// 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)",
],
// Path of the file where tests can be """decorated"""
setupFilesAfterEnv: ['<rootDir>/setupTests.js'],
// Stop immediately when a test fail
bail: true,
};

View File

@@ -1,22 +0,0 @@
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");

View File

@@ -1,41 +0,0 @@
{
"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": "^6.5.0",
"@ledgerhq/hw-transport-http": "^4.74.2",
"@ledgerhq/logs": "^5.50.0",
"@zondax/zemu": "^0.27.4",
"bignumber.js": "^9.0.0",
"bip32-path": "^0.4.2",
"core-js": "^3.7.0",
"ethereum-tx-decoder": "^3.0.0",
"ethers": "^5.5.1",
"fs-extra": "^10.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"
}
}

View File

@@ -1,19 +0,0 @@
import expect from 'expect'
expect.extend({
toMatchSnapshot(received, original) {
if(received.data.equals(original.data)){
return {
message: () => `snapshots are equal`,
pass: true
}
} else {
console.log("snapshots are not equal")
return {
message: () => `snapshots are not equal`,
pass: false
}
}
},
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 572 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 382 B

View File

@@ -1,38 +0,0 @@
import "core-js/stable";
import "regenerator-runtime/runtime";
import { EthAppPleaseEnableContractData } from "@ledgerhq/errors";
import { waitForAppScreen, zemu, nano_models } from './test.fixture';
nano_models.forEach(function(model) {
test("[Nano " + model.letter + "] Transfer on Ethereum clone app", zemu(model, async (sim, eth) => {
const tx = eth.signTransaction(
"44'/60'/0'/0/0",
'EB44850306DC4200825208945A321744667052AFFA8386ED49E00EF223CBFFC3876F9C9E7BF61818803D8080',
);
await waitForAppScreen(sim);
let clicks;
if (model.letter === 'S') clicks = 9;
else clicks = 5;
await sim.navigateAndCompareSnapshots('.', model.name + '_transfer_ethereum_clone', [clicks, -1, 0]);
await expect(tx).resolves.toEqual({
"r": "60df850d297e355596f87dc313a742032de4b59c5579186b3d59bdf31402fec0",
"s": "23c3a2beacabc1943d487a2e1d545e4c46c718b1e70e9d1c11a98828c9338927",
"v": "9e",
});
}, true));
});
nano_models.forEach(function(model) {
test("[Nano " + model.letter + "] Transfer on network 5234 on Ethereum clone", zemu(model, async (sim, eth) => {
const tx = eth.signTransaction(
"44'/60'/0'/0/0",
'ED44850306DC4200825208945A321744667052AFFA8386ED49E00EF223CBFFC3876F9C9E7BF61818808214728080',
);
await expect(tx).rejects.toEqual(new EthAppPleaseEnableContractData(
"Please enable Contract data on the Ethereum app Settings"
));
}, true));
});

View File

@@ -1,121 +0,0 @@
import Zemu, { DEFAULT_START_OPTIONS, DeviceModel } from '@zondax/zemu';
import Eth from '@ledgerhq/hw-app-eth';
import {RLP} from "ethers/lib/utils";
const transactionUploadDelay = 60000;
async function waitForAppScreen(sim, current_screen = null) {
if (current_screen === null) current_screen = sim.getMainMenuSnapshot();
await sim.waitUntilScreenIsNot(current_screen, transactionUploadDelay);
}
const sim_options_nano = {
...DEFAULT_START_OPTIONS,
logging: true,
X11: true,
startText: 'is ready'
};
const Resolve = require('path').resolve;
const NANOS_ELF_PATH = Resolve('elfs/ethereum_nanos.elf');
const NANOX_ELF_PATH = Resolve('elfs/ethereum_nanox.elf');
const NANOS_CLONE_ELF_PATH = Resolve("elfs/ethereum_classic_nanos.elf");
const NANOX_CLONE_ELF_PATH = Resolve("elfs/ethereum_classic_nanox.elf");
const nano_models: DeviceModel[] = [
{ name: 'nanos', letter: 'S', path: NANOS_ELF_PATH, clone_path: NANOS_CLONE_ELF_PATH }/*,
{ name: 'nanox', letter: 'X', path: NANOX_ELF_PATH, clone_path: NANOX_CLONE_ELF_PATH }*/
];
const TIMEOUT = 1000000;
// useful to take an apdu as a hex string and convert its JS representation
function apdu_as_string(str) {
let buffer = [];
for (let i = 0; i < str.length; i += 2) {
const str_extract = str.substring(i, i + 2);
buffer[i / 2] = parseInt(str_extract, 16);
}
return {
cla: buffer[0],
ins: buffer[1],
p1: buffer[2],
p2: buffer[3],
data: Buffer.from(buffer.slice(5))
};
}
async function send_apdu(ts, apdu) {
return ts.send(apdu.cla,
apdu.ins,
apdu.p1,
apdu.p2,
apdu.data);
}
// Generates a serializedTransaction from a rawHexTransaction copy pasted from etherscan.
function txFromEtherscan(rawTx) {
// Remove 0x prefix
rawTx = rawTx.slice(2);
let txType = rawTx.slice(0, 2);
if (txType == "02" || txType == "01") {
// Remove "02" prefix
rawTx = rawTx.slice(2);
} else {
txType = "";
}
let decoded = RLP.decode("0x" + rawTx);
if (txType != "") {
decoded = decoded.slice(0, decoded.length - 3); // remove v, r, s
} else {
decoded[decoded.length - 1] = "0x"; // empty
decoded[decoded.length - 2] = "0x"; // empty
decoded[decoded.length - 3] = "0x01"; // chainID 1
}
// Encode back the data, drop the '0x' prefix
let encoded = RLP.encode(decoded).slice(2);
// Don't forget to prepend the txtype
return txType + encoded;
}
function zemu(device, func, start_clone = false) {
return async () => {
jest.setTimeout(TIMEOUT);
let elf_path;
let lib_elf;
if (start_clone) {
elf_path = device.clone_path;
lib_elf = { 'Ethereum': device.path };
}
else {
elf_path = device.path;
}
const sim = new Zemu(elf_path, lib_elf);
try {
await sim.start({...sim_options_nano, model: device.name});
const transport = await sim.getTransport();
await func(sim, new Eth(transport));
} finally {
await sim.close();
}
};
}
module.exports = {
zemu,
waitForAppScreen,
sim_options_nano,
nano_models,
TIMEOUT,
txFromEtherscan,
apdu_as_string,
send_apdu
}

File diff suppressed because it is too large Load Diff