11import { createBlock , genRequestsRoot } from '@ethereumjs/block'
22import { createBlockchain } from '@ethereumjs/blockchain'
33import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
4- import { KECCAK256_RLP , createDepositRequest , hexToBytes , randomBytes } from '@ethereumjs/util'
5- import { sha256 } from 'ethereum-cryptography/keccak.js '
4+ import { createCLRequest , hexToBytes } from '@ethereumjs/util'
5+ import { sha256 } from 'ethereum-cryptography/sha256 '
66import { assert , describe , expect , it } from 'vitest'
77
88import { buildBlock , createVM , runBlock } from '../../../src/index.js'
@@ -14,14 +14,10 @@ const invalidRequestsRoot = hexToBytes(
1414 '0xc98048d6605eb79ecc08d90b8817f44911ec474acd8d11688453d2c6ef743bc5' ,
1515)
1616function getRandomDepositRequest ( ) : CLRequest < CLRequestType > {
17- const depositRequestData = {
18- pubkey : randomBytes ( 48 ) ,
19- withdrawalCredentials : randomBytes ( 32 ) ,
20- amount : randomBytes ( 8 ) ,
21- signature : randomBytes ( 96 ) ,
22- index : randomBytes ( 8 ) ,
23- }
24- return createDepositRequest ( depositRequestData ) as CLRequest < CLRequestType >
17+ const sampleDepositRequest = hexToBytes (
18+ '0x0000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030ac842878bb70009552a4cfcad801d6e659c50bd50d7d03306790cb455ce7363c5b6972f0159d170f625a99b2064dbefc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020010000000000000000000000818ccb1c4eda80270b04d6df822b1e72dd83c303000000000000000000000000000000000000000000000000000000000000000800405973070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060a747f75c72d0cf0d2b52504c7385b516f0523e2f0842416399f42b4aee5c6384a5674f6426b1cc3d0827886fa9b909e616f5c9f61f986013ed2b9bf37071cbae951136265b549f44e3c8e26233c0433e9124b7fd0dc86e82f9fedfc0a179d76900000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000' ,
19+ )
20+ return createCLRequest ( sampleDepositRequest )
2521}
2622
2723const common = new Common ( { chain : Mainnet , hardfork : Hardfork . Cancun , eips : [ 7685 ] } )
@@ -52,19 +48,19 @@ describe('EIP-7685 runBlock tests', () => {
5248 const requestsRoot = genRequestsRoot ( [ request ] , sha256 )
5349 const block = createBlock (
5450 {
55- requests : [ request ] ,
5651 header : { requestsRoot } ,
5752 } ,
5853 { common } ,
5954 )
6055 await expect ( async ( ) => runBlock ( vm , { block } ) ) . rejects . toThrow ( / i n v a l i d r e q u e s t s R o o t / )
6156 } )
57+
58+ // TODO: no way to test this without running block, why check why does this test pass
59+ // as it should not throw on some random request root
6260 it ( 'should error when requestsRoot does not match requests provided' , async ( ) => {
6361 const vm = await setupVM ( { common } )
64- const request = getRandomDepositRequest ( )
6562 const block = createBlock (
6663 {
67- requests : [ request ] ,
6864 header : { requestsRoot : invalidRequestsRoot } ,
6965 } ,
7066 { common } ,
@@ -91,8 +87,11 @@ describe('EIP 7685 buildBlock tests', () => {
9187 blockOpts : { calcDifficultyFromHeader : genesisBlock . header , freeze : false } ,
9288 } )
9389
94- const block = await blockBuilder . build ( )
90+ const { block } = await blockBuilder . build ( )
9591
96- assert . deepEqual ( block . header . requestsRoot , KECCAK256_RLP )
92+ assert . deepEqual (
93+ block . header . requestsRoot ,
94+ hexToBytes ( '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' ) ,
95+ )
9796 } )
9897} )
0 commit comments