From 559493438e5b6d06b82359e76019ea655384c466 Mon Sep 17 00:00:00 2001 From: ScottyPoi Date: Wed, 14 Aug 2024 11:16:32 -0600 Subject: [PATCH] update downstream --- packages/block/src/block/constructors.ts | 8 +++---- packages/block/test/eip4895block.spec.ts | 4 ++-- packages/block/test/eip7685block.spec.ts | 2 +- packages/block/test/header.spec.ts | 4 ++-- .../client/test/rpc/engine/preimages.spec.ts | 4 ++-- .../test/rpc/engine/withdrawals.spec.ts | 4 ++-- packages/tx/test/base.spec.ts | 4 ++-- packages/tx/test/legacy.spec.ts | 2 +- packages/util/examples/withdrawal.ts | 4 ++-- packages/util/test/withdrawal.spec.ts | 24 +++++++++++++------ packages/vm/src/buildBlock.ts | 5 ++-- .../api/EIPs/eip-4895-withdrawals.spec.ts | 6 ++--- 12 files changed, 41 insertions(+), 30 deletions(-) diff --git a/packages/block/src/block/constructors.ts b/packages/block/src/block/constructors.ts index 2a50ee08d0e..7b98f819015 100644 --- a/packages/block/src/block/constructors.ts +++ b/packages/block/src/block/constructors.ts @@ -11,11 +11,11 @@ import { ConsolidationRequest, DepositRequest, TypeOutput, - Withdrawal, WithdrawalRequest, bigIntToHex, bytesToHex, bytesToUtf8, + createWithdrawal, equalsBytes, fetchFromProvider, getProvider, @@ -127,7 +127,7 @@ export function createBlock(blockData: BlockData = {}, opts?: BlockOptions) { uncleHeaders.push(uh) } - const withdrawals = withdrawalsData?.map(Withdrawal.fromWithdrawalData) + const withdrawals = withdrawalsData?.map(createWithdrawal) // The witness data is planned to come in rlp serialized bytes so leave this // stub till that time const executionWitness = executionWitnessData @@ -232,7 +232,7 @@ export function createBlockFromBytesArray(values: BlockBytes, opts?: BlockOption address, amount, })) - ?.map(Withdrawal.fromWithdrawalData) + ?.map(createWithdrawal) let requests if (header.common.isActivatedEIP(7685)) { @@ -414,7 +414,7 @@ export async function createBlockFromExecutionPayload( } const transactionsTrie = await genTransactionsTrieRoot(txs, new Trie({ common: opts?.common })) - const withdrawals = withdrawalsData?.map((wData) => Withdrawal.fromWithdrawalData(wData)) + const withdrawals = withdrawalsData?.map((wData) => createWithdrawal(wData)) const withdrawalsRoot = withdrawals ? await genWithdrawalsTrieRoot(withdrawals, new Trie({ common: opts?.common })) : undefined diff --git a/packages/block/test/eip4895block.spec.ts b/packages/block/test/eip4895block.spec.ts index 4be6264c65b..35138d1489a 100644 --- a/packages/block/test/eip4895block.spec.ts +++ b/packages/block/test/eip4895block.spec.ts @@ -3,7 +3,7 @@ import { RLP } from '@ethereumjs/rlp' import { Address, KECCAK256_RLP, - Withdrawal, + createWithdrawalFromValuesArray, hexToBytes, randomBytes, zeros, @@ -40,7 +40,7 @@ describe('EIP4895 tests', () => { // get withdwalsArray const gethBlockBytesArray = RLP.decode(hexToBytes(`0x${gethWithdrawals8BlockRlp}`)) const withdrawals = (gethBlockBytesArray[3] as WithdrawalBytes[]).map((wa) => - Withdrawal.fromValuesArray(wa), + createWithdrawalFromValuesArray(wa), ) assert.equal(withdrawals.length, 8, '8 withdrawals should have been found') const gethWitdrawalsRoot = (gethBlockBytesArray[0] as Uint8Array[])[16] as Uint8Array diff --git a/packages/block/test/eip7685block.spec.ts b/packages/block/test/eip7685block.spec.ts index 928e2db558e..02dddb8bf5f 100644 --- a/packages/block/test/eip7685block.spec.ts +++ b/packages/block/test/eip7685block.spec.ts @@ -109,7 +109,7 @@ describe('7685 tests', () => { }) }) -describe('fromValuesArray tests', () => { +describe('createWithdrawalFromValuesArray tests', () => { it('should construct a block with empty requests root', () => { const block = createBlockFromBytesArray( [createBlockHeader({}, { common }).raw(), [], [], [], []], diff --git a/packages/block/test/header.spec.ts b/packages/block/test/header.spec.ts index a56e3c41f7c..80b4a58d40b 100644 --- a/packages/block/test/header.spec.ts +++ b/packages/block/test/header.spec.ts @@ -129,7 +129,7 @@ describe('[Block]: Header functions', () => { } }) - it('Initialization -> fromValuesArray()', () => { + it('Initialization -> createWithdrawalFromValuesArray()', () => { const common = new Common({ chain: Mainnet, hardfork: Hardfork.London }) const zero = new Uint8Array(0) const headerArray = [] @@ -156,7 +156,7 @@ describe('[Block]: Header functions', () => { ) }) - it('Initialization -> fromValuesArray() -> error cases', () => { + it('Initialization -> createWithdrawalFromValuesArray() -> error cases', () => { const headerArray = Array(22).fill(new Uint8Array(0)) // mock header data (if set to zeros(0) header throws) diff --git a/packages/client/test/rpc/engine/preimages.spec.ts b/packages/client/test/rpc/engine/preimages.spec.ts index d85891fc08d..389035cc24d 100644 --- a/packages/client/test/rpc/engine/preimages.spec.ts +++ b/packages/client/test/rpc/engine/preimages.spec.ts @@ -6,8 +6,8 @@ import { } from '@ethereumjs/block' import { createTxFromSerializedData } from '@ethereumjs/tx' import { - Withdrawal, bytesToHex, + createWithdrawal, equalsBytes, hexToBytes, intToBytes, @@ -50,7 +50,7 @@ async function genBlockWithdrawals(blockNumber: number) { } }) const withdrawalsRoot = bytesToHex( - await genWithdrawalsTrieRoot(withdrawals.map(Withdrawal.fromWithdrawalData)), + await genWithdrawalsTrieRoot(withdrawals.map(createWithdrawal)), ) return { withdrawals, withdrawalsRoot } diff --git a/packages/client/test/rpc/engine/withdrawals.spec.ts b/packages/client/test/rpc/engine/withdrawals.spec.ts index e46f000c896..3076e7de6bb 100644 --- a/packages/client/test/rpc/engine/withdrawals.spec.ts +++ b/packages/client/test/rpc/engine/withdrawals.spec.ts @@ -1,6 +1,6 @@ import { genWithdrawalsTrieRoot } from '@ethereumjs/block' import { Trie } from '@ethereumjs/trie' -import { Withdrawal, bigIntToHex, bytesToHex, intToHex } from '@ethereumjs/util' +import { bigIntToHex, bytesToHex, createWithdrawal, intToHex } from '@ethereumjs/util' import { assert, it } from 'vitest' import { INVALID_PARAMS } from '../../../src/rpc/error-code.js' @@ -105,7 +105,7 @@ for (const { name, withdrawals, withdrawalsRoot, gethBlockRlp } of testCases) { it(name, async () => { // check withdrawals root computation const computedWithdrawalsRoot = bytesToHex( - await genWithdrawalsTrieRoot(withdrawals.map(Withdrawal.fromWithdrawalData), new Trie()), + await genWithdrawalsTrieRoot(withdrawals.map(createWithdrawal), new Trie()), ) assert.equal( withdrawalsRoot, diff --git a/packages/tx/test/base.spec.ts b/packages/tx/test/base.spec.ts index aacbe718e9b..0e8b56a0e8b 100644 --- a/packages/tx/test/base.spec.ts +++ b/packages/tx/test/base.spec.ts @@ -184,7 +184,7 @@ describe('[BaseTransaction]', () => { } }) - it('fromValuesArray()', () => { + it('createWithdrawalFromValuesArray()', () => { let rlpData: any = legacyTxs[0].raw() rlpData[0] = toBytes('0x0') try { @@ -270,7 +270,7 @@ describe('[BaseTransaction]', () => { for (const tx of txType.txs) { assert.ok( txType.create.bytesArray(tx.raw() as any, { common }), - `${txType.name}: should do roundtrip raw() -> fromValuesArray()`, + `${txType.name}: should do roundtrip raw() -> createWithdrawalFromValuesArray()`, ) } } diff --git a/packages/tx/test/legacy.spec.ts b/packages/tx/test/legacy.spec.ts index cc666131242..bfdb6220dc1 100644 --- a/packages/tx/test/legacy.spec.ts +++ b/packages/tx/test/legacy.spec.ts @@ -99,7 +99,7 @@ describe('[Transaction]', () => { ) }) - it('Initialization -> decode with fromValuesArray()', () => { + it('Initialization -> decode with createWithdrawalFromValuesArray()', () => { for (const tx of txFixtures.slice(0, 4)) { const txData = tx.raw.map((rawTxData) => hexToBytes(rawTxData as PrefixedHexString)) const pt = createLegacyTxFromBytesArray(txData) diff --git a/packages/util/examples/withdrawal.ts b/packages/util/examples/withdrawal.ts index cf6d4b59590..10c4e98def8 100644 --- a/packages/util/examples/withdrawal.ts +++ b/packages/util/examples/withdrawal.ts @@ -1,6 +1,6 @@ -import { Withdrawal } from '@ethereumjs/util' +import { createWithdrawal } from '@ethereumjs/util' -const withdrawal = Withdrawal.fromWithdrawalData({ +const withdrawal = createWithdrawal({ index: 0n, validatorIndex: 65535n, address: '0x0000000000000000000000000000000000000000', diff --git a/packages/util/test/withdrawal.spec.ts b/packages/util/test/withdrawal.spec.ts index b090ac361c7..836788ca9ac 100644 --- a/packages/util/test/withdrawal.spec.ts +++ b/packages/util/test/withdrawal.spec.ts @@ -1,7 +1,15 @@ import { decode, encode } from '@ethereumjs/rlp' import { assert, describe, it } from 'vitest' -import { Withdrawal, bigIntToHex, bytesToHex, hexToBytes, intToHex } from '../src/index.js' +import { + bigIntToHex, + bytesToHex, + createWithdrawal, + createWithdrawalFromValuesArray, + hexToBytes, + intToHex, + withdrawalToBytesArray, +} from '../src/index.js' import type { WithdrawalBytes, WithdrawalData } from '../src/index.js' @@ -68,25 +76,27 @@ describe('Withdrawal', () => { // gethWithdrawals8Rlp is rlp encoded block with withdrawals in the 4th element of the top array const gethWithdrawalsBuffer = decode(hexToBytes(gethWithdrawals8BlockRlp))[3]! const gethWithdrawalsRlp = bytesToHex(encode(gethWithdrawalsBuffer)) - it('fromWithdrawalData and toBytesArray', () => { + it('createWithdrawal and withdrawalToBytesArray', () => { const withdrawals = withdrawalsGethVector.map((withdrawal) => - Withdrawal.fromWithdrawalData(withdrawal as WithdrawalData), + createWithdrawal(withdrawal as WithdrawalData), ) const withdrawalstoBytesArr = withdrawals.map((wt) => wt.raw()) const withdrawalsToRlp = bytesToHex(encode(withdrawalstoBytesArr)) assert.equal(gethWithdrawalsRlp, withdrawalsToRlp, 'The withdrawals to buffer should match') }) - it('toBytesArray from withdrawalData', () => { + it('withdrawalToBytesArray from withdrawalData', () => { const withdrawalsDatatoBytesArr = withdrawalsGethVector.map((withdrawal) => - Withdrawal.toBytesArray(withdrawal as WithdrawalData), + withdrawalToBytesArray(withdrawal as WithdrawalData), ) const withdrawalsDataToRlp = bytesToHex(encode(withdrawalsDatatoBytesArr)) assert.equal(gethWithdrawalsRlp, withdrawalsDataToRlp, 'The withdrawals to buffer should match') }) - it('fromValuesArray, toJSON and toValue', () => { - const withdrawals = (gethWithdrawalsBuffer as WithdrawalBytes[]).map(Withdrawal.fromValuesArray) + it('createWithdrawalFromValuesArray, toJSON and toValue', () => { + const withdrawals = (gethWithdrawalsBuffer as WithdrawalBytes[]).map( + createWithdrawalFromValuesArray, + ) const withdrawalsJson = withdrawals.map((wt) => wt.toJSON()) assert.deepEqual(withdrawalsGethVector, withdrawalsJson, 'Withdrawals json should match') diff --git a/packages/vm/src/buildBlock.ts b/packages/vm/src/buildBlock.ts index 82604b573db..c9324c77c42 100644 --- a/packages/vm/src/buildBlock.ts +++ b/packages/vm/src/buildBlock.ts @@ -17,7 +17,7 @@ import { GWEI_TO_WEI, KECCAK256_RLP, TypeOutput, - Withdrawal, + createWithdrawal, createZeroAddress, toBytes, toType, @@ -40,6 +40,7 @@ import type { BuildBlockOpts, BuilderOpts, RunTxResult, SealBlockOpts } from './ import type { VM } from './vm.js' import type { Block, HeaderData } from '@ethereumjs/block' import type { TypedTransaction } from '@ethereumjs/tx' +import type { Withdrawal } from '@ethereumjs/util' export enum BuildStatus { Reverted = 'reverted', @@ -94,7 +95,7 @@ export class BlockBuilder { gasLimit: opts.headerData?.gasLimit ?? opts.parentBlock.header.gasLimit, timestamp: opts.headerData?.timestamp ?? Math.round(Date.now() / 1000), } - this.withdrawals = opts.withdrawals?.map(Withdrawal.fromWithdrawalData) + this.withdrawals = opts.withdrawals?.map(createWithdrawal) if ( this.vm.common.isActivatedEIP(1559) && 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 87b421572f1..7b32837840d 100644 --- a/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts +++ b/packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts @@ -8,8 +8,8 @@ import { Address, GWEI_TO_WEI, KECCAK256_RLP, - Withdrawal, bytesToHex, + createWithdrawalFromValuesArray, hexToBytes, parseGethGenesisState, zeros, @@ -140,7 +140,7 @@ describe('EIP4895 tests', () => { const gethBlockBufferArray = decode(hexToBytes(gethWithdrawals8BlockRlp)) const withdrawals = (gethBlockBufferArray[3] as WithdrawalBytes[]).map((wa) => - Withdrawal.fromValuesArray(wa), + createWithdrawalFromValuesArray(wa), ) assert.equal(withdrawals[0].amount, BigInt(0), 'withdrawal 0 should have 0 amount') let block: Block @@ -213,7 +213,7 @@ describe('EIP4895 tests', () => { const gethBlockBufferArray = decode(hexToBytes(gethWithdrawals8BlockRlp)) const withdrawals = (gethBlockBufferArray[3] as WithdrawalBytes[]).map((wa) => - Withdrawal.fromValuesArray(wa), + createWithdrawalFromValuesArray(wa), ) const td = await blockchain.getTotalDifficulty(genesisBlock.hash())