Skip to content

Commit

Permalink
Common, Block, Blockchain, Client: removed Kovan chain support (EOL) (#…
Browse files Browse the repository at this point in the history
…2206)

* Common, Block, Blockchain, Client: removed Kovan chain support (EOL)

* Tx: additional Kovan-related test fixes

* Common: set mainnet HF to merge, fixed common and block tests

* Blockchain: fixed mainnet London->Merge related tests

* VM: fixed mainnet London->Merge related tests

* Client: attempted test fix (still fails)

* client: fix sendRawTransaction test

* monorepo: typo succesfully -> successfully

* ethash: fix block test

* ethash: fix miner test

* devp2p: attempt fixing test failures

* devp2p: remove console log

Co-authored-by: Gabriel Rocheleau <contact@rockwaterweb.com>
  • Loading branch information
holgerd77 and gabrocheleau committed Aug 23, 2022
1 parent 001e147 commit 5dc3fd7
Show file tree
Hide file tree
Showing 34 changed files with 142 additions and 295 deletions.
14 changes: 2 additions & 12 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,8 @@ export class BlockHeader {
}

if (nonce.length !== 8) {
// Hack to check for Kovan due to non-standard nonce length (65 bytes)
if (this._common.networkId() === BigInt(Chain.Kovan)) {
if (nonce.length !== 65) {
const msg = this._errorMsg(
`nonce must be 65 bytes on kovan, received ${nonce.length} bytes`
)
throw new Error(msg)
}
} else {
const msg = this._errorMsg(`nonce must be 8 bytes, received ${nonce.length} bytes`)
throw new Error(msg)
}
const msg = this._errorMsg(`nonce must be 8 bytes, received ${nonce.length} bytes`)
throw new Error(msg)
}

