11/* global describe, it, beforeEach */
22
33var assert = require ( 'assert' )
4-
54var Block = require ( '../src/block' )
65
76var fixtures = require ( './fixtures/block' )
87
98describe ( 'Block' , function ( ) {
9+ describe ( 'calculateTarget' , function ( ) {
10+ fixtures . targets . forEach ( function ( f ) {
11+ it ( 'returns ' + f . expected + ' for 0x' + f . bits , function ( ) {
12+ var bits = parseInt ( f . bits , 16 )
13+
14+ assert . equal ( Block . calculateTarget ( bits ) . toString ( 'hex' ) , f . expected )
15+ } )
16+ } )
17+ } )
18+
1019 describe ( 'fromBuffer/fromHex' , function ( ) {
1120 fixtures . valid . forEach ( function ( f ) {
1221 it ( 'imports the block: ' + f . description + ' correctly' , function ( ) {
@@ -52,7 +61,7 @@ describe('Block', function () {
5261 block = Block . fromHex ( f . hex )
5362 } )
5463
55- it ( 'calculates ' + f . hash + ' for the block: ' + f . description , function ( ) {
64+ it ( 'returns ' + f . hash + ' for the block: ' + f . description , function ( ) {
5665 assert . strictEqual ( block . getHash ( ) . toString ( 'hex' ) , f . hash )
5766 } )
5867 } )
@@ -66,7 +75,7 @@ describe('Block', function () {
6675 block = Block . fromHex ( f . hex )
6776 } )
6877
69- it ( 'calculates ' + f . id + ' for the block: ' + f . description , function ( ) {
78+ it ( 'returns ' + f . id + ' for the block: ' + f . description , function ( ) {
7079 assert . strictEqual ( block . getId ( ) , f . id )
7180 } )
7281 } )
@@ -87,4 +96,18 @@ describe('Block', function () {
8796 } )
8897 } )
8998 } )
99+
100+ describe ( 'checkProofOfWork' , function ( ) {
101+ fixtures . valid . forEach ( function ( f ) {
102+ var block
103+
104+ beforeEach ( function ( ) {
105+ block = Block . fromHex ( f . hex )
106+ } )
107+
108+ it ( 'returns ' + f . valid + ' for ' + f . id , function ( ) {
109+ assert . strictEqual ( block . checkProofOfWork ( ) , f . valid )
110+ } )
111+ } )
112+ } )
90113} )
0 commit comments