diff --git a/index.js b/index.js index 483b560..2e90320 100644 --- a/index.js +++ b/index.js @@ -937,6 +937,10 @@ Blockchain.prototype._iterator = function (name, func, cb) { blockNumber.iaddn(1) } else { blockNumber = false + // No more blocks, return + if (err instanceof levelup.errors.NotFoundError) { + return cb2() + } } cb2(err) }) diff --git a/test/index.js b/test/index.js index 079cf8d..a87d930 100644 --- a/test/index.js +++ b/test/index.js @@ -13,7 +13,7 @@ const BN = require('bn.js') const rlp = ethUtil.rlp test('blockchain test', function (t) { - t.plan(72) + t.plan(73) var blockchain = new Blockchain() var genesisBlock var blocks = [] @@ -253,7 +253,8 @@ test('blockchain test', function (t) { blockchain.iterator('test', function () { t.ok(false, 'should not call iterator function') done() - }, function () { + }, function (err) { + t.error(err, 'should not return error') t.ok(true, 'should finish iterating') done() })