Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monorepo: convert test data from JSON to objects #3642

Merged
merged 28 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9602773
common: test data
gabrocheleau Sep 6, 2024
5b716c8
devp2p: test data
gabrocheleau Sep 6, 2024
84d5264
block: convert block test data
gabrocheleau Sep 7, 2024
5db8f8f
blockchain: convert blockchain test data
gabrocheleau Sep 7, 2024
bcbd1bc
client: convert sim json configs
gabrocheleau Sep 7, 2024
10225a7
block: adjust BeaconPayloadJSON type
gabrocheleau Sep 7, 2024
3a92009
block: adjust from beacon payload test
gabrocheleau Sep 7, 2024
7631a64
block: adjust from rpc test
gabrocheleau Sep 7, 2024
ed6d438
block: adjust remaining blocks test data
gabrocheleau Sep 7, 2024
55e1486
block: add chainconfig type
gabrocheleau Sep 7, 2024
fbae7ae
chore: merge with master
gabrocheleau Sep 8, 2024
092c05e
Merge branch 'master' into monorepo/typescript-test-files
gabrocheleau Sep 8, 2024
befc8ac
block: adjust types and fix test
gabrocheleau Sep 8, 2024
1e98496
Merge branch 'monorepo/typescript-test-files' of https://github.com/e…
gabrocheleau Sep 8, 2024
b268563
blockchain: adjust blockchain test data
gabrocheleau Sep 8, 2024
efdd235
blockchain: adjust blockchain test data
gabrocheleau Sep 8, 2024
360131b
client: adjust test type issues
gabrocheleau Sep 9, 2024
5c37723
devp2p: fix test type issues
gabrocheleau Sep 9, 2024
1379cd2
tx: fix test import
gabrocheleau Sep 9, 2024
1a25fbe
devp2p: disable cspell for testdata
gabrocheleau Sep 9, 2024
85a3910
monorepo: fix spelling
gabrocheleau Sep 9, 2024
83836bb
common: remove unnecessary json parsing
gabrocheleau Sep 9, 2024
d44fdc7
vm: fix type issue in runTx
gabrocheleau Sep 9, 2024
a24e543
client: fix type issue in import
gabrocheleau Sep 9, 2024
80ef607
vm: fix import
gabrocheleau Sep 9, 2024
b9e9a5d
util: add numeric string type
gabrocheleau Sep 9, 2024
ac28a0d
block: use numeric string type
gabrocheleau Sep 9, 2024
7ef44bd
chore: fix merge conflicts
gabrocheleau Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/cspell-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@
"nickdodson",
"Kintsugi",
"deauthorization",
"mixhash",
"blockperiodseconds",
"filledwith",
"lllcversion",
"Netsplit",
"Statetest",
"testeth",
"PUSHDATA",
"chunkified"
]
Expand Down
16 changes: 8 additions & 8 deletions packages/block/src/from-beacon-payload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { bigIntToHex } from '@ethereumjs/util'

import type { ExecutionPayload } from './types.js'
import type { PrefixedHexString, VerkleExecutionWitness } from '@ethereumjs/util'
import type { NumericString, PrefixedHexString, VerkleExecutionWitness } from '@ethereumjs/util'

