Skip to content

Commit

Permalink
client: migrate test files from json to js objects (ethereumjs#3653)
Browse files Browse the repository at this point in the history
* common: test data

* devp2p: test data

* block: convert block test data

* blockchain: convert blockchain test data

* client: convert sim json configs

* block: adjust BeaconPayloadJSON type

* block: adjust from beacon payload test

* block: adjust from rpc test

* block: adjust remaining blocks test data

* block: add chainconfig type

* block: adjust types and fix test

* blockchain: adjust blockchain test data

* blockchain: adjust blockchain test data

* client: adjust test type issues

* devp2p: fix test type issues

* tx: fix test import

* devp2p: disable cspell for testdata

* monorepo: fix spelling

* common: remove unnecessary json parsing

* vm: fix type issue in runTx

* client: fix type issue in import

* vm: fix import

* util: add numeric string type

* block: use numeric string type

* client: migrate test data from json to ts

* client: adjust tests

* monorepo: misc type issues

* vm: fix test imports

* client: fix some tests

* client: fix geth genesis

---------

Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
  • Loading branch information
gabrocheleau and holgerd77 authored Sep 11, 2024
1 parent 0041c53 commit c85974a
Show file tree
Hide file tree
Showing 91 changed files with 9,864 additions and 9,771 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/rpc/modules/engine/CLConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type CLConnectionManagerOpts = {
inActivityCb?: () => void
}

type NewPayload = {
export type NewPayload = {
payload: ExecutionPayloadV1 | ExecutionPayloadV2 | ExecutionPayloadV3
response?: PayloadStatusV1
}

type ForkchoiceUpdate = {
export type ForkchoiceUpdate = {
state: ForkchoiceStateV1
response?: ForkchoiceResponseV1
headBlock?: Block
Expand Down
25 changes: 12 additions & 13 deletions packages/client/test/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import { Chain } from '../../src/blockchain/index.js'
import { Config } from '../../src/config.js'
import { VMExecution } from '../../src/execution/index.js'
import { closeRPC, setupChain } from '../rpc/helpers.js'
import blocksDataGoerli from '../testdata/blocks/goerli.json'
import blocksDataMainnet from '../testdata/blocks/mainnet.json'
import testnet from '../testdata/common/testnet.json'
import shanghaiJSON from '../testdata/geth-genesis/withdrawals.json'
import { goerliData } from '../testdata/blocks/goerli.js'
import { mainnetData } from '../testdata/blocks/mainnet.js'
import { testnetData } from '../testdata/common/testnet.js'
import { withdrawalsData } from '../testdata/geth-genesis/withdrawals.js'

import type { BlockData, ExecutionPayload } from '@ethereumjs/block'
import type { ExecutionPayload } from '@ethereumjs/block'
import type { Blockchain } from '@ethereumjs/blockchain'
import type { ChainConfig } from '@ethereumjs/common'

const shanghaiPayload = {
const shanghaiPayload: ExecutionPayload = {
blockNumber: '0x1',
parentHash: '0xfe950635b1bd2a416ff6283b0bbd30176e1b1125ad06fa729da9f3f4c1c61710',
feeRecipient: '0xaa00000000000000000000000000000000000000',
Expand Down Expand Up @@ -115,7 +114,7 @@ describe('[VMExecution]', () => {
let newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!()
assert.deepEqual(newHead.hash(), oldHead.hash(), 'should not modify blockchain on empty run')

blockchain = await createBlockchainFromBlocksData(blocksDataMainnet as BlockData[], {
blockchain = await createBlockchainFromBlocksData(mainnetData, {
validateBlocks: true,
validateConsensus: false,
})
Expand All @@ -124,7 +123,7 @@ describe('[VMExecution]', () => {
newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!()
assert.equal(newHead.header.number, BigInt(5), 'should run all blocks')

const common = createCustomCommon(testnet as ChainConfig, Mainnet)
const common = createCustomCommon(testnetData, Mainnet)
exec = await testSetup(blockchain, common)
await exec.run()
assert.equal(exec.hardfork, 'byzantium', 'should update HF on block run')
Expand All @@ -137,7 +136,7 @@ describe('[VMExecution]', () => {
})
let exec = await testSetup(blockchain)

blockchain = await createBlockchainFromBlocksData(blocksDataMainnet as BlockData[], {
blockchain = await createBlockchainFromBlocksData(mainnetData, {
validateBlocks: true,
validateConsensus: false,
})
Expand Down Expand Up @@ -181,7 +180,7 @@ describe('[VMExecution]', () => {
let newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!()
assert.deepEqual(newHead.hash(), oldHead.hash(), 'should not modify blockchain on empty run')

blockchain = await createBlockchainFromBlocksData(blocksDataGoerli as BlockData[], {
blockchain = await createBlockchainFromBlocksData(goerliData, {
validateBlocks: true,
validateConsensus: false,
common,
Expand All @@ -193,11 +192,11 @@ describe('[VMExecution]', () => {
})

it('Block execution / Hardforks PoA (goerli)', async () => {
const { server, execution, blockchain } = await setupChain(shanghaiJSON, 'post-merge', {
const { server, execution, blockchain } = await setupChain(withdrawalsData, 'post-merge', {
engine: true,
})

const block = await createBlockFromExecutionPayload(shanghaiPayload as ExecutionPayload, {
const block = await createBlockFromExecutionPayload(shanghaiPayload, {
common: new Common({ chain: Mainnet, hardfork: Hardfork.Shanghai }),
})
const oldHead = await blockchain.getIteratorHead()
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/integration/beaconsync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { createCommonFromGethGenesis } from '@ethereumjs/common'
import { assert, describe, it, vi } from 'vitest'

import { Event } from '../../src/types.js'
import genesisJSON from '../testdata/geth-genesis/post-merge.json'
import { postMergeData } from '../testdata/geth-genesis/post-merge.js'

import { destroy, setup, wait } from './util.js'

const common = createCommonFromGethGenesis(genesisJSON, { chain: 'post-merge' })
const common = createCommonFromGethGenesis(postMergeData, { chain: 'post-merge' })
common.setHardforkBy({ blockNumber: BigInt(0) })

describe('should sync blocks', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/integration/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function setup(
safeReorgDistance: 0,
})
// attach server to centralized event bus
;(server.config as any).events = serviceConfig.events
server.config.events = serviceConfig.events
const serviceOpts = {
config: serviceConfig,
chain,
Expand Down
8 changes: 4 additions & 4 deletions packages/client/test/rpc/debug/getRawReceipts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { encodeReceipt } from '@ethereumjs/vm'
import { loadKZG } from 'kzg-wasm'
import { assert, describe, it } from 'vitest'

import pow from '../../testdata/geth-genesis/pow.json'
import { powData } from '../../testdata/geth-genesis/pow.js'
import {
dummy,
getRPCClient,
Expand All @@ -29,7 +29,7 @@ const method2 = 'debug_getRawReceipts'

describe(method, () => {
it('call with legacy tx', async () => {
const { chain, common, execution, server } = await setupChain(pow, 'pow')
const { chain, common, execution, server } = await setupChain(powData, 'pow')
const rpc = getRPCClient(server)
// construct tx
const tx = createLegacyTx(
Expand All @@ -55,7 +55,7 @@ describe(method, () => {

it('call with 1559 tx', async () => {
const { chain, common, execution, server } = await setupChain(
gethGenesisStartLondon(pow),
gethGenesisStartLondon(powData),
'powLondon',
)
const rpc = getRPCClient(server)
Expand Down Expand Up @@ -86,7 +86,7 @@ describe(method, () => {
})

it('call with unknown block hash', async () => {
const { server } = await setupChain(pow, 'pow')
const { server } = await setupChain(powData, 'pow')
const rpc = getRPCClient(server)
// get a random tx hash
const res = await rpc.request(method, [
Expand Down
10 changes: 6 additions & 4 deletions packages/client/test/rpc/debug/getRawTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createFeeMarket1559Tx, createLegacyTx } from '@ethereumjs/tx'
import { bytesToHex } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import pow from '../../testdata/geth-genesis/pow.json'
import { powData } from '../../testdata/geth-genesis/pow.js'
import {
dummy,
getRPCClient,
Expand All @@ -15,7 +15,9 @@ const method = 'debug_getRawTransaction'

describe(method, () => {
it('call with legacy tx', async () => {
const { chain, common, execution, server } = await setupChain(pow, 'pow', { txLookupLimit: 1 })
const { chain, common, execution, server } = await setupChain(powData, 'pow', {
txLookupLimit: 1,
})
const rpc = getRPCClient(server)
// construct tx
const tx = createLegacyTx(
Expand All @@ -37,7 +39,7 @@ describe(method, () => {

it('call with 1559 tx', async () => {
const { chain, common, execution, server } = await setupChain(
gethGenesisStartLondon(pow),
gethGenesisStartLondon(powData),
'powLondon',
)
const rpc = getRPCClient(server)
Expand All @@ -60,7 +62,7 @@ describe(method, () => {
})

it('call with unknown tx hash', async () => {
const { server } = await setupChain(pow, 'pow')
const { server } = await setupChain(powData, 'pow')
const rpc = getRPCClient(server)
// get a random tx hash
const res = await rpc.request(method, [
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/rpc/debug/storageRangeAt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { assert, beforeEach, describe, it } from 'vitest'

import { INTERNAL_ERROR, INVALID_PARAMS } from '../../../src/rpc/error-code.js'
import genesisJSON from '../../testdata/geth-genesis/debug.json'
import { debugData } from '../../testdata/geth-genesis/debug.js'
import { dummy, getRPCClient, setupChain } from '../helpers.js'

import type { Block } from '@ethereumjs/block'
Expand Down Expand Up @@ -85,7 +85,7 @@ describe(method, () => {
// the second one updates a value in that contract, and the third one deploys
// another contract that does not put anything in its storage.

const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
txLookupLimit: 0,
})
const rpc = getRPCClient(server)
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/rpc/debug/traceCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { bytesToHex } from '@ethereumjs/util'
import { assert, describe, expect, expectTypeOf, it } from 'vitest'

import { toRPCTx } from '../../../src/rpc/types.js'
import genesisJSON from '../../testdata/geth-genesis/debug.json'
import { debugData } from '../../testdata/geth-genesis/debug.js'
import {
createClient,
createManager,
Expand Down Expand Up @@ -46,7 +46,7 @@ describe(method, async () => {
})

describe('trace a call', async () => {
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
txLookupLimit: 0,
})
const rpc = getRPCClient(server)
Expand Down
12 changes: 6 additions & 6 deletions packages/client/test/rpc/debug/traceTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { bytesToHex } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { INTERNAL_ERROR, INVALID_PARAMS } from '../../../src/rpc/error-code.js'
import genesisJSON from '../../testdata/geth-genesis/debug.json'
import { debugData } from '../../testdata/geth-genesis/debug.js'
import { baseSetup, dummy, getRPCClient, runBlockWithTxs, setupChain } from '../helpers.js'

const method = 'debug_traceTransaction'
Expand All @@ -19,7 +19,7 @@ describe(method, () => {
})

it('call with invalid parameters', async () => {
const { server } = await setupChain(genesisJSON, 'post-merge')
const { server } = await setupChain(debugData, 'post-merge')
const rpc = getRPCClient(server)
let res = await rpc.request(method, ['abcd', {}])
assert.equal(res.error.code, INVALID_PARAMS)
Expand All @@ -45,7 +45,7 @@ describe(method, () => {
})

it('call with valid parameters', async () => {
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
txLookupLimit: 0,
})
const rpc = getRPCClient(server)
Expand Down Expand Up @@ -74,7 +74,7 @@ describe(method, () => {
})

it('call with reverting code', async () => {
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
txLookupLimit: 0,
})
const rpc = getRPCClient(server)
Expand Down Expand Up @@ -103,7 +103,7 @@ describe(method, () => {
})

it('call with memory enabled', async () => {
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
txLookupLimit: 0,
})
const rpc = getRPCClient(server)
Expand Down Expand Up @@ -136,7 +136,7 @@ describe(method, () => {
})

it('call with stack disabled', async () => {
const { chain, common, execution, server } = await setupChain(genesisJSON, 'post-merge', {
const { chain, common, execution, server } = await setupChain(debugData, 'post-merge', {
txLookupLimit: 0,
})
const rpc = getRPCClient(server)
Expand Down
60 changes: 26 additions & 34 deletions packages/client/test/rpc/engine/CLConnectionManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,34 @@ import { assert, describe, expect, it, vi } from 'vitest'
import { Config } from '../../../src/index.js'
import { CLConnectionManager, ConnectionStatus } from '../../../src/rpc/modules/engine/index.js'
import { Event } from '../../../src/types.js'
import genesisJSON from '../../testdata/geth-genesis/post-merge.json'
import { postMergeData } from '../../testdata/geth-genesis/post-merge.js'

import type { PrefixedHexString } from '@ethereumjs/util'
import type { ForkchoiceUpdate, NewPayload } from '../../../src/rpc/modules/engine/index.js'

const payload = {
const payload: NewPayload = {
payload: {
parentHash:
'0xff10941138a407482a2651e3eaf0132f66c82ea1386a1f43287aa0fd6298698a' as PrefixedHexString,
feeRecipient: '0xf97e180c050e5ab072211ad2c213eb5aee4df134' as PrefixedHexString,
stateRoot:
'0x9933050575efffde6b1cdbfb9bca2f1a82df1c3e691f5878afe85eaf21df7d4f' as PrefixedHexString,
receiptsRoot:
'0x7d1842a048756ca0aa200ff3eb1b66a52434bc7c1ece5e179eb303a0efa1c944' as PrefixedHexString,
parentHash: '0xff10941138a407482a2651e3eaf0132f66c82ea1386a1f43287aa0fd6298698a',
feeRecipient: '0xf97e180c050e5ab072211ad2c213eb5aee4df134',
stateRoot: '0x9933050575efffde6b1cdbfb9bca2f1a82df1c3e691f5878afe85eaf21df7d4f',
receiptsRoot: '0x7d1842a048756ca0aa200ff3eb1b66a52434bc7c1ece5e179eb303a0efa1c944',
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040' as PrefixedHexString,
prevRandao:
'0xae8dc2c1223d402fb8e1a48ff6f0f15a543357aca40f34099ef5f5502f97d17d' as PrefixedHexString,
blockNumber: '0xd8d0' as PrefixedHexString,
gasLimit: '0x7a1200' as PrefixedHexString,
gasUsed: '0xc2f8e' as PrefixedHexString,
timestamp: '0x6230c760' as PrefixedHexString,
extraData: '0x' as PrefixedHexString,
baseFeePerGas: '0x3af046a' as PrefixedHexString,
blockHash:
'0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString,
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040',
prevRandao: '0xae8dc2c1223d402fb8e1a48ff6f0f15a543357aca40f34099ef5f5502f97d17d',
blockNumber: '0xd8d0',
gasLimit: '0x7a1200',
gasUsed: '0xc2f8e',
timestamp: '0x6230c760',
extraData: '0x',
baseFeePerGas: '0x3af046a',
blockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882',
transactions: [],
},
}
const update = {
const update: ForkchoiceUpdate = {
state: {
headBlockHash:
'0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString,
safeBlockHash:
'0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882' as PrefixedHexString,
finalizedBlockHash:
'0x90ce8a06162cf161cc7323aa30f1de70b30542cd5da65e521884f517a4548017' as PrefixedHexString,
headBlockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882',
safeBlockHash: '0x67b92008edff169c08bc186918a843f7363a747b50ed24d59fbfdee2ffd15882',
finalizedBlockHash: '0x90ce8a06162cf161cc7323aa30f1de70b30542cd5da65e521884f517a4548017',
},
}
describe('starts and stops connection manager', () => {
Expand All @@ -57,9 +49,9 @@ describe('starts and stops connection manager', () => {
})

describe('hardfork MergeForkBlock', () => {
;(genesisJSON.config as any).mergeForkBlock = 0
const params = parseGethGenesis(genesisJSON, 'post-merge')
const common = createCommonFromGethGenesis(genesisJSON, { chain: params.name })
postMergeData.config.mergeForkBlock = 0
const params = parseGethGenesis(postMergeData, 'post-merge')
const common = createCommonFromGethGenesis(postMergeData, { chain: params.name })
common.setHardforkBy({ blockNumber: 0 })
const config = new Config({ common })
it('instantiates with config', () => {
Expand All @@ -70,10 +62,10 @@ describe('hardfork MergeForkBlock', () => {
})
describe('postmerge hardfork', () => {
it('starts on mergeBlock', async () => {
;(genesisJSON.config as any).mergeForkBlock = 10
const params = parseGethGenesis(genesisJSON, 'post-merge')
postMergeData.config.mergeForkBlock = 10
const params = parseGethGenesis(postMergeData, 'post-merge')

const common = createCommonFromGethGenesis(genesisJSON, {
const common = createCommonFromGethGenesis(postMergeData, {
chain: params.name,
})
common.setHardforkBy({ blockNumber: 11 })
Expand Down
Loading

0 comments on commit c85974a

Please sign in to comment.