From: Chris Duncan Date: Thu, 10 Jul 2025 18:47:13 +0000 (-0700) Subject: Add refresh account test to Ledger. X-Git-Tag: v0.10.5~64 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=bd7a39a797966a0069a7d6933c87802b36b7ae61;p=libnemo.git Add refresh account test to Ledger. --- diff --git a/test/test.ledger.mjs b/test/test.ledger.mjs index 2ee701e..09022b9 100644 --- a/test/test.ledger.mjs +++ b/test/test.ledger.mjs @@ -3,9 +3,11 @@ 'use strict' -import { assert, click, isNode, suite, test } from './GLOBALS.mjs' +import { assert, click, isNode, process, suite, test } from './GLOBALS.mjs' import { NANO_TEST_VECTORS } from './VECTORS.js' -import { Account, LedgerWallet, ReceiveBlock, SendBlock } from '../dist/main.min.js' +import { Account, LedgerWallet, ReceiveBlock, Rpc, SendBlock } from '../dist/main.min.js' + +const rpc = new Rpc(process.env.NODE_URL ?? '', process.env.API_KEY_NAME) /** * HID interactions require user gestures, so to reduce clicks, the variables @@ -76,6 +78,21 @@ await suite('Ledger hardware wallet', { skip: false || isNode }, async () => { } }) + await test('refresh first three accounts (must already be opened to be refreshed)', async () => { + const accounts = await wallet.refresh(rpc, 0, 2) + + assert.exists(accounts) + for (const account of accounts) { + assert.ok(account instanceof Account) + assert.exists(account.address) + assert.exists(account.balance) + assert.ok(account.balance >= 0) + assert.exists(account.publicKey) + assert.exists(account.privateKey) + assert.equals(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000') + } + }) + await test('sign open block from block', async () => { openBlock = new ReceiveBlock( account, @@ -149,10 +166,6 @@ await suite('Ledger hardware wallet', { skip: false || isNode }, async () => { assert.ok(/[A-Fa-f0-9]{128}/.test(receiveBlock.signature)) }) - await test('destroy wallet', async () => { - await assert.resolves(wallet.destroy()) - }) - // nonce signing is currently broken: https://github.com/LedgerHQ/app-nano/pull/14 await test('sign a nonce', { skip: true }, async () => { const nonce = new TextEncoder().encode('0123456789abcdef') @@ -162,6 +175,10 @@ await suite('Ledger hardware wallet', { skip: false || isNode }, async () => { assert.OK(/[A-Fa-f0-9]{128}/.test(signature)) }) + await test('destroy wallet', async () => { + await assert.resolves(wallet.destroy()) + }) + await test('fail when using new', async () => { assert.throws(() => new LedgerWallet()) })