From: Chris Duncan Date: Wed, 10 Sep 2025 20:55:25 +0000 (-0700) Subject: Test invalid autolock config. X-Git-Tag: v0.10.5~22^2 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=ded7674671b7a8bcbc6551f4464a4124dc8e26ef;p=libnemo.git Test invalid autolock config. --- diff --git a/test/test.lock-unlock.mjs b/test/test.lock-unlock.mjs index 31a05e1..736fba8 100644 --- a/test/test.lock-unlock.mjs +++ b/test/test.lock-unlock.mjs @@ -138,7 +138,7 @@ await Promise.all([ await assert.resolves(wallet.destroy()) }) - await test('wallet automatic lock resets after user activity', { skip: false }, async () => { + await test('wallet automatic lock resets after user activity', { skip: true }, async () => { console.log('Starting autolock test...') const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) assert.equal(wallet.isLocked, true) @@ -183,33 +183,69 @@ await Promise.all([ }) }) - await test('configure autolock', { skip: false }, async () => { + await test('configure 10-second autolock', async () => { const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) assert.equal(wallet.isLocked, true) await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) assert.equal(wallet.isLocked, false) - await wallet.config({ timeout: 5 }) + await wallet.config({ timeout: 10 }) await new Promise(async (resolve) => { - console.log('Waiting 3 seconds...') + console.log('Waiting 6 seconds...') setTimeout(async () => { // should still be unlocked assert.equal(wallet.isLocked, false) assert.ok(await wallet.verify(NANO_TEST_VECTORS.MNEMONIC)) resolve(null) - }, 3000) + }, 6000) }) await new Promise(async (resolve) => { - console.log('Timer should not be reset by verify, waiting 3 more seconds...') + console.log('Timer should not be reset by verify, waiting 6 more seconds...') setTimeout(async () => { // should be locked from account() reset and not reset by verify() assert.equal(wallet.isLocked, true) await assert.rejects(wallet.verify(NANO_TEST_VECTORS.MNEMONIC)) await assert.resolves(wallet.destroy()) resolve(null) - }, 3000) + }, 6000) }) }) + + await test('fail to configure invalid autolock times', async () => { + const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD) + assert.equal(wallet.isLocked, true) + await wallet.unlock(NANO_TEST_VECTORS.PASSWORD) + assert.equal(wallet.isLocked, false) + + //@ts-expect-error + await assert.rejects(wallet.config()) + //@ts-expect-error + await assert.rejects(wallet.config(undefined)) + //@ts-expect-error + await assert.rejects(wallet.config(null)) + //@ts-expect-error + await assert.rejects(wallet.config(10n)) + //@ts-expect-error + await assert.rejects(wallet.config('10')) + //@ts-expect-error + await assert.rejects(wallet.config({})) + //@ts-expect-error + await assert.rejects(wallet.config({ timeout: null })) + //@ts-expect-error + await assert.rejects(wallet.config({ timeout: undefined })) + //@ts-expect-error + await assert.rejects(wallet.config({ timeout: 10n })) + //@ts-expect-error + await assert.rejects(wallet.config({ timeout: '10' })) + //@ts-expect-error + await assert.rejects(wallet.config({ timeout: {} })) + + // valid type but invalid value + await assert.rejects(wallet.config({ timeout: -1 })) + await assert.rejects(wallet.config({ timeout: 0 })) + await assert.rejects(wallet.config({ timeout: 9 })) + await assert.rejects(wallet.config({ timeout: 601 })) + }) }) ])