]> git.codecow.com Git - libnemo.git/commitdiff
Fix ledger tests.
authorChris Duncan <chris@zoso.dev>
Fri, 8 Aug 2025 20:03:28 +0000 (13:03 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 8 Aug 2025 20:03:28 +0000 (13:03 -0700)
test/test.ledger.mjs

index f5066088b2fd9aab5d3063eb7eb755b2d4ed246d..19edbac9e243189fede7e4ac7948063ed1a19470 100644 (file)
@@ -114,14 +114,14 @@ await Promise.all([
                })
 
                await test('sign open block from block', async () => {
-                       openBlock = new Block(account, '0', RECEIVE_BLOCK.representative, account.publicKey)
+                       openBlock = new Block(account, '0', '0', RECEIVE_BLOCK.representative)
                                .receive(RECEIVE_BLOCK.link, RECEIVE_BLOCK.balance)
 
-                       assert.ok(/^[A-Fa-f0-9]{64}$/.test(openBlock.hash))
+                       assert.ok(/^[A-F0-9]{64}$/i.test(openBlock.hash))
                        assert.nullish(openBlock.signature)
                        assert.equal(openBlock.account.publicKey, account.publicKey)
 
-                       const signature = await wallet.sign(0, openBlock)
+                       const signature = await wallet.sign(0, openBlock, 'hex')
 
                        assert.ok(/^[A-Fa-f0-9]{128}$/.test(signature))
 
@@ -139,21 +139,21 @@ await Promise.all([
                })
 
                await test('sign send block from wallet which requires cache to be up-to-date', async () => {
-                       sendBlock = new Block(account, openBlock.balance, SEND_BLOCK.representative, openBlock.hash)
+                       sendBlock = new Block(account, openBlock.balance, openBlock.hash, SEND_BLOCK.representative)
                                .send(account.address, '0')
 
                        assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash))
                        assert.nullish(sendBlock.signature)
                        assert.equal(sendBlock.account.publicKey, account.publicKey)
 
-                       const signature = await wallet.sign(0, sendBlock)
+                       const signature = await wallet.sign(0, sendBlock, 'hex')
 
                        assert.ok(/^[A-Fa-f0-9]{128}$/.test(signature))
                        assert.equal(signature, sendBlock.signature)
                })
 
                await test('sign a receive block from block object which can accept previous block for cache', async () => {
-                       receiveBlock = new Block(account, sendBlock.balance, RECEIVE_BLOCK.representative, sendBlock.hash)
+                       receiveBlock = new Block(account, sendBlock.balance, sendBlock.hash, RECEIVE_BLOCK.representative)
                                .receive(sendBlock.hash, '0')
 
                        assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash))
@@ -166,30 +166,26 @@ await Promise.all([
                        assert.ok(/^[A-Fa-f0-9]{128}$/.test(receiveBlock.signature ?? ''))
                })
 
-               await test('sign a send block from wallet without frontier block inheriting cache contents', async () => {
-                       sendBlock = new Block(account, receiveBlock.balance, SEND_BLOCK.representative, receiveBlock.hash)
+               await test('fail to sign a send block from wallet without caching frontier block', async () => {
+                       sendBlock = new Block(account, receiveBlock.balance, receiveBlock.hash, SEND_BLOCK.representative)
                                .send(account.address, '0')
 
                        assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash))
                        assert.nullish(sendBlock.signature)
                        assert.equal(sendBlock.account.publicKey, account.publicKey)
 
-                       const signature = await wallet.sign(0, sendBlock)
-
-                       assert.exists(sendBlock.signature)
-                       assert.ok(/^[A-Fa-f0-9]{128}$/.test(sendBlock.signature ?? ''))
-                       assert.equal(signature, sendBlock.signature)
+                       await assert.rejects(wallet.sign(0, sendBlock, 'hex'))
                })
 
-               await test('sign a receive block from wallet including frontier block for cache', async () => {
-                       sendBlock = new Block(account, receiveBlock.balance, RECEIVE_BLOCK.representative, receiveBlock.hash)
-                               .receive(receiveBlock.hash, '0')
+               await test('sign a send block from wallet including frontier block for cache', async () => {
+                       sendBlock = new Block(account, receiveBlock.balance, receiveBlock.hash, SEND_BLOCK.representative)
+                               .send(account.address, '0')
 
-                       assert.ok(/^[A-Fa-f0-9]{64}$/.test(receiveBlock.hash))
+                       assert.ok(/^[A-Fa-f0-9]{64}$/.test(sendBlock.hash))
                        assert.nullish(sendBlock.signature)
                        assert.equal(sendBlock.account.publicKey, account.publicKey)
 
-                       const signature = await wallet.sign(0, sendBlock, receiveBlock)
+                       const signature = await wallet.sign(0, sendBlock, 'hex', receiveBlock)
 
                        assert.exists(sendBlock.signature)
                        assert.ok(/^[A-Fa-f0-9]{128}$/.test(sendBlock.signature ?? ''))
@@ -207,7 +203,7 @@ await Promise.all([
                })
 
                await test('fail to sign a block without caching frontier', async () => {
-                       sendBlock = new Block(account, receiveBlock.balance, SEND_BLOCK.representative, receiveBlock.previous)
+                       sendBlock = new Block(account, receiveBlock.balance, receiveBlock.hash, SEND_BLOCK.representative)
                                .send(account.address, '0')
                        await assert.rejects(sendBlock.sign(0))
                })