diff --git a/index.js b/index.js index 5273453..191475b 100644 --- a/index.js +++ b/index.js @@ -830,7 +830,7 @@ Blockchain.prototype._iterator = function (name, func, cb) { async.whilst( () => blockNumber, run, - () => self._saveHeads(cb) + (err) => err ? cb(err) : self._saveHeads(cb) ) }) diff --git a/test/index.js b/test/index.js index ced9fa9..b15f8d3 100644 --- a/test/index.js +++ b/test/index.js @@ -11,7 +11,7 @@ const testData = require('./testdata.json') const BN = require('bn.js') test('blockchain test', function (t) { - t.plan(59) + t.plan(61) var blockchain = new Blockchain() var genesisBlock var blocks = [] @@ -220,6 +220,15 @@ test('blockchain test', function (t) { done() }) }, + function iterateError (done) { + blockchain.iterator('error', function (block, reorg, cb) { + cb(new Error('iterator func error')) + }, function (err) { + t.ok(err, 'should catch iterator func error') + t.equal(err.message, 'iterator func error', 'should return correct error') + done() + }) + }, function iterateEmpty (done) { var blockchain = new Blockchain() blockchain.validate = false