-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |