From 92944aad585c3e815c701c26546dc3e1e8cc2718 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 11 Aug 2025 09:03:38 -0700 Subject: [PATCH] Fix tests. --- test/perf.block.mjs | 3 +-- test/test.blake2b.mjs | 5 +++++ test/test.blocks.mjs | 9 ++++----- test/test.import-wallet.mjs | 2 +- test/test.refresh-accounts.mjs | 32 ++++++++++++++++---------------- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/test/perf.block.mjs b/test/perf.block.mjs index f1ee95c..6509110 100644 --- a/test/perf.block.mjs +++ b/test/perf.block.mjs @@ -24,8 +24,7 @@ await Promise.all([ const { account, balance, previous, representative } = NANO_TEST_VECTORS.SEND_BLOCK const times = [] const block = new Block(account, balance, representative, previous) - .send(0) - .to(NANO_TEST_VECTORS.SEND_BLOCK.link) + .send(NANO_TEST_VECTORS.SEND_BLOCK.link, 0) for (let i = 0; i < COUNT; i++) { const start = performance.now() await block.pow() diff --git a/test/test.blake2b.mjs b/test/test.blake2b.mjs index ee19f6e..32ffd75 100644 --- a/test/test.blake2b.mjs +++ b/test/test.blake2b.mjs @@ -105,10 +105,15 @@ await Promise.all([ await test('invalid output lengths', async () => { //@ts-expect-error assert.throws(() => new Blake2b()) + //@ts-expect-error assert.throws(() => new Blake2b(null)) + //@ts-expect-error assert.throws(() => new Blake2b(true)) + //@ts-expect-error assert.throws(() => new Blake2b('')) + //@ts-expect-error assert.throws(() => new Blake2b('a')) + //@ts-expect-error assert.throws(() => new Blake2b('1')) assert.throws(() => new Blake2b(0)) assert.throws(() => new Blake2b(65)) diff --git a/test/test.blocks.mjs b/test/test.blocks.mjs index 81fe264..731df8e 100644 --- a/test/test.blocks.mjs +++ b/test/test.blocks.mjs @@ -95,7 +95,7 @@ await Promise.all([ }), suite('Block signing using official test vectors', async () => { - const { ADDRESS_0, BIP39_SEED, BLAKE2B_ADDRESS_1, BLAKE2B_PUBLIC_1, BLAKE2B_SEED, OPEN_BLOCK, PASSWORD, PRIVATE_0, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS + const { ADDRESS_0, BIP39_SEED, BLAKE2B_ADDRESS_1, BLAKE2B_PUBLIC_1, BLAKE2B_SEED, OPEN_BLOCK, PASSWORD, PUBLIC_0, PRIVATE_0, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS await test('sign open block with BLAKE2b wallet', async () => { const wallet = await Wallet.load('BLAKE2b', PASSWORD, BLAKE2B_SEED) @@ -103,8 +103,7 @@ await Promise.all([ const block = new Block(BLAKE2B_ADDRESS_1, '0', OPEN_BLOCK.previous, OPEN_BLOCK.representative) .receive(OPEN_BLOCK.link, OPEN_BLOCK.balance) - const signature = await wallet.sign(1, block, 'hex') - assert.equal(block.signature, signature) + await wallet.sign(1, block) assert.ok(await block.verify(BLAKE2B_PUBLIC_1)) await wallet.destroy() @@ -116,8 +115,8 @@ await Promise.all([ const block = new Block(ADDRESS_0, '0', OPEN_BLOCK.previous, OPEN_BLOCK.representative) .receive(OPEN_BLOCK.link, OPEN_BLOCK.balance) - const signature = await wallet.sign(0, block, 'hex') - assert.equal(block.signature, signature) + await wallet.sign(0, block) + assert.ok(await block.verify(PUBLIC_0)) await wallet.destroy() }) diff --git a/test/test.import-wallet.mjs b/test/test.import-wallet.mjs index 784199c..b15abef 100644 --- a/test/test.import-wallet.mjs +++ b/test/test.import-wallet.mjs @@ -264,7 +264,7 @@ await Promise.all([ await test('export wallet IDs from storage and reimport them', async () => { const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) - const backups = await Wallet.export() + const backups = await Wallet.backup() assert.ok(backups.some(record => record.id === wallet.id)) diff --git a/test/test.refresh-accounts.mjs b/test/test.refresh-accounts.mjs index 3b149dc..0ddbb4e 100644 --- a/test/test.refresh-accounts.mjs +++ b/test/test.refresh-accounts.mjs @@ -11,17 +11,17 @@ import { NANO_TEST_VECTORS } from './VECTORS.mjs' */ let Account /** -* @type {typeof import('../dist/types.d.ts').Bip44Wallet} +* @type {typeof import('../dist/types.d.ts').Wallet} */ -let Bip44Wallet +let Wallet /** * @type {typeof import('../dist/types.d.ts').Rpc} */ let Rpc if (isNode) { - ({ Account, Bip44Wallet, Rpc } = await import('../dist/nodejs.min.js')) + ({ Account, Wallet, Rpc } = await import('../dist/nodejs.min.js')) } else { - ({ Account, Bip44Wallet, Rpc } = await import('../dist/browser.min.js')) + ({ Account, Wallet, Rpc } = await import('../dist/browser.min.js')) } const rpc = new Rpc(env.NODE_URL ?? '', env.API_KEY_NAME) @@ -30,7 +30,7 @@ await Promise.all([ suite('Refreshing account info', { skip: true }, async () => { await test('fetch balance, frontier, and representative', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.account() await account.refresh(rpc) @@ -56,7 +56,7 @@ await Promise.all([ }) await test('throw when refreshing unopened account', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.account(0x7fffffff) @@ -67,7 +67,7 @@ await Promise.all([ }) await test('throw when referencing invalid account index', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) await assert.rejects(wallet.account(0x80000000), @@ -77,7 +77,7 @@ await Promise.all([ }) await test('throw with invalid node', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const invalidNode = new Rpc('http://invalid.com') const account = await wallet.account() @@ -92,7 +92,7 @@ await Promise.all([ suite('Fetch next unopened account', { skip: true }, async () => { await test('return correct account from test vector', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.unopened(rpc) @@ -104,7 +104,7 @@ await Promise.all([ }) await test('return successfully for small batch size', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.unopened(rpc, 1) @@ -116,7 +116,7 @@ await Promise.all([ }) await test('return successfully for large batch size', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.unopened(rpc, 100) @@ -128,7 +128,7 @@ await Promise.all([ }) await test('should throw on invalid node URL', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) //@ts-expect-error @@ -146,7 +146,7 @@ await Promise.all([ }) await test('should throw on invalid batch size', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) //@ts-expect-error @@ -166,7 +166,7 @@ await Promise.all([ suite('Refreshing wallet accounts', { skip: true }, async () => { await test('should get balance, frontier, and representative for one account', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.refresh(rpc) const account = accounts[0] @@ -180,7 +180,7 @@ await Promise.all([ }) await test('should get balance, frontier, and representative for multiple accounts', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.refresh(rpc, 0, 2) @@ -191,7 +191,7 @@ await Promise.all([ }) await test('should handle failure gracefully', async () => { - const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) await assert.resolves(wallet.refresh(rpc, 0, 20)) -- 2.47.3