Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Iterator should return without errors if no more blocks #64

Merged
merged 1 commit into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
5 changes: 3 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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()
})
Expand Down