// check if the block used too much gas
Expand Down
33 changes: 23 additions & 10 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ tape('[Block]: block functions', function (t) {

const valuesArray = <BlockBuffer>[headerArray, [], []]

block = Block.fromValuesArray(valuesArray)
block = Block.fromValuesArray(valuesArray, { common })
st.ok(Object.isFrozen(block), 'block should be frozen by default')

block = Block.fromValuesArray(valuesArray, { freeze: false })
block = Block.fromValuesArray(valuesArray, { common, freeze: false })
st.ok(!Object.isFrozen(block), 'block should not be frozen when freeze deactivated in options')

st.end()
Expand Down Expand Up @@ -190,7 +190,8 @@ tape('[Block]: block functions', function (t) {

t.test('should test transaction validation', async function (st) {
const blockRlp = toBuffer(testDataPreLondon.blocks[0].rlp)
const block = Block.fromRLPSerializedBlock(blockRlp, { freeze: false })
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const block = Block.fromRLPSerializedBlock(blockRlp, { common, freeze: false })
await testTransactionValidation(st, block)
;(block.header as any).transactionsTrie = Buffer.alloc(32)
try {
Expand Down Expand Up @@ -270,14 +271,20 @@ tape('[Block]: block functions', function (t) {
})

t.test('should return the same block data from raw()', function (st) {
const block = Block.fromRLPSerializedBlock(toBuffer(testDataPreLondon2.blocks[2].rlp))
const blockFromRaw = Block.fromValuesArray(block.raw())
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
const block = Block.fromRLPSerializedBlock(toBuffer(testDataPreLondon2.blocks[2].rlp), {
common,
})
const blockFromRaw = Block.fromValuesArray(block.raw(), { common })
st.ok(block.hash().equals(blockFromRaw.hash()))
st.end()
})

t.test('should test toJSON', function (st) {
const block = Block.fromRLPSerializedBlock(toBuffer(testDataPreLondon2.blocks[2].rlp))
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
const block = Block.fromRLPSerializedBlock(toBuffer(testDataPreLondon2.blocks[2].rlp), {
common,
})
st.equal(typeof block.toJSON(), 'object')
st.end()
})
Expand Down Expand Up @@ -308,17 +315,21 @@ tape('[Block]: block functions', function (t) {
t.test(
'should set canonical difficulty if I provide a calcDifficultyFromHeader header',
function (st) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart })
let common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart })
const genesis = Block.fromBlockData({}, { common })

const nextBlockHeaderData = {
number: genesis.header.number + BigInt(1),
timestamp: genesis.header.timestamp + BigInt(10),
}

const blockWithoutDifficultyCalculation = Block.fromBlockData({
header: nextBlockHeaderData,
})
common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const blockWithoutDifficultyCalculation = Block.fromBlockData(
{
header: nextBlockHeaderData,
},
{ common }
)

// test if difficulty defaults to 0
st.equal(
Expand All @@ -333,6 +344,7 @@ tape('[Block]: block functions', function (t) {
header: nextBlockHeaderData,
},
{
common,
calcDifficultyFromHeader: genesis.header,
}
)
Expand All @@ -358,6 +370,7 @@ tape('[Block]: block functions', function (t) {
header: noParentHeaderData,
},
{
common,
calcDifficultyFromHeader: genesis.header,
}
)
Expand Down
17 changes: 14 additions & 3 deletions packages/block/test/from-rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ tape('[fromRPC]:', function (t) {
t.test(
'Should create a block with json data that includes a transaction with value parameter as integer string',
function (st) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const valueAsIntegerString = '1'
const blockDataTransactionValueAsInteger = blockData
blockDataTransactionValueAsInteger.transactions[0].value = valueAsIntegerString
const blockFromTransactionValueAsInteger = blockFromRpc(blockDataTransactionValueAsInteger)
const blockFromTransactionValueAsInteger = blockFromRpc(
blockDataTransactionValueAsInteger,
undefined,
{ common }
)
st.equal(
blockFromTransactionValueAsInteger.transactions[0].value.toString(),
valueAsIntegerString
Expand All @@ -56,11 +61,14 @@ tape('[fromRPC]:', function (t) {
t.test(
'Should create a block with json data that includes a transaction with defaults with gasPrice parameter as integer string',
function (st) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const gasPriceAsIntegerString = '1'
const blockDataTransactionGasPriceAsInteger = blockData
blockDataTransactionGasPriceAsInteger.transactions[0].gasPrice = gasPriceAsIntegerString
const blockFromTransactionGasPriceAsInteger = blockFromRpc(
blockDataTransactionGasPriceAsInteger
blockDataTransactionGasPriceAsInteger,
undefined,
{ common }
)
st.equal(
(blockFromTransactionGasPriceAsInteger.transactions[0] as Transaction).gasPrice.toString(),
Expand All @@ -74,7 +82,10 @@ tape('[fromRPC]:', function (t) {
t.test(
'should create a block given json data that includes a difficulty parameter of type integer string',
function (st) {
const blockDifficultyAsInteger = blockFromRpc(blockDataDifficultyAsInteger)
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const blockDifficultyAsInteger = blockFromRpc(blockDataDifficultyAsInteger, undefined, {
common,
})
st.equal(
blockDifficultyAsInteger.header.difficulty.toString(),
blockDataDifficultyAsInteger.difficulty
Expand Down
54 changes: 17 additions & 37 deletions packages/block/test/header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,25 @@ tape('[Block]: Header functions', function (t) {
})

t.test('Initialization -> fromRLPSerializedHeader()', function (st) {
let header = BlockHeader.fromHeaderData({}, { freeze: false })
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
let header = BlockHeader.fromHeaderData({}, { common, freeze: false })

const rlpHeader = header.serialize()
header = BlockHeader.fromRLPSerializedHeader(rlpHeader)
header = BlockHeader.fromRLPSerializedHeader(rlpHeader, {
common,
})
st.ok(Object.isFrozen(header), 'block should be frozen by default')

header = BlockHeader.fromRLPSerializedHeader(rlpHeader, { freeze: false })
header = BlockHeader.fromRLPSerializedHeader(rlpHeader, {
common,
freeze: false,
})
st.ok(!Object.isFrozen(header), 'block should not be frozen when freeze deactivated in options')

st.throws(
() =>
BlockHeader.fromRLPSerializedHeader(rlpHeader, {
common,
freeze: false,
hardforkByTTD: 1n, // Added to bypass defaulting hardforkByBlockNumber to true in static constructor
}),
Expand All @@ -91,21 +98,7 @@ tape('[Block]: Header functions', function (t) {
'f90214a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000850400000000808213888080a011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82faa00000000000000000000000000000000000000000000000000000000000000000880000000000000042',
'hex'
),
{ hardforkByBlockNumber: true }
)

st.equal(
header.hash().toString('hex'),
'd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3',
'genesis block should produce correct hash'
)

header = BlockHeader.fromRLPSerializedHeader(
Buffer.from(
'f90214a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000850400000000808213888080a011bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82faa00000000000000000000000000000000000000000000000000000000000000000880000000000000042',
'hex'
),
{ hardforkByBlockNumber: false }
{ common, hardforkByBlockNumber: false }
)
st.equal(
header.hash().toString('hex'),
Expand All @@ -126,6 +119,7 @@ tape('[Block]: Header functions', function (t) {
})

t.test('Initialization -> fromValuesArray()', function (st) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const zero = Buffer.alloc(0)
const headerArray = []
for (let item = 0; item < 15; item++) {
Expand All @@ -141,10 +135,10 @@ tape('[Block]: Header functions', function (t) {
headerArray[13] = zeros(32) // mixHash
headerArray[14] = zeros(8) // nonce

let header = BlockHeader.fromValuesArray(headerArray)
let header = BlockHeader.fromValuesArray(headerArray, { common })
st.ok(Object.isFrozen(header), 'block should be frozen by default')

header = BlockHeader.fromValuesArray(headerArray, { freeze: false })
header = BlockHeader.fromValuesArray(headerArray, { common, freeze: false })
st.ok(!Object.isFrozen(header), 'block should not be frozen when freeze deactivated in options')
st.end()
})
Expand Down Expand Up @@ -330,21 +324,6 @@ tape('[Block]: Header functions', function (t) {
'contains nonce length error message'
)

const kovanCommon = new Common({ chain: Chain.Kovan })
st.throws(
() => BlockHeader.fromHeaderData({ nonce: Buffer.alloc(5) }, { common: kovanCommon }),
(err: any) => err.message.includes('nonce must be 65 bytes on kovan'),
'contains kovan nonce error message'
)

st.doesNotThrow(
() =>
BlockHeader.fromHeaderData(
{ nonce: Buffer.alloc(65) },
{ common: kovanCommon, consensusFormatValidation: false }
),
'was able to create Kovan block with nonce 65 bytes long'
)
st.end()
})
/*
Expand Down Expand Up @@ -462,14 +441,15 @@ tape('[Block]: Header functions', function (t) {
})
*/
t.test('should test validateGasLimit()', function (st) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const testData = require('./testdata/bcBlockGasLimitTest.json').tests
const bcBlockGasLimitTestData = testData.BlockGasLimit2p63m1

for (const key of Object.keys(bcBlockGasLimitTestData)) {
const genesisRlp = toBuffer(bcBlockGasLimitTestData[key].genesisRLP)
const parentBlock = Block.fromRLPSerializedBlock(genesisRlp)
const parentBlock = Block.fromRLPSerializedBlock(genesisRlp, { common })
const blockRlp = toBuffer(bcBlockGasLimitTestData[key].blocks[0].rlp)
const block = Block.fromRLPSerializedBlock(blockRlp)
const block = Block.fromRLPSerializedBlock(blockRlp, { common })
st.doesNotThrow(() => block.validateGasLimit(parentBlock))
}

Expand Down
6 changes: 2 additions & 4 deletions packages/blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,11 +1246,11 @@ export class Blockchain implements BlockchainInterface {
stateRoot,
}
if (common.consensusType() === 'poa') {
if (common.genesis().extraData && common.chainName() !== 'kovan') {
if (common.genesis().extraData) {
// Ensure exta data is populated from genesis data if provided
header.extraData = common.genesis().extraData
} else {
// Add required extraData (32 bytes vanity + 65 bytes filled with zeroes (or if chain is Kovan)
// Add required extraData (32 bytes vanity + 65 bytes filled with zeroes
header.extraData = Buffer.concat([Buffer.alloc(32), Buffer.alloc(65).fill(0)])
}
}
Expand All @@ -1275,8 +1275,6 @@ export class Blockchain implements BlockchainInterface {
return require('./genesisStates/ropsten.json')
case 'rinkeby':
return require('./genesisStates/rinkeby.json')
case 'kovan':
return require('./genesisStates/kovan.json')
case 'goerli':
return require('./genesisStates/goerli.json')
case 'sepolia':
Expand Down
7 changes: 0 additions & 7 deletions packages/blockchain/src/genesisStates/kovan.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/blockchain/test/blockValidation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ tape('[Blockchain]: Block validation tests', (t) => {
await blockchain.putBlock(block1)
await blockchain.putBlock(block2)

st.pass('uncle blocks validated succesfully')
st.pass('uncle blocks validated successfully')
})

t.test('EIP1559 base fee tests', async (st) => {
Expand Down
22 changes: 13 additions & 9 deletions packages/blockchain/test/pos.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Block } from '@ethereumjs/block'
import { Common, Hardfork } from '@ethereumjs/common'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import * as tape from 'tape'

import { Blockchain } from '../src'
Expand Down Expand Up @@ -81,15 +81,19 @@ tape('Proof of Stake - inserting blocks into blockchain', async (t) => {
const td = await blockchain.getTotalDifficulty(latestHeader.hash())
t.equal(td, BigInt(1313601), 'should have calculated the correct post-Merge total difficulty')

const powBlock = Block.fromBlockData({
header: {
number: 16,
difficulty: BigInt(1),
parentHash: latestHeader.hash(),
timestamp: latestHeader.timestamp + BigInt(1),
gasLimit: BigInt(10000),
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
const powBlock = Block.fromBlockData(
{
header: {
number: 16,
difficulty: BigInt(1),
parentHash: latestHeader.hash(),
timestamp: latestHeader.timestamp + BigInt(1),
gasLimit: BigInt(10000),
},
},
})
{ common }
)
try {
await blockchain.putBlock(powBlock)
t.fail('should throw when inserting PoW block')
Expand Down
11 changes: 7 additions & 4 deletions packages/blockchain/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ export const generateConsecutiveBlock = (
difficultyChangeFactor = 1
}
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.MuirGlacier })
const tmpHeader = BlockHeader.fromHeaderData({
number: parentBlock.header.number + BigInt(1),
timestamp: parentBlock.header.timestamp + BigInt(10 + -difficultyChangeFactor * 9),
})
const tmpHeader = BlockHeader.fromHeaderData(
{
number: parentBlock.header.number + BigInt(1),
timestamp: parentBlock.header.timestamp + BigInt(10 + -difficultyChangeFactor * 9),
},
{ common }
)
const header = BlockHeader.fromHeaderData(
{
number: parentBlock.header.number + BigInt(1),
Expand Down
16 changes: 0 additions & 16 deletions packages/client/test/rpc/eth/chainId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ tape(`${method}: returns 3 for Ropsten`, async (t) => {
await baseRequest(t, server, req, 200, expectRes)
})

tape(`${method}: returns 42 for Kovan`, async (t) => {
BlockHeader.prototype._consensusFormatValidation = td.func<any>()
const manager = createManager(
createClient({ opened: true, commonChain: new Common({ chain: Chain.Kovan }) })
)
const server = startRPC(manager.getMethods())

const req = params(method, [])
const expectRes = (res: any) => {
const msg = 'should return chainId 42'
const chainId = BigInt(42).toString(16)
t.equal(res.body.result, `0x${chainId}`, msg)
}
await baseRequest(t, server, req, 200, expectRes)
})

tape(`reset TD`, (t) => {
BlockHeader.prototype._consensusFormatValidation = originalValidate
td.reset()
Expand Down
Loading

0 comments on commit 5dc3fd7

Please sign in to comment.