From: Chris Duncan Date: Tue, 8 Jul 2025 21:48:54 +0000 (-0700) Subject: Extract Ledger wallet tests to their own file. X-Git-Tag: v0.10.5~83 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=4bca7a00812b22ab9c68b3d67e4dea2851831c05;p=libnemo.git Extract Ledger wallet tests to their own file. --- diff --git a/test/test.create-wallet.mjs b/test/test.create-wallet.mjs index 4899787..a159b49 100644 --- a/test/test.create-wallet.mjs +++ b/test/test.create-wallet.mjs @@ -3,9 +3,9 @@ 'use strict' -import { assert, isNode, suite, test } from './GLOBALS.mjs' +import { assert, suite, test } from './GLOBALS.mjs' import { NANO_TEST_VECTORS } from './VECTORS.js' -import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '../dist/main.min.js' +import { Bip44Wallet, Blake2bWallet } from '../dist/main.min.js' await suite('Create wallets', async () => { @@ -49,28 +49,10 @@ await suite('Create wallets', async () => { await test('fail when using new', async () => { assert.throws(() => new Bip44Wallet()) assert.throws(() => new Blake2bWallet()) - assert.throws(() => new LedgerWallet()) }) await test('fail without a password', async () => { await assert.rejects(Bip44Wallet.create()) await assert.rejects(Blake2bWallet.create()) }) - - await test('connect to a Ledger device', { skip: false || isNode }, async () => { - const wallet = await LedgerWallet.create() - let status = await new Promise(resolve => { - const button = document.createElement('button') - button.innerText = 'Unlock Ledger, then click to continue' - button.addEventListener('click', async (event) => { - const connection = await wallet.connect() - document.body.removeChild(button) - resolve(connection) - }) - document.body.appendChild(button) - }) - - assert.equals(status, 'CONNECTED') - assert.equals((await wallet.close()).status, 'OK') - }) }) diff --git a/test/test.ledger.mjs b/test/test.ledger.mjs new file mode 100644 index 0000000..32ec01b --- /dev/null +++ b/test/test.ledger.mjs @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2025 Chris Duncan +// 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') + }) +}) diff --git a/test/test.main.mjs b/test/test.main.mjs index b917fa1..a2f78f9 100644 --- a/test/test.main.mjs +++ b/test/test.main.mjs @@ -1,15 +1,16 @@ // SPDX-FileCopyrightText: 2025 Chris Duncan // 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')