From d34c202f6f51a9878d1932c74aeb9d2c3d25d331 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 8 Jan 2025 07:10:08 -0800 Subject: [PATCH] Overhaul project structure by separating NanoPow code from its worker interface, consolidating test and performance code into one directory, creating additional import path mappings, and renaming files in general. --- package.json | 9 ++- src/lib/block.ts | 4 +- .../nano-pow/{nanopow-gl.ts => classes/gl.ts} | 77 ++++++++++--------- .../{nanopow-gpu.ts => classes/gpu.ts} | 59 +++++++------- src/lib/nano-pow/index.ts | 4 + src/lib/workers.ts | 11 ++- src/lib/workers/bip44-ckd.ts | 2 +- src/lib/workers/nano-nacl.ts | 2 +- src/lib/workers/nano-pow.ts | 43 +++++++++++ src/main.ts | 5 +- GLOBALS.mjs => test/GLOBALS.mjs | 0 test/{TEST_VECTORS.js => VECTORS.js} | 0 test/main.mjs | 14 ---- perf/account.perf.js => test/perf.account.js | 4 +- perf/block.perf.js => test/perf.block.js | 4 +- perf/main.mjs => test/perf.main.mjs | 6 +- perf/wallet.perf.js => test/perf.wallet.js | 4 +- ...te-pow.test.mjs => test.calculate-pow.mjs} | 4 +- ...wallet.test.mjs => test.create-wallet.mjs} | 4 +- ...unts.test.mjs => test.derive-accounts.mjs} | 4 +- ...wallet.test.mjs => test.import-wallet.mjs} | 4 +- ...wallet.mjs => test.lock-unlock-wallet.mjs} | 4 +- test/test.main.mjs | 14 ++++ ...ge-rolodex.mjs => test.manage-rolodex.mjs} | 4 +- ...nts.test.mjs => test.refresh-accounts.mjs} | 4 +- ...n-blocks.test.mjs => test.sign-blocks.mjs} | 4 +- test/{tools.test.mjs => test.tools.mjs} | 4 +- tsconfig.json | 3 +- 28 files changed, 182 insertions(+), 119 deletions(-) rename src/lib/nano-pow/{nanopow-gl.ts => classes/gl.ts} (83%) rename src/lib/nano-pow/{nanopow-gpu.ts => classes/gpu.ts} (85%) create mode 100644 src/lib/nano-pow/index.ts create mode 100644 src/lib/workers/nano-pow.ts rename GLOBALS.mjs => test/GLOBALS.mjs (100%) rename test/{TEST_VECTORS.js => VECTORS.js} (100%) delete mode 100644 test/main.mjs rename perf/account.perf.js => test/perf.account.js (95%) rename perf/block.perf.js => test/perf.block.js (96%) rename perf/main.mjs => test/perf.main.mjs (67%) rename perf/wallet.perf.js => test/perf.wallet.js (91%) rename test/{calculate-pow.test.mjs => test.calculate-pow.mjs} (88%) rename test/{create-wallet.test.mjs => test.create-wallet.mjs} (91%) rename test/{derive-accounts.test.mjs => test.derive-accounts.mjs} (93%) rename test/{import-wallet.test.mjs => test.import-wallet.mjs} (97%) rename test/{lock-unlock-wallet.mjs => test.lock-unlock-wallet.mjs} (96%) create mode 100644 test/test.main.mjs rename test/{manage-rolodex.mjs => test.manage-rolodex.mjs} (98%) rename test/{refresh-accounts.test.mjs => test.refresh-accounts.mjs} (98%) rename test/{sign-blocks.test.mjs => test.sign-blocks.mjs} (95%) rename test/{tools.test.mjs => test.tools.mjs} (95%) diff --git a/package.json b/package.json index f15a05b..cfa32f8 100644 --- a/package.json +++ b/package.json @@ -43,14 +43,17 @@ }, "scripts": { "build": "rm -rf dist && tsc && esbuild main.min=dist/main.js global.min=dist/global.js --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap", - "test": "npm run build && esbuild test.min=test/main.mjs --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap", + "test": "npm run build && esbuild test.min=test/test.main.mjs --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap", "test:node": "npm run build -- --platform=node && node --test --test-force-exit --env-file .env", "test:coverage": "npm run test:node -- --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:performance": "npm run build && esbuild perf.min=perf/main.mjs --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap" + "test:performance": "npm run build && esbuild perf.min=test/perf.main.mjs --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap" }, "imports": { - "#*": "./*" + "#~/*": "./src/lib/*", + "#dist/*": "./dist/*", + "#test/*": "./test/*", + "#nano-pow/*": "./src/lib/nano-pow/*" }, "optionalDependencies": { "@ledgerhq/hw-transport-web-ble": "^6.29.4", diff --git a/src/lib/block.ts b/src/lib/block.ts index 971c80f..7d669d5 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -8,7 +8,7 @@ import { dec, hex } from './convert.js' import { NanoNaCl } from './workers/nano-nacl.js' import { Pool } from './pool.js' import { Rpc } from './rpc.js' -import { PowGl, NanoPowGpu } from './workers.js' +import { NanoPow } from './workers.js' /** * Represents a block as defined by the Nano cryptocurrency protocol. The Block @@ -16,7 +16,7 @@ import { PowGl, NanoPowGpu } from './workers.js' * of three derived classes: SendBlock, ReceiveBlock, ChangeBlock. */ abstract class Block { - static #pool: Pool = new Pool(NanoPowGpu) + static #pool: Pool = new Pool(NanoPow) account: Account type: string = 'state' abstract subtype: 'send' | 'receive' | 'change' diff --git a/src/lib/nano-pow/nanopow-gl.ts b/src/lib/nano-pow/classes/gl.ts similarity index 83% rename from src/lib/nano-pow/nanopow-gl.ts rename to src/lib/nano-pow/classes/gl.ts index a99aa73..055dc14 100644 --- a/src/lib/nano-pow/nanopow-gl.ts +++ b/src/lib/nano-pow/classes/gl.ts @@ -2,31 +2,32 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Based on nano-webgl-pow by Ben Green (numtel) // https://github.com/numtel/nano-webgl-pow -import { WorkerInterface } from '../pool.js' -import { NanoPowGlFragmentShader, NanoPowGlVertexShader } from './shaders' - -export class PowGl extends WorkerInterface { - static { - PowGl.listen() - } - /** - * Calculates proof-of-work as described by the Nano cryptocurrency protocol. - * - * @param {any[]} data - Array of hashes and minimum thresholds - * @returns Promise for proof-of-work attached to original array objects - */ - static async work (data: any[]): Promise { - return new Promise(async (resolve, reject): Promise => { - for (const d of data) { - try { - d.work = await this.search(d.hash, d.threshold) - } catch (err) { - reject(err) - } - } - resolve(data) - }) - } +// import { WorkerInterface } from '#~/pool.js' +import { NanoPowGlFragmentShader, NanoPowGlVertexShader } from '#nano-pow/shaders/index.js' + +// export class NanoPowGl extends WorkerInterface { +// static { +// NanoPowGl.listen() +// } +// /** +// * Calculates proof-of-work as described by the Nano cryptocurrency protocol. +// * +// * @param {any[]} data - Array of hashes and minimum thresholds +// * @returns Promise for proof-of-work attached to original array objects +// */ +// static async work (data: any[]): Promise { +// return new Promise(async (resolve, reject): Promise => { +// for (const d of data) { +// try { +// d.work = await this.search(d.hash, d.threshold) +// } catch (err) { +// reject(err) +// } +// } +// resolve(data) +// }) +// } +export class NanoPowGl { /** Used to set canvas size. Must be a multiple of 256. */ static #WORKLOAD: number = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency)) @@ -130,7 +131,7 @@ export class PowGl extends WorkerInterface { * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation */ static async search (hash: string, threshold: number = 0xfffffff8): Promise { - if (PowGl.#gl == null) throw new Error('WebGL 2 is required') + if (NanoPowGl.#gl == null) throw new Error('WebGL 2 is required') if (!/^[A-F-a-f0-9]{64}$/.test(hash)) throw new Error(`invalid_hash ${hash}`) if (typeof threshold !== 'number') throw new TypeError(`Invalid threshold ${threshold}`) if (this.#gl == null) throw new Error('WebGL 2 is required') @@ -142,10 +143,10 @@ export class PowGl extends WorkerInterface { uboView.setUint32(i * 2, parseInt(uint32, 16)) } uboView.setUint32(128, threshold, true) - uboView.setFloat32(132, PowGl.#WORKLOAD - 1, true) - PowGl.#gl.bindBuffer(PowGl.#gl.UNIFORM_BUFFER, PowGl.#uboBuffer) - PowGl.#gl.bufferSubData(PowGl.#gl.UNIFORM_BUFFER, 0, uboView) - PowGl.#gl.bindBuffer(PowGl.#gl.UNIFORM_BUFFER, null) + uboView.setFloat32(132, NanoPowGl.#WORKLOAD - 1, true) + NanoPowGl.#gl.bindBuffer(NanoPowGl.#gl.UNIFORM_BUFFER, NanoPowGl.#uboBuffer) + NanoPowGl.#gl.bufferSubData(NanoPowGl.#gl.UNIFORM_BUFFER, 0, uboView) + NanoPowGl.#gl.bindBuffer(NanoPowGl.#gl.UNIFORM_BUFFER, null) // Start drawing to calculate one nonce per pixel let nonce = null @@ -185,7 +186,7 @@ export class PowGl extends WorkerInterface { return new Promise((resolve, reject): void => { try { requestAnimationFrame(async (): Promise => { - const result = await PowGl.checkQueryResult() + const result = await NanoPowGl.checkQueryResult() resolve(result) }) } catch (err) { @@ -221,9 +222,15 @@ export class PowGl extends WorkerInterface { } } +// export default ` +// const NanoPowGlFragmentShader = ${NanoPowGlFragmentShader} +// const NanoPowGlVertexShader = ${NanoPowGlVertexShader} +// // const WorkerInterface = ${WorkerInterface} +// const PowGl = ${NanoPowGl} +// ` + export default ` - const NanoPowGlFragmentShader = ${NanoPowGlFragmentShader} - const NanoPowGlVertexShader = ${NanoPowGlVertexShader} - const WorkerInterface = ${WorkerInterface} - const PowGl = ${PowGl} + const NanoPowGlFragmentShader = \`${NanoPowGlFragmentShader}\` + const NanoPowGlVertexShader = \`${NanoPowGlVertexShader}\` + const PowGl = ${NanoPowGl} ` diff --git a/src/lib/nano-pow/nanopow-gpu.ts b/src/lib/nano-pow/classes/gpu.ts similarity index 85% rename from src/lib/nano-pow/nanopow-gpu.ts rename to src/lib/nano-pow/classes/gpu.ts index 81ef6a1..b225007 100644 --- a/src/lib/nano-pow/nanopow-gpu.ts +++ b/src/lib/nano-pow/classes/gpu.ts @@ -2,35 +2,37 @@ // SPDX-License-Identifier: GPL-3.0-or-later // BLAKE2b hashing implementation derived from nano-webgl-pow by Ben Green (https://github.com/numtel/nano-webgl-pow) /// -import { WorkerInterface } from '../pool.js' -import { NanoPowGpuComputeShader } from './shaders' +// import { WorkerInterface } from '#~/pool.js' +import { NanoPowGpuComputeShader } from '#nano-pow/shaders/index.js' /** * Nano proof-of-work using WebGPU. */ -export class NanoPowGpu extends WorkerInterface { - static { - NanoPowGpu.listen() - } - - /** - * Calculates proof-of-work as described by the Nano cryptocurrency protocol. - * - * @param {any[]} data - Array of hashes and minimum thresholds - * @returns Promise for proof-of-work attached to original array objects - */ - static async work (data: any[]): Promise { - return new Promise(async (resolve, reject): Promise => { - for (const d of data) { - try { - d.work = await this.search(d.hash, d.threshold) - } catch (err) { - reject(err) - } - } - resolve(data) - }) - } +// export class NanoPowGpu extends WorkerInterface { +// static { +// NanoPowGpu.listen() +// } + +// /** +// * Calculates proof-of-work as described by the Nano cryptocurrency protocol. +// * +// * @param {any[]} data - Array of hashes and minimum thresholds +// * @returns Promise for proof-of-work attached to original array objects +// */ +// static async work (data: any[]): Promise { +// return new Promise(async (resolve, reject): Promise => { +// for (const d of data) { +// try { +// d.work = await this.search(d.hash, d.threshold) +// } catch (err) { +// reject(err) +// } +// } +// resolve(data) +// }) +// } +// */ +export class NanoPowGpu { // Initialize WebGPU static #device: GPUDevice | null = null @@ -210,8 +212,13 @@ export class NanoPowGpu extends WorkerInterface { } } +// export default ` +// const NanoPowGpuComputeShader = \`${NanoPowGpuComputeShader}\` +// const WorkerInterface = ${WorkerInterface} +// const NanoPowGpu = ${NanoPowGpu} +// ` + export default ` const NanoPowGpuComputeShader = \`${NanoPowGpuComputeShader}\` - const WorkerInterface = ${WorkerInterface} const NanoPowGpu = ${NanoPowGpu} ` diff --git a/src/lib/nano-pow/index.ts b/src/lib/nano-pow/index.ts new file mode 100644 index 0000000..bc02f2d --- /dev/null +++ b/src/lib/nano-pow/index.ts @@ -0,0 +1,4 @@ +import { NanoPowGl } from "./classes/gl" +import { NanoPowGpu } from "./classes/gpu" + +export { NanoPowGl, NanoPowGpu } diff --git a/src/lib/workers.ts b/src/lib/workers.ts index 71ac9ab..f91e41e 100644 --- a/src/lib/workers.ts +++ b/src/lib/workers.ts @@ -1,8 +1,7 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -import { default as Bip44Ckd } from './workers/bip44-ckd.js' -import { default as NanoNaCl } from './workers/nano-nacl.js' -import { default as PowGl } from './nano-pow/nanopow-gl.js' -import { default as NanoPowGpu } from './nano-pow/nanopow-gpu.js' - -export { Bip44Ckd, NanoNaCl, PowGl, NanoPowGpu } +import { default as Bip44Ckd } from '#~/workers/bip44-ckd.js' +import { default as NanoNaCl } from '#~/workers/nano-nacl.js' +import { default as NanoPow } from '#~/workers/nano-pow.js' +console.log(NanoPow) +export { Bip44Ckd, NanoNaCl, NanoPow } diff --git a/src/lib/workers/bip44-ckd.ts b/src/lib/workers/bip44-ckd.ts index 7764399..00c3bb2 100644 --- a/src/lib/workers/bip44-ckd.ts +++ b/src/lib/workers/bip44-ckd.ts @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -import { WorkerInterface } from '../pool.js' +import { WorkerInterface } from '#~/pool.js' type ExtendedKey = { privateKey: DataView diff --git a/src/lib/workers/nano-nacl.ts b/src/lib/workers/nano-nacl.ts index 3bbaf69..04af38a 100644 --- a/src/lib/workers/nano-nacl.ts +++ b/src/lib/workers/nano-nacl.ts @@ -4,7 +4,7 @@ 'use strict' import { Blake2b } from '../blake2b.js' -import { WorkerInterface } from '../pool.js' +import { WorkerInterface } from '#~/pool.js' // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri. // Public domain. diff --git a/src/lib/workers/nano-pow.ts b/src/lib/workers/nano-pow.ts new file mode 100644 index 0000000..49235f4 --- /dev/null +++ b/src/lib/workers/nano-pow.ts @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later +import { WorkerInterface } from '#~/pool.js' +import { NanoPowGpuComputeShader, NanoPowGlFragmentShader, NanoPowGlVertexShader } from '#nano-pow/shaders/index.js' +import { NanoPowGl, NanoPowGpu } from '#nano-pow/index.js' + +/** +* Nano proof-of-work using WebGPU. +*/ +export class NanoPow extends WorkerInterface { + static { + NanoPow.listen() + } + + /** + * Calculates proof-of-work as described by the Nano cryptocurrency protocol. + * + * @param {any[]} data - Array of hashes and minimum thresholds + * @returns Promise for proof-of-work attached to original array objects + */ + static async work (data: any[]): Promise { + return new Promise(async (resolve, reject): Promise => { + for (const d of data) { + try { + d.work = await NanoPowGpu.search(d.hash, d.threshold) + } catch (err) { + reject(err) + } + } + resolve(data) + }) + } +} + +export default ` + const NanoPowGpuComputeShader = \`${NanoPowGpuComputeShader}\` + const NanoPowGlFragmentShader = \`${NanoPowGlFragmentShader}\` + const NanoPowGlVertexShader = \`${NanoPowGlVertexShader}\` + const NanoPowGl = ${NanoPowGl} + const NanoPowGpu = ${NanoPowGpu} + const WorkerInterface = ${WorkerInterface} + const NanoPow = ${NanoPow} +` diff --git a/src/main.ts b/src/main.ts index 52b2a71..163c934 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,12 +4,11 @@ import { Account } from './lib/account.js' import { Blake2b } from './lib/blake2b.js' import { SendBlock, ReceiveBlock, ChangeBlock } from './lib/block.js' -import { PowGl } from './lib/nano-pow/nanopow-gl.js' -import { NanoPowGpu } from './lib/nano-pow/nanopow-gpu.js' +import { NanoPowGl, NanoPowGpu } from '#nano-pow/index.js' import { Rpc } from './lib/rpc.js' import { Rolodex } from './lib/rolodex.js' import { Safe } from './lib/safe.js' import { Tools } from './lib/tools.js' import { Bip44Wallet, Blake2bWallet, LedgerWallet } from './lib/wallet.js' -export { Account, Blake2b, SendBlock, ReceiveBlock, ChangeBlock, PowGl, NanoPowGpu, Rpc, Rolodex, Safe, Tools, Bip44Wallet, Blake2bWallet, LedgerWallet } +export { Account, Blake2b, SendBlock, ReceiveBlock, ChangeBlock, NanoPowGl as PowGl, NanoPowGpu, Rpc, Rolodex, Safe, Tools, Bip44Wallet, Blake2bWallet, LedgerWallet } diff --git a/GLOBALS.mjs b/test/GLOBALS.mjs similarity index 100% rename from GLOBALS.mjs rename to test/GLOBALS.mjs diff --git a/test/TEST_VECTORS.js b/test/VECTORS.js similarity index 100% rename from test/TEST_VECTORS.js rename to test/VECTORS.js diff --git a/test/main.mjs b/test/main.mjs deleted file mode 100644 index 1737521..0000000 --- a/test/main.mjs +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Chris Duncan -// SPDX-License-Identifier: GPL-3.0-or-later - -import './calculate-pow.test.mjs' -import './create-wallet.test.mjs' -import './derive-accounts.test.mjs' -import './import-wallet.test.mjs' -import './lock-unlock-wallet.mjs' -import './manage-rolodex.mjs' -import './refresh-accounts.test.mjs' -import './sign-blocks.test.mjs' -import './tools.test.mjs' - -console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') diff --git a/perf/account.perf.js b/test/perf.account.js similarity index 95% rename from perf/account.perf.js rename to test/perf.account.js index 0d7deef..a62076a 100644 --- a/perf/account.perf.js +++ b/test/perf.account.js @@ -3,8 +3,8 @@ 'use strict' -import { assert, average, skip, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, average, skip, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' await suite('Account performance', async () => { diff --git a/perf/block.perf.js b/test/perf.block.js similarity index 96% rename from perf/block.perf.js rename to test/perf.block.js index b23686c..79a41e2 100644 --- a/perf/block.perf.js +++ b/test/perf.block.js @@ -3,8 +3,8 @@ 'use strict' -import { assert, average, skip, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, average, skip, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { PowGl, NanoPowGpu, SendBlock } from '#dist/main.js' import 'nano-webgl-pow' diff --git a/perf/main.mjs b/test/perf.main.mjs similarity index 67% rename from perf/main.mjs rename to test/perf.main.mjs index a6b9de7..8858e1d 100644 --- a/perf/main.mjs +++ b/test/perf.main.mjs @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -// import './wallet.perf.js' -// import './account.perf.js' -import './block.perf.js' +// import './perf.wallet.js' +// import './perf.account.js' +import './perf.block.js' console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') diff --git a/perf/wallet.perf.js b/test/perf.wallet.js similarity index 91% rename from perf/wallet.perf.js rename to test/perf.wallet.js index 7ed3b14..a6e98dd 100644 --- a/perf/wallet.perf.js +++ b/test/perf.wallet.js @@ -3,8 +3,8 @@ 'use strict' -import { assert, average, skip, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, average, skip, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' await suite(`Wallet performance`, async () => { diff --git a/test/calculate-pow.test.mjs b/test/test.calculate-pow.mjs similarity index 88% rename from test/calculate-pow.test.mjs rename to test/test.calculate-pow.mjs index e33ff6c..f712e15 100644 --- a/test/calculate-pow.test.mjs +++ b/test/test.calculate-pow.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { SendBlock, Blake2b } from '#dist/main.js' await suite('Calculate proof-of-work', async () => { diff --git a/test/create-wallet.test.mjs b/test/test.create-wallet.mjs similarity index 91% rename from test/create-wallet.test.mjs rename to test/test.create-wallet.mjs index f0feaab..34b4ebf 100644 --- a/test/create-wallet.test.mjs +++ b/test/test.create-wallet.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, skip, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, skip, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '#dist/main.js' await suite('Create wallets', async () => { diff --git a/test/derive-accounts.test.mjs b/test/test.derive-accounts.mjs similarity index 93% rename from test/derive-accounts.test.mjs rename to test/test.derive-accounts.mjs index 562635a..309c6c3 100644 --- a/test/derive-accounts.test.mjs +++ b/test/test.derive-accounts.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, skip, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, skip, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '#dist/main.js' await suite('Account derivation', async () => { diff --git a/test/import-wallet.test.mjs b/test/test.import-wallet.mjs similarity index 97% rename from test/import-wallet.test.mjs rename to test/test.import-wallet.mjs index 5f7a6a7..a5502f8 100644 --- a/test/import-wallet.test.mjs +++ b/test/test.import-wallet.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, suite, test } from '#GLOBALS.mjs' -import { BIP32_TEST_VECTORS, CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, suite, test } from '#test/GLOBALS.mjs' +import { BIP32_TEST_VECTORS, CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/VECTORS.js' import { Account, Bip44Wallet, Blake2bWallet } from '#dist/main.js' await suite('Import wallets', async () => { diff --git a/test/lock-unlock-wallet.mjs b/test/test.lock-unlock-wallet.mjs similarity index 96% rename from test/lock-unlock-wallet.mjs rename to test/test.lock-unlock-wallet.mjs index 5ec6ec2..4c7577c 100644 --- a/test/lock-unlock-wallet.mjs +++ b/test/test.lock-unlock-wallet.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/VECTORS.js' import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' await suite('Lock and unlock wallets', async () => { diff --git a/test/test.main.mjs b/test/test.main.mjs new file mode 100644 index 0000000..413e356 --- /dev/null +++ b/test/test.main.mjs @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +import './test.calculate-pow.mjs' +import './test.create-wallet.mjs' +import './test.derive-accounts.mjs' +import './test.import-wallet.mjs' +import './test.lock-unlock-wallet.mjs' +import './test.manage-rolodex.mjs' +import './test.refresh-accounts.mjs' +import './test.sign-blocks.mjs' +import './test.tools.mjs' + +console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') diff --git a/test/manage-rolodex.mjs b/test/test.manage-rolodex.mjs similarity index 98% rename from test/manage-rolodex.mjs rename to test/test.manage-rolodex.mjs index 29c5005..2074b60 100644 --- a/test/manage-rolodex.mjs +++ b/test/test.manage-rolodex.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { Rolodex, Tools } from '#dist/main.js' await suite('Rolodex valid contact management', async () => { diff --git a/test/refresh-accounts.test.mjs b/test/test.refresh-accounts.mjs similarity index 98% rename from test/refresh-accounts.test.mjs rename to test/test.refresh-accounts.mjs index 89efbd1..7020198 100644 --- a/test/refresh-accounts.test.mjs +++ b/test/test.refresh-accounts.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, skip, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, skip, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { Account, Bip44Wallet, Rpc } from '#dist/main.js' let rpc diff --git a/test/sign-blocks.test.mjs b/test/test.sign-blocks.mjs similarity index 95% rename from test/sign-blocks.test.mjs rename to test/test.sign-blocks.mjs index f13abb6..282108e 100644 --- a/test/sign-blocks.test.mjs +++ b/test/test.sign-blocks.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, suite, test } from '#GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, suite, test } from '#test/GLOBALS.mjs' +import { NANO_TEST_VECTORS } from '#test/VECTORS.js' import { SendBlock, ReceiveBlock, ChangeBlock } from '#dist/main.js' await suite('Valid blocks', async () => { diff --git a/test/tools.test.mjs b/test/test.tools.mjs similarity index 95% rename from test/tools.test.mjs rename to test/test.tools.mjs index eabbb9f..899a70a 100644 --- a/test/tools.test.mjs +++ b/test/test.tools.mjs @@ -3,8 +3,8 @@ 'use strict' -import { assert, skip, suite, test } from '#GLOBALS.mjs' -import { RAW_MAX, NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' +import { assert, skip, suite, test } from '#test/GLOBALS.mjs' +import { RAW_MAX, NANO_TEST_VECTORS } from '#test/VECTORS.js' import { Bip44Wallet, Account, SendBlock, Rpc, Tools } from '#dist/main.js' let rpc diff --git a/tsconfig.json b/tsconfig.json index 1dab653..82d452f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,8 @@ "forceConsistentCasingInFileNames": true, "noErrorTruncation": true, "noFallthroughCasesInSwitch": true, - "strict": true + "strict": true, + "rootDir": "src" }, "include": [ "src/main.ts", -- 2.34.1