]> git.codecow.com Git - libnemo.git/commitdiff
Add tests for vault timer.
authorChris Duncan <chris@codecow.com>
Wed, 12 Aug 2026 06:05:22 +0000 (23:05 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 12 Aug 2026 06:05:22 +0000 (23:05 -0700)
test/main.test.mjs
test/test.vault-timer.mjs [new file with mode: 0644]

index acebb8fd0a1324445a0c2f5f156da880055983d9..1d4c3a823789c287d0eacbe24194365681f79c2c 100644 (file)
@@ -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 (file)
index 0000000..bc1048a
--- /dev/null
@@ -0,0 +1,84 @@
+//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
+//! 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())
+               })
+       })
+])