From 4bc0bb2366211a053c5b58a4bf7ed649fe5bd861 Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Tue, 7 May 2019 00:12:40 +0530 Subject: [PATCH 1/3] chain: add fee overflow test; rename error --- lib/blockchain/chain.js | 2 +- test/chain-test.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 93271b0e..026acb9a 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -770,7 +770,7 @@ class Chain extends AsyncEmitter { if (reward > consensus.MAX_MONEY) { throw new VerifyError(block, 'invalid', - 'bad-cb-amount', + 'bad-txns-accumulated-fee-outofrange', 100); } } diff --git a/test/chain-test.js b/test/chain-test.js index 45cfbd10..d196c055 100644 --- a/test/chain-test.js +++ b/test/chain-test.js @@ -10,7 +10,7 @@ const Script = require('../lib/script/script'); const Chain = require('../lib/blockchain/chain'); const WorkerPool = require('../lib/workers/workerpool'); const Miner = require('../lib/mining/miner'); -const MTX = require('../lib/primitives/mtx'); +const {Selector, MTX} = require('../lib/primitives/mtx'); const MemWallet = require('./util/memwallet'); const Network = require('../lib/protocol/network'); const Output = require('../lib/primitives/output'); @@ -815,6 +815,34 @@ describe('Chain', function() { 'bad-txns-txouttotal-toolarge'); }); + it('should fail to connect total fee toolarge', async () => { + const job = await cpu.createJob(); + + Selector.MAX_FEE = 50 * consensus.COIN; + + const outputs = [{ address: wallet.getAddress(), value: 0 }]; + const tx1 = await wallet.send({ + outputs: outputs, + hardFee: Selector.MAX_FEE + }); + job.pushTX(tx1.toTX()); + + const tx2 = await wallet.send({ + outputs: outputs, + hardFee: Selector.MAX_FEE + }); + job.pushTX(tx2.toTX()); + + consensus.MAX_MONEY = tx1.getFee() + tx2.getFee() - 1; + + job.refresh(); + assert.strictEqual(await mineBlock(job), + 'bad-txns-accumulated-fee-outofrange'); + + consensus.MAX_MONEY = 21000000 * consensus.COIN; + Selector.MAX_FEE = consensus.COIN / 10; + }); + it('should mine 111 multisig blocks', async () => { const flags = common.flags.DEFAULT_FLAGS & ~common.flags.VERIFY_POW; From 49143b2c164a243bc9e514a79e7347bcfb9f91fc Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Tue, 7 May 2019 03:48:31 +0530 Subject: [PATCH 2/3] chain: reset consensus params on assert fail --- test/chain-test.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/chain-test.js b/test/chain-test.js index d196c055..747d71d2 100644 --- a/test/chain-test.js +++ b/test/chain-test.js @@ -835,12 +835,14 @@ describe('Chain', function() { consensus.MAX_MONEY = tx1.getFee() + tx2.getFee() - 1; - job.refresh(); - assert.strictEqual(await mineBlock(job), - 'bad-txns-accumulated-fee-outofrange'); - - consensus.MAX_MONEY = 21000000 * consensus.COIN; - Selector.MAX_FEE = consensus.COIN / 10; + try { + job.refresh(); + assert.strictEqual(await mineBlock(job), + 'bad-txns-accumulated-fee-outofrange'); + } finally { + consensus.MAX_MONEY = 21000000 * consensus.COIN; + Selector.MAX_FEE = consensus.COIN / 10; + } }); it('should mine 111 multisig blocks', async () => { From d53fa0a1c53def06d34b55c555903b7c44a6d32f Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Tue, 7 May 2019 03:59:15 +0530 Subject: [PATCH 3/3] chain: extend try..finally; restore consts to copy --- test/chain-test.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/test/chain-test.js b/test/chain-test.js index 747d71d2..325e37ba 100644 --- a/test/chain-test.js +++ b/test/chain-test.js @@ -817,31 +817,33 @@ describe('Chain', function() { it('should fail to connect total fee toolarge', async () => { const job = await cpu.createJob(); + const outputs = [{ address: wallet.getAddress(), value: 0 }]; Selector.MAX_FEE = 50 * consensus.COIN; - - const outputs = [{ address: wallet.getAddress(), value: 0 }]; - const tx1 = await wallet.send({ - outputs: outputs, - hardFee: Selector.MAX_FEE - }); - job.pushTX(tx1.toTX()); - - const tx2 = await wallet.send({ - outputs: outputs, - hardFee: Selector.MAX_FEE - }); - job.pushTX(tx2.toTX()); - - consensus.MAX_MONEY = tx1.getFee() + tx2.getFee() - 1; + const maxFee = Selector.MAX_FEE; + const maxMoney = consensus.MAX_MONEY; try { + const tx1 = await wallet.send({ + outputs: outputs, + hardFee: Selector.MAX_FEE + }); + job.pushTX(tx1.toTX()); + + const tx2 = await wallet.send({ + outputs: outputs, + hardFee: Selector.MAX_FEE + }); + job.pushTX(tx2.toTX()); + + consensus.MAX_MONEY = tx1.getFee() + tx2.getFee() - 1; + job.refresh(); assert.strictEqual(await mineBlock(job), 'bad-txns-accumulated-fee-outofrange'); } finally { - consensus.MAX_MONEY = 21000000 * consensus.COIN; - Selector.MAX_FEE = consensus.COIN / 10; + Selector.MAX_FEE = maxFee; + consensus.MAX_MONEY = maxMoney; } });