Socket
Socket
Sign inDemoInstall

@zondax/zemu

Package Overview
Dependencies
Maintainers
1
Versions
166
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zondax/zemu - npm Package Compare versions

Comparing version 0.13.0 to 0.13.1

20

dist/src/emulator.js

@@ -110,3 +110,2 @@ "use strict";

docker.pull(imageName, function (err, stream) {
docker.modem.followProgress(stream, onFinished, onProgress);
function onProgress(event) {

@@ -124,6 +123,11 @@ // eslint-disable-next-line no-prototype-builtins

else {
console.log(err);
process.stdout.write("[DOCKER] " + err + "\n");
process.exit(1);
}
}
if (err) {
process.stdout.write("[DOCKER] " + err + "\n");
throw new Error(err);
}
docker.modem.followProgress(stream, onFinished, onProgress);
});

@@ -140,3 +144,3 @@ })];

return __awaiter(this, void 0, void 0, function () {
var docker, appFilename, appDir, dirBindings, libArgs, displaySetting, displayEnvironment, SDKoption, command, portBindings, environment, _a;
var docker, appFilename, appDir, dirBindings, libArgs, displaySetting, displayEnvironment, SDKoption, modelOptions, customOptions, command, portBindings, environment, _a;
var _b;

@@ -176,3 +180,11 @@ return __generator(this, function (_c) {

}
command = "/home/zondax/speculos/speculos.py --color LAGOON_BLUE " + displaySetting + " " + options.custom + " -m " + options.model + " " + SDKoption + " --vnc-port " + exports.DEFAULT_VNC_PORT + " " + exports.DEFAULT_APP_PATH + "/" + appFilename + " " + libArgs;
modelOptions = 'nanos';
if (options.model) {
modelOptions = options.model;
}
customOptions = '';
if (options.custom) {
customOptions = options.custom;
}
command = "/home/zondax/speculos/speculos.py --color LAGOON_BLUE " + displaySetting + " " + customOptions + " -m " + modelOptions + " " + SDKoption + " --vnc-port " + exports.DEFAULT_VNC_PORT + " " + exports.DEFAULT_APP_PATH + "/" + appFilename + " " + libArgs;
this.log("[ZEMU] Command: " + command);

@@ -179,0 +191,0 @@ portBindings = (_b = {},

52

dist/src/index.js

@@ -221,3 +221,3 @@ "use strict";

this.startOptions = options;
this.log("[ZEMU] Checking ELF");
this.log("Checking ELF");
Zemu.checkElf((_a = this.startOptions.model) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_MODEL, this.elfPath);

@@ -230,11 +230,12 @@ _c.label = 2;

_c.sent();
this.log("[ZEMU] Starting Container");
this.log("Starting Container");
return [4 /*yield*/, this.emuContainer.runContainer(options)];
case 4:
_c.sent();
this.log("[ZEMU] Started Container");
this.log("Started Container");
// eslint-disable-next-line func-names
return [4 /*yield*/, this.connect()["catch"](function (error) {
_this.log("[ZEMU] " + error);
_this.log("" + error);
_this.close();
throw error;
})];

@@ -244,3 +245,3 @@ case 5:

_c.sent();
this.log("[ZEMU] Get initial snapshot");
this.log("Get initial snapshot");
// Captures main screen

@@ -256,3 +257,3 @@ _b = this;

this.log("[ZEMU] " + e_1);
return [3 /*break*/, 8];
throw e_1;
case 8: return [2 /*return*/];

@@ -271,3 +272,3 @@ }

waitDelay = (_b = (_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.startDelay) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_START_DELAY;
this.log("[ZEMU] Wait VNC for " + waitDelay);
this.log("Wait VNC for " + waitDelay);
Zemu.delay(waitDelay);

@@ -289,3 +290,4 @@ return [4 /*yield*/, this.connectVNC()];

if ((_b = (_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.logging) !== null && _b !== void 0 ? _b : false) {
process.stdout.write(message + "\n");
var currentTimestamp = new Date().toISOString().slice(11, 23);
process.stdout.write("[ZEMU] " + currentTimestamp + ": " + message + "\n");
}

@@ -302,6 +304,6 @@ };

});
_this.log("[ZEMU] VNC Connection created " + _this.host + ":" + _this.vncPort);
_this.log("VNC Connection created " + _this.host + ":" + _this.vncPort);
var tmpVncSession = _this.vncSession;
_this.vncSession.on('connect', function () {
_this.log("[ZEMU] VNC Session ready");
_this.log("VNC Session ready");
// @ts-ignore

@@ -316,6 +318,6 @@ tmpVncSession.keyEvent(constants_1.KEYS.LEFT, constants_1.KEYS.NOT_PRESSED);

_this.vncSession.on('error', function (error) {
_this.log("[ZEMU] Could not connect to port " + tmpVncPort + " on " + tmpHost);
_this.log("Could not connect to port " + tmpVncPort + " on " + tmpHost);
reject(error);
});
setTimeout(function () { return reject(new Error('timeout on connectVNC')); }, 10000);
setTimeout(function () { return reject(new Error('timeout on connectVNC')); }, 6000);
})];

@@ -340,3 +342,3 @@ });

