Skip to content

Commit c24fd7d

Browse files
committed
blockchain: integrating Block 3.0.0
1 parent 0a66d2c commit c24fd7d

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

packages/blockchain/test/index.ts

+29-8
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ test('blockchain test', t => {
142142
st.error(err, 'no error')
143143
blockchain.getBlock(1, (err?: Error, block?: Block) => {
144144
st.error(err, 'no error')
145-
st.equal(block.hash().toString('hex'), blocks[1].hash().toString('hex'))
146-
st.end()
145+
if (block) {
146+
st.equal(block.hash().toString('hex'), blocks[1].hash().toString('hex'))
147+
st.end()
148+
} else {
149+
st.fail('block is not defined!')
150+
}
147151
})
148152
})
149153
})
@@ -158,8 +162,12 @@ test('blockchain test', t => {
158162
st.error(err, 'no error')
159163
blockchain.getBlock(genesisBlock.hash(), (err?: Error, block?: Block) => {
160164
st.error(err, 'no error')
161-
st.equal(block.hash().toString('hex'), genesisBlock.hash().toString('hex'))
162-
st.end()
165+
if (block) {
166+
st.equal(block.hash().toString('hex'), genesisBlock.hash().toString('hex'))
167+
st.end()
168+
} else {
169+
st.fail('block is not defined!')
170+
}
163171
})
164172
})
165173
})
@@ -370,7 +378,7 @@ test('blockchain test', t => {
370378
})
371379

372380
t.test('should catch iterator func error', async st => {
373-
const { blockchain, blocks, error } = await generateBlockchain(25)
381+
const { blockchain, error } = await generateBlockchain(25)
374382
st.error(error, 'no error')
375383
blockchain.iterator(
376384
'error',
@@ -585,9 +593,13 @@ test('blockchain test', t => {
585593
if (err) {
586594
return st.error(err)
587595
}
588-
st.equals(head.hash().toString('hex'), genesis.hash().toString('hex'), 'should get head')
589-
st.equals(blockchain._heads['head0'].toString('hex'), 'abcd', 'should get state root heads')
590-
st.end()
596+
if (genesis) {
597+
st.equals(head.hash().toString('hex'), genesis.hash().toString('hex'), 'should get head')
598+
st.equals(blockchain._heads['head0'].toString('hex'), 'abcd', 'should get state root heads')
599+
st.end()
600+
} else {
601+
st.fail()
602+
}
591603
})
592604
})
593605
})
@@ -627,6 +639,9 @@ test('blockchain test', t => {
627639
if (err) {
628640
return st.error(err)
629641
}
642+
if (!genesis) {
643+
return st.fail('genesis not defined!')
644+
}
630645
const blockchain = new Blockchain({ db: db })
631646
async.series(
632647
[
@@ -746,6 +761,9 @@ test('blockchain test', t => {
746761
if (err) {
747762
return st.error(err)
748763
}
764+
if (!block) {
765+
return st.fail('block not defined!')
766+
}
749767
st.equals(
750768
cachedHash.toString('hex'),
751769
block.hash().toString('hex'),
@@ -854,6 +872,9 @@ test('blockchain test', t => {
854872
if (err) {
855873
return st.error(err)
856874
}
875+
if (!getBlock) {
876+
return st.fail('getBlock not defined!')
877+
}
857878
t.equals(
858879
getBlock.hash().toString('hex'),
859880
block.hash().toString('hex'),

packages/blockchain/test/util.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { rlp, toBuffer, bufferToInt } from 'ethereumjs-util'
22
import BN = require('bn.js')
3-
import Blockchain, { Block } from '../src'
3+
import Blockchain from '../src'
44

55
const util = require('util')
66
import { Block } from 'ethereumjs-block'
@@ -43,7 +43,7 @@ export const generateBlocks = (numberOfBlocks: number, existingBlocks?: Block[])
4343
const block = new Block()
4444
block.header.number = toBuffer(i)
4545
block.header.parentHash = blocks[i - 1].hash()
46-
block.header.difficulty = block.header.canonicalDifficulty(blocks[i - 1])
46+
block.header.difficulty = toBuffer(block.header.canonicalDifficulty(blocks[i - 1]))
4747
block.header.gasLimit = toBuffer(8000000)
4848
block.header.timestamp = toBuffer(bufferToInt(blocks[i - 1].header.timestamp) + 1)
4949
blocks.push(block)

0 commit comments

Comments
 (0)