11import { createBlock } from '@ethereumjs/block'
22import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
3- import { RLP } from '@ethereumjs/rlp'
43import { createLegacyTx } from '@ethereumjs/tx'
54import {
65 Account ,
@@ -15,7 +14,7 @@ import {
1514} from '@ethereumjs/util'
1615import { assert , describe , it } from 'vitest'
1716
18- import { bytesToBigInt } from '../../../../util/src/bytes .js'
17+ import { CLRequestType } from '../../../../util/src/request .js'
1918import { runBlock } from '../../../src/index.js'
2019import { setupVM } from '../utils.js'
2120
@@ -33,11 +32,11 @@ const deploymentTxData = {
3332 gasLimit : BigInt ( '0x3d090' ) ,
3433 gasPrice : BigInt ( '0xe8d4a51000' ) ,
3534 data : hexToBytes (
36- '0x61049d5f556101af80600f5f395ff33373fffffffffffffffffffffffffffffffffffffffe1460a0573615156028575f545f5260205ff35b36603814156101ab5760115f54600182026001905f5b5f82111560595781019083028483029004916001019190603e565b9093900434106101ab57600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160b4575060105b5f5b8181146101585780604c02838201600302600401805490600101805490600101549160601b83528260140152807fffffffffffffffffffffffffffffffff0000000000000000000000000000000016826034015260401c906044018160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160b6565b910180921461016a5790600255610175565b90505f6002555f6003555b5f548061049d141561018457505f5b6001546002828201116101995750505f61019f565b01600290035b5f555f600155604c025ff35b5f5ffd' ,
35+ '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5f556101f480602d5f395ff33373fffffffffffffffffffffffffffffffffffffffe1460c7573615156028575f545f5260205ff35b36603814156101f05760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f057600182026001905f5b5f821115608057810190830284830290049160010191906065565b9093900434106101f057600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160db575060105b5f5b81811461017f5780604c02838201600302600401805490600101805490600101549160601b83528260140152807fffffffffffffffffffffffffffffffff0000000000000000000000000000000016826034015260401c906044018160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160dd565b9101809214610191579060025561019c565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101c957505f5b6001546002828201116101de5750505f6101e4565b01600290035b5f555f600155604c025ff35b5f5ffd' ,
3736 ) ,
3837 v : BigInt ( '0x1b' ) ,
3938 r : BigInt ( '0x539' ) ,
40- s : BigInt ( '0x48655fec580f6877 ' ) ,
39+ s : BigInt ( '0x10e740537d4d36b9 ' ) ,
4140}
4241
4342const deploymentTx = createLegacyTx ( deploymentTxData )
@@ -111,29 +110,34 @@ describe('EIP-7002 tests', () => {
111110 generatedBlock = e . block
112111 } )
113112
114- await runBlock ( vm , {
113+ let runBlockResults = await runBlock ( vm , {
115114 block : block2 ,
116115 skipHeaderValidation : true ,
117116 skipBlockValidation : true ,
118117 generate : true ,
119118 } )
120119
121120 // Ensure the request is generated
122- assert . ok ( generatedBlock ! . requests ! . length === 1 )
123-
124- const requestDecoded = RLP . decode ( generatedBlock ! . requests ! [ 0 ] . serialize ( ) . slice ( 1 ) )
121+ assert . ok ( runBlockResults . requests ! . length === 1 )
122+ assert . equal (
123+ generatedBlock ! . transactions . length ,
124+ 1 ,
125+ 'withdrawal transaction should be included' ,
126+ )
125127
126- const sourceAddressRequest = requestDecoded [ 0 ] as Uint8Array
127- const validatorPubkeyRequest = requestDecoded [ 1 ] as Uint8Array
128- const amountRequest = requestDecoded [ 2 ] as Uint8Array
128+ const withdrawalRequest = runBlockResults . requests ! [ 0 ]
129+ assert ( withdrawalRequest . type , CLRequestType . Withdrawal , 'make sure its withdrawal request' )
129130
131+ // amount is in le when contract pack it in requests
132+ const expectedRequestData = concatBytes (
133+ tx . getSenderAddress ( ) . bytes ,
134+ validatorPubkey ,
135+ amountBytes . reverse ( ) ,
136+ )
130137 // Ensure the requests are correct
131- assert . ok ( equalsBytes ( sourceAddressRequest , tx . getSenderAddress ( ) . bytes ) )
132- assert . ok ( equalsBytes ( validatorPubkey , validatorPubkeyRequest ) )
133- // the direct byte comparison fails because leading zeros have been stripped
134- // off the amountBytes because it was serialized in request from bigint
135- assert . equal ( bytesToBigInt ( amountBytes ) , bytesToBigInt ( amountRequest ) )
138+ assert . ok ( equalsBytes ( expectedRequestData , withdrawalRequest . data ) )
136139
140+ // generated block should be valid
137141 await runBlock ( vm , { block : generatedBlock ! , skipHeaderValidation : true , root } )
138142
139143 // Run block with 2 requests
@@ -152,7 +156,7 @@ describe('EIP-7002 tests', () => {
152156 { common } ,
153157 )
154158
155- await runBlock ( vm , {
159+ runBlockResults = await runBlock ( vm , {
156160 block : block3 ,
157161 skipHeaderValidation : true ,
158162 skipBlockValidation : true ,
@@ -161,7 +165,12 @@ describe('EIP-7002 tests', () => {
161165
162166 // Note: generatedBlock is now overridden with the new generated block (this is thus block number 3)
163167 // Ensure there are 2 requests
164- assert . ok ( generatedBlock ! . requests ! . length === 2 )
168+ assert . ok ( runBlockResults . requests ! . length === 1 )
169+ assert . equal (
170+ generatedBlock ! . transactions . length ,
171+ 2 ,
172+ 'withdrawal transactions should be included' ,
173+ )
165174 } )
166175
167176 it ( 'should throw when contract is not deployed' , async ( ) => {
0 commit comments