From: Chris Duncan Date: Wed, 20 Nov 2024 21:35:43 +0000 (-0800) Subject: Move performance tests into separate folder and add npm script to execute them. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=813571018213b05cb596c544fb43e7254b0ea294;p=libnemo.git Move performance tests into separate folder and add npm script to execute them. --- diff --git a/package.json b/package.json index 4c4e215..1d6f1e5 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "build": "rm -rf dist && tsc && esbuild main.min=dist/main.js global.min=dist/global.js --outdir=dist --target=es2022 --format=esm --platform=browser --bundle --minify --sourcemap", "test": "npm run build -- --platform=node && node --test --test-force-exit --env-file .env", "test:coverage": "npm run test -- --experimental-test-coverage", - "test:coverage:report": "npm run test:coverage -- --test-reporter=lcov --test-reporter-destination=coverage.info && genhtml coverage.info --output-directory test/coverage && rm coverage.info && xdg-open test/coverage/index.html" + "test:coverage:report": "npm run test:coverage -- --test-reporter=lcov --test-reporter-destination=coverage.info && genhtml coverage.info --output-directory test/coverage && rm coverage.info && xdg-open test/coverage/index.html", + "test:performance": "npm run test perf/*" }, "imports": { "#*": "./*" diff --git a/perf/account.mjs b/perf/account.mjs new file mode 100644 index 0000000..3b27cc8 --- /dev/null +++ b/perf/account.mjs @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +'use strict' + +import '#test/GLOBALS.mjs' +import { test } from 'node:test' +import { strict as assert } from 'assert' +import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' + +console.log('child key derivation performance test') + +test('BIP-44 ckd', async () => { + const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD) + await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + + const accounts = await wallet.accounts(0, 0x7fff) + + assert.equal(accounts.length, 0x8000) +}) + +test('BLAKE2b ckd', async () => { + const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) + await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + + const accounts = await wallet.accounts(0, 0x7fff) + + assert.equal(accounts.length, 0x8000) +}) diff --git a/perf/wallet.mjs b/perf/wallet.mjs new file mode 100644 index 0000000..bc90281 --- /dev/null +++ b/perf/wallet.mjs @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +'use strict' + +import '#test/GLOBALS.mjs' +import { test } from 'node:test' +import { strict as assert } from 'assert' +import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' + +console.log('wallet performance test') + +test('creating BIP-44 wallets', async () => { + const wallets = [] + for (let i = 0x80; i > 0; i--) { + wallets.push(await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)) + } + assert.equal(wallets.length, 0x80) +}) + +test('creating BLAKE2b wallets', async () => { + const wallets = [] + for (let i = 0x80; i > 0; i--) { + wallets.push(await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)) + } + assert.equal(wallets.length, 0x80) +}) diff --git a/test/performance.test.mjs b/test/performance.test.mjs deleted file mode 100644 index d7bd28e..0000000 --- a/test/performance.test.mjs +++ /dev/null @@ -1,50 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Chris Duncan -// SPDX-License-Identifier: GPL-3.0-or-later - -'use strict' - -import './GLOBALS.mjs' -import { describe, it } from 'node:test' -import { strict as assert } from 'assert' -import { NANO_TEST_VECTORS } from './TEST_VECTORS.js' -import { Bip44Wallet, Blake2bWallet } from '../dist/main.js' - -const skip = true - -describe('wallet generation performance', { skip }, async () => { - it('performance test creating BIP-44 wallets', async () => { - const wallets = [] - for (let i = 0x80; i > 0; i--) { - wallets.push(await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)) - } - assert.equal(wallets.length, 0x80) - }) - - it('performance test creating BLAKE2b wallets', async () => { - const wallets = [] - for (let i = 0x80; i > 0; i--) { - wallets.push(await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)) - } - assert.equal(wallets.length, 0x80) - }) -}) - -describe('child key derivation performance', { skip }, async () => { - it('performance test of BIP-44 ckd', async () => { - const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD) - await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - - const accounts = await wallet.accounts(0, 0x7fff) - - assert.equal(accounts.length, 0x8000) - }) - - it('performance test of BLAKE2b ckd', async () => { - const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) - await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - - const accounts = await wallet.accounts(0, 0x7fff) - - assert.equal(accounts.length, 0x8000) - }) -})