11import { createLegacyTx } from '@ethereumjs/tx'
2- import { bytesToHex , createContractAddress , hexToBytes } from '@ethereumjs/util'
2+ import {
3+ bigIntToHex ,
4+ bytesToHex ,
5+ createContractAddress ,
6+ hexToBigInt ,
7+ hexToBytes ,
8+ } from '@ethereumjs/util'
39import { assert , describe , it } from 'vitest'
410
511import { INVALID_PARAMS } from '../../../src/rpc/error-code.ts'
@@ -75,7 +81,7 @@ describe(method, async () => {
7581 { common } ,
7682 ) . sign ( dummy . privKey )
7783
78- await runBlockWithTxs ( chain , execution , [ tx1 , tx2 , tx3 , tx4 ] )
84+ let block = await runBlockWithTxs ( chain , execution , [ tx1 , tx2 , tx3 , tx4 ] )
7985
8086 // compare the logs
8187 let res = await rpc . request ( method , [ { fromBlock : 'earliest' , toBlock : 'latest' } ] )
@@ -100,6 +106,12 @@ describe(method, async () => {
100106 assert . fail ( `should return the correct logs (fromBlock/toBlock as 'earliest' and 'latest')` )
101107 }
102108
109+ assert . strictEqual (
110+ hexToBigInt ( res . result [ 0 ] . blockTimestamp ) ,
111+ block . header . timestamp ,
112+ `should return the correct blockTimestamp (fromBlock/toBlock as 'earliest' and 'latest')` ,
113+ )
114+
103115 // get the logs using fromBlock/toBlock as numbers
104116 res = await rpc . request ( method , [ { fromBlock : '0x0' , toBlock : '0x1' } ] )
105117 assert . strictEqual (
@@ -206,6 +218,40 @@ describe(method, async () => {
206218 20 ,
207219 'should return the correct logs (filter by blockHash)' ,
208220 )
221+
222+ // test adding more logs and checking timestamps against multiple blocks
223+ const tx5 = createLegacyTx (
224+ {
225+ ...txData ,
226+ data,
227+ to : contractAddr1 ,
228+ nonce : 4 ,
229+ } ,
230+ { common } ,
231+ ) . sign ( dummy . privKey )
232+ const tx6 = createLegacyTx (
233+ {
234+ ...txData ,
235+ data,
236+ to : contractAddr2 ,
237+ nonce : 5 ,
238+ } ,
239+ { common } ,
240+ ) . sign ( dummy . privKey )
241+
242+ const block1Timestamp = bigIntToHex ( block . header . timestamp )
243+ block = await runBlockWithTxs ( chain , execution , [ tx5 , tx6 ] )
244+ const block2Timestamp = bigIntToHex ( block . header . timestamp )
245+
246+ res = await rpc . request ( method , [ { fromBlock : 'earliest' , toBlock : 'latest' } ] )
247+ const block1Logs : any [ ] = res . result . filter ( ( log : any ) => log . blockNumber === '0x1' )
248+ const block2Logs : any [ ] = res . result . filter ( ( log : any ) => log . blockNumber === '0x2' )
249+
250+ assert . isTrue (
251+ block1Logs . every ( ( log ) => log . blockTimestamp === block1Timestamp ) &&
252+ block2Logs . every ( ( log ) => log . blockTimestamp === block2Timestamp ) ,
253+ 'should return the correct log timestamps across multiple blocks' ,
254+ )
209255 } )
210256
211257 it ( 'call with invalid params' , async ( ) => {
0 commit comments