From 4bc0bb2366211a053c5b58a4bf7ed649fe5bd861 Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Tue, 7 May 2019 00:12:40 +0530 Subject: [PATCH] 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;