From: Chris Duncan Date: Fri, 6 Dec 2024 02:30:17 +0000 (-0800) Subject: Fix async testing. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=0b3e341fa4c6185a318c22c39db59a6a1e0d29f8;p=libnemo.git Fix async testing. --- diff --git a/test/GLOBALS.mjs b/test/GLOBALS.mjs index 410d2ae..73872f3 100644 --- a/test/GLOBALS.mjs +++ b/test/GLOBALS.mjs @@ -57,7 +57,7 @@ export const assert = { notEqual: (a, b) => { return a !== b }, - rejects: (fn, msg) => { + rejects: async (fn, msg) => { try { if (!(fn instanceof Promise)) throw new Error(msg ?? 'expected async function') fn.then(() => { throw new Error(msg ?? 'expected async function to reject') }) @@ -66,7 +66,7 @@ export const assert = { return true } }, - resolves: (fn, msg) => { + resolves: async (fn, msg) => { try { if (!(fn instanceof Promise)) throw new Error('expected async function') fn.then(() => { return true }) @@ -78,8 +78,8 @@ export const assert = { }, throws: (fn, msg) => { try { - const r = fn() - if (r instanceof Promise) throw new Error('expected synchronous function') + if (fn instanceof Promise) throw new Error('expected synchronous function') + fn() throw new Error(msg ?? `expected function to throw an exception`) } catch (err) { return true diff --git a/test/create-wallet.test.mjs b/test/create-wallet.test.mjs index ec7c448..494556c 100644 --- a/test/create-wallet.test.mjs +++ b/test/create-wallet.test.mjs @@ -35,7 +35,7 @@ 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 - assert.resolves(Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD, arg)) + await assert.resolves(Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD, arg)) } }) @@ -50,9 +50,9 @@ test('fail when using new', () => { test('fail without a password', async () => { //@ts-expect-error - assert.rejects(Bip44Wallet.create()) + await assert.rejects(Bip44Wallet.create()) //@ts-expect-error - assert.rejects(Blake2bWallet.create()) + await assert.rejects(Blake2bWallet.create()) }) skip('connect to ledger', async () => { diff --git a/test/import-wallet.test.mjs b/test/import-wallet.test.mjs index 1585620..707e2e6 100644 --- a/test/import-wallet.test.mjs +++ b/test/import-wallet.test.mjs @@ -196,9 +196,9 @@ test('import wallet with test vectors test', () => { test('invalid wallet', async () => { test('throw when given invalid entropy', async () => { - assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C797')) - assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, '6CAF5A42BB8074314AAE20295975ECE663BE7AAD945A73613D193B0CC41C79701')) - assert.rejects(async () => await Bip44Wallet.fromEntropy(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0.replaceAll(/./g, 'x'))) + 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('should throw when given a seed with an invalid length', async () => {