]> git.codecow.com Git - libnemo.git/commitdiff
Extract Ledger wallet tests to their own file.
authorChris Duncan <chris@zoso.dev>
Tue, 8 Jul 2025 21:48:54 +0000 (14:48 -0700)
committerChris Duncan <chris@zoso.dev>
Tue, 8 Jul 2025 21:48:54 +0000 (14:48 -0700)
test/test.create-wallet.mjs
test/test.ledger.mjs [new file with mode: 0644]
test/test.main.mjs

index 4899787c2540b80d120b877f4643eba1dc8c2700..a159b49dcac74e95f0c8937e50562839372da604 100644 (file)
@@ -3,9 +3,9 @@
 \r
 'use strict'\r
 \r
-import { assert, isNode, suite, test } from './GLOBALS.mjs'\r
+import { assert, suite, test } from './GLOBALS.mjs'\r
 import { NANO_TEST_VECTORS } from './VECTORS.js'\r
-import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '../dist/main.min.js'\r
+import { Bip44Wallet, Blake2bWallet } from '../dist/main.min.js'\r
 \r
 await suite('Create wallets', async () => {\r
 \r
@@ -49,28 +49,10 @@ await suite('Create wallets', async () => {
        await test('fail when using new', async () => {\r
                assert.throws(() => new Bip44Wallet())\r
                assert.throws(() => new Blake2bWallet())\r
-               assert.throws(() => new LedgerWallet())\r
        })\r
 \r
        await test('fail without a password', async () => {\r
                await assert.rejects(Bip44Wallet.create())\r
                await assert.rejects(Blake2bWallet.create())\r
        })\r
-\r
-       await test('connect to a Ledger device', { skip: false || isNode }, async () => {\r
-               const wallet = await LedgerWallet.create()\r
-               let status = await new Promise(resolve => {\r
-                       const button = document.createElement('button')\r
-                       button.innerText = 'Unlock Ledger, then click to continue'\r
-                       button.addEventListener('click', async (event) => {\r
-                               const connection = await wallet.connect()\r
-                               document.body.removeChild(button)\r
-                               resolve(connection)\r
-                       })\r
-                       document.body.appendChild(button)\r
-               })\r
-\r
-               assert.equals(status, 'CONNECTED')\r
-               assert.equals((await wallet.close()).status, 'OK')\r
-       })\r
 })\r
diff --git a/test/test.ledger.mjs b/test/test.ledger.mjs
new file mode 100644 (file)
index 0000000..32ec01b
--- /dev/null
@@ -0,0 +1,38 @@
+// SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+'use strict'
+
+import { assert, isNode, suite, test } from './GLOBALS.mjs'
+import { NANO_TEST_VECTORS } from './VECTORS.js'
+import { LedgerWallet } from '../dist/main.min.js'
+
+async function click (text, fn) {
+       return new Promise(resolve => {
+               const button = document.createElement('button')
+               button.innerText = text
+               button.addEventListener('click', async (event) => {
+                       const result = await fn
+                       document.body.removeChild(button)
+                       resolve(result)
+               })
+               document.body.appendChild(button)
+       })
+}
+
+await suite('Ledger hardware wallet', async () => {
+
+       await test('fail when using new', async () => {
+               assert.throws(() => new LedgerWallet())
+       })
+
+       await test('connect to a Ledger device and then disconnect', { skip: false || isNode }, async () => {
+               const wallet = await LedgerWallet.create()
+               const openStatus = await click('Unlock, then click to connect', wallet.connect())
+
+               assert.equals(openStatus, 'CONNECTED')
+
+               const closeStatus = await click('Click to close', wallet.close())
+               assert.equals(closeStatus.status, 'OK')
+       })
+})
index b917fa15f7d48f4b74a6eca4f3aa6cc9b21285b8..a2f78f9165fee01a69584c4cea5c468b2ff658ad 100644 (file)
@@ -1,15 +1,16 @@
 // SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
 // SPDX-License-Identifier: GPL-3.0-or-later
 
-import './test.blake2b.mjs'
-import './test.calculate-pow.mjs'
-import './test.create-wallet.mjs'
-import './test.derive-accounts.mjs'
-import './test.import-wallet.mjs'
-import './test.lock-unlock.mjs'
-import './test.manage-rolodex.mjs'
-import './test.refresh-accounts.mjs'
-import './test.sign-blocks.mjs'
-import './test.tools.mjs'
+// import './test.blake2b.mjs'
+// import './test.calculate-pow.mjs'
+// import './test.create-wallet.mjs'
+// import './test.derive-accounts.mjs'
+// import './test.import-wallet.mjs'
+import './test.ledger.mjs'
+// import './test.lock-unlock.mjs'
+// import './test.manage-rolodex.mjs'
+// import './test.refresh-accounts.mjs'
+// import './test.sign-blocks.mjs'
+// import './test.tools.mjs'
 
 console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')