From: Chris Duncan Date: Wed, 12 Aug 2026 06:05:22 +0000 (-0700) Subject: Add tests for vault timer. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=626c080509802296705b34b588a0b48e11f0ff94;p=libnemo.git Add tests for vault timer. --- diff --git a/test/main.test.mjs b/test/main.test.mjs index acebb8f..1d4c3a8 100644 --- a/test/main.test.mjs +++ b/test/main.test.mjs @@ -15,6 +15,7 @@ import './test.lock-unlock.mjs' import './test.manage-rolodex.mjs' import './test.refresh-accounts.mjs' import './test.tools.mjs' +import './test.vault-timer.mjs' import './test.wallet-sign.mjs' console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') diff --git a/test/test.vault-timer.mjs b/test/test.vault-timer.mjs new file mode 100644 index 0000000..bc1048a --- /dev/null +++ b/test/test.vault-timer.mjs @@ -0,0 +1,84 @@ +//! SPDX-FileCopyrightText: 2025 Chris Duncan +//! SPDX-License-Identifier: GPL-3.0-or-later + +'use strict' + +import { Wallet } from 'libnemo' +import { assert, suite, test } from './GLOBALS.mjs' +import { CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS, TEST_PASSWORD } from './VECTORS.mjs' + +await Promise.all([ + suite('Autolock Exodus wallet (slowest derivation time, largest pause window)', async () => { + + await test('lock after 10s timeout and not before', async () => { + const wallet = await Wallet.load('Exodus', TEST_PASSWORD, CUSTOM_TEST_VECTORS.EXODUS.BIP39_SEED_0) + await wallet.unlock(TEST_PASSWORD) + + await wallet.config({ timeout: 10 }) + await new Promise(r => setTimeout(r, 8_000)) + assert.ok(!wallet.isLocked, 'wallet should be unlocked') + await new Promise(r => setTimeout(r, 1_000)) + assert.ok(wallet.isLocked, 'wallet should be locked') + + await assert.resolves(wallet.destroy()) + }) + + await test('stay unlocked for 5s, derive to reset timer, then lock after additional 10s', async () => { + const wallet = await Wallet.load('Exodus', TEST_PASSWORD, CUSTOM_TEST_VECTORS.EXODUS.BIP39_SEED_0) + await wallet.unlock(TEST_PASSWORD) + await wallet.config({ timeout: 10 }) + + await new Promise(r => setTimeout(r, 5_000)) + assert.ok(!wallet.isLocked, 'wallet should be unlocked') + + await wallet.accounts(0, 1000) + await new Promise(r => setTimeout(r, 5_000)) + assert.ok(!wallet.isLocked, 'wallet should be unlocked') + + await new Promise(r => setTimeout(r, 5_000)) + assert.ok(wallet.isLocked, 'wallet should be locked') + + await assert.resolves(wallet.destroy()) + }) + + await test('config for 10s autolock, verify after 5s does not reset timer, still locks after additional 5s', async () => { + const wallet = await Wallet.load('Exodus', TEST_PASSWORD, CUSTOM_TEST_VECTORS.EXODUS.BIP39_SEED_0) + await wallet.unlock(TEST_PASSWORD) + await wallet.config({ timeout: 10 }) + + await new Promise(r => setTimeout(r, 5_000)) + assert.ok(!wallet.isLocked, 'wallet should be unlocked') + + await wallet.verify(CUSTOM_TEST_VECTORS.EXODUS.BIP39_SEED_0) + await new Promise(r => setTimeout(r, 5_000)) + assert.ok(wallet.isLocked, 'wallet should be locked') + + await wallet.lock() + await wallet.unlock(TEST_PASSWORD) + await new Promise(r => setTimeout(r, 5_000)) + assert.ok(!wallet.isLocked, 'wallet should be unlocked') + + await wallet.verify(CUSTOM_TEST_VECTORS.EXODUS.BIP39_SEED_1) + await new Promise(r => setTimeout(r, 5_000)) + assert.ok(wallet.isLocked, 'wallet should be locked') + + await assert.resolves(wallet.destroy()) + }) + + await test('after first autolock, subsequent autolocks still work', async () => { + const wallet = await Wallet.load('Exodus', TEST_PASSWORD, CUSTOM_TEST_VECTORS.EXODUS.BIP39_SEED_0) + await wallet.unlock(TEST_PASSWORD) + await wallet.config({ timeout: 10 }) + assert.ok(!wallet.isLocked) + + await new Promise(r => setTimeout(r, 10_000)) + assert.ok(wallet.isLocked) + + await wallet.unlock(TEST_PASSWORD) + await new Promise(r => setTimeout(r, 10_000)) + assert.ok(wallet.isLocked) + + await assert.resolves(wallet.destroy()) + }) + }) +])