From 655ac37ba0addd18ab88982efe2e7a4583f5ee04 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Fri, 17 Jul 2015 10:53:02 -0400 Subject: [PATCH] changes in response to feedback --- integration/index.js | 2 +- lib/block.js | 34 ++---------------------- lib/db.js | 1 - test/block.unit.js | 30 --------------------- test/data/wallet.json | 61 ------------------------------------------- test/db.unit.js | 2 +- 6 files changed, 4 insertions(+), 126 deletions(-) delete mode 100644 test/data/wallet.json diff --git a/integration/index.js b/integration/index.js index 34a1435c..94c9024c 100644 --- a/integration/index.js +++ b/integration/index.js @@ -22,7 +22,7 @@ describe('Basic Functionality', function() { before(function(done) { this.timeout(30000); - bitcoind = require('../')({ + bitcoind = require('../').daemon({ directory: process.env.BITCOINDJS_DIR || '~/.bitcoin', }); diff --git a/lib/block.js b/lib/block.js index 363d3e42..1e5660da 100644 --- a/lib/block.js +++ b/lib/block.js @@ -22,38 +22,8 @@ function Block(obj) { util.inherits(Block, BaseBlock); Block.prototype.validate = function(chain, callback) { - var self = this; - - // Get previous block - chain.db.getBlock(self.prevHash, function(err, prevBlock) { - if (err) { - return callback(err); - } - - // Validate POW - - // First make sure the current block hash is less than the target derived from this block's bits - if (!self.validProofOfWork(chain)) { - return callback(new Error('Invalid proof of work (hash is greater than target)')); - } - - // Second make sure that this block's bits is correct based off of the last block - chain.getNextWorkRequired(prevBlock, function(err, bits) { - if (err) { - return callback(err); - } - - if (bits !== self.bits) { - return callback(new Error( - 'Invalid proof of work, expected block bits "' + self.bits + '" to equal "' + bits + '"' - )); - } - - // Validate block data - chain.db.validateBlockData(self, callback); - }); - }); - + // bitcoind does all validation + setImmediate(callback); }; /** diff --git a/lib/db.js b/lib/db.js index 47a2a0f4..1d5d852d 100644 --- a/lib/db.js +++ b/lib/db.js @@ -263,7 +263,6 @@ DB.prototype.getAPIMethods = function() { return [ ['getTransaction', this, this.getTransaction, 2], ['getBalance', this, this.getBalance, 2], - ['sendFunds', this, this.sendFunds, 2], ['getOutputs', this, this.getOutputs, 2], ['getUnspentOutputs', this, this.getUnspentOutputs, 2], ['isSpent', this, this.isSpent, 2] diff --git a/test/block.unit.js b/test/block.unit.js index 3c027f92..039fd994 100644 --- a/test/block.unit.js +++ b/test/block.unit.js @@ -23,36 +23,6 @@ describe('Bitcoin Block', function() { }); }); - describe('#validate', function() { - it('rejects with invalid proof of work because hash is greater', function(done) { - var block = new Block(chainData[1]); - block.validProofOfWork = sinon.stub().returns(false); - block.validate({ - db: { - getBlock: sinon.stub().callsArgWith(1, null, {}) - } - }, function(err) { - should.exist(err); - err.message.should.match(/Invalid proof of work/); - done(); - }); - }); - it('rejects with unexpected bits for chain', function(done) { - var block = new Block(chainData[1]); - block.validProofOfWork = sinon.stub().returns(true); - block.validate({ - db: { - getBlock: sinon.stub().callsArgWith(1, null, {}) - }, - getNextWorkRequired: sinon.stub().callsArgWith(1, null, 0x1d00ffff) - }, function(err) { - should.exist(err); - err.message.should.match(/Invalid proof of work, expected block bits/); - done(); - }); - }); - }); - describe('#validProofOfWork', function() { it('returns false if block hash is greater than target from bits', function() { var block = new Block(chainData[1]); diff --git a/test/data/wallet.json b/test/data/wallet.json deleted file mode 100644 index d2dfa37c..00000000 --- a/test/data/wallet.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "xprivkey": "tprv8ZgxMBicQKsPeHnrBXa8NfcpBQExTXq9gz8ijFPx6EJonZ5xiMt4kqWYRPJb5AmvNkTxV5qMTzkCUUfC4s3MQhpBcLg9AtpCAg5mqMeRqVr", - "utxos": { - "mv7aNQh6soUFysgh1Ax82BKBTyf1V4qWha": [ - { - "txId" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9", - "outputIndex" : 0, - "address" : "mv7aNQh6soUFysgh1Ax82BKBTyf1V4qWha", - "script" : "76a914a01e048440b4cc651df6bdc41ec47781788b4b6d88ac", - "satoshis" : 70000 - } - ], - "mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L": [ - { - "txId" : "b0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9", - "outputIndex" : 1, - "address" : "mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L", - "script" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac", - "satoshis" : 30000 - } - ] - }, - "utxosAmount": { - "mv7aNQh6soUFysgh1Ax82BKBTyf1V4qWha": [ - { - "txId" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9", - "outputIndex" : 0, - "address" : "mv7aNQh6soUFysgh1Ax82BKBTyf1V4qWha", - "script" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac", - "amount" : 0.0007 - } - ], - "mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L": [ - { - "txId" : "b0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9", - "outputIndex" : 1, - "address" : "mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L", - "script" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac", - "amount" : 0.0003 - } - ] - }, - "utxosNaN": { - "mv7aNQh6soUFysgh1Ax82BKBTyf1V4qWha": [ - { - "txId" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9", - "outputIndex" : 0, - "address" : "mv7aNQh6soUFysgh1Ax82BKBTyf1V4qWha", - "script" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac" - } - ], - "mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L": [ - { - "txId" : "b0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9", - "outputIndex" : 1, - "address" : "mzso6uXxfDCq4L6xAffUD9BPWo6bdFBZ2L", - "script" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac" - } - ] - } -} diff --git a/test/db.unit.js b/test/db.unit.js index 88a2d6c1..3bca746d 100644 --- a/test/db.unit.js +++ b/test/db.unit.js @@ -385,7 +385,7 @@ describe('Bitcoin DB', function() { it('should return the correct methods', function() { var db = new DB({path: 'path', store: memdown}); var methods = db.getAPIMethods(); - methods.length.should.equal(6); + methods.length.should.equal(5); }); });