case 0:
this.log('[ZEMU] Close');
this.log('Close');
return [4 /*yield*/, this.emuContainer.stop()];

@@ -373,3 +375,3 @@ case 1:

vncSession = this.vncSession;
this.log('[ZEMU] Requested snapshot');
this.log('Requested snapshot');
return [2 /*return*/, new Promise(function (resolve, reject) {

@@ -402,3 +404,3 @@ var session = _this.getSession();

Zemu.prototype.waitUntilScreenIsNot = function (screen, timeout) {
if (timeout === void 0) { timeout = 10000; }
if (timeout === void 0) { timeout = 2000; }
return __awaiter(this, void 0, void 0, function () {

@@ -447,9 +449,9 @@ var start, inputSnapshotBufferHex, currentSnapshotBufferHex, elapsed;

localBackClickCount = typeof backClickCount === 'undefined' ? 0 : backClickCount;
this.log("[ZEMU] forward: " + snapshotCount + " backwards: " + localBackClickCount);
this.log("[ZEMU] golden " + snapshotPrefixGolden);
this.log("[ZEMU] tmp " + snapshotPrefixTmp);
this.log("forward: " + snapshotCount + " backwards: " + localBackClickCount);
this.log("golden " + snapshotPrefixGolden);
this.log("tmp " + snapshotPrefixTmp);
imageIndex = 0;
indexStr = '00000';
filename = snapshotPrefixTmp + "/" + indexStr + ".png";
this.log("[ZEMU] Start " + filename);
this.log("Start " + filename);
return [4 /*yield*/, this.snapshot(filename)

@@ -470,3 +472,3 @@ // Move forward to the end

_a.sent();
this.log("[ZEMU] Click Right " + filename);
this.log("Click Right " + filename);
_a.label = 4;

@@ -484,3 +486,3 @@ case 4:

filename = snapshotPrefixTmp + "/" + indexStr + ".png";
this.log("[ZEMU] Click Left " + filename);
this.log("Click Left " + filename);
return [4 /*yield*/, this.clickLeft("" + filename)];

@@ -501,3 +503,3 @@ case 7:

filename = snapshotPrefixTmp + "/" + indexStr + ".png";
this.log("[ZEMU] Click Right " + filename);
this.log("Click Right " + filename);
return [4 /*yield*/, this.clickRight("" + filename)];

@@ -514,10 +516,10 @@ case 11:

filename = snapshotPrefixTmp + "/" + indexStr + ".png";
this.log("[ZEMU] Click Both " + filename);
this.log("Click Both " + filename);
return [4 /*yield*/, this.clickBoth("" + filename)];
case 14:
_a.sent();
this.log("[ZEMU] Start comparison");
this.log("Start comparison");
for (j = 0; j < imageIndex + 1; j += 1) {
indexStr = ("" + j).padStart(5, '0');
this.log("[ZEMU] Checked " + snapshotPrefixTmp + "/" + indexStr + ".png");
this.log("Checked " + snapshotPrefixTmp + "/" + indexStr + ".png");
img1 = Zemu.LoadPng2RGB(snapshotPrefixTmp + "/" + indexStr + ".png");

@@ -524,0 +526,0 @@ img2 = Zemu.LoadPng2RGB(snapshotPrefixGolden + "/" + indexStr + ".png");

@@ -5,3 +5,3 @@ {

"license": "Apache-2.0",
"version": "0.13.0",
"version": "0.13.1",
"description": "Zemu Testing Framework",

@@ -8,0 +8,0 @@ "main": "./dist/src/index.js",

@@ -67,4 +67,2 @@ /** ******************************************************************************

docker.pull(imageName, (err: any, stream: any) => {
docker.modem.followProgress(stream, onFinished, onProgress)
function onProgress(event: any) {

@@ -82,6 +80,13 @@ // eslint-disable-next-line no-prototype-builtins

} else {
console.log(err)
process.stdout.write(`[DOCKER] ${err}\n`)
process.exit(1)
}
}
if (err) {
process.stdout.write(`[DOCKER] ${err}\n`)
throw new Error(err)
}
docker.modem.followProgress(stream, onFinished, onProgress)
})

@@ -131,4 +136,14 @@ })

const command = `/home/zondax/speculos/speculos.py --color LAGOON_BLUE ${displaySetting} ${options.custom} -m ${options.model} ${SDKoption} --vnc-port ${DEFAULT_VNC_PORT} ${DEFAULT_APP_PATH}/${appFilename} ${libArgs}`
let modelOptions = 'nanos';
if (options.model) {
modelOptions = options.model
}
let customOptions = '';
if (options.custom) {
customOptions = options.custom
}
const command = `/home/zondax/speculos/speculos.py --color LAGOON_BLUE ${displaySetting} ${customOptions} -m ${modelOptions} ${SDKoption} --vnc-port ${DEFAULT_VNC_PORT} ${DEFAULT_APP_PATH}/${appFilename} ${libArgs}`
this.log(`[ZEMU] Command: ${command}`)

@@ -135,0 +150,0 @@

@@ -163,3 +163,3 @@ /** ******************************************************************************

static async stopAllEmuContainers() {
const timer = setTimeout(function () {
const timer = setTimeout(function() {
console.log('Could not kill all containers before timeout!')

@@ -194,3 +194,3 @@ process.exit(1)

this.log(`[ZEMU] Checking ELF`)
this.log(`Checking ELF`)
Zemu.checkElf(this.startOptions.model ?? DEFAULT_MODEL, this.elfPath)

@@ -201,14 +201,15 @@

this.log(`[ZEMU] Starting Container`)
this.log(`Starting Container`)
await this.emuContainer.runContainer(options)
this.log(`[ZEMU] Started Container`)
this.log(`Started Container`)
// eslint-disable-next-line func-names
await this.connect().catch(error => {
this.log(`[ZEMU] ${error}`)
this.log(`${error}`)
this.close()
throw error
})
this.log(`[ZEMU] Get initial snapshot`)
this.log(`Get initial snapshot`)

@@ -219,2 +220,3 @@ // Captures main screen

this.log(`[ZEMU] ${e}`)
throw e;
}

@@ -227,3 +229,3 @@ }

this.log(`[ZEMU] Wait VNC for ${waitDelay}`)
this.log(`Wait VNC for ${waitDelay}`)
Zemu.delay(waitDelay)

@@ -238,3 +240,4 @@

if (this.startOptions?.logging ?? false) {
process.stdout.write(`${message}\n`)
const currentTimestamp = new Date().toISOString().slice(11,23);
process.stdout.write(`[ZEMU] ${currentTimestamp}: ${message}\n`)
}

@@ -250,7 +253,7 @@ }

this.log(`[ZEMU] VNC Connection created ${this.host}:${this.vncPort}`)
this.log(`VNC Connection created ${this.host}:${this.vncPort}`)
const tmpVncSession = this.vncSession
this.vncSession.on('connect', () => {
this.log(`[ZEMU] VNC Session ready`)
this.log(`VNC Session ready`)

@@ -267,7 +270,7 @@ // @ts-ignore

this.vncSession.on('error', error => {
this.log(`[ZEMU] Could not connect to port ${tmpVncPort} on ${tmpHost}`)
reject(error)
this.log(`Could not connect to port ${tmpVncPort} on ${tmpHost}`)
reject(error);
})
setTimeout(() => reject(new Error('timeout on connectVNC')), 10000)
setTimeout(() => reject(new Error('timeout on connectVNC')), 6000)
})

@@ -288,3 +291,3 @@ }

async close() {
this.log('[ZEMU] Close')
this.log('Close')
await this.emuContainer.stop()

@@ -315,3 +318,3 @@ if (this.vncSession) {

this.log('[ZEMU] Requested snapshot')
this.log('Requested snapshot')
return new Promise((resolve, reject) => {

@@ -344,3 +347,3 @@ const session = this.getSession()

async waitUntilScreenIsNot(screen: any, timeout = 10000) {
async waitUntilScreenIsNot(screen: any, timeout = 2000) {
const start = new Date()

@@ -370,5 +373,5 @@ const inputSnapshotBufferHex = (await screen).buffer.toString('hex')

this.log(`[ZEMU] forward: ${snapshotCount} backwards: ${localBackClickCount}`)
this.log(`[ZEMU] golden ${snapshotPrefixGolden}`)
this.log(`[ZEMU] tmp ${snapshotPrefixTmp}`)
this.log(`forward: ${snapshotCount} backwards: ${localBackClickCount}`)
this.log(`golden ${snapshotPrefixGolden}`)
this.log(`tmp ${snapshotPrefixTmp}`)

@@ -378,3 +381,3 @@ let imageIndex = 0

let filename = `${snapshotPrefixTmp}/${indexStr}.png`
this.log(`[ZEMU] Start ${filename}`)
this.log(`Start ${filename}`)
await this.snapshot(filename)

@@ -388,3 +391,3 @@

await this.clickRight(filename)
this.log(`[ZEMU] Click Right ${filename}`)
this.log(`Click Right ${filename}`)
}

@@ -397,3 +400,3 @@

filename = `${snapshotPrefixTmp}/${indexStr}.png`
this.log(`[ZEMU] Click Left ${filename}`)
this.log(`Click Left ${filename}`)
await this.clickLeft(`${filename}`)

@@ -406,3 +409,3 @@ }

filename = `${snapshotPrefixTmp}/${indexStr}.png`
this.log(`[ZEMU] Click Right ${filename}`)
this.log(`Click Right ${filename}`)
await this.clickRight(`${filename}`)

@@ -414,9 +417,9 @@ }

filename = `${snapshotPrefixTmp}/${indexStr}.png`
this.log(`[ZEMU] Click Both ${filename}`)
this.log(`Click Both ${filename}`)
await this.clickBoth(`${filename}`)
this.log(`[ZEMU] Start comparison`)
this.log(`Start comparison`)
for (let j = 0; j < imageIndex + 1; j += 1) {
indexStr = `${j}`.padStart(5, '0')
this.log(`[ZEMU] Checked ${snapshotPrefixTmp}/${indexStr}.png`)
this.log(`Checked ${snapshotPrefixTmp}/${indexStr}.png`)
const img1 = Zemu.LoadPng2RGB(`${snapshotPrefixTmp}/${indexStr}.png`)

@@ -423,0 +426,0 @@ const img2 = Zemu.LoadPng2RGB(`${snapshotPrefixGolden}/${indexStr}.png`)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc