From 083b617970001e197096c56828ea255fcf84fe31 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Tue, 28 Aug 2018 13:26:24 +0200 Subject: [PATCH] Fix: iterator should return if no more blocks Signed-off-by: Sina Mahmoodi --- index.js | 4 ++++ test/index.js | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) 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() })