Skip to content

Commit

Permalink
Add tests for fakeBlockChain
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 9, 2018
1 parent 6feba49 commit 1300642
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/api/fakeBlockChain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const tape = require('tape')
const fakeBlockchain = require('../../lib/fakeBlockChain')

tape('fakeBlockChain', (t) => {
const blockchain = fakeBlockchain

t.test('should fail to get block by invalid type', (st) => {
blockchain.getBlock(null, (err, block) => {
st.ok(err, 'should return error')
st.notOk(block)
st.end()
})
})

t.test('should get block hash by number', (st) => {
blockchain.getBlock(1, isValidBlock(st))
})

t.test('should get block hash by buffer', (st) => {
blockchain.getBlock(Buffer.from('0x0'), isValidBlock(st))
})

t.test('should "del" block', (st) => {
blockchain.delBlock('0x0', (err) => {
st.error(err)
st.end()
})
})
})

const isValidBlock = (st) => (err, block) => {
st.notOk(err)
st.ok(block, 'should return non-empty value')
st.ok(Buffer.isBuffer(block.hash()), 'block hash should of type buffer')
st.end()
}

0 comments on commit 1300642

Please sign in to comment.