]> git.codecow.com Git - libnemo.git/commitdiff
Add refresh account test to Ledger.
authorChris Duncan <chris@zoso.dev>
Thu, 10 Jul 2025 18:47:13 +0000 (11:47 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 10 Jul 2025 18:47:13 +0000 (11:47 -0700)
test/test.ledger.mjs

index 2ee701ed2ea23955900b38ce003e3262af984dc7..09022b96171a25cc9ba1becf740431fd04a2fc0d 100644 (file)
@@ -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())
        })