From fe7397fb0bf610611cdfb521d0becb989872493a Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Mon, 10 Aug 2015 14:05:05 -0400 Subject: [PATCH 1/3] Added a check for txindex enabled in the config. --- lib/node.js | 3 +++ test/node.unit.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/node.js b/lib/node.js index 3d9c429d..9bc128ae 100644 --- a/lib/node.js +++ b/lib/node.js @@ -86,6 +86,9 @@ Node.prototype._loadBitcoinConf = function(config) { } } + $.checkState((this.bitcoinConfiguration.txindex && this.bitcoinConfiguration.txindex == 1), + 'Txindex option is required in order to use most of the features of bitcore-node. \ +Please add "txindex=1" to your configuration.'); }; Node.prototype._loadBitcoind = function(config) { diff --git a/test/node.unit.js b/test/node.unit.js index 438fae88..9b7405b3 100644 --- a/test/node.unit.js +++ b/test/node.unit.js @@ -22,6 +22,13 @@ BaseNode.prototype._loadConfiguration = sinon.spy(); BaseNode.prototype._initialize = sinon.spy(); chainlib.Node = BaseNode; +var BadNode = proxyquire('../lib/node', { + chainlib: chainlib, + fs: { + readFileSync: sinon.stub().returns(fs.readFileSync(__dirname + '/data/badbitcoin.conf')) + } +}); + var Node = proxyquire('../lib/node', { chainlib: chainlib, fs: { @@ -117,6 +124,12 @@ describe('Bitcoind Node', function() { node._loadBitcoind({datadir: './test', testnet: true}); should.exist(node.bitcoind); }); + it('should throw an exception if txindex isn\'t enabled in the configuration', function() { + var node = new BadNode({}); + (function() { + node._loadBitcoinConf({datadir: './test'}); + }).should.throw('Txindex option'); + }); }); describe('#_syncBitcoindAncestor', function() { it('will find an ancestor 6 deep', function() { From 2b775af7a0419485606e717769c9b076a1cdb228 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Mon, 10 Aug 2015 14:31:45 -0400 Subject: [PATCH 2/3] Added the badbitcoin.conf --- test/data/badbitcoin.conf | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/data/badbitcoin.conf diff --git a/test/data/badbitcoin.conf b/test/data/badbitcoin.conf new file mode 100644 index 00000000..c69affa1 --- /dev/null +++ b/test/data/badbitcoin.conf @@ -0,0 +1,16 @@ +#testnet=1 +#irc=0 +#upnp=0 +server=1 + +whitelist=127.0.0.1 + +# listen on different ports +port=20000 + +rpcallowip=127.0.0.1 + +rpcuser=bitcoin +rpcpassword=local321 + + From 7a539a26ffc8bbb920c6e3cd8fbc3cf4544f4f3e Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Tue, 11 Aug 2015 09:45:38 -0400 Subject: [PATCH 3/3] added additional message. --- lib/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index 9bc128ae..89dd2399 100644 --- a/lib/node.js +++ b/lib/node.js @@ -88,7 +88,7 @@ Node.prototype._loadBitcoinConf = function(config) { $.checkState((this.bitcoinConfiguration.txindex && this.bitcoinConfiguration.txindex == 1), 'Txindex option is required in order to use most of the features of bitcore-node. \ -Please add "txindex=1" to your configuration.'); +Please add "txindex=1" to your configuration and reindex an existing database if necessary with reindex=1'); }; Node.prototype._loadBitcoind = function(config) {