Skip to content

Commit

Permalink
blockchain: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Oct 15, 2020
1 parent ca15b65 commit 528fb00
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions packages/blockchain/test/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BN, rlp } from 'ethereumjs-util'
import { Block } from '@ethereumjs/block'
import { BN, rlp, toBuffer } from 'ethereumjs-util'
import { Block, BlockHeader } from '@ethereumjs/block'
import Common from '@ethereumjs/common'
import Blockchain from '../src'
const level = require('level-mem')
Expand Down Expand Up @@ -63,24 +63,30 @@ export const generateConsecutiveBlock = (
parentBlock: Block,
difficultyChangeFactor: number,
): Block => {
const common = new Common({ chain: 'mainnet', hardfork: 'muirGlacier' })
const block = new Block(undefined, { common })
block.header.number = toBuffer(new BN(parentBlock.header.number).add(new BN(1)))
block.header.parentHash = parentBlock.hash()
block.header.gasLimit = toBuffer(8000000)
if (difficultyChangeFactor > 1) {
difficultyChangeFactor = 1
}
block.header.timestamp = toBuffer(
bufferToInt(parentBlock.header.timestamp) + (10 + -difficultyChangeFactor * 9),
)
block.header.difficulty = toBuffer(block.header.canonicalDifficulty(parentBlock))
return new Block(
const common = new Common({ chain: 'mainnet', hardfork: 'muirGlacier' })
const tmpHeader = BlockHeader.fromHeaderData({
number: new BN(parentBlock.header.number).add(new BN(1)),
timestamp: parentBlock.header.timestamp.addn(10 + -difficultyChangeFactor * 9),
})
const header = BlockHeader.fromHeaderData(
{
header: block.header,
number: new BN(parentBlock.header.number).add(new BN(1)),
parentHash: parentBlock.hash(),
gasLimit: new BN(8000000),
timestamp: parentBlock.header.timestamp.addn(10 + -difficultyChangeFactor * 9),
difficulty: new BN(tmpHeader.canonicalDifficulty(parentBlock)),
},
{
common,
},
{ common },
)

const block = new Block(header, undefined, undefined, { common })

return block
}

export const isConsecutive = (blocks: Block[]) => {
Expand Down

0 comments on commit 528fb00

Please sign in to comment.