]> git.codecow.com Git - libnemo.git/commitdiff
Consolidate user activation timeouts into click generator.
authorChris Duncan <chris@zoso.dev>
Sun, 3 May 2026 13:28:29 +0000 (06:28 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 3 May 2026 13:28:29 +0000 (06:28 -0700)
test/GLOBALS.mjs
test/test.blocks.mjs
test/test.ledger.mjs
test/test.manage-rolodex.mjs
test/test.tools.mjs
test/test.wallet-sign.mjs

index 7f21fb90d2908a972e83ff52c55c84518ae84b62..cd638ff6e0c56f816c9c097cce650129ed2591b9 100644 (file)
@@ -85,6 +85,8 @@ export async function click (text, fn) {
                        button.after(hourglass)
                        try {
                                const result = await fn()
+                               console.log('Click done, waiting 6 seconds to reset transient user activation timer...')
+                               await new Promise(r => setTimeout(r, 6000))
                                resolve(result)
                        } catch (err) {
                                reject(err)
index 7f1e64f9f5d7840cb5fef92b0852d0e04d29bf03..12caf6be88ed9656cf96493304a2ecc9855d1cc1 100644 (file)
@@ -20,8 +20,6 @@ await Promise.all([
                                'Sign and autogen PoW when processing',\r
                                async () => block.sign(OPEN_BLOCK.key)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.nullish(block.work)\r
                        const result = await assert.rejects(block.process(rpc))\r
@@ -117,8 +115,6 @@ await Promise.all([
                                'Sign with BLAKE2b',\r
                                async () => wallet.sign(1, block)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.ok(await block.verify(BLAKE2B_PUBLIC_1))\r
 \r
                        await assert.resolves(wallet.destroy())\r
@@ -134,8 +130,6 @@ await Promise.all([
                                'Sign with BIP-44',\r
                                async () => wallet.sign(0, block)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.ok(await block.verify(PUBLIC_0))\r
 \r
                        await assert.resolves(wallet.destroy())\r
@@ -151,8 +145,6 @@ await Promise.all([
                                'Sign with Exodus',\r
                                async () => wallet.sign(0, block)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.ok(await block.verify(EXODUS.PUBLIC_0))\r
 \r
                        await assert.resolves(wallet.destroy())\r
@@ -179,8 +171,6 @@ await Promise.all([
                                'Fail to sign while locked',\r
                                async () => wallet.sign(0, block)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.ok(block.signature === undefined)\r
 \r
                        await wallet.destroy()\r
@@ -195,8 +185,6 @@ await Promise.all([
                                'Sign open block with key',\r
                                async () => block.sign(OPEN_BLOCK.key)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.equal(block.hash, OPEN_BLOCK.hash)\r
                        assert.equal(block.signature, OPEN_BLOCK.signature)\r
                })\r
@@ -210,8 +198,6 @@ await Promise.all([
                                'Sign receive block with key',\r
                                async () => block.sign(RECEIVE_BLOCK.key)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(block.hash, RECEIVE_BLOCK.hash)\r
                        assert.equal(block.signature, RECEIVE_BLOCK.signature)\r
@@ -225,8 +211,6 @@ await Promise.all([
                                'Sign receive block without work',\r
                                async () => block.sign(RECEIVE_BLOCK.key)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(block.hash, RECEIVE_BLOCK.hash)\r
                        assert.equal(block.signature, RECEIVE_BLOCK.signature)\r
@@ -247,8 +231,6 @@ await Promise.all([
                                'Sign Ledger-derived block using BIP-44 wallet',\r
                                async () => wallet.sign(0, block)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(block.signature, LEDGER_NANOS.OPEN_BLOCK.signature)\r
                        assert.ok(await block.verify(account.publicKey))\r
@@ -265,8 +247,6 @@ await Promise.all([
                                'Sign send block with key',\r
                                async () => block.sign(SEND_BLOCK.key)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(block.hash, SEND_BLOCK.hash)\r
                        assert.equal(block.signature, SEND_BLOCK.signature)\r
@@ -280,8 +260,6 @@ await Promise.all([
                                'Sign send block without work',\r
                                async () => block.sign(SEND_BLOCK.key)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(block.hash, SEND_BLOCK.hash)\r
                        assert.equal(block.signature, SEND_BLOCK.signature)\r
@@ -299,8 +277,6 @@ await Promise.all([
                                'Sign change block with key',\r
                                async () => block.sign('781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3') // Did not find a private key at nano docs for this address\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(block.signature?.toUpperCase(), 'A3C3C66D6519CBC0A198E56855942DEACC6EF741021A1B11279269ADC587DE1DA53CD478B8A47553231104CF24D742E1BB852B0546B87038C19BAE20F9082B0D')\r
                        assert.equal(block.work, work)\r
@@ -314,8 +290,6 @@ await Promise.all([
                                'Sign change block without work',\r
                                async () => block.sign(PRIVATE_0)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(block.signature?.toUpperCase(), '2BD2F905E74B5BEE3E2277CED1D1E3F7535E5286B6E22F7B08A814AA9E5C4E1FEA69B61D60B435ADC2CE756E6EE5F5BE7EC691FE87E024A0B22A3D980CA5B305')\r
                        assert.nullish(block.work)\r
@@ -331,8 +305,6 @@ await Promise.all([
                                //@ts-expect-error\r
                                async () => block.sign()\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.nullish(block.signature)\r
 \r
                        await assert.rejects(click(\r
@@ -340,24 +312,18 @@ await Promise.all([
                                //@ts-expect-error\r
                                async () => block.sign(null)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.nullish(block.signature)\r
 \r
                        await assert.rejects(click(\r
                                'fail to sign with invalid string length',\r
                                async () => block.sign('1')\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.nullish(block.signature)\r
 \r
                        await assert.rejects(click(\r
                                'fail to sign with invalid string characters',\r
                                async () => block.sign('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.nullish(block.signature)\r
                })\r
        })\r
index e90957c715076a4baa6ad80fab137cf1279fa633..0a1ce889fd628d5998ab31795effa85e86f538a4 100644 (file)
@@ -36,7 +36,7 @@ await Promise.all([
                        /** @type {Block} */ openBlock,
                        /** @type {Block} */ sendBlock,
                        /** @type {Block} */ receiveBlock,
-                       restored
+                       /** @type {Wallet} */ restored
                try {
                        wallet = await Wallet.create('Ledger')
                } catch {
@@ -53,8 +53,9 @@ await Promise.all([
 
                        await click(
                                'Reset permissions, then click to continue',
-                               async () => new Promise(r => setTimeout(r, 5000))
+                               async () => { }
                        )
+                       // should initially be locked and disconnected after 6s timeout in click()
                        await assert.rejects(wallet.unlock())
                        assert.equal(wallet.isLocked, true)
                        assert.equal(Ledger.status, 'DISCONNECTED')
@@ -62,72 +63,48 @@ await Promise.all([
 
                        await assert.rejects(click(
                                'Unlock device, quit Nano app, then click to continue',
-                               async () => wallet.unlock()
+                               async () => {
+                                       wallet.unlock()
+                                       assert.equal(wallet.isLocked, true)
+                                       assert.equal(Ledger.status, 'BUSY')
+                                       assert.equal(status, 'BUSY')
+                               }
                        ))
+
+                       // should still be locked and busy after 6s timeout in click()
                        assert.equal(wallet.isLocked, true)
                        assert.equal(Ledger.status, 'BUSY')
                        assert.equal(status, 'BUSY')
 
-                       await new Promise(async (resolve, reject) => {
-                               console.log('Waiting 6 seconds...')
-                               setTimeout(async () => {
-                                       try {
-                                               // should still be locked and busy
-                                               assert.equal(wallet.isLocked, true)
-                                               assert.equal(Ledger.status, 'BUSY')
-                                               assert.equal(status, 'BUSY')
-                                               resolve(null)
-                                       } catch (err) {
-                                               reject(err)
-                                       }
-                               }, 6000)
-                       })
-
                        await assert.rejects(click(
                                'Open Nano app on device, allow device to auto-lock, then click to continue',
-                               async () => wallet.unlock()
+                               async () => {
+                                       wallet.unlock()
+                                       assert.equal(wallet.isLocked, true)
+                                       assert.equal(Ledger.status, 'LOCKED')
+                               }
                        ))
+
+                       // should still be locked after 6s timeout in click()
                        assert.equal(wallet.isLocked, true)
                        assert.equal(Ledger.status, 'LOCKED')
-
-                       await new Promise(async (resolve, reject) => {
-                               console.log('Waiting 6 seconds...')
-                               setTimeout(async () => {
-                                       try {
-                                               // should still be locked
-                                               assert.equal(wallet.isLocked, true)
-                                               assert.equal(Ledger.status, 'LOCKED')
-                                               assert.equal(status, 'LOCKED')
-                                               resolve(null)
-                                       } catch (err) {
-                                               reject(err)
-                                       }
-                               }, 6000)
-                       })
+                       assert.equal(status, 'LOCKED')
 
                        await assert.resolves(click(
                                'Unlock device, verify Nano app is open, then click to continue',
-                               async () => wallet.unlock()
+                               async () => {
+                                       wallet.unlock()
+                                       assert.equal(wallet.isLocked, false)
+                                       assert.equal(Ledger.status, 'CONNECTED')
+                                       assert.equal(status, 'CONNECTED')
+                               }
                        ))
+
+                       // should still be unlocked after 6s timeout in click()
                        assert.equal(wallet.isLocked, false)
                        assert.equal(Ledger.status, 'CONNECTED')
                        assert.equal(status, 'CONNECTED')
 
-                       await new Promise(async (resolve, reject) => {
-                               console.log('Waiting 6 seconds...')
-                               setTimeout(async () => {
-                                       try {
-                                               // should still be unlocked
-                                               assert.equal(wallet.isLocked, false)
-                                               assert.equal(Ledger.status, 'CONNECTED')
-                                               assert.equal(status, 'CONNECTED')
-                                               resolve(null)
-                                       } catch (err) {
-                                               reject(err)
-                                       }
-                               }, 6000)
-                       })
-
                        await new Promise(async (resolve, reject) => {
                                console.log('Waiting 90 seconds...')
                                setTimeout(async () => {
@@ -145,34 +122,41 @@ await Promise.all([
 
                        await assert.resolves(click(
                                'Unlock device again, then click to continue',
-                               async () => { }
+                               async () => {
+                                       assert.equal(wallet.isLocked, false)
+                                       assert.equal(Ledger.status, 'CONNECTED')
+                                       assert.equal(status, 'CONNECTED')
+                               }
                        ))
-                       assert.equal(wallet.isLocked, false)
-                       assert.equal(Ledger.status, 'CONNECTED')
-                       assert.equal(status, 'CONNECTED')
                })
 
                await test('switch between interfaces', { skip: false || isNode || navigator?.usb == null }, async () => {
                        await assert.resolves(click(
                                'Verify current interface is HID, switch to unlocked Bluetooth device, then click to continue',
-                               async () => wallet.config({ connection: 'ble' })
+                               async () => {
+                                       wallet.config({ connection: 'ble' })
+                                       assert.equal(wallet.isLocked, true)
+                                       assert.equal(Ledger.status, 'BUSY')
+                               }
                        ))
-                       assert.equal(wallet.isLocked, true)
-                       assert.equal(Ledger.status, 'BUSY')
 
                        await assert.resolves(click(
                                'Verify current interface is BLE, switch back to unlocked USB device, then click to continue',
-                               async () => wallet.config({ connection: 'usb' })
+                               async () => {
+                                       wallet.config({ connection: 'usb' })
+                                       assert.equal(wallet.isLocked, false)
+                                       assert.equal(Ledger.status, 'CONNECTED')
+                               }
                        ))
-                       assert.equal(wallet.isLocked, false)
-                       assert.equal(Ledger.status, 'CONNECTED')
 
                        await assert.resolves(click(
                                'Verify current interface is USB, then click to continue',
-                               async () => wallet.config({ connection: 'hid' })
+                               async () => {
+                                       wallet.config({ connection: 'hid' })
+                                       assert.equal(wallet.isLocked, false)
+                                       assert.equal(Ledger.status, 'CONNECTED')
+                               }
                        ))
-                       assert.equal(wallet.isLocked, false)
-                       assert.equal(Ledger.status, 'CONNECTED')
                })
 
                await test('verify mnemonic', async () => {
@@ -343,12 +327,14 @@ await Promise.all([
 
                        await click(
                                'Click to finish Ledger tests by destroying wallet',
-                               async () => new Promise(r => setTimeout(r))
+                               async () => {
+                                       await new Promise(r => setTimeout(r))
+                                       await assert.resolves(wallet.destroy())
+                                       await assert.rejects(wallet.unlock())
+                                       await wallet.destroy()
+                                       await restored.destroy()
+                               }
                        )
-                       await assert.resolves(wallet.destroy())
-                       await assert.rejects(wallet.unlock())
-                       await wallet.destroy()
-                       await restored.destroy()
                })
        })
 ])
index 5e0de97f7fa7027ad029b406e6e8fe5ad341e87b..a9c2d16e69966fc97fbbf5299994c7d72636f921 100644 (file)
@@ -193,8 +193,6 @@ await Promise.all([
                                        signature = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0 + NANO_TEST_VECTORS.PUBLIC_0, data)
                                }
                        ))
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')
-                       await new Promise(r => setTimeout(r, 6000))
 
                        await assert.resolves(Rolodex.add('JohnDoe', NANO_TEST_VECTORS.ADDRESS_0))
                        const result = await Rolodex.verify('JohnDoe', signature, data)
@@ -212,8 +210,6 @@ await Promise.all([
                                        signature = await Tools.sign(NANO_TEST_VECTORS.PRIVATE_0 + NANO_TEST_VECTORS.PUBLIC_0, data)
                                }
                        ))
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')
-                       await new Promise(r => setTimeout(r, 6000))
 
                        await assert.resolves(Rolodex.add('JaneSmith', NANO_TEST_VECTORS.ADDRESS_1))
                        const result = await Rolodex.verify('JaneSmith', signature, data)
index ed40572ba18c882dbf8bc9423a3ed829edd3ec9b..8420179dec92f3d9aaa6dc9445388db59b9830c6 100644 (file)
@@ -110,8 +110,6 @@ await Promise.all([
                                        result = Tools.sign(NANO_TEST_VECTORS.PRIVATE_0 + NANO_TEST_VECTORS.PUBLIC_0, m)\r
                                }\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.equal(result.toLowerCase(), '0ceebbc0b9b3a270a30bad1eef4eddc0931effd8d5c0b7cab007fcc61f30d3ee9760cd93d7eeb5b654ecc0d9d17bc7a6d53bee54aa163a8272f425fb1184e30e')\r
                })\r
index c6f1d6a7bf411c7519d6c20fb44524bbc1b3bfb2..ba038b644f4645830c85cc3c57d22131126d2644 100644 (file)
@@ -24,8 +24,6 @@ await Promise.all([
                                        signature = await wallet.sign(0, data)\r
                                }\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
                        assert.ok(await Tools.verify(account.publicKey, signature, data))\r
                        await assert.resolves(wallet.destroy())\r
                })\r
@@ -41,8 +39,6 @@ await Promise.all([
                                'Sign to test subsequent verification success',\r
                                async () => sendBlock.sign(wallet, 0)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.ok(await sendBlock.verify(account.publicKey))\r
                        await assert.resolves(wallet.destroy())\r
@@ -59,8 +55,6 @@ await Promise.all([
                                'Sign to test subsequent verification failure',\r
                                async () => sendBlock.sign(wallet, 0)\r
                        ))\r
-                       console.log('Click done, waiting 6 seconds to reset transient user activation timer...')\r
-                       await new Promise(r => setTimeout(r, 6000))\r
 \r
                        assert.ok(await sendBlock.verify(account.publicKey))\r
 \r