Skip to content

Commit

Permalink
format zemu
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Jan 15, 2025
1 parent 1e2fd68 commit fc2c45b
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 141 deletions.
24 changes: 0 additions & 24 deletions tests_zemu/.eslintrc.js

This file was deleted.

36 changes: 36 additions & 0 deletions tests_zemu/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: {
window: 'readonly',
document: 'readonly',
process: 'readonly',
require: 'readonly',
},
parserOptions: {
project: 'tsconfig.json',
},
},
ignores: ['dist/*', 'node_modules/*'],
plugins: {
'unused-imports': require('eslint-plugin-unused-imports'),
'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
'eslint-plugin-tsdoc': require('eslint-plugin-tsdoc'),
},
rules: {
curly: 'warn',
'prefer-const': 'warn',
'no-else-return': 'warn',
complexity: ['warn', 1000],
'no-unneeded-ternary': 'warn',
'no-alert': 'warn',
'no-empty': 'warn',
'no-useless-catch': 'error',
'require-await': 'warn',
'no-continue': 'warn',
'no-console': 'off',
'unused-imports/no-unused-imports': 'warn',
'no-magic-numbers': 'off',
},
}
25 changes: 15 additions & 10 deletions tests_zemu/globalsetup.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import Zemu from '@zondax/zemu'
const Zemu = require('@zondax/zemu')

