Skip to content

Commit

Permalink
update downstream
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Aug 14, 2024
1 parent 88f9382 commit 5594934
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 30 deletions.
8 changes: 4 additions & 4 deletions packages/block/src/block/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
ConsolidationRequest,
DepositRequest,
TypeOutput,
Withdrawal,
WithdrawalRequest,
bigIntToHex,
bytesToHex,
bytesToUtf8,
createWithdrawal,
equalsBytes,
fetchFromProvider,
getProvider,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/block/test/eip4895block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RLP } from '@ethereumjs/rlp'
import {
Address,
KECCAK256_RLP,
Withdrawal,
createWithdrawalFromValuesArray,
hexToBytes,
randomBytes,
zeros,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/eip7685block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [], [], [], []],
Expand Down
4 changes: 2 additions & 2 deletions packages/block/test/header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/rpc/engine/preimages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from '@ethereumjs/block'
import { createTxFromSerializedData } from '@ethereumjs/tx'
import {
Withdrawal,
bytesToHex,
createWithdrawal,
equalsBytes,
hexToBytes,
intToBytes,
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/rpc/engine/withdrawals.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/tx/test/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('[BaseTransaction]', () => {
}
})

it('fromValuesArray()', () => {
it('createWithdrawalFromValuesArray()', () => {
let rlpData: any = legacyTxs[0].raw()
rlpData[0] = toBytes('0x0')
try {
Expand Down Expand Up @@ -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()`,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tx/test/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/util/examples/withdrawal.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
24 changes: 17 additions & 7 deletions packages/util/test/withdrawal.spec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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')

Expand Down
5 changes: 3 additions & 2 deletions packages/vm/src/buildBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
GWEI_TO_WEI,
KECCAK256_RLP,
TypeOutput,
Withdrawal,
createWithdrawal,
createZeroAddress,
toBytes,
toType,
Expand All @@ -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',
Expand Down Expand Up @@ -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) &&
Expand Down
6 changes: 3 additions & 3 deletions packages/vm/test/api/EIPs/eip-4895-withdrawals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
Address,
GWEI_TO_WEI,
KECCAK256_RLP,
Withdrawal,
bytesToHex,
createWithdrawalFromValuesArray,
hexToBytes,
parseGethGenesisState,
zeros,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())

Expand Down

0 comments on commit 5594934

Please sign in to comment.