From: Chris Duncan Date: Fri, 6 Dec 2024 22:21:34 +0000 (-0800) Subject: Await tests so they actually finish. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=36381fb2716e8b7978865c9772860c2d289c7dd9;p=libnemo.git Await tests so they actually finish. --- diff --git a/perf/account.perf.js b/perf/account.perf.js index 59b6e44..4ce0a81 100644 --- a/perf/account.perf.js +++ b/perf/account.perf.js @@ -7,7 +7,7 @@ import { assert, skip, test } from '#GLOBALS.mjs' import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' -test('BIP-44 ckd performance test', async () => { +await test('BIP-44 ckd performance test', async () => { const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -17,7 +17,7 @@ test('BIP-44 ckd performance test', async () => { assert.equals(accounts.length, 0x8000) }) -test('BLAKE2b ckd performance test', async () => { +await test('BLAKE2b ckd performance test', async () => { const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) diff --git a/perf/wallet.perf.js b/perf/wallet.perf.js index 5024366..4b845a1 100644 --- a/perf/wallet.perf.js +++ b/perf/wallet.perf.js @@ -7,7 +7,7 @@ import { assert, skip, test } from '#GLOBALS.mjs' import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' -test('creating BIP-44 wallets performance test', async () => { +await test('creating BIP-44 wallets performance test', async () => { const wallets = [] for (let i = 0x80; i > 0; i--) { wallets.push(await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)) @@ -15,7 +15,7 @@ test('creating BIP-44 wallets performance test', async () => { assert.equals(wallets.length, 0x80) }) -test('creating BLAKE2b wallets performance test', async () => { +await test('creating BLAKE2b wallets performance test', async () => { const wallets = [] for (let i = 0x80; i > 0; i--) { wallets.push(await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)) diff --git a/test/create-wallet.test.mjs b/test/create-wallet.test.mjs index 5a6bfe5..dc051ef 100644 --- a/test/create-wallet.test.mjs +++ b/test/create-wallet.test.mjs @@ -7,7 +7,7 @@ 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('BIP-44 wallet with random entropy', async () => { +await test('BIP-44 wallet with random entropy', async () => { const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -19,7 +19,7 @@ test('BIP-44 wallet with random entropy', async () => { assert.ok(/[A-Fa-f0-9]{32,64}/.test(wallet.seed)) }) -test('BLAKE2b wallet with random entropy', async () => { +await test('BLAKE2b wallet with random entropy', async () => { const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -31,7 +31,7 @@ test('BLAKE2b wallet with random entropy', async () => { assert.ok(/[A-Fa-f0-9]{32,64}/.test(wallet.seed)) }) -test('BIP-44 replace invalid salt with empty string', async () => { +await test('BIP-44 replace invalid salt with empty string', async () => { const invalidArgs = [null, true, false, 0, 1, 2, { "foo": "bar" }] for (const arg of invalidArgs) { //@ts-expect-error @@ -39,7 +39,7 @@ test('BIP-44 replace invalid salt with empty string', async () => { } }) -test('fail when using new', () => { +await test('fail when using new', () => { //@ts-expect-error assert.throws(() => new Bip44Wallet()) //@ts-expect-error @@ -48,7 +48,7 @@ test('fail when using new', () => { assert.throws(() => new LedgerWallet()) }) -test('fail without a password', async () => { +await test('fail without a password', async () => { //@ts-expect-error await assert.rejects(Bip44Wallet.create()) //@ts-expect-error diff --git a/test/derive-accounts.test.mjs b/test/derive-accounts.test.mjs index 0b04f81..ecbea6a 100644 --- a/test/derive-accounts.test.mjs +++ b/test/derive-accounts.test.mjs @@ -7,7 +7,7 @@ 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('should derive the first account from the given BIP-44 seed', async () => { +await 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() @@ -18,7 +18,7 @@ test('should derive the first account from the given BIP-44 seed', async () => { assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) }) -test('should derive low indexed accounts from the given BIP-44 seed', async () => { +await 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) @@ -32,7 +32,7 @@ test('should derive low indexed accounts from the given BIP-44 seed', async () = assert.equals(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2) }) -test('should derive high indexed accounts from the given seed', async () => { +await 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) const accounts = await wallet.accounts(0x70000000, 0x700000ff) @@ -49,7 +49,7 @@ test('should derive high indexed accounts from the given seed', async () => { } }) -test('should derive accounts for a BLAKE2b wallet', async () => { +await 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) diff --git a/test/import-wallet.test.mjs b/test/import-wallet.test.mjs index 15b87ef..b0690a9 100644 --- a/test/import-wallet.test.mjs +++ b/test/import-wallet.test.mjs @@ -7,7 +7,7 @@ import { assert, test } from '#GLOBALS.mjs' import { BIP32_TEST_VECTORS, CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Account, Bip44Wallet, Blake2bWallet } from '#dist/main.js' -test('import a wallet with the official Nano test vectors mnemonic', async () => { +await test('import a wallet with the official Nano test vectors mnemonic', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -22,13 +22,13 @@ test('import a wallet with the official Nano test vectors mnemonic', async () => assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) }) -test('import a wallet with the checksum starting with a zero', async () => { +await test('import a wallet with the checksum starting with a zero', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, 'food define cancel major spoon trash cigar basic aim bless wolf win ability seek paddle bench seed century group they mercy address monkey cake') await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) assert.equals(wallet.seed, 'F665F804E5907985455D1E5A7AD344843A2ED4179A7E06EEF263DE925FF6F4C0991B0A9344FCEE939FE0F1B1841B8C9B20FEACF6B954B74B2D26A01906B758E2') }) -test('import a wallet with a 12-word phrase', async () => { +await test('import a wallet with a 12-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_0) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -41,7 +41,7 @@ test('import a wallet with a 12-word phrase', async () => { assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_0) }) -test('import a wallet with a 15-word phrase', async () => { +await test('import a wallet with a 15-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -54,7 +54,7 @@ test('import a wallet with a 15-word phrase', async () => { assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_1) }) -test('import a wallet with a 18-word phrase', async () => { +await test('import a wallet with a 18-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_2) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -67,7 +67,7 @@ test('import a wallet with a 18-word phrase', async () => { assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_2) }) -test('import a wallet with a 21-word phrase', async () => { +await test('import a wallet with a 21-word phrase', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, CUSTOM_TEST_VECTORS.ENTROPY_3) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -80,7 +80,7 @@ test('import a wallet with a 21-word phrase', async () => { assert.equals(account.address, CUSTOM_TEST_VECTORS.ADDRESS_3) }) -test('import a wallet with the official Nano test vectors seed', async () => { +await test('import a wallet with the official Nano test vectors 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() @@ -95,7 +95,7 @@ test('import a wallet with the official Nano test vectors seed', async () => { assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0) }) -test('import a BIP-44 wallet with the zero seed', async () => { +await test('import a BIP-44 wallet with the zero seed', async () => { const wallet = await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0, TREZOR_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(0, 3) @@ -114,7 +114,7 @@ test('import a BIP-44 wallet with the zero seed', async () => { } }) -test('import a BLAKE2b wallet with the zero seed', async () => { +await test('import a BLAKE2b wallet with the zero seed', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(0, 3) @@ -134,7 +134,7 @@ test('import a BLAKE2b wallet with the zero seed', async () => { } }) -test('import a BLAKE2b wallet with Trezor test vectors', async () => { +await test('import a BLAKE2b wallet with Trezor test vectors', async () => { const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts(0, 1) @@ -155,7 +155,7 @@ test('import a BLAKE2b wallet with Trezor test vectors', async () => { assert.equals(accounts[1].address, TREZOR_TEST_VECTORS.BLAKE2B_1_ADDRESS_1) }) -test('get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => { +await test('get identical BLAKE2b wallets when created with a seed versus with its derived mnemonic', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_2) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const walletAccounts = await wallet.accounts() @@ -177,7 +177,7 @@ test('get identical BLAKE2b wallets when created with a seed versus with its der assert.equals(importedAccount.publicKey, walletAccount.publicKey) }) -test('get identical BLAKE2b wallets when created with max entropy value', async () => { +await test('get identical BLAKE2b wallets when created with max entropy value', async () => { const wallet = await Blake2bWallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.MNEMONIC_3) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const accounts = await wallet.accounts() @@ -193,20 +193,20 @@ test('get identical BLAKE2b wallets when created with max entropy value', async assert.equals(accounts[0].address, TREZOR_TEST_VECTORS.BLAKE2B_3_ADDRESS_0) }) -test('reject when given invalid entropy', async () => { +await test('reject when given invalid entropy', async () => { await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797')) await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701')) await assert.rejects(Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x'))) }) -test('reject when given a seed with an invalid length', async () => { +await test('reject when given a seed with an invalid length', async () => { await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED + 'f'), `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length + 1}-character string.`) await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED.slice(0, -1)), `Expected a ${NANO_TEST_VECTORS.BIP39_SEED.length}-character seed, but received ${NANO_TEST_VECTORS.BIP39_SEED.length - 1}-character string.`) }) -test('reject when given a seed containing non-hex characters', async () => { +await test('reject when given a seed containing non-hex characters', async () => { await assert.rejects(Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.SEED_0.replace(/./, 'g')), 'Seed contains invalid hexadecimal characters.') await assert.rejects(Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1.replace(/./, 'g')), @@ -214,7 +214,7 @@ test('reject when given a seed containing non-hex characters', async () => { }) -test('retrieve a Bip44Wallet from storage using an ID', async () => { +await test('retrieve a Bip44Wallet from storage using an ID', async () => { const id = (await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)).id const wallet = await Bip44Wallet.restore(id) @@ -232,7 +232,7 @@ test('retrieve a Bip44Wallet from storage using an ID', async () => { assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('retrieve a Blake2bWallet from storage using an ID', async () => { +await test('retrieve a Blake2bWallet from storage using an ID', async () => { const id = (await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)).id const wallet = await Blake2bWallet.restore(id) diff --git a/test/lock-unlock-wallet.mjs b/test/lock-unlock-wallet.mjs index 5ce3a4e..85a55ab 100644 --- a/test/lock-unlock-wallet.mjs +++ b/test/lock-unlock-wallet.mjs @@ -7,7 +7,7 @@ import { assert, test } from '#GLOBALS.mjs' import { NANO_TEST_VECTORS, TREZOR_TEST_VECTORS } from '#test/TEST_VECTORS.js' import { Bip44Wallet, Blake2bWallet } from '#dist/main.js' -test('locking and unlocking a Bip44Wallet with a password', async () => { +await test('locking and unlocking a Bip44Wallet with a password', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) assert.ok('mnemonic' in wallet) @@ -24,7 +24,7 @@ test('locking and unlocking a Bip44Wallet with a password', async () => { assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('locking and unlocking a Bip44Wallet with a random CryptoKey', async () => { +await test('locking and unlocking a Bip44Wallet with a random CryptoKey', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -45,7 +45,7 @@ test('locking and unlocking a Bip44Wallet with a random CryptoKey', async () => assert.equals(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('fail to unlock a Bip44Wallet with different passwords', async () => { +await test('fail to unlock a Bip44Wallet with different passwords', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const lockResult = await wallet.lock(TREZOR_TEST_VECTORS.PASSWORD) @@ -58,7 +58,7 @@ test('fail to unlock a Bip44Wallet with different passwords', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('fail to unlock a Bip44Wallet with different keys', async () => { +await test('fail to unlock a Bip44Wallet with different keys', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -73,7 +73,7 @@ test('fail to unlock a Bip44Wallet with different keys', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('fail to unlock a Bip44Wallet with different valid inputs', async () => { +await test('fail to unlock a Bip44Wallet with different valid inputs', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -84,7 +84,7 @@ test('fail to unlock a Bip44Wallet with different valid inputs', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('fail to unlock a Bip44Wallet with no input', async () => { +await test('fail to unlock a Bip44Wallet with no input', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -105,7 +105,7 @@ test('fail to unlock a Bip44Wallet with no input', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('fail to unlock a Bip44Wallet with invalid input', async () => { +await test('fail to unlock a Bip44Wallet with invalid input', async () => { const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -126,7 +126,7 @@ test('fail to unlock a Bip44Wallet with invalid input', async () => { assert.notEqual(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) }) -test('locking and unlocking a Blake2bWallet with a password', async () => { +await test('locking and unlocking a Blake2bWallet with a password', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0) assert.ok('mnemonic' in wallet) @@ -143,7 +143,7 @@ test('locking and unlocking a Blake2bWallet with a password', async () => { assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0) }) -test('locking and unlocking a Blake2bWallet with a random CryptoKey', async () => { +await test('locking and unlocking a Blake2bWallet with a random CryptoKey', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -165,7 +165,7 @@ test('locking and unlocking a Blake2bWallet with a random CryptoKey', async () = assert.equals(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) -test('fail to unlock a Blake2bWallet with different passwords', async () => { +await test('fail to unlock a Blake2bWallet with different passwords', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' }) @@ -175,7 +175,7 @@ test('fail to unlock a Blake2bWallet with different passwords', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) -test('fail to unlock a Blake2bWallet with different keys', async () => { +await test('fail to unlock a Blake2bWallet with different keys', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const rightKey = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -190,7 +190,7 @@ test('fail to unlock a Blake2bWallet with different keys', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) -test('fail to unlock a Blake2bWallet with different valid inputs', async () => { +await test('fail to unlock a Blake2bWallet with different valid inputs', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) const key = await globalThis.crypto.subtle.generateKey({ name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']) @@ -201,7 +201,7 @@ test('fail to unlock a Blake2bWallet with different valid inputs', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) -test('fail to unlock a Blake2bWallet with no input', async () => { +await test('fail to unlock a Blake2bWallet with no input', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -222,7 +222,7 @@ test('fail to unlock a Blake2bWallet with no input', async () => { assert.notEqual(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_1) }) -test('fail to unlock a Blake2bWallet with invalid input', async () => { +await test('fail to unlock a Blake2bWallet with invalid input', async () => { const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) diff --git a/test/manage-rolodex.mjs b/test/manage-rolodex.mjs index bef4635..206aa51 100644 --- a/test/manage-rolodex.mjs +++ b/test/manage-rolodex.mjs @@ -9,7 +9,7 @@ import { Rolodex, Tools } from '#dist/main.js' console.log('> rolodex valid contact management <') -test('should create a rolodex and add two contacts', async () => { +await test('should create a rolodex and add two contacts', async () => { const rolodex = new Rolodex() assert.equals(rolodex.constructor, Rolodex) await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) @@ -24,13 +24,13 @@ test('should create a rolodex and add two contacts', async () => { assert.equals(rolodex.getAddresses('JaneSmith')[0], NANO_TEST_VECTORS.ADDRESS_1) }) -test('should get a name from an address', async () => { +await test('should get a name from an address', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) assert.equals(rolodex.getName(NANO_TEST_VECTORS.ADDRESS_0), 'JohnDoe') }) -test('should add three addresses to the same contact', async () => { +await test('should add three addresses to the same contact', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_1) await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_2) @@ -41,7 +41,7 @@ test('should add three addresses to the same contact', async () => { assert.equals(rolodex.getAddresses('JohnDoe')[2], NANO_TEST_VECTORS.ADDRESS_0) }) -test('should update the name on an existing entry', async () => { +await test('should update the name on an existing entry', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) await rolodex.add('JaneSmith', NANO_TEST_VECTORS.ADDRESS_0) @@ -50,14 +50,14 @@ test('should update the name on an existing entry', async () => { assert.equals(rolodex.getAddresses('JaneSmith')[0], NANO_TEST_VECTORS.ADDRESS_0) }) -test('should return empty address array for an unknown contact', async () => { +await test('should return empty address array for an unknown contact', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) assert.equals(Array.isArray(rolodex.getAddresses('JaneSmith')), true) assert.equals(rolodex.getAddresses('JaneSmith').length, 0) }) -test('should return empty address array for blank contact names', () => { +await test('should return empty address array for blank contact names', () => { const rolodex = new Rolodex() //@ts-expect-error assert.equals(Array.isArray(rolodex.getAddresses(undefined)), true) @@ -71,14 +71,14 @@ test('should return empty address array for blank contact names', () => { assert.equals(rolodex.getAddresses('').length, 0) }) -test('should return null for an unknown address', async () => { +await test('should return null for an unknown address', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) assert.ok(rolodex.getName(NANO_TEST_VECTORS.ADDRESS_1) === null) assert.ok(rolodex.getName(NANO_TEST_VECTORS.ADDRESS_1) !== undefined) }) -test('should return null for a blank address', async () => { +await test('should return null for a blank address', async () => { const rolodex = new Rolodex() await rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0) //@ts-expect-error @@ -95,13 +95,13 @@ test('should return null for a blank address', async () => { console.log('> rolodex exceptions <') -test('should throw if adding no data', async () => { +await test('should throw if adding no data', async () => { const rolodex = new Rolodex() //@ts-expect-error await assert.rejects(rolodex.add()) }) -test('should throw if passed no address', async () => { +await test('should throw if passed no address', async () => { const rolodex = new Rolodex() //@ts-expect-error await assert.rejects(rolodex.add('JohnDoe')) @@ -112,7 +112,7 @@ test('should throw if passed no address', async () => { await assert.rejects(rolodex.add('JohnDoe', '')) }) -test('should throw if name is blank', async () => { +await test('should throw if name is blank', async () => { const rolodex = new Rolodex() //@ts-expect-error await assert.rejects(rolodex.add(undefined, NANO_TEST_VECTORS.ADDRESS_0)) @@ -123,7 +123,7 @@ test('should throw if name is blank', async () => { console.log('> rolodex data signature verification <') -test('should verify valid data and signature', async () => { +await test('should verify valid data and signature', async () => { const data = 'Test data' const signature = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, data) const rolodex = new Rolodex() @@ -132,7 +132,7 @@ test('should verify valid data and signature', async () => { assert.equals(result, true) }) -test('should reject incorrect contact for signature', async () => { +await test('should reject incorrect contact for signature', async () => { const data = 'Test data' const signature = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, data) const rolodex = new Rolodex() diff --git a/test/refresh-accounts.test.mjs b/test/refresh-accounts.test.mjs index 8fcbac5..b2870b9 100644 --- a/test/refresh-accounts.test.mjs +++ b/test/refresh-accounts.test.mjs @@ -17,7 +17,7 @@ if (process) { console.log('refreshing account info') -test('fetch balance, frontier, and representative', async () => { +await test('fetch balance, frontier, and representative', 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() @@ -45,7 +45,7 @@ test('fetch balance, frontier, and representative', async () => { assert.notEqual(account.representative?.address, '') }) -test('throw when refreshing unopened account', async () => { +await test('throw when refreshing unopened account', 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(0x7fffffff) @@ -54,14 +54,14 @@ test('throw when refreshing unopened account', async () => { { message: 'Account not found' }) }) -test('throw when referencing invalid account index', async () => { +await test('throw when referencing invalid account index', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) await assert.rejects(wallet.accounts(0x80000000), { message: 'Invalid child key index 0x80000000' }) }) -test('throw with invalid node', async () => { +await test('throw with invalid node', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const invalidNode = new Rpc('http://invalid.com') @@ -73,7 +73,7 @@ test('throw with invalid node', async () => { console.log('finding next unopened account') -test('return correct account from test vector', async () => { +await test('return correct account from test vector', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.getNextNewAccount(rpc) @@ -82,7 +82,7 @@ test('return correct account from test vector', async () => { assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_1) }) -test('return successfully for small batch size', async () => { +await test('return successfully for small batch size', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.getNextNewAccount(rpc, 1) @@ -91,7 +91,7 @@ test('return successfully for small batch size', async () => { assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_1) }) -test('return successfully for large batch size', async () => { +await test('return successfully for large batch size', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const account = await wallet.getNextNewAccount(rpc, 100) @@ -100,7 +100,7 @@ test('return successfully for large batch size', async () => { assert.equals(account.publicKey, NANO_TEST_VECTORS.PUBLIC_1) }) -test('should throw on invalid node URL', async () => { +await test('should throw on invalid node URL', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) //@ts-expect-error @@ -115,7 +115,7 @@ test('should throw on invalid node URL', async () => { await assert.rejects(wallet.getNextNewAccount('foo')) }) -test('should throw on invalid batch size', async () => { +await test('should throw on invalid batch size', async () => { const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) //@ts-expect-error diff --git a/test/sign-blocks.test.mjs b/test/sign-blocks.test.mjs index d6bea6a..12c8227 100644 --- a/test/sign-blocks.test.mjs +++ b/test/sign-blocks.test.mjs @@ -9,7 +9,7 @@ import { SendBlock, ReceiveBlock, ChangeBlock } from '#dist/main.js' console.log('> valid blocks <') -test('should not allow negative balances', async () => { +await test('should not allow negative balances', async () => { assert.throws(() => { const block = new SendBlock( NANO_TEST_VECTORS.ADDRESS_0, @@ -22,7 +22,7 @@ test('should not allow negative balances', async () => { }, { message: 'Negative balance' }) }) -test('should allow zero balances', async () => { +await test('should allow zero balances', async () => { const block = new SendBlock( NANO_TEST_VECTORS.ADDRESS_0, '9007199254740991', @@ -35,7 +35,7 @@ test('should allow zero balances', async () => { assert.equals(block.balance, BigInt(0)) }) -test('should subtract balance from SendBlock correctly', async () => { +await test('should subtract balance from SendBlock correctly', async () => { const block = new SendBlock( NANO_TEST_VECTORS.ADDRESS_0, '3000000000000000000000000000000', @@ -47,7 +47,7 @@ test('should subtract balance from SendBlock correctly', async () => { assert.equals(block.balance, 1000000000000000000000000000000n) }) -test('should add balance from ReceiveBlock correctly', async () => { +await test('should add balance from ReceiveBlock correctly', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.ADDRESS_0, '2000000000000000000000000000000', @@ -61,7 +61,7 @@ test('should add balance from ReceiveBlock correctly', async () => { console.log('> block signing tests using official test vectors <') -test('should create a valid signature for an open block', async () => { +await test('should create a valid signature for an open block', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.OPEN_BLOCK.account, '0', @@ -76,7 +76,7 @@ test('should create a valid signature for an open block', async () => { assert.equals(block.signature, NANO_TEST_VECTORS.OPEN_BLOCK.signature) }) -test('should create a valid signature for a receive block', async () => { +await test('should create a valid signature for a receive block', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.RECEIVE_BLOCK.account, NANO_TEST_VECTORS.RECEIVE_BLOCK.balance, @@ -91,7 +91,7 @@ test('should create a valid signature for a receive block', async () => { assert.equals(block.signature, NANO_TEST_VECTORS.RECEIVE_BLOCK.signature) }) -test('should create a valid signature for a receive block without work', async () => { +await test('should create a valid signature for a receive block without work', async () => { const block = new ReceiveBlock( NANO_TEST_VECTORS.RECEIVE_BLOCK.account, NANO_TEST_VECTORS.RECEIVE_BLOCK.balance, @@ -106,7 +106,7 @@ test('should create a valid signature for a receive block without work', async ( assert.equals(block.work, '') }) -test('should create a valid signature for a send block', async () => { +await test('should create a valid signature for a send block', async () => { const block = new SendBlock( NANO_TEST_VECTORS.SEND_BLOCK.account, NANO_TEST_VECTORS.SEND_BLOCK.balance, @@ -121,7 +121,7 @@ test('should create a valid signature for a send block', async () => { assert.equals(block.signature, NANO_TEST_VECTORS.SEND_BLOCK.signature) }) -test('should create a valid signature for a send block without work', async () => { +await test('should create a valid signature for a send block without work', async () => { const block = new SendBlock( NANO_TEST_VECTORS.SEND_BLOCK.account, NANO_TEST_VECTORS.SEND_BLOCK.balance, @@ -136,7 +136,7 @@ test('should create a valid signature for a send block without work', async () = assert.equals(block.work, '') }) -test('should create a valid signature for a change rep block', async () => { +await test('should create a valid signature for a change rep block', async () => { const work = '0000000000000000' const block = new ChangeBlock( 'nano_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php', @@ -150,7 +150,7 @@ test('should create a valid signature for a change rep block', async () => { assert.equals(block.work, work) }) -test('should create a valid signature for a change rep block without work', async () => { +await test('should create a valid signature for a change rep block without work', async () => { const block = new ChangeBlock( NANO_TEST_VECTORS.ADDRESS_0, '0', diff --git a/test/tools.test.mjs b/test/tools.test.mjs index 1d713a9..1ab56a9 100644 --- a/test/tools.test.mjs +++ b/test/tools.test.mjs @@ -17,79 +17,79 @@ if (process) { console.log('> unit conversion tests <') -test('should convert nano to raw', async () => { +await test('should convert nano to raw', async () => { const result = await Tools.convert('1', 'NANO', 'RAW') assert.equals(result, '1000000000000000000000000000000') }) -test('should convert raw to nano', async () => { +await test('should convert raw to nano', async () => { const result = await Tools.convert('1000000000000000000000000000000', 'RAW', 'NANO') assert.equals(result, '1') }) -test('should convert 1 raw to 10^-29 nano', async () => { +await test('should convert 1 raw to 10^-29 nano', async () => { const result = await Tools.convert('1', 'RAW', 'NANO') assert.equals(result, '.000000000000000000000000000001') }) -test('should ignore leading and trailing zeros', async () => { +await test('should ignore leading and trailing zeros', async () => { const result = await Tools.convert('0011002200.0033004400', 'nano', 'nano') assert.equals(result, '11002200.00330044') }) -test('should convert raw to nyano', async () => { +await test('should convert raw to nyano', async () => { const result = await Tools.convert(RAW_MAX, 'RAW', 'NYANO') assert.equals(result, '340282366920938.463463374607431768211455') }) -test('should convert case-insensitive nyano to raw', async () => { +await test('should convert case-insensitive nyano to raw', async () => { const result = await Tools.convert('0.000000000000000123456789', 'nYaNo', 'rAw') assert.equals(result, '123456789') }) -test('should convert nano to pico', async () => { +await test('should convert nano to pico', async () => { const result = await Tools.convert('123.456', 'nano', 'pico') assert.equals(result, '123456') }) -test('should convert knano to pico', async () => { +await test('should convert knano to pico', async () => { const result = await Tools.convert('123.456', 'nano', 'pico') assert.equals(result, '123456') }) -test('should throw if amount exceeds raw max', async () => { +await test('should throw if amount exceeds raw max', async () => { await assert.rejects(Tools.convert(RAW_MAX, 'NANO', 'RAW'), { message: 'Amount exceeds Nano limits' }) }) -test('should throw if amount exceeds raw min', async () => { +await test('should throw if amount exceeds raw min', async () => { await assert.rejects(Tools.convert('0.1', 'RAW', 'NANO'), { message: 'Amount must be at least 1 raw' }) }) -test('should throw if amount is blank', async () => { +await test('should throw if amount is blank', async () => { await assert.rejects(Tools.convert('', 'RAW', 'NANO'), { message: 'Invalid amount' }) }) -test('should throw if amount has non-digit characters', async () => { +await test('should throw if amount has non-digit characters', async () => { await assert.rejects(Tools.convert('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'RAW', 'NANO'), { message: 'Invalid amount' }) }) console.log('> signature tests <') -test('should sign data with a single parameter', async () => { +await test('should sign data with a single parameter', async () => { const result = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, 'miro@metsanheimo.fi') assert.equals(result, 'FECB9B084065ADC969904B55A0099C63746B68DF41FECB713244D387EED83A80B9D4907278C5EBC0998A5FC8BA597FBAAABBFCE0ABD2CA2212ACFE788637040C') }) -test('should sign data with multiple parameters', async () => { +await test('should sign data with multiple parameters', async () => { const result = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0, 'miro@metsanheimo.fi', 'somePassword') assert.equals(result, 'BB534F9B469AF451B1941FFEF8EE461FC5D284B5D393140900C6E13A65EF08D0AE2BC77131EE182922F66C250C7237A83878160457D5C39A70E55F7FCE925804') }) -test('should verify a signature using the public key', async () => { +await test('should verify a signature using the public key', async () => { const result = await Tools.verify(NANO_TEST_VECTORS.PUBLIC_0, 'FECB9B084065ADC969904B55A0099C63746B68DF41FECB713244D387EED83A80B9D4907278C5EBC0998A5FC8BA597FBAAABBFCE0ABD2CA2212ACFE788637040C', 'miro@metsanheimo.fi') assert.equals(result, true) @@ -100,7 +100,7 @@ test('should verify a signature using the public key', async () => { assert.equals(result3, false) }) -test('should verify a block using the public key', async () => { +await test('should verify a block using the public key', 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() @@ -118,7 +118,7 @@ test('should verify a block using the public key', async () => { assert.equals(valid, true) }) -test('should reject a block using the wrong public key', async () => { +await test('should reject a block using the wrong public key', 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() @@ -138,7 +138,7 @@ test('should reject a block using the wrong public key', async () => { assert.equals(valid, false) }) -test('sweeper throws without required parameters', async () => { +await test('sweeper throws without required parameters', async () => { //@ts-expect-error await assert.rejects(Tools.sweep(), 'Missing required sweep arguments')