const catchExit = async () => {
process.on('SIGINT', () => {
Zemu.stopAllEmuContainers(function () {
process.exit()
})
/**
* Sets up a handler to stop all emulator containers when a SIGINT is received.
*/
const catchExit = () => {
process.on('SIGINT', async () => {
await Zemu.default.stopAllEmuContainers()
process.exit()
})
}

/**
* Initializes the emulator environment by setting up exit handlers,
* pulling the latest emulator image, and stopping any running emulator containers.
*/
module.exports = async () => {
await catchExit()
await Zemu.checkAndPullImage()
await Zemu.stopAllEmuContainers()
catchExit()
await Zemu.default.checkAndPullImage()
await Zemu.default.stopAllEmuContainers()
}
//
2 changes: 2 additions & 0 deletions tests_zemu/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transformIgnorePatterns: ['^.+\\.js$'],
reporters: ['default', ['summary', { summaryThreshold: 1 }]],
globalSetup: './globalsetup.js',
}
35 changes: 21 additions & 14 deletions tests_zemu/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
{
"name": "integration-tests",
"author": "Zondax AG",
"license": "Apache-2.0",
"version": "1.0.0",
"description": "",
"types": "./dist/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Zondax/ledger-penumbra"
},
"keywords": [
"Zondax",
"Ledger"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Zondax/ledger-penumbra"
},
"license": "Apache-2.0",
"author": "Zondax AG",
"types": "./dist/index.d.ts",
"scripts": {
"clean": "ts-node tests/pullImageKillOld.ts",
"format": "FORCE_COLOR=1 prettier --write . && sort-package-json",
"format:check": "FORCE_COLOR=1 prettier --check .",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"test": "yarn clean && jest --maxConcurrency 3",
"test_dev": "jest",
"try": "node try.mjs"
Expand All @@ -28,21 +32,24 @@
"@matteoh2o1999/github-actions-jest-reporter": "^3.0.0",
"@types/jest": "^29.5.14",
"@types/ledgerhq__hw-transport": "^4.21.8",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "^8.18.2",
"@typescript-eslint/eslint-plugin": "^8.20.0",
"@typescript-eslint/parser": "^8.20.0",
"blakejs": "^1.2.1",
"crypto-js": "4.2.0",
"ed25519-supercop": "^2.0.1",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.10.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-prettier": "^5.2.2",
"eslint-plugin-tsdoc": "^0.4.0",
"eslint-plugin-unused-imports": "^4.1.4",
"jest": "29.7.0",
"jssha": "^3.3.1",
"prettier": "^3.4.2",
"sort-package-json": "^2.14.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
"typescript": "^5.7.3"
}
}
1 change: 0 additions & 1 deletion tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ export const defaultOptions = {

export const txBlobExample =
'0abe020abb020aa8010a300a0a08c8daccb4a6f185e40612220a2029ea9c2f3371f6a487e7e95c247041f4a356f983eb064e5d2b3bcf322ca96a10122085197c5d60cf28b5ec756a657957b310072396577956fd5cd421ca62b4a6bc091a520a50890bc98e3698aa4578e419b028da5672e627c280d8b06166f4c42d5366bccf1fcf3b296cd61e8d744a21f75f2fb697183e18595d8a79008539d8fb138b405db09db65cc42d54c0e772e5d42d5f20b52f10f1a9e496d5f01d1a20732b53ee807140dd5672768ec1a38be09c531a0c6fc185d5f51c18f5f2261d012220f2e2f45f0ea734d7c11321cbf20427b379cfed6f71874ff97e8bcbbfce2d3d012a2073ec22fcaeccfadc720dd0350cf6af7ec274a74be832e8334613638edfd2fb10322093043bfea2094b0398f0e14bccc66a9ec335bbfd1f8e8b4c2c21428947f5e50d121c08cec08d8e1e1206757673762d361a0c0a0a08d6fab2e5c4f992aa0b'

74 changes: 36 additions & 38 deletions tests_zemu/tests/effect_hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,49 @@ describe('Standard', function () {
})

describe.each(ACTIONS_TESTCASES)('Wallet transactions', function (data) {
test.concurrent.each(models)('sign', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new PenumbraApp(sim.getTransport())
test.concurrent.each(models)('sign', async function (m) {
const sim = new Zemu(m.path)
try {
await sim.start({ ...defaultOptions, model: m.name })
const app = new PenumbraApp(sim.getTransport())

const messageToSign = Buffer.from(data.blob, 'hex')
const messageToSign = Buffer.from(data.blob, 'hex')

const addressIndex: AddressIndex = {
account: ACCOUNT_ID,
randomizer: undefined,
}
// do not wait here... we need to navigate
const signatureRequest = app.sign(PENUMBRA_PATH, messageToSign)
const addressIndex: AddressIndex = {
account: ACCOUNT_ID,
randomizer: undefined,
}
// do not wait here... we need to navigate
const signatureRequest = app.sign(PENUMBRA_PATH, messageToSign)

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_${data.name}`)
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot())
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_${data.name}`)


const signatureResponse = await signatureRequest
console.log("Effect hash:", signatureResponse.effectHash.toString('hex'))
const signatureResponse = await signatureRequest
console.log('Effect hash:', signatureResponse.effectHash.toString('hex'))

if (signatureResponse.spendAuthSignatures.length > 0) {
signatureResponse.spendAuthSignatures.forEach((signature, index) => {
console.log(`Spend Auth Signature ${index + 1}: ${signature.toString('hex')}`);
})
} else {
console.log("No spend auth signatures available.");
}
if (signatureResponse.spendAuthSignatures.length > 0) {
signatureResponse.spendAuthSignatures.forEach((signature, index) => {
console.log(`Spend Auth Signature ${index + 1}: ${signature.toString('hex')}`)
})
} else {
console.log('No spend auth signatures available.')
}

if (signatureResponse.delegatorVoteSignatures.length > 0) {
signatureResponse.delegatorVoteSignatures.forEach((signature, index) => {
console.log(`Delegator Vote Signature ${index + 1}: ${signature.toString('hex')}`);
});
} else {
console.log("No delegator vote signatures available.");
}
if (signatureResponse.delegatorVoteSignatures.length > 0) {
signatureResponse.delegatorVoteSignatures.forEach((signature, index) => {
console.log(`Delegator Vote Signature ${index + 1}: ${signature.toString('hex')}`)
})
} else {
console.log('No delegator vote signatures available.')
}

// Now verify effect hash
expect(signatureResponse.effectHash.toString('hex')).toEqual(data.expected_effect_hash)

} finally {
await sim.close()
}
// Now verify effect hash
expect(signatureResponse.effectHash.toString('hex')).toEqual(data.expected_effect_hash)
} finally {
await sim.close()
}
})
})
})
Loading

0 comments on commit fc2c45b

Please sign in to comment.