]> git.codecow.com Git - libnemo.git/commitdiff
Fix sweep account index check and test assertion.
authorChris Duncan <chris@zoso.dev>
Mon, 18 Aug 2025 21:23:56 +0000 (14:23 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 18 Aug 2025 21:23:56 +0000 (14:23 -0700)
src/lib/tools.ts
test/test.tools.mjs

index f9b08e988019ba980ec6be93c8cc01e4779332dd..f45701836ef906d7c59a40ee9e836b1d1f8ceb79 100644 (file)
@@ -147,19 +147,18 @@ export async function sweep (
                throw new TypeError('RPC must be a valid node')
        }
        const blockQueue: Promise<void>[] = []
-       const results: { status: 'success' | 'error', address: string, message: string }[] = []
+       const results: SweepResult[] = []
 
        const recipientAccount = Account.load(recipient)
        const accounts = await wallet.refresh(rpc, from, to)
        for (const account of accounts) {
-               if (account.representative?.address && account.frontier && account.index) {
-                       const block = new Block(account).send(recipientAccount, account.balance ?? 0n)
-                       await Promise.all([
-                               block.pow(),
-                               block.sign(wallet, account.index)
-                       ])
+               if (account.representative?.address && account.frontier && account.index != null) {
+                       const block = await new Block(account)
+                               .send(recipientAccount, account.balance ?? 0n)
+                               .sign(wallet, account.index)
                        const blockRequest: Promise<void> = new Promise(async (resolve) => {
                                try {
+                                       await block.pow()
                                        const hash = await block.process(rpc)
                                        results.push({ status: 'success', address: block.account.address, message: hash })
                                } catch (err: any) {
index 31c7d47662cdce3716f92999e1ae7469ffd0a118..20ae465eff8e89e04303635e58180586db7e8878 100644 (file)
@@ -182,7 +182,7 @@ await Promise.all([
                        await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
                        const results = await Tools.sweep(rpc, wallet, NANO_TEST_VECTORS.ADDRESS_1)\r
 \r
-                       assert.ok(results)\r
+                       assert.exists(results)\r
                        assert.equal(results.length, 1)\r
 \r
                        await assert.resolves(wallet.destroy())\r