type BeaconWithdrawal = {
index: PrefixedHexString
Expand Down Expand Up @@ -39,17 +39,17 @@ export type BeaconPayloadJSON = {
receipts_root: PrefixedHexString
logs_bloom: PrefixedHexString
prev_randao: PrefixedHexString
block_number: PrefixedHexString
gas_limit: PrefixedHexString
gas_used: PrefixedHexString
timestamp: PrefixedHexString
block_number: NumericString
gas_limit: NumericString
gas_used: NumericString
timestamp: NumericString
extra_data: PrefixedHexString
base_fee_per_gas: PrefixedHexString
base_fee_per_gas: NumericString
block_hash: PrefixedHexString
transactions: PrefixedHexString[]
withdrawals?: BeaconWithdrawal[]
blob_gas_used?: PrefixedHexString
excess_blob_gas?: PrefixedHexString
blob_gas_used?: NumericString
excess_blob_gas?: NumericString
parent_beacon_block_root?: PrefixedHexString
// requests data
deposit_requests?: BeaconDepositRequest[]
Expand Down
3 changes: 2 additions & 1 deletion packages/block/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ConsolidationRequestV1,
DepositRequestV1,
JSONRPCWithdrawal,
NumericString,
PrefixedHexString,
RequestBytes,
VerkleExecutionWitness,
Expand Down Expand Up @@ -224,7 +225,7 @@ export interface JSONRPCBlock {
stateRoot: PrefixedHexString // the root of the final state trie of the block.
receiptsRoot: PrefixedHexString // the root of the receipts trie of the block.
miner: PrefixedHexString // the address of the beneficiary to whom the mining rewards were given.
difficulty: PrefixedHexString // integer of the difficulty for this block.
difficulty: PrefixedHexString | NumericString // integer of the difficulty for this block. Can be a 0x-prefixed hex string or a string integer
totalDifficulty: PrefixedHexString // integer of the total difficulty of the chain until this block.
extraData: PrefixedHexString // the “extra data” field of this block.
size: PrefixedHexString // integer the size of this block in bytes.
Expand Down
38 changes: 18 additions & 20 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { genTransactionsTrieRoot } from '../src/helpers.js'
import {
type Block,
type BlockBytes,
type JSONRPCBlock,
createBlock,
createBlockFromBytesArray,
createBlockFromRLP,
Expand All @@ -24,13 +23,12 @@ import {
paramsBlock,
} from '../src/index.js'

import * as testDataGenesis from './testdata/genesisHashesTest.json'
import * as testDataFromRPCGoerli from './testdata/testdata-from-rpc-goerli.json'
import * as testDataPreLondon2 from './testdata/testdata_pre-london-2.json'
import * as testDataPreLondon from './testdata/testdata_pre-london.json'
import * as testnetMerge from './testdata/testnetMerge.json'
import { genesisHashesTestData } from './testdata/genesisHashesTest.js'
import { testdataFromRPCGoerliData } from './testdata/testdata-from-rpc-goerli.js'
import { testdataPreLondon2Data } from './testdata/testdata_pre-london-2.js'
import { testdataPreLondonData } from './testdata/testdata_pre-london.js'
import { testnetMergeData } from './testdata/testnetMerge.js'

import type { ChainConfig } from '@ethereumjs/common'
import type { NestedUint8Array, PrefixedHexString } from '@ethereumjs/util'

describe('[Block]: block functions', () => {
Expand Down Expand Up @@ -100,7 +98,7 @@ describe('[Block]: block functions', () => {
})

it('initialization -> setHardfork option', () => {
const common = createCustomCommon(testnetMerge.default as ChainConfig, Mainnet)
const common = createCustomCommon(testnetMergeData, Mainnet)

let block = createBlock(
{
Expand Down Expand Up @@ -152,7 +150,7 @@ describe('[Block]: block functions', () => {

it('should test block validation on pow chain', async () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
const blockRlp = hexToBytes(testDataPreLondon.default.blocks[0].rlp as PrefixedHexString)
const blockRlp = hexToBytes(testdataPreLondonData.blocks[0].rlp as PrefixedHexString)
try {
createBlockFromRLP(blockRlp, { common })
assert.ok(true, 'should pass')
Expand All @@ -165,7 +163,7 @@ describe('[Block]: block functions', () => {
const common = new Common({ chain: Goerli, hardfork: Hardfork.Chainstart })

try {
createBlockFromRPC(testDataFromRPCGoerli.default as JSONRPCBlock, [], { common })
createBlockFromRPC(testdataFromRPCGoerliData, [], { common })
assert.ok(true, 'does not throw')
} catch (error: any) {
assert.fail('error thrown')
Expand All @@ -178,7 +176,7 @@ describe('[Block]: block functions', () => {
}

it('should test transaction validation - invalid tx trie', async () => {
const blockRlp = hexToBytes(testDataPreLondon.default.blocks[0].rlp as PrefixedHexString)
const blockRlp = hexToBytes(testdataPreLondonData.blocks[0].rlp as PrefixedHexString)
const common = new Common({ chain: Mainnet, hardfork: Hardfork.London })
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
await testTransactionValidation(block)
Expand Down Expand Up @@ -219,7 +217,7 @@ describe('[Block]: block functions', () => {

it('should test transaction validation with legacy tx in london', async () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.London })
const blockRlp = hexToBytes(testDataPreLondon.default.blocks[0].rlp as PrefixedHexString)
const blockRlp = hexToBytes(testdataPreLondonData.blocks[0].rlp as PrefixedHexString)
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
await testTransactionValidation(block)
;(block.transactions[0] as any).gasPrice = BigInt(0)
Expand All @@ -232,7 +230,7 @@ describe('[Block]: block functions', () => {

it('should test uncles hash validation', async () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
const blockRlp = hexToBytes(testDataPreLondon2.default.blocks[2].rlp as PrefixedHexString)
const blockRlp = hexToBytes(testdataPreLondon2Data.blocks[2].rlp as PrefixedHexString)
const block = createBlockFromRLP(blockRlp, { common, freeze: false })
assert.equal(block.uncleHashIsValid(), true)
;(block.header as any).uncleHash = new Uint8Array(32)
Expand Down Expand Up @@ -321,16 +319,16 @@ describe('[Block]: block functions', () => {

it('should test genesis hashes (mainnet default)', () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Chainstart })
const rlp = hexToBytes(`0x${testDataGenesis.default.test.genesis_rlp_hex}`)
const hash = hexToBytes(`0x${testDataGenesis.default.test.genesis_hash}`)
const rlp = hexToBytes(`0x${genesisHashesTestData.test.genesis_rlp_hex}`)
const hash = hexToBytes(`0x${genesisHashesTestData.test.genesis_hash}`)
const block = createBlockFromRLP(rlp, { common })
assert.ok(equalsBytes(block.hash(), hash), 'genesis hash match')
})

it('should test hash() method (mainnet default)', () => {
let common = new Common({ chain: Mainnet, hardfork: Hardfork.Chainstart })
const rlp = hexToBytes(`0x${testDataGenesis.default.test.genesis_rlp_hex}`)
const hash = hexToBytes(`0x${testDataGenesis.default.test.genesis_hash}`)
const rlp = hexToBytes(`0x${genesisHashesTestData.test.genesis_rlp_hex}`)
const hash = hexToBytes(`0x${genesisHashesTestData.test.genesis_hash}`)
let block = createBlockFromRLP(rlp, { common })
assert.ok(equalsBytes(block.hash(), hash), 'genesis hash match')

Expand Down Expand Up @@ -369,7 +367,7 @@ describe('[Block]: block functions', () => {
it('should return the same block data from raw()', () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
const block = createBlockFromRLP(
toBytes(testDataPreLondon2.default.blocks[2].rlp as PrefixedHexString),
toBytes(testdataPreLondon2Data.blocks[2].rlp as PrefixedHexString),
{
common,
},
Expand All @@ -381,7 +379,7 @@ describe('[Block]: block functions', () => {
it('should test toJSON', () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Istanbul })
const block = createBlockFromRLP(
toBytes(testDataPreLondon2.default.blocks[2].rlp as PrefixedHexString),
toBytes(testdataPreLondon2Data.blocks[2].rlp as PrefixedHexString),
{
common,
},
Expand All @@ -391,7 +389,7 @@ describe('[Block]: block functions', () => {

it('DAO hardfork', () => {
const blockData = RLP.decode(
testDataPreLondon2.default.blocks[0].rlp as PrefixedHexString,
testdataPreLondon2Data.blocks[0].rlp as PrefixedHexString,
) as NestedUint8Array
// Set block number from test block to mainnet DAO fork block 1920000
blockData[0][8] = hexToBytes('0x1D4C00')
Expand Down
6 changes: 3 additions & 3 deletions packages/block/test/eip1559block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createBlock, createBlockHeader } from '../src/index.js'
// Older version at https://github.com/abdelhamidbakhta/besu/blob/bf54b6c0b40d3015fc85ff9b078fbc26592d80c0/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/core/fees/basefee-test.json
import { paramsBlock } from '../src/params.js'

import * as eip1559BaseFee from './testdata/eip1559baseFee.json'
import { eip1559baseFeeData } from './testdata/eip1559baseFee.js'

const common = new Common({
eips: [1559],
Expand Down Expand Up @@ -450,8 +450,8 @@ describe('EIP1559 tests', () => {
})

it('Header -> calcNextBaseFee()', () => {
for (let index = 0; index < eip1559BaseFee.length; index++) {
const item = eip1559BaseFee[index]
for (let index = 0; index < eip1559baseFeeData.length; index++) {
const item = eip1559baseFeeData[index]
const result = createBlockHeader(
{
baseFeePerGas: BigInt(item.parentBaseFee),
Expand Down
9 changes: 5 additions & 4 deletions packages/block/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { fakeExponential, getNumBlobs } from '../src/helpers.js'
import { createBlock, createBlockHeader } from '../src/index.js'
import { paramsBlock } from '../src/params.js'

import gethGenesis from './testdata/4844-hardfork.json'
import { hardfork4844Data } from './testdata/4844-hardfork.js'

import type { TypedTransaction } from '@ethereumjs/tx'
import type { Kzg } from '@ethereumjs/util'
Expand All @@ -24,7 +24,7 @@ describe('EIP4844 header tests', () => {
beforeAll(async () => {
const kzg = await loadKZG()

common = createCommonFromGethGenesis(gethGenesis, {
common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
customCrypto: { kzg },
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('blob gas tests', () => {
let blobGasPerBlob: bigint
beforeAll(async () => {
const kzg = await loadKZG()
common = createCommonFromGethGenesis(gethGenesis, {
common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
params: paramsBlock,
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('transaction validation tests', () => {
let blobGasPerBlob: bigint
beforeAll(async () => {
kzg = await loadKZG()
common = createCommonFromGethGenesis(gethGenesis, {
common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
params: paramsBlock,
Expand Down Expand Up @@ -237,6 +237,7 @@ describe('transaction validation tests', () => {
)
const blockJSON = blockWithValidTx.toJSON()
blockJSON.header!.blobGasUsed = '0x0'
// @ts-expect-error
const blockWithInvalidHeader = createBlock(blockJSON, { common })
assert.throws(
() => blockWithInvalidHeader.validateBlobTransactions(parentHeader),
Expand Down
4 changes: 2 additions & 2 deletions packages/block/test/eip4895block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createBlock, createBlockFromRLP, createBlockHeader } from '../src/index
import type { WithdrawalBytes, WithdrawalData } from '@ethereumjs/util'

const gethWithdrawals8BlockRlp =
'f903e1f90213a0fe950635b1bd2a416ff6283b0bbd30176e1b1125ad06fa729da9f3f4c1c61710a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794aa00000000000000000000000000000000000000a07f7510a0cb6203f456e34ec3e2ce30d6c5590ded42c10a9cf3f24784119c5afba056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018401c9c380802f80a0ff0000000000000000000000000000000000000000000000000000000000000088000000000000000007a0b695b29ec7ee934ef6a68838b13729f2d49fffe26718de16a1a9ed94a4d7d06dc0c0f901c6da8082ffff94000000000000000000000000000000000000000080f83b0183010000940100000000000000000000000000000000000000a00100000000000000000000000000000000000000000000000000000000000000f83b0283010001940200000000000000000000000000000000000000a00200000000000000000000000000000000000000000000000000000000000000f83b0383010002940300000000000000000000000000000000000000a00300000000000000000000000000000000000000000000000000000000000000f83b0483010003940400000000000000000000000000000000000000a00400000000000000000000000000000000000000000000000000000000000000f83b0583010004940500000000000000000000000000000000000000a00500000000000000000000000000000000000000000000000000000000000000f83b0683010005940600000000000000000000000000000000000000a00600000000000000000000000000000000000000000000000000000000000000f83b0783010006940700000000000000000000000000000000000000a00700000000000000000000000000000000000000000000000000000000000000'
'0xf903e1f90213a0fe950635b1bd2a416ff6283b0bbd30176e1b1125ad06fa729da9f3f4c1c61710a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794aa00000000000000000000000000000000000000a07f7510a0cb6203f456e34ec3e2ce30d6c5590ded42c10a9cf3f24784119c5afba056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018401c9c380802f80a0ff0000000000000000000000000000000000000000000000000000000000000088000000000000000007a0b695b29ec7ee934ef6a68838b13729f2d49fffe26718de16a1a9ed94a4d7d06dc0c0f901c6da8082ffff94000000000000000000000000000000000000000080f83b0183010000940100000000000000000000000000000000000000a00100000000000000000000000000000000000000000000000000000000000000f83b0283010001940200000000000000000000000000000000000000a00200000000000000000000000000000000000000000000000000000000000000f83b0383010002940300000000000000000000000000000000000000a00300000000000000000000000000000000000000000000000000000000000000f83b0483010003940400000000000000000000000000000000000000a00400000000000000000000000000000000000000000000000000000000000000f83b0583010004940500000000000000000000000000000000000000a00500000000000000000000000000000000000000000000000000000000000000f83b0683010005940600000000000000000000000000000000000000a00600000000000000000000000000000000000000000000000000000000000000f83b0783010006940700000000000000000000000000000000000000a00700000000000000000000000000000000000000000000000000000000000000'

const common = new Common({
chain: Mainnet,
Expand All @@ -38,7 +38,7 @@ common.hardforkBlock = function (hardfork: string | undefined) {
describe('EIP4895 tests', () => {
it('should correctly generate withdrawalsRoot', async () => {
// get withdrawalsArray
const gethBlockBytesArray = RLP.decode(hexToBytes(`0x${gethWithdrawals8BlockRlp}`))
const gethBlockBytesArray = RLP.decode(hexToBytes(gethWithdrawals8BlockRlp))
const withdrawals = (gethBlockBytesArray[3] as WithdrawalBytes[]).map((wa) =>
createWithdrawalFromBytesArray(wa),
)
Expand Down
Loading
Loading