From: Chris Duncan Date: Fri, 6 Dec 2024 07:05:39 +0000 (-0800) Subject: Initialize wallet on each account derivation test to avoid race conditions from worke... X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=960ed86aefd146f6ecbe82c060df3b9b618ec571;p=libnemo.git Initialize wallet on each account derivation test to avoid race conditions from workers generating accounts and posting conflicting messages back to the main thread. --- diff --git a/test/derive-accounts.test.mjs b/test/derive-accounts.test.mjs index 50f93d7..1189d1a 100644 --- a/test/derive-accounts.test.mjs +++ b/test/derive-accounts.test.mjs @@ -7,69 +7,75 @@ import { assert, skip, test } from '#GLOBALS.mjs' import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '#dist/main.js' -test('derive child accounts from the same seed', async () => { +test('should derive the first account from the given BIP-44 seed', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + const accounts = await wallet.accounts() - test('should derive the first account from the given BIP-44 seed', async () => { - const accounts = await wallet.accounts() - - assert.equals(accounts.length, 1) - assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0) - assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0) - assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) - }) - - test('should derive low indexed accounts from the given BIP-44 seed', async () => { - const accounts = await wallet.accounts(1, 2) - - assert.equals(accounts.length, 2) - assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_1) - assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_1) - assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_1) - assert.equals(accounts[1].privateKey, NANO_TEST_VECTORS.PRIVATE_2) - assert.equals(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_2) - assert.equals(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2) - }) - - test('should derive high indexed accounts from the given seed', async () => { - const accounts = await wallet.accounts(0x70000000, 0x700000ff) - - assert.equals(accounts.length, 0x100) - for (const a of accounts) { - assert.exists(a) - assert.exists(a.address) - assert.exists(a.publicKey) - assert.exists(a.privateKey) - assert.exists(a.index) - } - }) - - test('should derive accounts for a BLAKE2b wallet', async () => { - const bwallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) - await bwallet.unlock(NANO_TEST_VECTORS.PASSWORD) - const lowAccounts = await bwallet.accounts(0, 2) + assert.equals(accounts.length, 1) + assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_0) + assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_0) + assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) +}) - assert.equals(lowAccounts.length, 3) - for (const a of lowAccounts) { - assert.exists(a) - assert.exists(a.address) - assert.exists(a.publicKey) - assert.exists(a.privateKey) - assert.exists(a.index) - } +test('should derive low indexed accounts from the given BIP-44 seed', async () => { + const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + const accounts = await wallet.accounts(1, 2) + + assert.equals(accounts.length, 2) + assert.equals(accounts[0].privateKey, NANO_TEST_VECTORS.PRIVATE_1) + assert.equals(accounts[0].publicKey, NANO_TEST_VECTORS.PUBLIC_1) + assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_1) + assert.equals(accounts[1].privateKey, NANO_TEST_VECTORS.PRIVATE_2) + assert.equals(accounts[1].publicKey, NANO_TEST_VECTORS.PUBLIC_2) + assert.equals(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2) +}) - const highAccounts = await bwallet.accounts(0x70000000, 0x700000ff) +test('should derive high indexed accounts from the given seed', async () => { + const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) + await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + let accounts + try { + accounts = await wallet.accounts(0x70000000, 0x700000ff) + } catch (err) { + throw new Error(err.message) + } + + assert.equals(accounts.length, 0x100) + for (const a of accounts) { + assert.exists(a) + assert.exists(a.address) + assert.exists(a.publicKey) + assert.exists(a.privateKey) + assert.exists(a.index) + } +}) - assert.equals(highAccounts.length, 0x100) - for (const a of highAccounts) { - assert.exists(a) - assert.exists(a.address) - assert.exists(a.publicKey) - assert.exists(a.privateKey) - assert.exists(a.index) - } - }) +test('should derive accounts for a BLAKE2b wallet', async () => { + const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) + await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + const lowAccounts = await wallet.accounts(0, 2) + + assert.equals(lowAccounts.length, 3) + for (const a of lowAccounts) { + assert.exists(a) + assert.exists(a.address) + assert.exists(a.publicKey) + assert.exists(a.privateKey) + assert.exists(a.index) + } + + const highAccounts = await wallet.accounts(0x70000000, 0x700000ff) + + assert.equals(highAccounts.length, 0x100) + for (const a of highAccounts) { + assert.exists(a) + assert.exists(a.address) + assert.exists(a.publicKey) + assert.exists(a.privateKey) + assert.exists(a.index) + } }) skip('Ledger device accounts', async () => {