diff --git a/packages/block/examples/1559.ts b/packages/block/examples/1559.ts index ed836dec4f..6a21d52eb1 100644 --- a/packages/block/examples/1559.ts +++ b/packages/block/examples/1559.ts @@ -1,8 +1,8 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) -const block = createBlockFromBlockData( +const block = createBlock( { header: { baseFeePerGas: BigInt(10), @@ -19,7 +19,7 @@ console.log(Number(block.header.calcNextBaseFee())) // 11 // So for creating a block with a matching base fee in a certain // chain context you can do: -const blockWithMatchingBaseFee = createBlockFromBlockData( +const blockWithMatchingBaseFee = createBlock( { header: { baseFeePerGas: block.header.calcNextBaseFee(), diff --git a/packages/block/examples/4844.ts b/packages/block/examples/4844.ts index a88f701620..78534a0034 100644 --- a/packages/block/examples/4844.ts +++ b/packages/block/examples/4844.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { create4844BlobTx } from '@ethereumjs/tx' import { createAddressFromPrivateKey } from '@ethereumjs/util' @@ -20,7 +20,7 @@ const main = async () => { { common }, ) - const block = createBlockFromBlockData( + const block = createBlock( { header: { excessBlobGas: 0n, diff --git a/packages/block/examples/clique.ts b/packages/block/examples/clique.ts index 2caa565d64..f6e8f9b30f 100644 --- a/packages/block/examples/clique.ts +++ b/packages/block/examples/clique.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart }) @@ -6,5 +6,5 @@ const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart } console.log(common.consensusType()) // 'poa' console.log(common.consensusAlgorithm()) // 'clique' -createBlockFromBlockData({ header: { extraData: new Uint8Array(97) } }, { common }) +createBlock({ header: { extraData: new Uint8Array(97) } }, { common }) console.log(`Old Clique Proof-of-Authority block created`) diff --git a/packages/block/examples/pos.ts b/packages/block/examples/pos.ts index c05220b05c..e4d0c2ba1c 100644 --- a/packages/block/examples/pos.ts +++ b/packages/block/examples/pos.ts @@ -1,9 +1,9 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common } from '@ethereumjs/common' const common = new Common({ chain: Chain.Mainnet }) -const block = createBlockFromBlockData( +const block = createBlock( { // Provide your block data here or use default values }, diff --git a/packages/block/examples/pow.ts b/packages/block/examples/pow.ts index 8f2c1f4075..2ed9729f8f 100644 --- a/packages/block/examples/pow.ts +++ b/packages/block/examples/pow.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) @@ -6,5 +6,5 @@ const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart console.log(common.consensusType()) // 'pow' console.log(common.consensusAlgorithm()) // 'ethash' -createBlockFromBlockData({}, { common }) +createBlock({}, { common }) console.log(`Old Proof-of-Work block created`) diff --git a/packages/block/examples/withdrawals.ts b/packages/block/examples/withdrawals.ts index 5229db9dfa..7349737749 100644 --- a/packages/block/examples/withdrawals.ts +++ b/packages/block/examples/withdrawals.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common } from '@ethereumjs/common' import { Address, hexToBytes } from '@ethereumjs/util' @@ -13,7 +13,7 @@ const withdrawal = { amount: BigInt(1000), } -const block = createBlockFromBlockData( +const block = createBlock( { header: { withdrawalsRoot: hexToBytes( diff --git a/packages/block/src/block.ts b/packages/block/src/block.ts index 8d302cf687..25848fa589 100644 --- a/packages/block/src/block.ts +++ b/packages/block/src/block.ts @@ -23,7 +23,7 @@ import { genRequestsTrieRoot, genTransactionsTrieRoot, genWithdrawalsTrieRoot } import { BlockHeader, type createBlockFromBeaconPayloadJson, - type createBlockFromBlockData, + type createBlock, type createBlockFromExecutionPayload, type createBlockFromJsonRpcProvider, type createBlockFromRLPSerializedBlock, @@ -55,7 +55,7 @@ import type { * A block object can be created with one of the following constructor methods * (separate from the Block class to allow for tree shaking): * - * - {@link createBlockFromBlockData } + * - {@link createBlock } * - {@link createBlockFromValuesArray } * - {@link createBlockFromRLPSerializedBlock } * - {@link createBlockFromRPC } diff --git a/packages/block/src/constructors.ts b/packages/block/src/constructors.ts index 7a5f866009..0ebe25e67a 100644 --- a/packages/block/src/constructors.ts +++ b/packages/block/src/constructors.ts @@ -123,7 +123,7 @@ export function createHeaderFromRLP(serializedHeaderData: Uint8Array, opts: Bloc * @param blockData * @param opts */ -export function createBlockFromBlockData(blockData: BlockData = {}, opts?: BlockOptions) { +export function createBlock(blockData: BlockData = {}, opts?: BlockOptions) { const { header: headerData, transactions: txsData, @@ -475,7 +475,7 @@ export async function createBlockFromExecutionPayload( } // we are not setting setHardfork as common is already set to the correct hf - const block = createBlockFromBlockData( + const block = createBlock( { header, transactions: txs, withdrawals, executionWitness, requests }, opts, ) diff --git a/packages/block/src/from-rpc.ts b/packages/block/src/from-rpc.ts index 513e7b402c..ee162df098 100644 --- a/packages/block/src/from-rpc.ts +++ b/packages/block/src/from-rpc.ts @@ -8,7 +8,7 @@ import { toType, } from '@ethereumjs/util' -import { createBlockFromBlockData } from './constructors.js' +import { createBlock } from './constructors.js' import { blockHeaderFromRpc } from './header-from-rpc.js' import type { BlockOptions, JsonRpcBlock } from './index.js' @@ -64,7 +64,7 @@ export function createBlockFromRpc( const bytes = hexToBytes(req as PrefixedHexString) return CLRequestFactory.fromSerializedRequest(bytes) }) - return createBlockFromBlockData( + return createBlock( { header, transactions, uncleHeaders, withdrawals: blockParams.withdrawals, requests }, options, ) diff --git a/packages/block/test/block.spec.ts b/packages/block/test/block.spec.ts index 99e821125c..c96d28c558 100644 --- a/packages/block/test/block.spec.ts +++ b/packages/block/test/block.spec.ts @@ -12,7 +12,7 @@ import { import { assert, describe, it } from 'vitest' import { - createBlockFromBlockData, + createBlock, createBlockFromRLPSerializedBlock, createBlockFromValuesArray, } from '../src/constructors.js' @@ -32,12 +32,12 @@ import type { NestedUint8Array, PrefixedHexString } from '@ethereumjs/util' describe('[Block]: block functions', () => { it('should test block initialization', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const genesis = createBlockFromBlockData({}, { common }) + const genesis = createBlock({}, { common }) assert.ok(bytesToHex(genesis.hash()), 'block should initialize') const params = JSON.parse(JSON.stringify(paramsBlock)) params['1']['minGasLimit'] = 3000 // 5000 - let block = createBlockFromBlockData({}, { params }) + let block = createBlock({}, { params }) assert.equal( block.common.param('minGasLimit'), BigInt(3000), @@ -46,10 +46,10 @@ describe('[Block]: block functions', () => { // test default freeze values // also test if the options are carried over to the constructor - block = createBlockFromBlockData({}) + block = createBlock({}) assert.ok(Object.isFrozen(block), 'block should be frozen by default') - block = createBlockFromBlockData({}, { freeze: false }) + block = createBlock({}, { freeze: false }) assert.ok( !Object.isFrozen(block), 'block should not be frozen when freeze deactivated in options', @@ -100,7 +100,7 @@ describe('[Block]: block functions', () => { customChains: customChains as ChainConfig[], }) - let block = createBlockFromBlockData( + let block = createBlock( { header: { number: 12, // Berlin block @@ -111,7 +111,7 @@ describe('[Block]: block functions', () => { ) assert.equal(block.common.hardfork(), Hardfork.Berlin, 'should use setHardfork option') - block = createBlockFromBlockData( + block = createBlock( { header: { number: 20, // Future block @@ -125,7 +125,7 @@ describe('[Block]: block functions', () => { 'should use setHardfork option (td > threshold)', ) - block = createBlockFromBlockData( + block = createBlock( { header: { number: 12, // Berlin block, @@ -143,7 +143,7 @@ describe('[Block]: block functions', () => { it('should initialize with undefined parameters without throwing', () => { assert.doesNotThrow(function () { - createBlockFromBlockData() + createBlock() }) }) @@ -151,18 +151,15 @@ describe('[Block]: block functions', () => { const common = new Common({ chain: Chain.Goerli }) const opts = { common } assert.doesNotThrow(function () { - createBlockFromBlockData({}, opts) + createBlock({}, opts) }) }) it('should throw when trying to initialize with uncle headers on a PoA network', () => { const common = new Common({ chain: Chain.Mainnet }) - const uncleBlock = createBlockFromBlockData( - { header: { extraData: new Uint8Array(117) } }, - { common }, - ) + const uncleBlock = createBlock({ header: { extraData: new Uint8Array(117) } }, { common }) assert.throws(function () { - createBlockFromBlockData({ uncleHeaders: [uncleBlock.header] }, { common }) + createBlock({ uncleHeaders: [uncleBlock.header] }, { common }) }) }) @@ -212,9 +209,9 @@ describe('[Block]: block functions', () => { gasLimit: 53000, gasPrice: 7, }) - const blockTest = createBlockFromBlockData({ transactions: [tx] }) + const blockTest = createBlock({ transactions: [tx] }) const txTrie = await blockTest.genTxTrie() - const block = createBlockFromBlockData({ + const block = createBlock({ header: { transactionsTrie: txTrie, }, @@ -229,7 +226,7 @@ describe('[Block]: block functions', () => { }) it('should test transaction validation with empty transaction list', async () => { - const block = createBlockFromBlockData({}) + const block = createBlock({}) await testTransactionValidation(block) }) @@ -264,7 +261,7 @@ describe('[Block]: block functions', () => { const unsignedTx = createLegacyTx({}) const txRoot = await genTransactionsTrieRoot([unsignedTx]) - let block = createBlockFromBlockData({ + let block = createBlock({ transactions: [unsignedTx], header: { transactionsTrie: txRoot, @@ -286,7 +283,7 @@ describe('[Block]: block functions', () => { const zeroRoot = zeros(32) // Tx root - block = createBlockFromBlockData({ + block = createBlock({ transactions: [unsignedTx], header: { transactionsTrie: zeroRoot, @@ -295,7 +292,7 @@ describe('[Block]: block functions', () => { await checkThrowsAsync(block.validateData(false, false), 'invalid transaction trie') // Withdrawals root - block = createBlockFromBlockData( + block = createBlock( { header: { withdrawalsRoot: zeroRoot, @@ -307,7 +304,7 @@ describe('[Block]: block functions', () => { await checkThrowsAsync(block.validateData(false, false), 'invalid withdrawals trie') // Uncle root - block = createBlockFromBlockData( + block = createBlock( { header: { uncleHash: zeroRoot, @@ -321,7 +318,7 @@ describe('[Block]: block functions', () => { const common = new Common({ chain: Chain.Mainnet, eips: [6800], hardfork: Hardfork.Cancun }) // Note: `executionWitness: undefined` will still initialize an execution witness in the block // So, only testing for `null` here - block = createBlockFromBlockData({ executionWitness: null }, { common }) + block = createBlock({ executionWitness: null }, { common }) await checkThrowsAsync( block.validateData(false, false), 'Invalid block: ethereumjs stateless client needs executionWitness', @@ -329,9 +326,9 @@ describe('[Block]: block functions', () => { }) it('should test isGenesis (mainnet default)', () => { - const block = createBlockFromBlockData({ header: { number: 1 } }) + const block = createBlock({ header: { number: 1 } }) assert.notEqual(block.isGenesis(), true) - const genesisBlock = createBlockFromBlockData({ header: { number: 0 } }) + const genesisBlock = createBlock({ header: { number: 0 } }) assert.equal(genesisBlock.isGenesis(), true) }) @@ -432,7 +429,7 @@ describe('[Block]: block functions', () => { it('should set canonical difficulty if I provide a calcDifficultyFromHeader header', () => { let common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const genesis = createBlockFromBlockData({}, { common }) + const genesis = createBlock({}, { common }) const nextBlockHeaderData = { number: genesis.header.number + BigInt(1), @@ -440,7 +437,7 @@ describe('[Block]: block functions', () => { } common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const blockWithoutDifficultyCalculation = createBlockFromBlockData( + const blockWithoutDifficultyCalculation = createBlock( { header: nextBlockHeaderData, }, @@ -455,7 +452,7 @@ describe('[Block]: block functions', () => { ) // test if we set difficulty if we have a "difficulty header" in options; also verify this is equal to reported canonical difficulty. - const blockWithDifficultyCalculation = createBlockFromBlockData( + const blockWithDifficultyCalculation = createBlock( { header: nextBlockHeaderData, }, @@ -481,7 +478,7 @@ describe('[Block]: block functions', () => { timestamp: genesis.header.timestamp + BigInt(10), } - const block_farAhead = createBlockFromBlockData( + const block_farAhead = createBlock( { header: noParentHeaderData, }, @@ -499,7 +496,7 @@ describe('[Block]: block functions', () => { it('should be able to initialize shanghai blocks with correct hardfork defaults', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai }) - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) assert.equal(block.common.hardfork(), Hardfork.Shanghai, 'hardfork should be set to shanghai') assert.deepEqual(block.withdrawals, [], 'withdrawals should be set to default empty array') }) diff --git a/packages/block/test/difficulty.spec.ts b/packages/block/test/difficulty.spec.ts index 0fe8987844..37ff6701fe 100644 --- a/packages/block/test/difficulty.spec.ts +++ b/packages/block/test/difficulty.spec.ts @@ -11,7 +11,7 @@ import * as difficultyEIP2384_random_to20M from '../../ethereum-tests/Difficulty import * as difficultyFrontier from '../../ethereum-tests/DifficultyTests/dfFrontier/difficultyFrontier.json' import * as difficultyGrayGlacier from '../../ethereum-tests/DifficultyTests/dfGrayGlacier/difficultyGrayGlacier.json' import * as difficultyHomestead from '../../ethereum-tests/DifficultyTests/dfHomestead/difficultyHomestead.json' -import { createBlockFromBlockData } from '../src/constructors.js' +import { createBlock } from '../src/constructors.js' import type { Block } from '../src/index.js' @@ -57,7 +57,7 @@ describe('[Header]: difficulty tests', () => { }) const blockOpts = { common } const uncleHash = test.parentUncles === '0x00' ? undefined : test.parentUncles - const parentBlock = createBlockFromBlockData( + const parentBlock = createBlock( { header: { timestamp: test.parentTimestamp, @@ -68,7 +68,7 @@ describe('[Header]: difficulty tests', () => { blockOpts, ) - const block = createBlockFromBlockData( + const block = createBlock( { header: { timestamp: test.currentTimestamp, @@ -92,7 +92,7 @@ describe('[Header]: difficulty tests', () => { const common = new Common({ chain }) const blockOpts = { common, setHardfork: true } const uncleHash = test.parentUncles === '0x00' ? undefined : test.parentUncles - const parentBlock = createBlockFromBlockData( + const parentBlock = createBlock( { header: { timestamp: test.parentTimestamp, @@ -104,7 +104,7 @@ describe('[Header]: difficulty tests', () => { blockOpts, ) - const block = createBlockFromBlockData( + const block = createBlock( { header: { timestamp: test.currentTimestamp, diff --git a/packages/block/test/eip1559block.spec.ts b/packages/block/test/eip1559block.spec.ts index 4390f26fb2..d3e43e22c9 100644 --- a/packages/block/test/eip1559block.spec.ts +++ b/packages/block/test/eip1559block.spec.ts @@ -3,7 +3,7 @@ import { create1559FeeMarketTx } from '@ethereumjs/tx' import { hexToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' -import { createBlockFromBlockData, createHeader } from '../src/constructors.js' +import { createBlock, createHeader } from '../src/constructors.js' // Test data from Besu (retrieved via Discord) // 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' @@ -17,7 +17,7 @@ const common = new Common({ params: paramsBlock, }) -const genesis = createBlockFromBlockData({}) +const genesis = createBlock({}) // Small hack to hack in the activation block number // (Otherwise there would be need for a custom chain only for testing purposes) @@ -106,7 +106,7 @@ describe('EIP1559 tests', () => { }) it('Header -> _genericFormValidation -> success case', async () => { - createBlockFromBlockData( + createBlock( { header: { number: BigInt(1), @@ -147,7 +147,7 @@ describe('EIP1559 tests', () => { }) it('Header -> validate() -> success cases', async () => { - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: BigInt(1), @@ -162,7 +162,7 @@ describe('EIP1559 tests', () => { common, }, ) - createBlockFromBlockData( + createBlock( { header: { number: BigInt(2), @@ -223,7 +223,7 @@ describe('EIP1559 tests', () => { assert.ok(true, 'should not throw when elasticity is exactly matched') }) - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: BigInt(1), @@ -415,7 +415,7 @@ describe('EIP1559 tests', () => { }, { common }, ).sign(hexToBytes(`0x${'46'.repeat(32)}`)) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: BigInt(1), diff --git a/packages/block/test/eip4788block.spec.ts b/packages/block/test/eip4788block.spec.ts index b69b5c960c..b6d7d574d8 100644 --- a/packages/block/test/eip4788block.spec.ts +++ b/packages/block/test/eip4788block.spec.ts @@ -2,7 +2,7 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common' import { bytesToHex, zeros } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' -import { createBlockFromBlockData, createHeader } from '../src/constructors.js' +import { createBlock, createHeader } from '../src/constructors.js' describe('EIP4788 header tests', () => { it('should work', () => { @@ -54,7 +54,7 @@ describe('EIP4788 header tests', () => { ) }, 'correctly instantiates an EIP4788 block header') - const block = createBlockFromBlockData( + const block = createBlock( { header: createHeader({}, { common }), }, diff --git a/packages/block/test/eip4844block.spec.ts b/packages/block/test/eip4844block.spec.ts index 5742f9c274..72f6346ce9 100644 --- a/packages/block/test/eip4844block.spec.ts +++ b/packages/block/test/eip4844block.spec.ts @@ -9,7 +9,7 @@ import { import { loadKZG } from 'kzg-wasm' import { assert, beforeAll, describe, it } from 'vitest' -import { createBlockFromBlockData, createHeader } from '../src/constructors.js' +import { createBlock, createHeader } from '../src/constructors.js' import { fakeExponential, getNumBlobs } from '../src/helpers.js' import { paramsBlock } from '../src/params.js' @@ -87,7 +87,7 @@ describe('EIP4844 header tests', () => { ) }, 'correctly instantiates an EIP4844 block header') - const block = createBlockFromBlockData( + const block = createBlock( { header: createHeader({}, { common, skipConsensusFormatValidation: true }), }, @@ -215,7 +215,7 @@ describe('transaction validation tests', () => { }, { common, skipConsensusFormatValidation: true }, ) - const block = createBlockFromBlockData( + const block = createBlock( { header: blockHeader, transactions }, { common, skipConsensusFormatValidation: true }, ) @@ -234,7 +234,7 @@ describe('transaction validation tests', () => { ) const blockJson = blockWithValidTx.toJSON() blockJson.header!.blobGasUsed = '0x0' - const blockWithInvalidHeader = createBlockFromBlockData(blockJson, { common }) + const blockWithInvalidHeader = createBlock(blockJson, { common }) assert.throws( () => blockWithInvalidHeader.validateBlobTransactions(parentHeader), 'block blobGasUsed mismatch', diff --git a/packages/block/test/eip4895block.spec.ts b/packages/block/test/eip4895block.spec.ts index acbad96844..3750b4dfb8 100644 --- a/packages/block/test/eip4895block.spec.ts +++ b/packages/block/test/eip4895block.spec.ts @@ -11,7 +11,7 @@ import { import { assert, describe, it } from 'vitest' import { - createBlockFromBlockData, + createBlock, createBlockFromRLPSerializedBlock, createHeader, } from '../src/constructors.js' @@ -95,7 +95,7 @@ describe('EIP4895 tests', () => { const earlyCommon = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) assert.throws( () => { - createBlockFromBlockData( + createBlock( { withdrawals: [], }, @@ -109,7 +109,7 @@ describe('EIP4895 tests', () => { 'should throw when setting withdrawals with EIP4895 not being activated', ) assert.doesNotThrow(() => { - createBlockFromBlockData( + createBlock( {}, { common, @@ -117,7 +117,7 @@ describe('EIP4895 tests', () => { ) }, 'should not throw when withdrawals is undefined with EIP4895 being activated') assert.doesNotThrow(() => { - createBlockFromBlockData( + createBlock( { header: { withdrawalsRoot: zeros(32), @@ -129,7 +129,7 @@ describe('EIP4895 tests', () => { }, ) }) - const block = createBlockFromBlockData( + const block = createBlock( { header: { withdrawalsRoot: zeros(32), @@ -150,7 +150,7 @@ describe('EIP4895 tests', () => { }, { common }, ) - const validBlock = createBlockFromBlockData( + const validBlock = createBlock( { header: validHeader, withdrawals: [], @@ -168,7 +168,7 @@ describe('EIP4895 tests', () => { amount: BigInt(1000), } - const validBlockWithWithdrawal = createBlockFromBlockData( + const validBlockWithWithdrawal = createBlock( { header: { withdrawalsRoot: hexToBytes( @@ -193,7 +193,7 @@ describe('EIP4895 tests', () => { amount: BigInt(2000), } - const validBlockWithWithdrawal2 = createBlockFromBlockData( + const validBlockWithWithdrawal2 = createBlock( { header: { withdrawalsRoot: hexToBytes( @@ -218,7 +218,7 @@ describe('EIP4895 tests', () => { }, 'hashed block with withdrawals') }) it('should throw if no withdrawal array is provided', () => { - const blockWithWithdrawals = createBlockFromBlockData({}, { common }) + const blockWithWithdrawals = createBlock({}, { common }) const rlp = blockWithWithdrawals.serialize() const rlpDecoded = RLP.decode(rlp) as Uint8Array[] // remove withdrawals root @@ -237,7 +237,7 @@ describe('EIP4895 tests', () => { }) it('should return early when withdrawals root equals KECCAK256_RLP', async () => { - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) // Set invalid withdrawalsRoot in cache block['cache'].withdrawalsTrieRoot = randomBytes(32) assert.ok( diff --git a/packages/block/test/eip7685block.spec.ts b/packages/block/test/eip7685block.spec.ts index 0de42326c7..dd370c2286 100644 --- a/packages/block/test/eip7685block.spec.ts +++ b/packages/block/test/eip7685block.spec.ts @@ -9,7 +9,7 @@ import { import { assert, describe, expect, it } from 'vitest' import { - createBlockFromBlockData, + createBlock, createBlockFromRPC, createBlockFromValuesArray, createHeader, @@ -46,7 +46,7 @@ const common = new Common({ }) describe('7685 tests', () => { it('should instantiate block with defaults', () => { - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) assert.deepEqual(block.header.requestsRoot, KECCAK256_RLP) const block2 = new Block(undefined, undefined, undefined, undefined, { common }) assert.deepEqual(block.header.requestsRoot, KECCAK256_RLP) @@ -55,7 +55,7 @@ describe('7685 tests', () => { it('should instantiate a block with requests', async () => { const request = getRandomDepositRequest() const requestsRoot = await genRequestsTrieRoot([request]) - const block = createBlockFromBlockData( + const block = createBlock( { requests: [request], header: { requestsRoot }, @@ -67,7 +67,7 @@ describe('7685 tests', () => { }) it('RequestsRootIsValid should return false when requestsRoot is invalid', async () => { const request = getRandomDepositRequest() - const block = createBlockFromBlockData( + const block = createBlock( { requests: [request], header: { requestsRoot: randomBytes(32) }, @@ -86,7 +86,7 @@ describe('7685 tests', () => { // Construct block with requests in correct order - const block = createBlockFromBlockData( + const block = createBlock( { requests, header: { requestsRoot }, @@ -98,7 +98,7 @@ describe('7685 tests', () => { // Throws when requests are not ordered correctly await expect(async () => - createBlockFromBlockData( + createBlock( { requests: [request1, request3, request2], header: { requestsRoot }, diff --git a/packages/block/test/header.spec.ts b/packages/block/test/header.spec.ts index 0e750c9d25..7251933151 100644 --- a/packages/block/test/header.spec.ts +++ b/packages/block/test/header.spec.ts @@ -13,7 +13,7 @@ import { import { assert, describe, it } from 'vitest' import { - createBlockFromBlockData, + createBlock, createBlockFromRLPSerializedBlock, createHeader, createHeaderFromRLP, @@ -204,7 +204,7 @@ describe('[Block]: Header functions', () => { it('should validate extraData', async () => { // PoW let common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - let genesis = createBlockFromBlockData({}, { common }) + let genesis = createBlock({}, { common }) const number = 1 let parentHash = genesis.hash() @@ -248,7 +248,7 @@ describe('[Block]: Header functions', () => { // PoA common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart }) - genesis = createBlockFromBlockData({ header: { extraData: new Uint8Array(97) } }, { common }) + genesis = createBlock({ header: { extraData: new Uint8Array(97) } }, { common }) parentHash = genesis.hash() gasLimit = genesis.header.gasLimit diff --git a/packages/block/test/mergeBlock.spec.ts b/packages/block/test/mergeBlock.spec.ts index a56ec1d43a..9446addde0 100644 --- a/packages/block/test/mergeBlock.spec.ts +++ b/packages/block/test/mergeBlock.spec.ts @@ -10,7 +10,7 @@ import { import { assert, describe, it } from 'vitest' import { Block } from '../src/block.js' -import { createBlockFromBlockData, createHeader } from '../src/constructors.js' +import { createBlock, createHeader } from '../src/constructors.js' import type { BlockHeader } from '../src/header.js' @@ -115,7 +115,7 @@ describe('[Header]: Casper PoS / The Merge Functionality', () => { it('EIP-4399: prevRando should return mixHash value', () => { const mixHash = new Uint8Array(32).fill(3) - let block = createBlockFromBlockData({ header: { mixHash } }, { common }) + let block = createBlock({ header: { mixHash } }, { common }) assert.ok( equalsBytes(block.header.prevRandao, mixHash), 'prevRandao should return mixHash value', @@ -123,7 +123,7 @@ describe('[Header]: Casper PoS / The Merge Functionality', () => { const commonLondon = common.copy() commonLondon.setHardfork(Hardfork.London) - block = createBlockFromBlockData({ header: { mixHash } }, { common: commonLondon }) + block = createBlock({ header: { mixHash } }, { common: commonLondon }) try { block.header.prevRandao assert.fail('should have thrown') diff --git a/packages/block/test/util.ts b/packages/block/test/util.ts deleted file mode 100644 index c6d39e9847..0000000000 --- a/packages/block/test/util.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Chain, Common, Hardfork } from '@ethereumjs/common' -import { RLP } from '@ethereumjs/rlp' -import { BIGINT_0, BIGINT_1, utf8ToBytes } from '@ethereumjs/util' -import { keccak256 } from 'ethereum-cryptography/keccak' - -import { createBlockFromBlockData } from '../src/constructors.js' - -import type { Block, BlockHeader } from '../src/index.js' - -/** - * This helper function creates a valid block (except the PoW) with the ability to add uncles. Returns a Block. - * @param parentBlock - The Parent block to build upon - * @param extraData - Extra data graffiti in order to create equal blocks (like block number) but with different hashes - * @param uncles - Optional, an array of uncle headers. Automatically calculates the uncleHash. - */ -function createBlock( - parentBlock: Block, - extraData: string, - uncles?: BlockHeader[], - common?: Common, -): Block { - uncles = uncles ?? [] - common = common ?? new Common({ chain: Chain.Mainnet }) - - if (extraData.length > 32) { - throw new Error('extra data graffiti must be 32 bytes or less') - } - - const number = parentBlock.header.number + BIGINT_1 - const timestamp = parentBlock.header.timestamp + BIGINT_1 - - const uncleHash = keccak256(RLP.encode(uncles.map((uh) => uh.raw()))) - - const londonHfBlock = common.hardforkBlock(Hardfork.London) - const baseFeePerGas = - typeof londonHfBlock === 'bigint' && londonHfBlock !== BIGINT_0 && number > londonHfBlock - ? parentBlock.header.calcNextBaseFee() - : undefined - - return createBlockFromBlockData( - { - header: { - number, - parentHash: parentBlock.hash(), - timestamp, - gasLimit: parentBlock.header.gasLimit, - extraData: utf8ToBytes(extraData), - uncleHash, - baseFeePerGas, - }, - uncleHeaders: uncles, - }, - { - common, - calcDifficultyFromHeader: parentBlock.header, - }, - ) -} - -export { createBlock } diff --git a/packages/blockchain/examples/simple.ts b/packages/blockchain/examples/simple.ts index cd45156323..5bdbd4f4c6 100644 --- a/packages/blockchain/examples/simple.ts +++ b/packages/blockchain/examples/simple.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Common, Hardfork } from '@ethereumjs/common' import { bytesToHex } from '@ethereumjs/util' @@ -13,7 +13,7 @@ const main = async () => { }) // We use minimal data to provide a sequence of blocks (increasing number, difficulty, and then setting parent hash to previous block) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: 1n, @@ -23,7 +23,7 @@ const main = async () => { }, { common, setHardfork: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2n, diff --git a/packages/blockchain/src/blockchain.ts b/packages/blockchain/src/blockchain.ts index a9a45d740e..54bab9f588 100644 --- a/packages/blockchain/src/blockchain.ts +++ b/packages/blockchain/src/blockchain.ts @@ -1,4 +1,4 @@ -import { Block, BlockHeader, createBlockFromBlockData } from '@ethereumjs/block' +import { Block, BlockHeader, createBlock } from '@ethereumjs/block' import { Chain, Common, ConsensusAlgorithm, ConsensusType, Hardfork } from '@ethereumjs/common' import { AsyncEventEmitter, @@ -1282,7 +1282,7 @@ export class Blockchain implements BlockchainInterface { header.extraData = concatBytes(new Uint8Array(32), new Uint8Array(65)) } } - return createBlockFromBlockData( + return createBlock( { header, withdrawals: common.isActivatedEIP(4895) ? [] : undefined }, { common }, ) diff --git a/packages/blockchain/src/constructors.ts b/packages/blockchain/src/constructors.ts index 8be3ba2426..dce7e3f485 100644 --- a/packages/blockchain/src/constructors.ts +++ b/packages/blockchain/src/constructors.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { BIGINT_0, equalsBytes } from '@ethereumjs/util' import { @@ -91,7 +91,7 @@ export async function createBlockchain(opts: BlockchainOptions = {}) { /** * Creates a blockchain from a list of block objects, - * objects must be readable by {@link createBlockFromBlockData} + * objects must be readable by {@link createBlock} * * @param blockData List of block objects * @param opts Constructor options, see {@link BlockchainOptions} @@ -102,7 +102,7 @@ export async function createBlockchainFromBlocksData( ) { const blockchain = await createBlockchain(opts) for (const blockData of blocksData) { - const block = createBlockFromBlockData(blockData, { + const block = createBlock(blockData, { common: blockchain.common, setHardfork: true, }) diff --git a/packages/blockchain/test/blockValidation.spec.ts b/packages/blockchain/test/blockValidation.spec.ts index bbe06fe26e..9c24c497a2 100644 --- a/packages/blockchain/test/blockValidation.spec.ts +++ b/packages/blockchain/test/blockValidation.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { Chain, Common, ConsensusAlgorithm, Hardfork } from '@ethereumjs/common' import { Ethash } from '@ethereumjs/ethash' import { RLP } from '@ethereumjs/rlp' @@ -8,7 +8,7 @@ import { assert, describe, expect, it } from 'vitest' import { EthashConsensus, createBlockchain } from '../src/index.js' -import { createBlock } from './util.js' +import { generateBlock } from './util.js' import type { ConsensusDict } from '../src/index.js' @@ -19,11 +19,11 @@ describe('[Blockchain]: Block validation tests', () => { const genesis = blockchain.genesisBlock - const uncleBlock = createBlock(genesis, 'uncle', [], common) + const uncleBlock = generateBlock(genesis, 'uncle', [], common) - const block1 = createBlock(genesis, 'block1', [], common) - const block2 = createBlock(block1, 'block2', [uncleBlock.header], common) - const block3 = createBlock(block2, 'block3', [uncleBlock.header], common) + const block1 = generateBlock(genesis, 'block1', [], common) + const block2 = generateBlock(block1, 'block2', [uncleBlock.header], common) + const block3 = generateBlock(block2, 'block3', [uncleBlock.header], common) await blockchain.putBlock(uncleBlock) await blockchain.putBlock(block1) @@ -46,12 +46,12 @@ describe('[Blockchain]: Block validation tests', () => { const genesis = blockchain.genesisBlock - const emptyBlock = createBlockFromBlockData({ header: { number: BigInt(1) } }, { common }) + const emptyBlock = createBlock({ header: { number: BigInt(1) } }, { common }) - const uncleBlock = createBlock(emptyBlock, 'uncle', [], common) - const block1 = createBlock(genesis, 'block1', [], common) - const block2 = createBlock(block1, 'block2', [], common) - const block3 = createBlock(block2, 'block3', [uncleBlock.header], common) + const uncleBlock = generateBlock(emptyBlock, 'uncle', [], common) + const block1 = generateBlock(genesis, 'block1', [], common) + const block2 = generateBlock(block1, 'block2', [], common) + const block3 = generateBlock(block2, 'block3', [uncleBlock.header], common) await blockchain.putBlock(block1) await blockchain.putBlock(block2) @@ -73,16 +73,16 @@ describe('[Blockchain]: Block validation tests', () => { const genesis = blockchain.genesisBlock - const uncleBlock = createBlock(genesis, 'uncle', [], common) + const uncleBlock = generateBlock(genesis, 'uncle', [], common) let lastBlock = genesis for (let i = 0; i < 7; i++) { - const block = createBlock(lastBlock, 'block' + i.toString(), [], common) + const block = generateBlock(lastBlock, 'block' + i.toString(), [], common) await blockchain.putBlock(block) lastBlock = block } - const blockWithUnclesTooOld = createBlock( + const blockWithUnclesTooOld = generateBlock( lastBlock, 'too-old-uncle', [uncleBlock.header], @@ -106,8 +106,8 @@ describe('[Blockchain]: Block validation tests', () => { const genesis = blockchain.genesisBlock - const uncleBlock = createBlock(genesis, 'uncle', [], common) - const block1 = createBlock(genesis, 'block1', [uncleBlock.header], common) + const uncleBlock = generateBlock(genesis, 'uncle', [], common) + const block1 = generateBlock(genesis, 'block1', [uncleBlock.header], common) await blockchain.putBlock(uncleBlock) @@ -130,7 +130,7 @@ describe('[Blockchain]: Block validation tests', () => { const genesis = blockchain.genesisBlock - const uncleBlock = createBlockFromBlockData( + const uncleBlock = createBlock( { header: { number: genesis.header.number + BigInt(1), @@ -142,8 +142,8 @@ describe('[Blockchain]: Block validation tests', () => { { common }, ) - const block1 = createBlock(genesis, 'block1', [], common) - const block2 = createBlock(block1, 'block2', [uncleBlock.header], common) + const block1 = generateBlock(genesis, 'block1', [], common) + const block2 = generateBlock(block1, 'block2', [uncleBlock.header], common) await blockchain.putBlock(block1) @@ -164,8 +164,8 @@ describe('[Blockchain]: Block validation tests', () => { const genesis = blockchain.genesisBlock - const block1 = createBlock(genesis, 'block1', [], common) - const block2 = createBlock(block1, 'block2', [block1.header], common) + const block1 = generateBlock(genesis, 'block1', [], common) + const block2 = generateBlock(block1, 'block2', [block1.header], common) await blockchain.putBlock(block1) @@ -187,11 +187,11 @@ describe('[Blockchain]: Block validation tests', () => { const genesis = blockchain.genesisBlock - const uncleBlock = createBlock(genesis, 'uncle', [], common) + const uncleBlock = generateBlock(genesis, 'uncle', [], common) await blockchain.putBlock(uncleBlock) - const block1 = createBlock(genesis, 'block1', [], common) - const block2 = createBlock(block1, 'block2', [uncleBlock.header], common) + const block1 = generateBlock(genesis, 'block1', [], common) + const block2 = generateBlock(block1, 'block2', [uncleBlock.header], common) await blockchain.putBlock(block1) await blockchain.putBlock(block2) @@ -239,7 +239,7 @@ describe('[Blockchain]: Block validation tests', () => { }, ) - const block = createBlockFromBlockData({ header }, { common }) + const block = createBlock({ header }, { common }) await blockchain.putBlock(block) try { const header = createHeader( @@ -255,7 +255,7 @@ describe('[Blockchain]: Block validation tests', () => { common, }, ) - const block2 = createBlockFromBlockData({ header }, { common }) + const block2 = createBlock({ header }, { common }) await blockchain.putBlock(block2) } catch (e: any) { const expectedError = 'Invalid block: base fee not correct' @@ -311,7 +311,7 @@ describe('[Blockchain]: Block validation tests', () => { common.setHardfork(Hardfork.Berlin) const mainnetForkBlock = common.hardforkBlock(Hardfork.London) - const rootBlock = createBlockFromBlockData( + const rootBlock = createBlock( { header: { parentHash: blockchain.genesisBlock.hash(), @@ -323,10 +323,15 @@ describe('[Blockchain]: Block validation tests', () => { ) await blockchain.putBlock(rootBlock) - const unclePreFork = createBlock(rootBlock, 'unclePreFork', [], common) - const canonicalBlock = createBlock(rootBlock, 'canonicalBlock', [], common) + const unclePreFork = generateBlock(rootBlock, 'unclePreFork', [], common) + const canonicalBlock = generateBlock(rootBlock, 'canonicalBlock', [], common) await blockchain.putBlock(canonicalBlock) - const preForkBlock = createBlock(canonicalBlock, 'preForkBlock', [unclePreFork.header], common) + const preForkBlock = generateBlock( + canonicalBlock, + 'preForkBlock', + [unclePreFork.header], + common, + ) await blockchain.putBlock(preForkBlock) assert.deepEqual( @@ -335,7 +340,7 @@ describe('[Blockchain]: Block validation tests', () => { 'able to put pre-london block in chain with pre-london uncles', ) common.setHardfork(Hardfork.London) - const forkBlock = createBlock(preForkBlock, 'forkBlock', [], common) + const forkBlock = generateBlock(preForkBlock, 'forkBlock', [], common) await blockchain.putBlock(forkBlock) assert.equal(common.hardfork(), Hardfork.London, 'validation did not change common hardfork') @@ -349,7 +354,7 @@ describe('[Blockchain]: Block validation tests', () => { forkBlockHeaderData.uncleHash = bytesToHex(keccak256(RLP.encode([uncleHeader.raw()]))) - const forkBlock_ValidCommon = createBlockFromBlockData( + const forkBlock_ValidCommon = createBlock( { header: forkBlockHeaderData, uncleHeaders: [uncleHeaderData], @@ -369,7 +374,7 @@ describe('[Blockchain]: Block validation tests', () => { assert.doesNotThrow( () => - createBlockFromBlockData( + createBlock( { header: forkBlockHeaderData, uncleHeaders: [uncleHeaderData], @@ -394,7 +399,7 @@ describe('EIP 7685: requests field validation tests', () => { const blockchain = await createBlockchain({ common, }) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: 1n, @@ -410,7 +415,7 @@ describe('EIP 7685: requests field validation tests', () => { await expect(async () => blockchain.putBlock(block)).rejects.toThrow('invalid requestsRoot') - const blockWithRequest = createBlockFromBlockData( + const blockWithRequest = createBlock( { header: { number: 1n, diff --git a/packages/blockchain/test/clique.spec.ts b/packages/blockchain/test/clique.spec.ts index 1159b17889..f02d185c96 100644 --- a/packages/blockchain/test/clique.spec.ts +++ b/packages/blockchain/test/clique.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, @@ -90,10 +90,7 @@ const initWithSigners = async (signers: Signer[], common?: Common) => { ...signers.map((s) => s.address.toBytes()), new Uint8Array(65), ) - const genesisBlock = createBlockFromBlockData( - { header: { gasLimit: GAS_LIMIT, extraData } }, - { common }, - ) + const genesisBlock = createBlock({ header: { gasLimit: GAS_LIMIT, extraData } }, { common }) blocks.push(genesisBlock) const consensusDict: ConsensusDict = {} @@ -158,7 +155,7 @@ function getBlock( // set signer const cliqueSigner = signer.privateKey - return createBlockFromBlockData(blockData, { common, freeze: false, cliqueSigner }) + return createBlock(blockData, { common, freeze: false, cliqueSigner }) } const addNextBlockReorg = async ( @@ -227,7 +224,7 @@ describe('Clique: Initialization', () => { unauthorizedSigner.toBytes(), new Uint8Array(65), ) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number, extraData } }, { common: COMMON, cliqueSigner: A.privateKey }, ) @@ -249,7 +246,7 @@ describe('Clique: Initialization', () => { const number = BigInt(2) const extraData = new Uint8Array(97) let difficulty = BigInt(5) - let block = createBlockFromBlockData( + let block = createBlock( { header: { number, @@ -274,7 +271,7 @@ describe('Clique: Initialization', () => { difficulty = BigInt(1) const cliqueSigner = A.privateKey - block = createBlockFromBlockData( + block = createBlock( { header: { number, diff --git a/packages/blockchain/test/customConsensus.spec.ts b/packages/blockchain/test/customConsensus.spec.ts index 8775375827..5865eb33eb 100644 --- a/packages/blockchain/test/customConsensus.spec.ts +++ b/packages/blockchain/test/customConsensus.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Common, Hardfork } from '@ethereumjs/common' import { bytesToHex } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -67,7 +67,7 @@ describe('Custom consensus validation rules', () => { it('should validat custom consensus rules', async () => { const common = new Common({ chain: testnet, hardfork: Hardfork.Chainstart }) const blockchain = await createBlockchain({ common, validateConsensus: true, consensusDict }) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: 1n, @@ -92,7 +92,7 @@ describe('Custom consensus validation rules', () => { assert.fail('should have put block with valid difficulty and extraData') } - const blockWithBadDifficulty = createBlockFromBlockData( + const blockWithBadDifficulty = createBlock( { header: { number: 2n, @@ -114,7 +114,7 @@ describe('Custom consensus validation rules', () => { ) } - const blockWithBadExtraData = createBlockFromBlockData( + const blockWithBadExtraData = createBlock( { header: { number: 2n, diff --git a/packages/blockchain/test/index.spec.ts b/packages/blockchain/test/index.spec.ts index 17a8e15c8d..f4a35eab20 100644 --- a/packages/blockchain/test/index.spec.ts +++ b/packages/blockchain/test/index.spec.ts @@ -1,5 +1,5 @@ import { - createBlockFromBlockData, + createBlock, createBlockFromRLPSerializedBlock, createHeader, createHeaderFromValuesArray, @@ -85,7 +85,7 @@ describe('blockchain test', () => { it('should add a genesis block without errors', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const genesisBlock = createBlockFromBlockData({ header: { number: 0 } }, { common }) + const genesisBlock = createBlock({ header: { number: 0 } }, { common }) const blockchain = await createBlockchain({ common, validateBlocks: true, @@ -100,7 +100,7 @@ describe('blockchain test', () => { }) it('should not validate a block incorrectly flagged as genesis', async () => { - const genesisBlock = createBlockFromBlockData({ header: { number: BigInt(8) } }) + const genesisBlock = createBlock({ header: { number: BigInt(8) } }) try { await createBlockchain({ validateBlocks: true, @@ -126,7 +126,7 @@ describe('blockchain test', () => { const gasLimit = 8000000 const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisBlock = createBlockFromBlockData({ header: { gasLimit } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit } }, { common }) blocks.push(genesisBlock) const blockchain = await createBlockchain({ @@ -147,7 +147,7 @@ describe('blockchain test', () => { gasLimit, }, } - const block = createBlockFromBlockData(blockData, { + const block = createBlock(blockData, { calcDifficultyFromHeader: lastBlock.header, common, }) @@ -171,7 +171,7 @@ describe('blockchain test', () => { const gasLimit = 8000000 const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisBlock = createBlockFromBlockData({ header: { gasLimit } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit } }, { common }) blocks.push(genesisBlock) const blockchain = await createBlockchain({ @@ -189,7 +189,7 @@ describe('blockchain test', () => { gasLimit, }, } - const block = createBlockFromBlockData(blockData, { + const block = createBlock(blockData, { calcDifficultyFromHeader: genesisBlock.header, common, }) @@ -207,7 +207,7 @@ describe('blockchain test', () => { it('getBlock(): should get block by hash / not existing', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) const gasLimit = 8000000 - const genesisBlock = createBlockFromBlockData({ header: { gasLimit } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit } }, { common }) const blockchain = await createBlockchain({ common, @@ -550,7 +550,7 @@ describe('blockchain test', () => { it('should put multiple blocks at once', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) const blocks: Block[] = [] - const genesisBlock = createBlockFromBlockData({ header: { gasLimit: 8000000 } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit: 8000000 } }, { common }) blocks.push(...generateBlocks(15, [genesisBlock])) const blockchain = await createBlockchain({ validateBlocks: true, @@ -561,14 +561,14 @@ describe('blockchain test', () => { }) it('should validate', async () => { - const genesisBlock = createBlockFromBlockData({ header: { gasLimit: 8000000 } }) + const genesisBlock = createBlock({ header: { gasLimit: 8000000 } }) const blockchain = await createBlockchain({ validateBlocks: true, validateConsensus: false, genesisBlock, }) - const invalidBlock = createBlockFromBlockData({ header: { number: 50 } }) + const invalidBlock = createBlock({ header: { number: 50 } }) try { await blockchain.putBlock(invalidBlock) assert.fail('should not validate an invalid block') @@ -615,7 +615,7 @@ describe('blockchain test', () => { const gasLimit = 8000000 const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisBlock = createBlockFromBlockData({ header: { gasLimit } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit } }, { common }) let blockchain = await createBlockchain({ db, validateBlocks: true, @@ -654,7 +654,7 @@ describe('blockchain test', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) const opts: BlockOptions = { common } - const genesisBlock = createBlockFromBlockData({ header: { gasLimit } }, opts) + const genesisBlock = createBlock({ header: { gasLimit } }, opts) const blockchain = await createBlockchain({ validateBlocks: true, validateConsensus: false, @@ -670,7 +670,7 @@ describe('blockchain test', () => { }, } opts.calcDifficultyFromHeader = genesisBlock.header - const block = createBlockFromBlockData(blockData, opts) + const block = createBlock(blockData, opts) const headerData1 = { number: 1, @@ -713,7 +713,7 @@ describe('blockchain test', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) const gasLimit = 8000000 - const genesisBlock = createBlockFromBlockData({ header: { gasLimit } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit } }, { common }) const blockData1 = { header: { @@ -731,11 +731,11 @@ describe('blockchain test', () => { const blocks = [ genesisBlock, - createBlockFromBlockData(blockData1, { + createBlock(blockData1, { common, calcDifficultyFromHeader: genesisBlock.header, }), - createBlockFromBlockData(blockData2, { + createBlock(blockData2, { common: new Common({ chain: Chain.Sepolia, hardfork: Hardfork.Chainstart }), calcDifficultyFromHeader: genesisBlock.header, }), @@ -792,7 +792,7 @@ describe('initialization tests', () => { it('should allow to put a custom genesis block', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const genesisBlock = createBlockFromBlockData( + const genesisBlock = createBlock( { header: { extraData: utf8ToBytes('custom extra data'), @@ -820,7 +820,7 @@ describe('initialization tests', () => { it('should not allow to change the genesis block in the database', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const genesisBlock = createBlockFromBlockData( + const genesisBlock = createBlock( { header: { extraData: utf8ToBytes('custom extra data'), @@ -832,7 +832,7 @@ describe('initialization tests', () => { const blockchain = await createBlockchain({ common, genesisBlock }) const db = blockchain.db - const otherGenesisBlock = createBlockFromBlockData( + const otherGenesisBlock = createBlock( { header: { extraData: utf8ToBytes('other extra data'), diff --git a/packages/blockchain/test/pos.spec.ts b/packages/blockchain/test/pos.spec.ts index 37c69f67a4..4cf0a6abea 100644 --- a/packages/blockchain/test/pos.spec.ts +++ b/packages/blockchain/test/pos.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { bytesToHex } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -22,7 +22,7 @@ const buildChain = async (blockchain: Blockchain, common: Common, height: number } else if (number > londonBlockNumber) { baseFeePerGas = blocks[number - 1].header.calcNextBaseFee() } - const block = createBlockFromBlockData( + const block = createBlock( { header: { number, @@ -90,7 +90,7 @@ describe('Proof of Stake - inserting blocks into blockchain', () => { ) const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) - const powBlock = createBlockFromBlockData( + const powBlock = createBlock( { header: { number: 16, diff --git a/packages/blockchain/test/reorg.spec.ts b/packages/blockchain/test/reorg.spec.ts index b060838d3d..f92d8a7260 100644 --- a/packages/blockchain/test/reorg.spec.ts +++ b/packages/blockchain/test/reorg.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, ConsensusAlgorithm, Hardfork } from '@ethereumjs/common' import { Address, equalsBytes, hexToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -14,7 +14,7 @@ import type { Block } from '@ethereumjs/block' describe('reorg tests', () => { it('should correctly reorg the chain if the total difficulty is higher on a lower block number than the current head block', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.MuirGlacier }) - const genesis = createBlockFromBlockData( + const genesis = createBlock( { header: { number: BigInt(0), @@ -67,10 +67,7 @@ describe('reorg tests', () => { it('should correctly reorg a poa chain and remove blocks from clique snapshots', async () => { const common = new Common({ chain: Chain.Goerli, hardfork: Hardfork.Chainstart }) - const genesisBlock = createBlockFromBlockData( - { header: { extraData: new Uint8Array(97) } }, - { common }, - ) + const genesisBlock = createBlock({ header: { extraData: new Uint8Array(97) } }, { common }) const consensusDict: ConsensusDict = {} consensusDict[ConsensusAlgorithm.Clique] = new CliqueConsensus() @@ -92,7 +89,7 @@ describe('reorg tests', () => { const beneficiary1 = new Address(new Uint8Array(20).fill(1)) const beneficiary2 = new Address(new Uint8Array(20).fill(2)) - const block1_low = createBlockFromBlockData( + const block1_low = createBlock( { header: { ...base, @@ -103,7 +100,7 @@ describe('reorg tests', () => { }, { common }, ) - const block2_low = createBlockFromBlockData( + const block2_low = createBlock( { header: { ...base, @@ -117,7 +114,7 @@ describe('reorg tests', () => { { common }, ) - const block1_high = createBlockFromBlockData( + const block1_high = createBlock( { header: { ...base, @@ -128,7 +125,7 @@ describe('reorg tests', () => { }, { common }, ) - const block2_high = createBlockFromBlockData( + const block2_high = createBlock( { header: { ...base, @@ -139,7 +136,7 @@ describe('reorg tests', () => { }, { common }, ) - const block3_high = createBlockFromBlockData( + const block3_high = createBlock( { header: { ...base, diff --git a/packages/blockchain/test/util.ts b/packages/blockchain/test/util.ts index 893d9d487f..7c5407e944 100644 --- a/packages/blockchain/test/util.ts +++ b/packages/blockchain/test/util.ts @@ -1,4 +1,4 @@ -import { Block, createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { Block, createBlock, createHeader } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' import { @@ -24,7 +24,7 @@ export const generateBlocks = (numberOfBlocks: number, existingBlocks?: Block[]) const opts = { common } if (blocks.length === 0) { - const genesis = createBlockFromBlockData({ header: { gasLimit } }, opts) + const genesis = createBlock({ header: { gasLimit } }, opts) blocks.push(genesis) } @@ -38,7 +38,7 @@ export const generateBlocks = (numberOfBlocks: number, existingBlocks?: Block[]) timestamp: lastBlock.header.timestamp + BigInt(1), }, } - const block = createBlockFromBlockData(blockData, { + const block = createBlock(blockData, { common, calcDifficultyFromHeader: lastBlock.header, }) @@ -124,7 +124,7 @@ export const createTestDB = async (): Promise< [DB, Block] > => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Chainstart }) - const genesis = createBlockFromBlockData({ header: { number: 0 } }, { common }) + const genesis = createBlock({ header: { number: 0 } }, { common }) const db = new MapDB() await db.batch([ @@ -184,7 +184,7 @@ export const createTestDB = async (): Promise< * @param extraData - Extra data graffiti in order to create equal blocks (like block number) but with different hashes * @param uncles - Optional, an array of uncle headers. Automatically calculates the uncleHash. */ -function createBlock( +function generateBlock( parentBlock: Block, extraData: string, uncles?: BlockHeader[], @@ -208,7 +208,7 @@ function createBlock( ? parentBlock.header.calcNextBaseFee() : undefined - return createBlockFromBlockData( + return createBlock( { header: { number, @@ -228,4 +228,4 @@ function createBlock( ) } -export { createBlock } +export { generateBlock } diff --git a/packages/client/src/rpc/modules/eth.ts b/packages/client/src/rpc/modules/eth.ts index 86d303501c..5378dbfd48 100644 --- a/packages/client/src/rpc/modules/eth.ts +++ b/packages/client/src/rpc/modules/eth.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Hardfork } from '@ethereumjs/common' import { Capability, @@ -593,7 +593,7 @@ export class Eth { gasLimit: transaction.gas, } - const blockToRunOn = createBlockFromBlockData( + const blockToRunOn = createBlock( { header: { parentHash: block.hash(), diff --git a/packages/client/test/blockchain/chain.spec.ts b/packages/client/test/blockchain/chain.spec.ts index f684122bad..5297024af2 100644 --- a/packages/client/test/blockchain/chain.spec.ts +++ b/packages/client/test/blockchain/chain.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { KeyEncoding, ValueEncoding, bytesToHex, equalsBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -59,7 +59,7 @@ describe('[Chain]', () => { difficulty: BigInt(0xabcdffff), parentHash: chain.genesis.hash(), } - const block = createBlockFromBlockData({ header: headerData } as BlockData, { + const block = createBlock({ header: headerData } as BlockData, { common: config.chainCommon, }) @@ -133,7 +133,7 @@ describe('[Chain]', () => { difficulty: BigInt(0xabcdffff), parentHash: chain.genesis.hash(), } - const block = createBlockFromBlockData({ header: headerData } as BlockData, { + const block = createBlock({ header: headerData } as BlockData, { common: config.chainCommon, }) await chain.putBlocks([block]) diff --git a/packages/client/test/integration/fullethereumservice.spec.ts b/packages/client/test/integration/fullethereumservice.spec.ts index c1ff4edc12..5e372207d7 100644 --- a/packages/client/test/integration/fullethereumservice.spec.ts +++ b/packages/client/test/integration/fullethereumservice.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' @@ -81,7 +81,7 @@ describe( }) peer.eth!.send('NewBlockHashes', [[hash, BigInt(2)]]) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: 1, diff --git a/packages/client/test/integration/mocks/mockchain.ts b/packages/client/test/integration/mocks/mockchain.ts index 7a1c12bea8..e05af7c5c9 100644 --- a/packages/client/test/integration/mocks/mockchain.ts +++ b/packages/client/test/integration/mocks/mockchain.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Hardfork } from '@ethereumjs/common' import { Chain } from '../../../src/blockchain/index.js' @@ -30,7 +30,7 @@ export class MockChain extends Chain { const common = this.config.chainCommon const blocks: Block[] = [] for (let number = 0; number < this.height; number++) { - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: number + 1, diff --git a/packages/client/test/miner/miner.spec.ts b/packages/client/test/miner/miner.spec.ts index f13db4b436..ba0febeba3 100644 --- a/packages/client/test/miner/miner.spec.ts +++ b/packages/client/test/miner/miner.spec.ts @@ -1,4 +1,4 @@ -import { BlockHeader, createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { BlockHeader, createBlock, createHeader } from '@ethereumjs/block' import { Common, Chain as CommonChain, @@ -59,7 +59,7 @@ class FakeChain { } get blocks() { return { - latest: createBlockFromBlockData(), + latest: createBlock(), height: BigInt(0), } } @@ -79,7 +79,7 @@ class FakeChain { }, validateHeader: () => {}, getIteratorHead: () => { - return createBlockFromBlockData({ header: { number: 1 } }) + return createBlock({ header: { number: 1 } }) }, getTotalDifficulty: () => { return 1n @@ -430,7 +430,7 @@ describe('assembleBlocks() -> should not include tx under the baseFee', async () common, }) const chain = new FakeChain() as any - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) Object.defineProperty(chain, 'headers', { get() { return { latest: block.header, height: block.header.number } @@ -478,10 +478,7 @@ describe('assembleBlocks() -> should not include tx under the baseFee', async () describe("assembleBlocks() -> should stop assembling a block after it's full", async () => { const chain = new FakeChain() as any const gasLimit = 100000 - const block = createBlockFromBlockData( - { header: { gasLimit } }, - { common: customCommon, setHardfork: true }, - ) + const block = createBlock({ header: { gasLimit } }, { common: customCommon, setHardfork: true }) Object.defineProperty(chain, 'headers', { get() { return { latest: block.header, height: BigInt(0) } diff --git a/packages/client/test/net/protocol/ethprotocol.spec.ts b/packages/client/test/net/protocol/ethprotocol.spec.ts index 20fdc24c23..76b4b821e2 100644 --- a/packages/client/test/net/protocol/ethprotocol.spec.ts +++ b/packages/client/test/net/protocol/ethprotocol.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Common, Chain as CommonChain, Hardfork } from '@ethereumjs/common' import { TransactionType, create1559FeeMarketTx, createTxFromTxData } from '@ethereumjs/tx' import { @@ -87,7 +87,7 @@ describe('[EthProtocol]', () => { const chain = await Chain.create({ config }) const p = new EthProtocol({ config, chain }) const td = BigInt(100) - const block = createBlockFromBlockData({}, { common: config.chainCommon }) + const block = createBlock({}, { common: config.chainCommon }) const res = p.decode(p.messages.filter((message) => message.name === 'NewBlock')[0], [ block.raw(), bigIntToBytes(td), @@ -104,7 +104,7 @@ describe('[EthProtocol]', () => { const config = new Config({ accountCache: 10000, storageCache: 1000 }) const chain = await Chain.create({ config }) const p = new EthProtocol({ config, chain }) - const block = createBlockFromBlockData({}) + const block = createBlock({}) const res = p.decode(p.messages.filter((message) => message.name === 'GetReceipts')[0], [ bigIntToBytes(1n), [block.hash()], diff --git a/packages/client/test/rpc/debug/getRawBlock.spec.ts b/packages/client/test/rpc/debug/getRawBlock.spec.ts index b2a0fe7e50..224b812f29 100644 --- a/packages/client/test/rpc/debug/getRawBlock.spec.ts +++ b/packages/client/test/rpc/debug/getRawBlock.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { createCustomCommon } from '@ethereumjs/common' import { create4844BlobTx, createLegacyTx } from '@ethereumjs/tx' import { bytesToHex, createZeroAddress, hexToBytes } from '@ethereumjs/util' @@ -31,11 +31,10 @@ const block = { serialize: () => createHeader({ number: 1 }).serialize(), }, toJSON: () => ({ - ...createBlockFromBlockData({ header: { number: 1 } }).toJSON(), + ...createBlock({ header: { number: 1 } }).toJSON(), transactions: transactions2, }), - serialize: () => - createBlockFromBlockData({ header: { number: 1 }, transactions: transactions2 }).serialize(), + serialize: () => createBlock({ header: { number: 1 }, transactions: transactions2 }).serialize(), transactions: transactions2, uncleHeaders: [], } @@ -48,8 +47,8 @@ const genesisBlock = { header: { number: BigInt(0), }, - toJSON: () => ({ ...createBlockFromBlockData({ header: { number: 0 } }).toJSON(), transactions }), - serialize: () => createBlockFromBlockData({ header: { number: 0 }, transactions }).serialize(), + toJSON: () => ({ ...createBlock({ header: { number: 0 } }).toJSON(), transactions }), + serialize: () => createBlock({ header: { number: 0 }, transactions }).serialize(), transactions, uncleHeaders: [], } @@ -125,8 +124,8 @@ describe(method, async () => { }) describe('call with block with blob txs', () => { it('retrieves a block with a blob tx in it', async () => { - const genesisBlock = createBlockFromBlockData({ header: { number: 0 } }) - const block1 = createBlockFromBlockData( + const genesisBlock = createBlock({ header: { number: 0 } }) + const block1 = createBlock( { header: { number: 1, parentHash: genesisBlock.header.hash() }, transactions: [mockedBlobTx3], diff --git a/packages/client/test/rpc/debug/getRawHeader.spec.ts b/packages/client/test/rpc/debug/getRawHeader.spec.ts index d804abd253..de43fe3ada 100644 --- a/packages/client/test/rpc/debug/getRawHeader.spec.ts +++ b/packages/client/test/rpc/debug/getRawHeader.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { createCustomCommon } from '@ethereumjs/common' import { create4844BlobTx, createLegacyTx } from '@ethereumjs/tx' import { bytesToHex, createZeroAddress, hexToBytes } from '@ethereumjs/util' @@ -31,11 +31,10 @@ const block = { serialize: () => createHeader({ number: 1 }).serialize(), }, toJSON: () => ({ - ...createBlockFromBlockData({ header: { number: 1 } }).toJSON(), + ...createBlock({ header: { number: 1 } }).toJSON(), transactions: transactions2, }), - serialize: () => - createBlockFromBlockData({ header: { number: 1 }, transactions: transactions2 }).serialize(), + serialize: () => createBlock({ header: { number: 1 }, transactions: transactions2 }).serialize(), transactions: transactions2, uncleHeaders: [], } @@ -49,8 +48,8 @@ const genesisBlock = { number: BigInt(0), serialize: () => createHeader({ number: 0 }).serialize(), }, - toJSON: () => ({ ...createBlockFromBlockData({ header: { number: 0 } }).toJSON(), transactions }), - serialize: () => createBlockFromBlockData({ header: { number: 0 }, transactions }).serialize(), + toJSON: () => ({ ...createBlock({ header: { number: 0 } }).toJSON(), transactions }), + serialize: () => createBlock({ header: { number: 0 }, transactions }).serialize(), transactions, uncleHeaders: [], } @@ -130,8 +129,8 @@ describe(method, async () => { }) describe('call with block with blob txs', () => { it('retrieves a block with a blob tx in it', async () => { - const genesisBlock = createBlockFromBlockData({ header: { number: 0 } }) - const block1 = createBlockFromBlockData( + const genesisBlock = createBlock({ header: { number: 0 } }) + const block1 = createBlock( { header: { number: 1, parentHash: genesisBlock.header.hash() }, transactions: [mockedBlobTx3], diff --git a/packages/client/test/rpc/debug/traceCall.spec.ts b/packages/client/test/rpc/debug/traceCall.spec.ts index 9476c8e943..2680f1f98b 100644 --- a/packages/client/test/rpc/debug/traceCall.spec.ts +++ b/packages/client/test/rpc/debug/traceCall.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createTxFromTxData } from '@ethereumjs/tx' import { bytesToHex } from '@ethereumjs/util' import { assert, describe, expect, expectTypeOf, it } from 'vitest' @@ -65,7 +65,7 @@ describe('trace a call', async () => { tx.getSenderAddress = () => { return dummy.addr } - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) block.transactions[0] = tx await runBlockWithTxs(chain, execution, [tx], true) diff --git a/packages/client/test/rpc/debug/traceTransaction.spec.ts b/packages/client/test/rpc/debug/traceTransaction.spec.ts index 60f0719406..a97e182873 100644 --- a/packages/client/test/rpc/debug/traceTransaction.spec.ts +++ b/packages/client/test/rpc/debug/traceTransaction.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createTxFromTxData } from '@ethereumjs/tx' import { bytesToHex } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -64,7 +64,7 @@ describe(method, () => { tx.getSenderAddress = () => { return dummy.addr } - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) block.transactions[0] = tx await runBlockWithTxs(chain, execution, [tx], true) @@ -93,7 +93,7 @@ describe(method, () => { tx.getSenderAddress = () => { return dummy.addr } - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) block.transactions[0] = tx await runBlockWithTxs(chain, execution, [tx], true) @@ -122,7 +122,7 @@ describe(method, () => { tx.getSenderAddress = () => { return dummy.addr } - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) block.transactions[0] = tx await runBlockWithTxs(chain, execution, [tx], true) @@ -155,7 +155,7 @@ describe(method, () => { tx.getSenderAddress = () => { return dummy.addr } - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) block.transactions[0] = tx await runBlockWithTxs(chain, execution, [tx], true) diff --git a/packages/client/test/rpc/engine/CLConnectionManager.spec.ts b/packages/client/test/rpc/engine/CLConnectionManager.spec.ts index 6051ed54de..396cb7ef0e 100644 --- a/packages/client/test/rpc/engine/CLConnectionManager.spec.ts +++ b/packages/client/test/rpc/engine/CLConnectionManager.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Common, parseGethGenesis } from '@ethereumjs/common' import { assert, describe, expect, it, vi } from 'vitest' @@ -122,7 +122,7 @@ describe('updates stats when a new block is processed', () => { const manager = new CLConnectionManager({ config }) manager.lastForkchoiceUpdate(update) manager.lastNewPayload(payload) - const block = createBlockFromBlockData({ + const block = createBlock({ header: { parentHash: payload.payload.blockHash, number: payload.payload.blockNumber, diff --git a/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts b/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts index 421e78fbe8..ef74cafbc3 100644 --- a/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts +++ b/packages/client/test/rpc/engine/forkchoiceUpdatedV1.spec.ts @@ -1,4 +1,4 @@ -import { BlockHeader, createBlockFromBlockData } from '@ethereumjs/block' +import { BlockHeader, createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { bytesToHex, randomBytes, zeros } from '@ethereumjs/util' import { assert, describe, it, vi } from 'vitest' @@ -29,9 +29,9 @@ const validPayloadAttributes = { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Paris }) -function createBlock(parentBlock: Block) { +function createBlockFromParent(parentBlock: Block) { const prevRandao = randomBytes(32) - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parentBlock.hash(), @@ -166,7 +166,7 @@ describe(method, () => { engine: true, }) const rpc = getRpcClient(server) - const newBlock = createBlockFromBlockData( + const newBlock = createBlock( { header: { number: blocks[0].blockNumber, @@ -307,13 +307,13 @@ describe(method, () => { const canonical = [genesis] for (let i = 0; i < 2; i++) { - canonical.push(createBlock(canonical[canonical.length - 1])) + canonical.push(createBlockFromParent(canonical[canonical.length - 1])) } // Build an alternative payload const reorg = [genesis] for (let i = 0; i < 2; i++) { - reorg.push(createBlock(reorg[reorg.length - 1])) + reorg.push(createBlockFromParent(reorg[reorg.length - 1])) } const canonicalPayload = canonical.map( @@ -347,13 +347,13 @@ describe(method, () => { const canonical = [genesis] for (let i = 0; i < 2; i++) { - canonical.push(createBlock(canonical[canonical.length - 1])) + canonical.push(createBlockFromParent(canonical[canonical.length - 1])) } // Build an alternative payload const reorg = [genesis] for (let i = 0; i < 2; i++) { - reorg.push(createBlock(reorg[reorg.length - 1])) + reorg.push(createBlockFromParent(reorg[reorg.length - 1])) } const canonicalPayload = canonical.map( diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts index 3d390fec9b..9fffa532d2 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByHashV1.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' import { createTxFromTxData } from '@ethereumjs/tx' @@ -72,7 +72,7 @@ describe(method, () => { }, { common }, ).sign(pkey) - const block = createBlockFromBlockData( + const block = createBlock( { transactions: [tx], header: createHeader( @@ -82,7 +82,7 @@ describe(method, () => { }, { common, skipConsensusFormatValidation: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { transactions: [tx2], header: createHeader( @@ -158,7 +158,7 @@ describe(method, () => { }, { common }, ).sign(pkey) - const block = createBlockFromBlockData( + const block = createBlock( { transactions: [tx], header: createHeader( @@ -168,7 +168,7 @@ describe(method, () => { }, { common, skipConsensusFormatValidation: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { transactions: [tx2], header: createHeader( diff --git a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts index 26fcb7a259..3918c355ab 100644 --- a/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts +++ b/packages/client/test/rpc/engine/getPayloadBodiesByRangeV1.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' import { createTxFromTxData } from '@ethereumjs/tx' @@ -68,7 +68,7 @@ describe(method, () => { }, { common }, ).sign(pkey) - const block = createBlockFromBlockData( + const block = createBlock( { transactions: [tx], header: createHeader( @@ -78,7 +78,7 @@ describe(method, () => { }, { common, skipConsensusFormatValidation: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { transactions: [tx2], header: createHeader( @@ -150,7 +150,7 @@ describe(method, () => { }, { common }, ).sign(pkey) - const block = createBlockFromBlockData( + const block = createBlock( { transactions: [tx], header: createHeader( @@ -160,7 +160,7 @@ describe(method, () => { }, { common, skipConsensusFormatValidation: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { transactions: [tx2], header: createHeader( diff --git a/packages/client/test/rpc/engine/preimages.spec.ts b/packages/client/test/rpc/engine/preimages.spec.ts index 9e06517a2e..d85891fc08 100644 --- a/packages/client/test/rpc/engine/preimages.spec.ts +++ b/packages/client/test/rpc/engine/preimages.spec.ts @@ -1,6 +1,6 @@ import { BlockHeader, - createBlockFromBlockData, + createBlock, genTransactionsTrieRoot, genWithdrawalsTrieRoot, } from '@ethereumjs/block' @@ -97,7 +97,7 @@ async function runBlock( coinbase, } const blockData = { header: headerData, transactions: txs, withdrawals } - const executeBlock = createBlockFromBlockData(blockData, { common }) + const executeBlock = createBlock(blockData, { common }) const executePayload = blockToExecutionPayload(executeBlock, BigInt(0)).executionPayload const res = await rpc.request('engine_newPayloadV2', [executePayload]) assert.equal(res.result.status, 'VALID', 'valid status should be received') diff --git a/packages/client/test/rpc/eth/call.spec.ts b/packages/client/test/rpc/eth/call.spec.ts index 98ff195b83..3f10c99101 100644 --- a/packages/client/test/rpc/eth/call.spec.ts +++ b/packages/client/test/rpc/eth/call.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { createLegacyTx } from '@ethereumjs/tx' @@ -56,7 +56,7 @@ describe(method, () => { return address } const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), diff --git a/packages/client/test/rpc/eth/estimateGas.spec.ts b/packages/client/test/rpc/eth/estimateGas.spec.ts index 5c68aa7e7a..5e3ea04e59 100644 --- a/packages/client/test/rpc/eth/estimateGas.spec.ts +++ b/packages/client/test/rpc/eth/estimateGas.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { createCommonFromGethGenesis } from '@ethereumjs/common' import { getGenesis } from '@ethereumjs/genesis' @@ -65,7 +65,7 @@ describe( return address } const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), @@ -129,7 +129,7 @@ describe( service.execution.vm.common.setHardfork('london') service.chain.config.chainCommon.setHardfork('london') const headBlock = await service.chain.getCanonicalHeadBlock() - const londonBlock = createBlockFromBlockData( + const londonBlock = createBlock( { header: createHeader( { diff --git a/packages/client/test/rpc/eth/getBalance.spec.ts b/packages/client/test/rpc/eth/getBalance.spec.ts index 8b03a6e546..ec1e29d6e8 100644 --- a/packages/client/test/rpc/eth/getBalance.spec.ts +++ b/packages/client/test/rpc/eth/getBalance.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { getGenesis } from '@ethereumjs/genesis' @@ -52,7 +52,7 @@ describe( tx.getSenderAddress = () => { return address } - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) block.transactions[0] = tx const result = await runBlock(vm, { block, generate: true, skipBlockValidation: true }) diff --git a/packages/client/test/rpc/eth/getBlockByNumber.spec.ts b/packages/client/test/rpc/eth/getBlockByNumber.spec.ts index 4bec9dd941..5eb27b1105 100644 --- a/packages/client/test/rpc/eth/getBlockByNumber.spec.ts +++ b/packages/client/test/rpc/eth/getBlockByNumber.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createCustomCommon } from '@ethereumjs/common' import { create4844BlobTx, createLegacyTx } from '@ethereumjs/tx' import { createZeroAddress, hexToBytes } from '@ethereumjs/util' @@ -25,14 +25,13 @@ const transactions2 = [mockedTx2] const block = { hash: () => blockHash, - serialize: () => - createBlockFromBlockData({ header: { number: 1 }, transactions: transactions2 }).serialize(), + serialize: () => createBlock({ header: { number: 1 }, transactions: transactions2 }).serialize(), header: { number: BigInt(1), hash: () => blockHash, }, toJSON: () => ({ - ...createBlockFromBlockData({ header: { number: 1 } }).toJSON(), + ...createBlock({ header: { number: 1 } }).toJSON(), transactions: transactions2, }), transactions: transactions2, @@ -45,12 +44,12 @@ function createChain(headBlock = block) { ) const genesisBlock = { hash: () => genesisBlockHash, - serialize: () => createBlockFromBlockData({ header: { number: 0 }, transactions }).serialize(), + serialize: () => createBlock({ header: { number: 0 }, transactions }).serialize(), header: { number: BigInt(0), }, toJSON: () => ({ - ...createBlockFromBlockData({ header: { number: 0 } }).toJSON(), + ...createBlock({ header: { number: 0 } }).toJSON(), transactions, }), transactions, @@ -166,8 +165,8 @@ describe(method, async () => { describe('call with block with blob txs', () => { it('retrieves a block with a blob tx in it', async () => { - const genesisBlock = createBlockFromBlockData({ header: { number: 0 } }) - const block1 = createBlockFromBlockData( + const genesisBlock = createBlock({ header: { number: 0 } }) + const block1 = createBlock( { header: { number: 1, parentHash: genesisBlock.header.hash() }, transactions: [mockedBlobTx3], diff --git a/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts b/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts index df9b14ceac..8cd9c58e96 100644 --- a/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts +++ b/packages/client/test/rpc/eth/getBlockTransactionCountByNumber.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { getGenesis } from '@ethereumjs/genesis' @@ -43,7 +43,7 @@ describe(method, () => { return address } const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), @@ -99,7 +99,7 @@ describe(method, () => { } const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), diff --git a/packages/client/test/rpc/eth/getCode.spec.ts b/packages/client/test/rpc/eth/getCode.spec.ts index a580abc3c1..79a1414837 100644 --- a/packages/client/test/rpc/eth/getCode.spec.ts +++ b/packages/client/test/rpc/eth/getCode.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { getGenesis } from '@ethereumjs/genesis' @@ -69,7 +69,7 @@ describe(method, () => { return address } const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), diff --git a/packages/client/test/rpc/eth/getProof.spec.ts b/packages/client/test/rpc/eth/getProof.spec.ts index dd3befdfcb..ee89336805 100644 --- a/packages/client/test/rpc/eth/getProof.spec.ts +++ b/packages/client/test/rpc/eth/getProof.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Common } from '@ethereumjs/common' import { createLegacyTx } from '@ethereumjs/tx' @@ -132,7 +132,7 @@ describe(method, async () => { return address } const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), @@ -164,7 +164,7 @@ describe(method, async () => { storeTx.getSenderAddress = () => { return address } - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { parentHash: ranBlock!.hash(), diff --git a/packages/client/test/rpc/eth/getStorageAt.spec.ts b/packages/client/test/rpc/eth/getStorageAt.spec.ts index b51f409155..39fd257111 100644 --- a/packages/client/test/rpc/eth/getStorageAt.spec.ts +++ b/packages/client/test/rpc/eth/getStorageAt.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createLegacyTx } from '@ethereumjs/tx' import { createAddressFromString } from '@ethereumjs/util' import { runBlock } from '@ethereumjs/vm' @@ -33,7 +33,7 @@ describe(method, async () => { const signedTx = tx.sign(tx.getHashedMessageToSign()) const parent = await chain.blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), diff --git a/packages/client/test/rpc/eth/getTransactionCount.spec.ts b/packages/client/test/rpc/eth/getTransactionCount.spec.ts index 334725ecca..20eb5439bc 100644 --- a/packages/client/test/rpc/eth/getTransactionCount.spec.ts +++ b/packages/client/test/rpc/eth/getTransactionCount.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { getGenesis } from '@ethereumjs/genesis' @@ -55,7 +55,7 @@ describe(method, () => { return address } const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), diff --git a/packages/client/test/rpc/mockBlockchain.ts b/packages/client/test/rpc/mockBlockchain.ts index 2a00b29418..d9432f6ee0 100644 --- a/packages/client/test/rpc/mockBlockchain.ts +++ b/packages/client/test/rpc/mockBlockchain.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createLegacyTx } from '@ethereumjs/tx' import { equalsBytes, toBytes } from '@ethereumjs/util' @@ -13,13 +13,13 @@ export function mockBlockchain(options: any = {}) { const transactions = options.transactions ?? [createLegacyTx({}).sign(dummy.privKey)] const block = { hash: () => toBytes(blockHash), - serialize: () => createBlockFromBlockData({ header: { number }, transactions }).serialize(), + serialize: () => createBlock({ header: { number }, transactions }).serialize(), header: { number: BigInt(number), hash: () => toBytes(blockHash), }, toJSON: () => ({ - ...createBlockFromBlockData({ header: { number } }).toJSON(), + ...createBlock({ header: { number } }).toJSON(), hash: options.hash ?? blockHash, transactions: transactions.map((t: LegacyTransaction) => t.toJSON()), }), @@ -35,7 +35,7 @@ export function mockBlockchain(options: any = {}) { return block }, getCanonicalHeadHeader: () => { - return createBlockFromBlockData().header + return createBlock().header }, getIteratorHead: () => { return block diff --git a/packages/client/test/rpc/txpool/content.spec.ts b/packages/client/test/rpc/txpool/content.spec.ts index 623a368c64..4eb2f0b0b7 100644 --- a/packages/client/test/rpc/txpool/content.spec.ts +++ b/packages/client/test/rpc/txpool/content.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { getGenesis } from '@ethereumjs/genesis' @@ -32,7 +32,7 @@ describe(method, () => { await vm.stateManager.generateCanonicalGenesis!(getGenesis(1)) const gasLimit = 2000000 const parent = await blockchain.getCanonicalHeadHeader() - const block = createBlockFromBlockData( + const block = createBlock( { header: { parentHash: parent.hash(), @@ -51,7 +51,7 @@ describe(method, () => { service.execution.vm.common.setHardfork('london') service.chain.config.chainCommon.setHardfork('london') const headBlock = await service.chain.getCanonicalHeadBlock() - const londonBlock = createBlockFromBlockData( + const londonBlock = createBlock( { header: createHeader( { diff --git a/packages/client/test/sync/beaconsync.spec.ts b/packages/client/test/sync/beaconsync.spec.ts index 722f2f6104..550846418c 100644 --- a/packages/client/test/sync/beaconsync.spec.ts +++ b/packages/client/test/sync/beaconsync.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { MemoryLevel } from 'memory-level' import * as td from 'testdouble' import { assert, describe, it, vi } from 'vitest' @@ -218,7 +218,7 @@ describe('[BeaconSynchronizer]', async () => { const chain = await Chain.create({ config }) const skeleton = new Skeleton({ chain, config, metaDB: new MemoryLevel() }) const sync = new BeaconSynchronizer({ config, pool, chain, execution, skeleton }) - const head = createBlockFromBlockData({ header: { number: BigInt(15) } }) + const head = createBlock({ header: { number: BigInt(15) } }) await skeleton['putBlock'](head) ;(skeleton as any).status.progress.subchains = [ { @@ -227,14 +227,14 @@ describe('[BeaconSynchronizer]', async () => { }, ] await sync.open() - const block = createBlockFromBlockData({ + const block = createBlock({ header: { number: BigInt(16), parentHash: head.hash() }, }) assert.ok(await sync.extendChain(block), 'should extend chain successfully') assert.ok(await sync.setHead(block), 'should set head successfully') assert.equal(skeleton.bounds().head, BigInt(16), 'head should be updated') - const gapBlock = createBlockFromBlockData({ header: { number: BigInt(18) } }) + const gapBlock = createBlock({ header: { number: BigInt(18) } }) assert.notOk(await sync.extendChain(gapBlock), 'should not extend chain with gapped block') assert.ok( await sync.setHead(gapBlock), diff --git a/packages/client/test/sync/fetcher/reverseblockfetcher.spec.ts b/packages/client/test/sync/fetcher/reverseblockfetcher.spec.ts index 71fde3f121..867cf84a47 100644 --- a/packages/client/test/sync/fetcher/reverseblockfetcher.spec.ts +++ b/packages/client/test/sync/fetcher/reverseblockfetcher.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { MemoryLevel } from 'memory-level' import { assert, describe, it, vi } from 'vitest' @@ -195,29 +195,29 @@ describe('[ReverseBlockFetcher]', async () => { count: BigInt(5), timeout: 5, }) - const block47 = createBlockFromBlockData( + const block47 = createBlock( { header: { number: BigInt(47), difficulty: BigInt(1) } }, { setHardfork: true }, ) - const block48 = createBlockFromBlockData( + const block48 = createBlock( { header: { number: BigInt(48), parentHash: block47.hash(), difficulty: BigInt(1) }, }, { setHardfork: true }, ) - const block49 = createBlockFromBlockData( + const block49 = createBlock( { header: { number: BigInt(49), parentHash: block48.hash(), difficulty: BigInt(1) }, }, { setHardfork: true }, ) - const block4 = createBlockFromBlockData( + const block4 = createBlock( { header: { number: BigInt(4), difficulty: BigInt(1) }, }, { setHardfork: true }, ) - const block5 = createBlockFromBlockData( + const block5 = createBlock( { header: { number: BigInt(5), difficulty: BigInt(1), parentHash: block4.hash() }, }, diff --git a/packages/client/test/sync/fullsync.spec.ts b/packages/client/test/sync/fullsync.spec.ts index f6acbb3da3..0df617ac9e 100644 --- a/packages/client/test/sync/fullsync.spec.ts +++ b/packages/client/test/sync/fullsync.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import * as td from 'testdouble' import { assert, describe, it, vi } from 'vitest' @@ -235,10 +235,10 @@ describe('[FullSynchronizer]', async () => { ] ;(sync as any).pool = { peers } - const chainTip = createBlockFromBlockData({ + const chainTip = createBlock({ header: {}, }) - const newBlock = createBlockFromBlockData({ + const newBlock = createBlock({ header: { parentHash: chainTip.hash(), }, @@ -277,10 +277,10 @@ describe('[FullSynchronizer]', async () => { execution, }) - const chainTip = createBlockFromBlockData({ + const chainTip = createBlock({ header: {}, }) - const newBlock = createBlockFromBlockData({ + const newBlock = createBlock({ header: { parentHash: chainTip.hash(), }, diff --git a/packages/client/test/sync/skeleton.spec.ts b/packages/client/test/sync/skeleton.spec.ts index 3903edbbbe..434c8625ea 100644 --- a/packages/client/test/sync/skeleton.spec.ts +++ b/packages/client/test/sync/skeleton.spec.ts @@ -1,4 +1,4 @@ -import { BlockHeader, createBlockFromBlockData } from '@ethereumjs/block' +import { BlockHeader, createBlock } from '@ethereumjs/block' import { Common, createCommonFromGethGenesis } from '@ethereumjs/common' import { equalsBytes, utf8ToBytes } from '@ethereumjs/util' import { MemoryLevel } from 'memory-level' @@ -19,23 +19,14 @@ type Subchain = { } const common = new Common({ chain: 1 }) -const block49 = createBlockFromBlockData({ header: { number: 49 } }, { common }) -const block49B = createBlockFromBlockData( - { header: { number: 49, extraData: utf8ToBytes('B') } }, - { common }, -) -const block50 = createBlockFromBlockData( - { header: { number: 50, parentHash: block49.hash() } }, - { common }, -) -const block50B = createBlockFromBlockData( +const block49 = createBlock({ header: { number: 49 } }, { common }) +const block49B = createBlock({ header: { number: 49, extraData: utf8ToBytes('B') } }, { common }) +const block50 = createBlock({ header: { number: 50, parentHash: block49.hash() } }, { common }) +const block50B = createBlock( { header: { number: 50, parentHash: block49.hash(), gasLimit: 999 } }, { common }, ) -const block51 = createBlockFromBlockData( - { header: { number: 51, parentHash: block50.hash() } }, - { common }, -) +const block51 = createBlock({ header: { number: 51, parentHash: block50.hash() } }, { common }) describe('[Skeleton]/ startup scenarios ', () => { it('starts the chain when starting the skeleton', async () => { @@ -435,15 +426,15 @@ describe('[Skeleton] / setHead', async () => { await chain.open() const genesis = await chain.getBlock(BigInt(0)) - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: 1, parentHash: genesis.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2, parentHash: block1.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block3 = createBlockFromBlockData( + const block3 = createBlock( { header: { number: 3, difficulty: 100 } }, { common, setHardfork: true }, ) @@ -547,23 +538,23 @@ describe('[Skeleton] / setHead', async () => { await chain.open() const genesis = await chain.getBlock(BigInt(0)) - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: 1, parentHash: genesis.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2, parentHash: block1.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block3 = createBlockFromBlockData( + const block3 = createBlock( { header: { number: 3, parentHash: block2.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block4 = createBlockFromBlockData( + const block4 = createBlock( { header: { number: 4, parentHash: block3.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block5 = createBlockFromBlockData( + const block5 = createBlock( { header: { number: 5, parentHash: block4.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) @@ -626,23 +617,23 @@ describe('[Skeleton] / setHead', async () => { const genesis = await chain.getBlock(BigInt(0)) - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: 1, parentHash: genesis.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2, parentHash: block1.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block3 = createBlockFromBlockData( + const block3 = createBlock( { header: { number: 3, parentHash: block2.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block4 = createBlockFromBlockData( + const block4 = createBlock( { header: { number: 4, parentHash: block3.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block5 = createBlockFromBlockData( + const block5 = createBlock( { header: { number: 5, parentHash: block4.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) @@ -695,15 +686,15 @@ describe('[Skeleton] / setHead', async () => { // restore linkedStatus skeleton['status'].linked = prevLinked - const block41 = createBlockFromBlockData( + const block41 = createBlock( { header: { number: 4, parentHash: block3.hash(), difficulty: 101 } }, { common, setHardfork: true }, ) - const block51 = createBlockFromBlockData( + const block51 = createBlock( { header: { number: 5, parentHash: block41.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block61 = createBlockFromBlockData( + const block61 = createBlock( { header: { number: 6, parentHash: block51.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) @@ -726,15 +717,15 @@ describe('[Skeleton] / setHead', async () => { assert.equal(skeleton['status'].linked, true, 'should be linked') assert.equal(chain.blocks.height, BigInt(6), 'all blocks should be in chain') - const block71 = createBlockFromBlockData( + const block71 = createBlock( { header: { number: 7, parentHash: block61.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block81 = createBlockFromBlockData( + const block81 = createBlock( { header: { number: 8, parentHash: block71.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) - const block91 = createBlockFromBlockData( + const block91 = createBlock( { header: { number: 9, parentHash: block81.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) @@ -777,11 +768,11 @@ describe('[Skeleton] / setHead', async () => { ) // do a very common reorg that happens in a network: reorged head block - const block92 = createBlockFromBlockData( + const block92 = createBlock( { header: { number: 9, parentHash: block81.hash(), difficulty: 101 } }, { common, setHardfork: true }, ) - const block102 = createBlockFromBlockData( + const block102 = createBlock( { header: { number: 10, parentHash: block92.hash(), difficulty: 100 } }, { common, setHardfork: true }, ) @@ -836,31 +827,31 @@ describe('[Skeleton] / setHead', async () => { await chain.open() const genesisBlock = await chain.getBlock(BigInt(0)) - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: 1, parentHash: genesisBlock.hash(), difficulty: 100 } }, { common }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2, parentHash: block1.hash(), difficulty: 100 } }, { common }, ) - const block3PoW = createBlockFromBlockData( + const block3PoW = createBlock( { header: { number: 3, parentHash: block2.hash(), difficulty: 100 } }, { common }, ) - const block3PoS = createBlockFromBlockData( + const block3PoS = createBlock( { header: { number: 3, parentHash: block2.hash(), difficulty: 0 } }, { common, setHardfork: BigInt(200) }, ) - const block4InvalidPoS = createBlockFromBlockData( + const block4InvalidPoS = createBlock( { header: { number: 4, parentHash: block3PoW.hash(), difficulty: 0 } }, { common, setHardfork: BigInt(200) }, ) - const block4PoS = createBlockFromBlockData( + const block4PoS = createBlock( { header: { number: 4, parentHash: block3PoS.hash(), difficulty: 0 } }, { common, setHardfork: BigInt(200) }, ) - const block5 = createBlockFromBlockData( + const block5 = createBlock( { header: { number: 5, parentHash: block4PoS.hash(), difficulty: 0 } }, { common, setHardfork: BigInt(200) }, ) @@ -941,19 +932,19 @@ describe('[Skeleton] / setHead', async () => { await chain.open() const genesisBlock = await chain.getBlock(BigInt(0)) - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: 1, parentHash: genesisBlock.hash(), difficulty: 100 } }, { common }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2, parentHash: block1.hash(), difficulty: 100 } }, { common }, ) - const block3PoW = createBlockFromBlockData( + const block3PoW = createBlock( { header: { number: 3, parentHash: block2.hash(), difficulty: 100 } }, { common }, ) - const block4InvalidPoS = createBlockFromBlockData( + const block4InvalidPoS = createBlock( { header: { number: 4, parentHash: block3PoW.hash(), difficulty: 0 } }, { common, setHardfork: 200 }, ) @@ -1016,19 +1007,19 @@ describe('[Skeleton] / setHead', async () => { await chain.open() const genesisBlock = await chain.getBlock(BigInt(0)) - const block1 = createBlockFromBlockData( + const block1 = createBlock( { header: { number: 1, parentHash: genesisBlock.hash(), difficulty: 100 } }, { common }, ) - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2, parentHash: block1.hash(), difficulty: 100 } }, { common }, ) - const block2PoS = createBlockFromBlockData( + const block2PoS = createBlock( { header: { number: 2, parentHash: block1.hash(), difficulty: 0 } }, { common }, ) - const block3 = createBlockFromBlockData( + const block3 = createBlock( { header: { number: 3, parentHash: block2.hash(), difficulty: 0 } }, { common }, ) diff --git a/packages/client/test/sync/txpool.spec.ts b/packages/client/test/sync/txpool.spec.ts index a8cabaa964..8a9b468c0b 100644 --- a/packages/client/test/sync/txpool.spec.ts +++ b/packages/client/test/sync/txpool.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { DefaultStateManager } from '@ethereumjs/statemanager' import { create1559FeeMarketTx, create2930AccessListTx } from '@ethereumjs/tx' @@ -766,12 +766,12 @@ describe('[TxPool]', async () => { assert.equal(pool.pool.size, 1, 'pool size 1') // Craft block with tx not in pool - let block = createBlockFromBlockData({ transactions: [txA02] }, { common }) + let block = createBlock({ transactions: [txA02] }, { common }) pool.removeNewBlockTxs([block]) assert.equal(pool.pool.size, 1, 'pool size 1') // Craft block with tx in pool - block = createBlockFromBlockData({ transactions: [txA01] }, { common }) + block = createBlock({ transactions: [txA01] }, { common }) pool.removeNewBlockTxs([block]) assert.equal(pool.pool.size, 0, 'pool should be empty') @@ -789,20 +789,20 @@ describe('[TxPool]', async () => { assert.equal(poolContent.length, 2, 'two txs') // Craft block with tx not in pool - block = createBlockFromBlockData({ transactions: [txA02] }, { common }) + block = createBlock({ transactions: [txA02] }, { common }) pool.removeNewBlockTxs([block]) assert.equal(pool.pool.size, 1, 'pool size 1') poolContent = pool.pool.get(address)! assert.equal(poolContent.length, 2, 'two txs') // Craft block with tx in pool - block = createBlockFromBlockData({ transactions: [txB01] }, { common }) + block = createBlock({ transactions: [txB01] }, { common }) pool.removeNewBlockTxs([block]) poolContent = pool.pool.get(address)! assert.equal(poolContent.length, 1, 'only one tx') // Craft block with tx in pool - block = createBlockFromBlockData({ transactions: [txB02] }, { common }) + block = createBlock({ transactions: [txB02] }, { common }) pool.removeNewBlockTxs([block]) assert.equal(pool.pool.size, 0, 'pool size 0') diff --git a/packages/common/examples/customCrypto.ts b/packages/common/examples/customCrypto.ts index 3b1c601963..92e1fd8c20 100644 --- a/packages/common/examples/customCrypto.ts +++ b/packages/common/examples/customCrypto.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common } from '@ethereumjs/common' import { keccak256, waitReady } from '@polkadot/wasm-crypto' @@ -7,7 +7,7 @@ const main = async () => { await waitReady() const common = new Common({ chain: Chain.Mainnet, customCrypto: { keccak256 } }) - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) // Method invocations within EthereumJS library instantiations where the common // instance above is passed will now use the custom keccak256 implementation diff --git a/packages/ethash/examples/miner.ts b/packages/ethash/examples/miner.ts index c4f294b8c0..39800318b5 100644 --- a/packages/ethash/examples/miner.ts +++ b/packages/ethash/examples/miner.ts @@ -1,10 +1,10 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Ethash } from '@ethereumjs/ethash' import { MapDB, bytesToHex } from '@ethereumjs/util' import type { DBObject } from '@ethereumjs/util' -const block = createBlockFromBlockData( +const block = createBlock( { header: { difficulty: BigInt(100), diff --git a/packages/ethash/src/index.ts b/packages/ethash/src/index.ts index 7146af7203..dd3b148fca 100644 --- a/packages/ethash/src/index.ts +++ b/packages/ethash/src/index.ts @@ -1,4 +1,4 @@ -import { Block, BlockHeader, createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { Block, BlockHeader, createBlock, createHeader } from '@ethereumjs/block' import { RLP } from '@ethereumjs/rlp' import { BIGINT_0, @@ -96,7 +96,7 @@ export class Miner { const data = this.block.toJSON() data.header!.mixHash = solution.mixHash data.header!.nonce = solution.nonce - return createBlockFromBlockData(data, { common: this.block.common }) + return createBlock(data, { common: this.block.common }) } else { const data = this.blockHeader.toJSON() data.mixHash = solution.mixHash diff --git a/packages/ethash/test/block.spec.ts b/packages/ethash/test/block.spec.ts index 86edb0bd4f..ce05a05472 100644 --- a/packages/ethash/test/block.spec.ts +++ b/packages/ethash/test/block.spec.ts @@ -1,5 +1,5 @@ import { - createBlockFromBlockData, + createBlock, createBlockFromRLPSerializedBlock, createBlockFromValuesArray, } from '@ethereumjs/block' @@ -22,7 +22,7 @@ describe('Verify POW for valid and invalid blocks', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesis = createBlockFromBlockData({}, { common }) + const genesis = createBlock({}, { common }) const genesisResult = await e.verifyPOW(genesis) assert.ok(genesisResult, 'genesis block should be valid') diff --git a/packages/ethash/test/miner.spec.ts b/packages/ethash/test/miner.spec.ts index 3f69b95a33..91f1683c0a 100644 --- a/packages/ethash/test/miner.spec.ts +++ b/packages/ethash/test/miner.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { MapDB } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -15,7 +15,7 @@ describe('Miner', () => { it('Check if miner works as expected', async () => { const e = new Ethash(cacheDb) - const block = createBlockFromBlockData( + const block = createBlock( { header: { difficulty: BigInt(100), @@ -37,7 +37,7 @@ describe('Miner', () => { const solution = await miner.iterate(-1) - const validBlock = createBlockFromBlockData( + const validBlock = createBlock( { header: { difficulty: block.header.difficulty, @@ -57,7 +57,7 @@ describe('Miner', () => { it('Check if it is possible to mine Blocks and BlockHeaders', async () => { const e = new Ethash(cacheDb as any) - const block = createBlockFromBlockData( + const block = createBlock( { header: { difficulty: BigInt(100), @@ -70,7 +70,7 @@ describe('Miner', () => { const solution = await miner.mine(-1) assert.ok( - e.verifyPOW(createBlockFromBlockData({ header: solution.toJSON() }, { common })), + e.verifyPOW(createBlock({ header: solution.toJSON() }, { common })), 'successfully mined block', ) @@ -83,7 +83,7 @@ describe('Miner', () => { it('Check if it is possible to stop the miner', async () => { const e = new Ethash(cacheDb as any) - const block = createBlockFromBlockData( + const block = createBlock( { header: { difficulty: BigInt(10000000000000), @@ -118,7 +118,7 @@ describe('Miner', () => { it('Should keep common when mining blocks or headers', async () => { const e = new Ethash(cacheDb as any) - const block = createBlockFromBlockData( + const block = createBlock( { header: { difficulty: BigInt(100), diff --git a/packages/statemanager/test/statelessVerkleStateManager.spec.ts b/packages/statemanager/test/statelessVerkleStateManager.spec.ts index 8f8f74df82..d6b951349f 100644 --- a/packages/statemanager/test/statelessVerkleStateManager.spec.ts +++ b/packages/statemanager/test/statelessVerkleStateManager.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createCommonFromGethGenesis } from '@ethereumjs/common' import { createTxFromSerializedData } from '@ethereumjs/tx' import { @@ -36,12 +36,9 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { const decodedTxs = verkleBlockJSON.transactions.map((tx) => createTxFromSerializedData(hexToBytes(tx as PrefixedHexString)), ) - const block = createBlockFromBlockData( - { ...verkleBlockJSON, transactions: decodedTxs } as BlockData, - { - common, - }, - ) + const block = createBlock({ ...verkleBlockJSON, transactions: decodedTxs } as BlockData, { + common, + }) it('initPreState()', async () => { const stateManager = new StatelessVerkleStateManager({ verkleCrypto }) diff --git a/packages/vm/examples/buildBlock.ts b/packages/vm/examples/buildBlock.ts index b8f9bd3f6d..9c27a784c8 100644 --- a/packages/vm/examples/buildBlock.ts +++ b/packages/vm/examples/buildBlock.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common } from '@ethereumjs/common' import { createLegacyTx } from '@ethereumjs/tx' import { Account, bytesToHex, createAddressFromPrivateKey, hexToBytes } from '@ethereumjs/util' @@ -8,7 +8,7 @@ const main = async () => { const common = new Common({ chain: Chain.Mainnet }) const vm = await VM.create({ common }) - const parentBlock = createBlockFromBlockData( + const parentBlock = createBlock( { header: { number: 1n } }, { skipConsensusFormatValidation: true }, ) diff --git a/packages/vm/examples/run-blockchain.ts b/packages/vm/examples/run-blockchain.ts index b5115de95d..69d6200641 100644 --- a/packages/vm/examples/run-blockchain.ts +++ b/packages/vm/examples/run-blockchain.ts @@ -6,7 +6,7 @@ // 4. Puts the blocks from ../utils/blockchain-mock-data "blocks" attribute into the Blockchain // 5. Runs the Blockchain on the VM. -import { createBlockFromBlockData, createBlockFromRLPSerializedBlock } from '@ethereumjs/block' +import { createBlock, createBlockFromRLPSerializedBlock } from '@ethereumjs/block' import { EthashConsensus, createBlockchain } from '@ethereumjs/blockchain' import { Common, ConsensusAlgorithm, ConsensusType } from '@ethereumjs/common' import { Ethash } from '@ethereumjs/ethash' @@ -30,7 +30,7 @@ async function main() { const validatePow = common.consensusType() === ConsensusType.ProofOfWork const validateBlocks = true - const genesisBlock = createBlockFromBlockData({ header: testData.genesisBlockHeader }, { common }) + const genesisBlock = createBlock({ header: testData.genesisBlockHeader }, { common }) const consensusDict: ConsensusDict = {} consensusDict[ConsensusAlgorithm.Ethash] = new EthashConsensus(new Ethash()) diff --git a/packages/vm/examples/run-solidity-contract.ts b/packages/vm/examples/run-solidity-contract.ts index 37f53c8f91..d05d3db8c9 100644 --- a/packages/vm/examples/run-solidity-contract.ts +++ b/packages/vm/examples/run-solidity-contract.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { createLegacyTx } from '@ethereumjs/tx' import { bytesToHex, createAddressFromPrivateKey, hexToBytes } from '@ethereumjs/util' @@ -18,7 +18,7 @@ const INITIAL_GREETING = 'Hello, World!' const SECOND_GREETING = 'Hola, Mundo!' const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) -const block = createBlockFromBlockData({ header: { extraData: new Uint8Array(97) } }, { common }) +const block = createBlock({ header: { extraData: new Uint8Array(97) } }, { common }) const __filename = fileURLToPath(import.meta.url) // get the resolved path to the file const __dirname = path.dirname(__filename) // get the name of the directory diff --git a/packages/vm/src/buildBlock.ts b/packages/vm/src/buildBlock.ts index 1083fdf888..fa3080afaf 100644 --- a/packages/vm/src/buildBlock.ts +++ b/packages/vm/src/buildBlock.ts @@ -1,5 +1,5 @@ import { - createBlockFromBlockData, + createBlock, genRequestsTrieRoot, genTransactionsTrieRoot, genWithdrawalsTrieRoot, @@ -257,7 +257,7 @@ export class BlockBuilder { } const blockData = { header, transactions: this.transactions } - const block = createBlockFromBlockData(blockData, this.blockOpts) + const block = createBlock(blockData, this.blockOpts) const result = await runTx(this.vm, { tx, block, skipHardForkValidation }) @@ -363,7 +363,7 @@ export class BlockBuilder { requests, } - const block = createBlockFromBlockData(blockData, blockOpts) + const block = createBlock(blockData, blockOpts) if (this.blockOpts.putBlockIntoBlockchain === true) { await this.vm.blockchain.putBlock(block) diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index 59db66b8d6..c574a23972 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, genRequestsTrieRoot } from '@ethereumjs/block' +import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block' import { ConsensusType, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' import { StatelessVerkleStateManager } from '@ethereumjs/statemanager' @@ -255,7 +255,7 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise { } // create a reasonable default if no block is given - opts.block = opts.block ?? createBlockFromBlockData({}, { common: vm.common }) + opts.block = opts.block ?? createBlock({}, { common: vm.common }) if (opts.skipHardForkValidation !== true) { // Find and set preMerge hf for easy access later diff --git a/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts b/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts index 52e495c9be..ab9e8235bc 100644 --- a/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts +++ b/packages/vm/test/api/EIPs/eip-1559-FeeMarket.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { AccessListEIP2930Transaction, @@ -54,7 +54,7 @@ function makeBlock(baseFee: bigint, transaction: TypedTransaction, txType: Trans const signed = transaction.sign(pkey) const json = signed.toJSON() json.type = txType - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: BigInt(1), diff --git a/packages/vm/test/api/EIPs/eip-2935-historical-block-hashes.spec.ts b/packages/vm/test/api/EIPs/eip-2935-historical-block-hashes.spec.ts index 7df0b543a3..61ec4aaf30 100644 --- a/packages/vm/test/api/EIPs/eip-2935-historical-block-hashes.spec.ts +++ b/packages/vm/test/api/EIPs/eip-2935-historical-block-hashes.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Hardfork, createCustomCommon } from '@ethereumjs/common' import { createLegacyTx } from '@ethereumjs/tx' @@ -284,7 +284,7 @@ describe('EIP 2935: historical block hashes', () => { // validate the contract code cases // const result = await runTx(vm, { tx, block, skipHardForkValidation: true }) - const block = createBlockFromBlockData( + const block = createBlock( { header: { baseFeePerGas: BigInt(7), diff --git a/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts b/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts index 1e9d5d23db..6bfb02a335 100644 --- a/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3074-authcall.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { EVMErrorMessage } from '@ethereumjs/evm' import { createLegacyTx } from '@ethereumjs/tx' @@ -35,7 +35,7 @@ const common = new Common({ const privateKey = hexToBytes('0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109') const authAddress = new Address(privateToAddress(privateKey)) -const block = createBlockFromBlockData( +const block = createBlock( { header: { baseFeePerGas: BigInt(7), diff --git a/packages/vm/test/api/EIPs/eip-3198-BaseFee.spec.ts b/packages/vm/test/api/EIPs/eip-3198-BaseFee.spec.ts index 8c8562b133..9f91d442c8 100644 --- a/packages/vm/test/api/EIPs/eip-3198-BaseFee.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3198-BaseFee.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx' import { Address, hexToBytes, privateToAddress } from '@ethereumjs/util' @@ -43,7 +43,7 @@ function makeBlock(baseFee: bigint, transaction: TypedTransaction) { const signed = transaction.sign(pkey) const json = signed.toJSON() - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: BigInt(1), diff --git a/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts b/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts index a3367ba614..4e9c0e5677 100644 --- a/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts +++ b/packages/vm/test/api/EIPs/eip-3651-warm-coinbase.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { createLegacyTx } from '@ethereumjs/tx' import { Account, Address, hexToBytes, privateToAddress } from '@ethereumjs/util' @@ -17,7 +17,7 @@ const common = new Common({ eips: [3651], }) -const block = createBlockFromBlockData( +const block = createBlock( { header: { baseFeePerGas: 7, diff --git a/packages/vm/test/api/EIPs/eip-4399-supplant-difficulty-opcode-with-prevrando.spec.ts b/packages/vm/test/api/EIPs/eip-4399-supplant-difficulty-opcode-with-prevrando.spec.ts index db4327f6ed..4c1c750ebb 100644 --- a/packages/vm/test/api/EIPs/eip-4399-supplant-difficulty-opcode-with-prevrando.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4399-supplant-difficulty-opcode-with-prevrando.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { bytesToBigInt, hexToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -19,10 +19,7 @@ describe('EIP-4399 -> 0x44 (DIFFICULTY) should return PREVRANDAO', () => { timestamp: genesis.header.timestamp + BigInt(1), gasLimit: genesis.header.gasLimit, } - let block = createBlockFromBlockData( - { header }, - { common, calcDifficultyFromHeader: genesis.header }, - ) + let block = createBlock({ header }, { common, calcDifficultyFromHeader: genesis.header }) // Track stack let stack: any = [] @@ -41,7 +38,7 @@ describe('EIP-4399 -> 0x44 (DIFFICULTY) should return PREVRANDAO', () => { common.setHardfork(Hardfork.Paris) const prevRandao = bytesToBigInt(new Uint8Array(32).fill(1)) - block = createBlockFromBlockData( + block = createBlock( { header: { ...header, diff --git a/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts b/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts index 8e84fab200..7ff08e06b8 100644 --- a/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4788-beaconroot.spec.ts @@ -9,7 +9,7 @@ * - Input length < 32 bytes (reverts) */ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { type TransactionType, type TxData, createTxFromTxData } from '@ethereumjs/tx' import { @@ -63,7 +63,7 @@ function beaconrootBlock( }, { common, freeze: false }, ) - const block = createBlockFromBlockData( + const block = createBlock( { header, transactions: newTxData, diff --git a/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts b/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts index 76bae0226d..d6e32739b5 100644 --- a/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Hardfork, createCommonFromGethGenesis } from '@ethereumjs/common' import { create4844BlobTx } from '@ethereumjs/tx' @@ -32,7 +32,7 @@ describe('EIP4844 tests', () => { hardfork: Hardfork.Cancun, customCrypto: { kzg }, }) - const genesisBlock = createBlockFromBlockData( + const genesisBlock = createBlock( { header: { gasLimit: 50000, parentBeaconBlockRoot: zeros(32) } }, { common }, ) diff --git a/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts b/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts index 50a704a2d8..ea3790d5a1 100644 --- a/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, genWithdrawalsTrieRoot } from '@ethereumjs/block' +import { createBlock, genWithdrawalsTrieRoot } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork, createCommonFromGethGenesis } from '@ethereumjs/common' import { decode } from '@ethereumjs/rlp' @@ -90,7 +90,7 @@ describe('EIP4895 tests', () => { }) index++ } - const block = createBlockFromBlockData( + const block = createBlock( { header: { baseFeePerGas: BigInt(7), @@ -147,7 +147,7 @@ describe('EIP4895 tests', () => { let postState: string // construct a block with just the 0th withdrawal should have no effect on state - block = createBlockFromBlockData( + block = createBlock( { header: { baseFeePerGas: BigInt(7), @@ -169,7 +169,7 @@ describe('EIP4895 tests', () => { ) // construct a block with all the withdrawals - block = createBlockFromBlockData( + block = createBlock( { header: { baseFeePerGas: BigInt(7), diff --git a/packages/vm/test/api/EIPs/eip-6110.spec.ts b/packages/vm/test/api/EIPs/eip-6110.spec.ts index 15398ef033..91e383c0c6 100644 --- a/packages/vm/test/api/EIPs/eip-6110.spec.ts +++ b/packages/vm/test/api/EIPs/eip-6110.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork, getInitializedChains } from '@ethereumjs/common' import { createTxFromTxData } from '@ethereumjs/tx' import { @@ -56,7 +56,7 @@ describe('EIP-6110 runBlock tests', () => { await vm.stateManager.putAccount(beaconContractAddress, beaconContractAccount) await vm.stateManager.putCode(beaconContractAddress, depositContractByteCode) await vm.stateManager.putAccount(sender, createAccount({ balance: 540000000030064771065n })) - const block = createBlockFromBlockData( + const block = createBlock( { transactions: [depositTx], }, @@ -89,7 +89,7 @@ describe('EIP-7685 buildBlock tests', () => { await vm.stateManager.putAccount(beaconContractAddress, beaconContractAccount) await vm.stateManager.putCode(beaconContractAddress, depositContractByteCode) await vm.stateManager.putAccount(sender, createAccount({ balance: 540000000030064771065n })) - const block = createBlockFromBlockData({}, { common }) + const block = createBlock({}, { common }) ;(vm.blockchain as any)['dbManager']['getHeader'] = () => block.header const blockBuilder = await buildBlock(vm, { parentBlock: block }) await blockBuilder.addTransaction(depositTx) diff --git a/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts b/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts index 142bfb2a3f..6ce2496ab8 100644 --- a/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts +++ b/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Hardfork, createCustomCommon } from '@ethereumjs/common' import { createEVM } from '@ethereumjs/evm' import { StatelessVerkleStateManager } from '@ethereumjs/statemanager' @@ -26,12 +26,9 @@ const parentStateRoot = hexToBytes( '0x64e1a647f42e5c2e3c434531ccf529e1b3e93363a40db9fc8eec81f492123510', ) -const block = createBlockFromBlockData( - { ...verkleBlockJSON, transactions: decodedTxs } as BlockData, - { - common, - }, -) +const block = createBlock({ ...verkleBlockJSON, transactions: decodedTxs } as BlockData, { + common, +}) describe('EIP 6800 tests', () => { it('successfully run transactions statelessly using the block witness', async () => { diff --git a/packages/vm/test/api/EIPs/eip-7002.spec.ts b/packages/vm/test/api/EIPs/eip-7002.spec.ts index aeb126607d..1adfdbb5bc 100644 --- a/packages/vm/test/api/EIPs/eip-7002.spec.ts +++ b/packages/vm/test/api/EIPs/eip-7002.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' import { createLegacyTx } from '@ethereumjs/tx' @@ -71,7 +71,7 @@ function generateTx(nonce: bigint) { describe('EIP-7002 tests', () => { it('should correctly create requests', async () => { const vm = await setupVM({ common }) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: 1, @@ -96,7 +96,7 @@ describe('EIP-7002 tests', () => { const tx = generateTx(BigInt(0)) // Call withdrawals contract with a withdrawals request - const block2 = createBlockFromBlockData( + const block2 = createBlock( { header: { number: 2, @@ -142,7 +142,7 @@ describe('EIP-7002 tests', () => { const tx2 = generateTx(BigInt(1)) const tx3 = generateTx(BigInt(2)) - const block3 = createBlockFromBlockData( + const block3 = createBlock( { header: { number: 3, @@ -167,7 +167,7 @@ describe('EIP-7002 tests', () => { it('should throw when contract is not deployed', async () => { const vm = await setupVM({ common }) - const block = createBlockFromBlockData( + const block = createBlock( { header: { number: 1, diff --git a/packages/vm/test/api/EIPs/eip-7685.spec.ts b/packages/vm/test/api/EIPs/eip-7685.spec.ts index 887a137f54..4c9055ff1a 100644 --- a/packages/vm/test/api/EIPs/eip-7685.spec.ts +++ b/packages/vm/test/api/EIPs/eip-7685.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, genRequestsTrieRoot } from '@ethereumjs/block' +import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { @@ -34,7 +34,7 @@ const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Cancun, eip describe('EIP-7685 runBlock tests', () => { it('should not error when a valid requestsRoot is provided', async () => { const vm = await setupVM({ common }) - const emptyBlock = createBlockFromBlockData({}, { common }) + const emptyBlock = createBlock({}, { common }) const res = await runBlock(vm, { block: emptyBlock, generate: true, @@ -44,10 +44,7 @@ describe('EIP-7685 runBlock tests', () => { it('should error when an invalid requestsRoot is provided', async () => { const vm = await setupVM({ common }) - const emptyBlock = createBlockFromBlockData( - { header: { requestsRoot: invalidRequestsRoot } }, - { common }, - ) + const emptyBlock = createBlock({ header: { requestsRoot: invalidRequestsRoot } }, { common }) await expect(async () => runBlock(vm, { block: emptyBlock, @@ -58,7 +55,7 @@ describe('EIP-7685 runBlock tests', () => { const vm = await setupVM({ common }) const request = getRandomDepositRequest() const requestsRoot = await genRequestsTrieRoot([request]) - const block = createBlockFromBlockData( + const block = createBlock( { requests: [request], header: { requestsRoot }, @@ -70,7 +67,7 @@ describe('EIP-7685 runBlock tests', () => { it('should error when requestsRoot does not match requests provided', async () => { const vm = await setupVM({ common }) const request = getRandomDepositRequest() - const block = createBlockFromBlockData( + const block = createBlock( { requests: [request], header: { requestsRoot: invalidRequestsRoot }, @@ -88,7 +85,7 @@ describe('EIP 7685 buildBlock tests', () => { hardfork: Hardfork.Cancun, eips: [7685, 1559, 4895, 4844, 4788], }) - const genesisBlock = createBlockFromBlockData( + const genesisBlock = createBlock( { header: { gasLimit: 50000, baseFeePerGas: 100 } }, { common }, ) diff --git a/packages/vm/test/api/buildBlock.spec.ts b/packages/vm/test/api/buildBlock.spec.ts index 61f1a3875d..d5f9f6c494 100644 --- a/packages/vm/test/api/buildBlock.spec.ts +++ b/packages/vm/test/api/buildBlock.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { EthashConsensus, createBlockchain } from '@ethereumjs/blockchain' import { Chain, @@ -32,7 +32,7 @@ const pKeyAddress = createAddressFromPrivateKey(privateKey) describe('BlockBuilder', () => { it('should build a valid block', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisBlock = createBlockFromBlockData({ header: { gasLimit: 50000 } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit: 50000 } }, { common }) const blockchain = await createBlockchain({ genesisBlock, common, validateConsensus: false }) const vm = await VM.create({ common, blockchain }) @@ -69,7 +69,7 @@ describe('BlockBuilder', () => { it('should throw if adding a transaction exceeds the block gas limit', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) const vm = await VM.create({ common }) - const genesis = createBlockFromBlockData({}, { common }) + const genesis = createBlock({}, { common }) const blockBuilder = await buildBlock(vm, { parentBlock: genesis }) const gasLimit = genesis.header.gasLimit + BigInt(1) @@ -97,7 +97,7 @@ describe('BlockBuilder', () => { it('should correctly seal a PoW block', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisBlock = createBlockFromBlockData({ header: { gasLimit: 50000 } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit: 50000 } }, { common }) const consensusDict: ConsensusDict = {} consensusDict[ConsensusAlgorithm.Ethash] = new EthashConsensus(new Ethash()) @@ -199,7 +199,7 @@ describe('BlockBuilder', () => { // extraData: [vanity, activeSigner, seal] const extraData = concatBytes(new Uint8Array(32), signer.address.toBytes(), new Uint8Array(65)) const cliqueSigner = signer.privateKey - const genesisBlock = createBlockFromBlockData( + const genesisBlock = createBlock( { header: { gasLimit: 50000, extraData } }, { common, cliqueSigner }, ) @@ -235,7 +235,7 @@ describe('BlockBuilder', () => { it('should throw if block already built or reverted', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisBlock = createBlockFromBlockData({ header: { gasLimit: 50000 } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit: 50000 } }, { common }) const blockchain = await createBlockchain({ genesisBlock, common, validateConsensus: false }) const vm = await VM.create({ common, blockchain }) @@ -289,7 +289,7 @@ describe('BlockBuilder', () => { it('should build a block without any txs', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) - const genesisBlock = createBlockFromBlockData({ header: { gasLimit: 50000 } }, { common }) + const genesisBlock = createBlock({ header: { gasLimit: 50000 } }, { common }) const blockchain = await createBlockchain({ genesisBlock, common, validateConsensus: false }) const vm = await VM.create({ common, blockchain }) const vmCopy = await vm.shallowCopy() @@ -311,7 +311,7 @@ describe('BlockBuilder', () => { it('should build a 1559 block with legacy and 1559 txs', async () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London, eips: [1559] }) - const genesisBlock = createBlockFromBlockData( + const genesisBlock = createBlock( { header: { gasLimit: 50000, baseFeePerGas: 100 } }, { common }, ) diff --git a/packages/vm/test/api/customChain.spec.ts b/packages/vm/test/api/customChain.spec.ts index 16a68310d2..501c23058d 100644 --- a/packages/vm/test/api/customChain.spec.ts +++ b/packages/vm/test/api/customChain.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Common, Hardfork } from '@ethereumjs/common' import { createTxFromTxData } from '@ethereumjs/tx' @@ -55,7 +55,7 @@ const common = new Common({ hardfork: Hardfork.Chainstart, customChains: [testChain] as ChainConfig[], }) -const block = createBlockFromBlockData( +const block = createBlock( { header: { gasLimit: 21_000, diff --git a/packages/vm/test/api/runBlock.spec.ts b/packages/vm/test/api/runBlock.spec.ts index 72cbb51570..34922e6f74 100644 --- a/packages/vm/test/api/runBlock.spec.ts +++ b/packages/vm/test/api/runBlock.spec.ts @@ -1,5 +1,5 @@ import { - createBlockFromBlockData, + createBlock, createBlockFromRLPSerializedBlock, createBlockFromValuesArray, } from '@ethereumjs/block' @@ -176,7 +176,7 @@ describe('runBlock() -> successful API parameter usage', async () => { ) function getBlock(common: Common): Block { - return createBlockFromBlockData( + return createBlock( { header: { number: BigInt(10000000), @@ -239,7 +239,7 @@ describe('runBlock() -> API parameter usage/data errors', async () => { it('should fail when block gas limit higher than 2^63-1', async () => { const vm = await VM.create({ common }) - const block = createBlockFromBlockData({ + const block = createBlock({ header: { gasLimit: hexToBytes('0x8000000000000000'), }, @@ -383,7 +383,7 @@ describe('runBlock() -> runtime behavior', async () => { ).sign(otherUser.privateKey) // create block with the signer and txs - const block = createBlockFromBlockData( + const block = createBlock( { header: { extraData: new Uint8Array(97) }, transactions: [tx, tx] }, { common, cliqueSigner: signer.privateKey }, ) @@ -427,7 +427,7 @@ it('should correctly reflect generated fields', async () => { // get a receipt trie root of for the empty receipts set, // which is a well known constant. const bytes32Zeros = new Uint8Array(32) - const block = createBlockFromBlockData({ + const block = createBlock({ header: { receiptTrie: bytes32Zeros, transactionsTrie: bytes32Zeros, gasUsed: BigInt(1) }, }) @@ -661,7 +661,7 @@ describe('runBlock() -> tx types', async () => { }, { common }, ).sign(defaultSenderPkey) - const block = createBlockFromBlockData( + const block = createBlock( { transactions: [tx1, tx2], }, diff --git a/packages/vm/test/api/runTx.spec.ts b/packages/vm/test/api/runTx.spec.ts index b7b4623c13..4c6f799933 100644 --- a/packages/vm/test/api/runTx.spec.ts +++ b/packages/vm/test/api/runTx.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createHeader } from '@ethereumjs/block' +import { createBlock, createHeader } from '@ethereumjs/block' import { Blockchain, createBlockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork, createCommonFromGethGenesis } from '@ethereumjs/common' import { @@ -61,10 +61,7 @@ describe('runTx() -> successful API parameter usage', async () => { let block if (vm.common.consensusType() === 'poa') { // Setup block with correct extraData for POA - block = createBlockFromBlockData( - { header: { extraData: new Uint8Array(97) } }, - { common: vm.common }, - ) + block = createBlock({ header: { extraData: new Uint8Array(97) } }, { common: vm.common }) } const res = await runTx(vm, { tx, block }) @@ -95,7 +92,7 @@ describe('runTx() -> successful API parameter usage', async () => { const caller = tx.getSenderAddress() const acc = createAccountWithDefaults() await vm.stateManager.putAccount(caller, acc) - const block = createBlockFromBlockData({}, { common: vm.common.copy() }) + const block = createBlock({}, { common: vm.common.copy() }) await runTx(vm, { tx, block }) assert.ok(true, 'matched hardfork should run without throwing') }) @@ -110,7 +107,7 @@ describe('runTx() -> successful API parameter usage', async () => { const caller = tx.getSenderAddress() const acc = createAccountWithDefaults() await vm.stateManager.putAccount(caller, acc) - const block = createBlockFromBlockData({}, { common: vm.common.copy() }) + const block = createBlock({}, { common: vm.common.copy() }) block.common.setHardfork(Hardfork.Paris) try { @@ -153,7 +150,7 @@ describe('runTx() -> successful API parameter usage', async () => { const caller = tx.getSenderAddress() const acc = createAccountWithDefaults() await vm.stateManager.putAccount(caller, acc) - const block = createBlockFromBlockData({}, { common: vm.common.copy() }) + const block = createBlock({}, { common: vm.common.copy() }) tx.common.setHardfork(Hardfork.GrayGlacier) block.common.setHardfork(Hardfork.GrayGlacier) @@ -233,7 +230,7 @@ describe('runTx() -> successful API parameter usage', async () => { const tx = unsignedTx.sign(privateKey) const coinbase = hexToBytes('0x00000000000000000000000000000000000000ff') - const block = createBlockFromBlockData( + const block = createBlock( { header: { gasLimit: transferCost - 1, @@ -441,7 +438,7 @@ describe('runTx() -> API parameter usage/data errors', () => { for (const txType of TRANSACTION_TYPES) { const vm = await VM.create({ common }) const tx = getTransaction(vm.common, txType.type, true) - const block = createBlockFromBlockData({ header: { baseFeePerGas: 100000 } }, { common }) + const block = createBlock({ header: { baseFeePerGas: 100000 } }, { common }) try { await runTx(vm, { tx, block }) assert.fail('should fail') @@ -723,7 +720,7 @@ describe('runTx() -> consensus bugs', () => { const tx = create1559FeeMarketTx(txData, { common }).sign(pkey) - const block = createBlockFromBlockData({ header: { baseFeePerGas: 0x0c } }, { common }) + const block = createBlock({ header: { baseFeePerGas: 0x0c } }, { common }) const result = await runTx(vm, { tx, block }) assert.equal( @@ -901,7 +898,7 @@ describe('EIP 4844 transaction tests', () => { // Stub getBlock to produce a valid parent header under EIP 4844 Blockchain.prototype.getBlock = async () => { - return createBlockFromBlockData( + return createBlock( { header: createHeader( { @@ -929,7 +926,7 @@ describe('EIP 4844 transaction tests', () => { const tx = getTransaction(common, 3, true) as BlobEIP4844Transaction - const block = createBlockFromBlockData( + const block = createBlock( { header: createHeader( { diff --git a/packages/vm/test/api/types.spec.ts b/packages/vm/test/api/types.spec.ts index ed8102e275..2f5e55fb83 100644 --- a/packages/vm/test/api/types.spec.ts +++ b/packages/vm/test/api/types.spec.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData } from '@ethereumjs/block' +import { createBlock } from '@ethereumjs/block' import { Chain, Common, Hardfork } from '@ethereumjs/common' import { create2930AccessListTx, createLegacyTx } from '@ethereumjs/tx' import { assert, describe, it } from 'vitest' @@ -21,10 +21,10 @@ describe('[Types]', () => { const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Berlin }) // Block - const block: Omit< - Required, - 'withdrawals' | 'executionWitness' - > = createBlockFromBlockData({}, { common }) + const block: Omit, 'withdrawals' | 'executionWitness'> = createBlock( + {}, + { common }, + ) assert.ok(block, 'block') // Transactions diff --git a/packages/vm/test/tester/runners/BlockchainTestsRunner.ts b/packages/vm/test/tester/runners/BlockchainTestsRunner.ts index 15d2a4c1b0..013bfd3582 100644 --- a/packages/vm/test/tester/runners/BlockchainTestsRunner.ts +++ b/packages/vm/test/tester/runners/BlockchainTestsRunner.ts @@ -1,4 +1,4 @@ -import { createBlockFromBlockData, createBlockFromRLPSerializedBlock } from '@ethereumjs/block' +import { createBlock, createBlockFromRLPSerializedBlock } from '@ethereumjs/block' import { EthashConsensus, createBlockchain } from '@ethereumjs/blockchain' import { ConsensusAlgorithm } from '@ethereumjs/common' import { Ethash } from '@ethereumjs/ethash' @@ -67,7 +67,7 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes const header = formatBlockHeader(testData.genesisBlockHeader) const withdrawals = common.isActivatedEIP(4895) ? [] : undefined const blockData = { header, withdrawals } - const genesisBlock = createBlockFromBlockData(blockData, { common }) + const genesisBlock = createBlock(blockData, { common }) if (typeof testData.genesisRLP === 'string') { const rlp = toBytes(testData.genesisRLP)