From: Chris Duncan Date: Fri, 8 Aug 2025 20:03:28 +0000 (-0700) Subject: Fix ledger tests. X-Git-Tag: v0.10.5~43^2 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=adfa6363820c0b0abbfc4b87e02f49595389baf5;p=libnemo.git Fix ledger tests. --- diff --git a/test/test.ledger.mjs b/test/test.ledger.mjs index f506608..19edbac 100644 --- a/test/test.ledger.mjs +++ b/test/test.ledger.mjs @@ -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)) })