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

Commit

Permalink
Fix _saveHeads cb, add test case
Browse files Browse the repository at this point in the history
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
  • Loading branch information
s1na committed Aug 2, 2018
1 parent e927afc commit fcc98b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ Blockchain.prototype._iterator = function (name, func, cb) {
async.whilst(
() => blockNumber,
run,
(err) => self._saveHeads(() => cb(err))
(err) => err ? cb(err) : self._saveHeads(cb)
)
})

Expand Down
11 changes: 10 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fcc98b1

Please sign in to comment.