From: Chris Duncan Date: Sat, 2 Aug 2025 20:15:57 +0000 (-0700) Subject: Fix lock and unlock tests. X-Git-Tag: v0.10.5~47^2~1 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=d522a5ec195e2a9fdda55dbc6f4de9ea817fc239;p=libnemo.git Fix lock and unlock tests. --- diff --git a/test/test.lock-unlock.mjs b/test/test.lock-unlock.mjs index 31a9727..623e7db 100644 --- a/test/test.lock-unlock.mjs +++ b/test/test.lock-unlock.mjs @@ -34,79 +34,37 @@ await Promise.all([ const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) assert.equal(unlockResult, true) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.equal(wallet.mnemonic, NANO_TEST_VECTORS.MNEMONIC) - assert.equal(wallet.seed, NANO_TEST_VECTORS.BIP39_SEED) + assert.ok(await wallet.verify(NANO_TEST_VECTORS.MNEMONIC)) + assert.ok(await wallet.verify(NANO_TEST_VECTORS.BIP39_SEED)) await assert.resolves(wallet.destroy()) }) - await test('locking and unlocking a Bip44Wallet Account with a password', async () => { - const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) - await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - const account = await wallet.account() - const lockResult = await wallet.lock() - - assert.equal(lockResult, true) - - const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - - assert.equal(unlockResult, true) - await assert.resolves(wallet.destroy()) - }) - await test('fail to unlock a Bip44Wallet with different passwords', async () => { const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) const lockResult = await wallet.lock() - await assert.rejects(wallet.unlock(NANO_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' }) + await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' }) assert.equal(lockResult, true) assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) - - await assert.resolves(wallet.destroy()) - }) - - await test('fail to unlock a Bip44Wallet with different valid inputs', async () => { - const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) - const key = crypto.getRandomValues(new Uint8Array(64)) - - await assert.rejects(wallet.unlock(crypto.randomUUID()), { message: 'Failed to unlock wallet' }) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) + assert.ok(wallet.mnemonic === undefined) + assert.ok(wallet.seed === undefined) + await assert.rejects(wallet.verify(NANO_TEST_VECTORS.MNEMONIC)) + await assert.rejects(wallet.verify(NANO_TEST_VECTORS.BIP39_SEED)) await assert.resolves(wallet.destroy()) }) - await test('fail to unlock a Bip44Wallet with no input', async () => { + await test('fail to unlock a Bip44Wallet with invalid input', async () => { const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) //@ts-expect-error await assert.rejects(wallet.unlock(), { message: 'Failed to unlock wallet' }) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) - - await assert.resolves(wallet.destroy()) - }) - - await test('fail to unlock a Bip44Wallet with invalid input', async () => { - const wallet = await Wallet.import('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) - //@ts-expect-error await assert.rejects(wallet.unlock(1), { message: 'Failed to unlock wallet' }) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) await assert.resolves(wallet.destroy()) }) @@ -116,31 +74,15 @@ await Promise.all([ assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) + assert.ok(wallet.mnemonic === undefined) + assert.ok(wallet.seed === undefined) const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) assert.equal(unlockResult, true) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.equal(wallet.mnemonic, TREZOR_TEST_VECTORS.MNEMONIC_0) - assert.equal(wallet.seed, TREZOR_TEST_VECTORS.ENTROPY_0) - - await assert.resolves(wallet.destroy()) - }) - - await test('locking and unlocking a Blake2bWallet Account with a password', async () => { - const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0) - await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - const account = await wallet.account() - const lockResult = await wallet.lock() + assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.MNEMONIC_0)) + assert.ok(await wallet.verify(TREZOR_TEST_VECTORS.ENTROPY_0)) - assert.equal(lockResult, true) - - const unlockResult = await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) - - assert.equal(unlockResult, true) await assert.resolves(wallet.destroy()) }) @@ -150,21 +92,10 @@ await Promise.all([ await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' }) assert.ok('mnemonic' in wallet) assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) - - await assert.resolves(wallet.destroy()) - }) - - await test('fail to unlock a Blake2bWallet with different valid inputs', async () => { - const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) - const key = crypto.getRandomValues(new Uint8Array(64)) - - await assert.rejects(wallet.unlock(crypto.randomUUID()), { message: 'Failed to unlock wallet' }) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) + assert.ok(wallet.mnemonic === undefined) + assert.ok(wallet.seed === undefined) + await assert.rejects(wallet.verify(TREZOR_TEST_VECTORS.MNEMONIC_1)) + await assert.rejects(wallet.verify(TREZOR_TEST_VECTORS.ENTROPY_1)) await assert.resolves(wallet.destroy()) }) @@ -174,23 +105,8 @@ await Promise.all([ //@ts-expect-error await assert.rejects(wallet.unlock(), { message: 'Failed to unlock wallet' }) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) - - await assert.resolves(wallet.destroy()) - }) - - await test('fail to unlock a Blake2bWallet with invalid input', async () => { - const wallet = await Wallet.import('BLAKE2b', NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1) - //@ts-expect-error await assert.rejects(wallet.unlock(1), { message: 'Failed to unlock wallet' }) - assert.ok('mnemonic' in wallet) - assert.ok('seed' in wallet) - assert.throws(() => wallet.mnemonic) - assert.throws(() => wallet.seed) await assert.resolves(wallet.destroy()) })