-
Notifications
You must be signed in to change notification settings - Fork 837
client: add blockTimestamp to eth_getLogs, add tests #4074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
aaeebe0
00f530a
45c563d
890d22c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import { createLegacyTx } from '@ethereumjs/tx' | ||
| import { bytesToHex, createContractAddress, hexToBytes } from '@ethereumjs/util' | ||
| import { | ||
| bigIntToHex, | ||
| bytesToHex, | ||
| createContractAddress, | ||
| hexToBigInt, | ||
| hexToBytes, | ||
| } from '@ethereumjs/util' | ||
| import { assert, describe, it } from 'vitest' | ||
|
|
||
| import { INVALID_PARAMS } from '../../../src/rpc/error-code.ts' | ||
|
|
@@ -75,7 +81,7 @@ describe(method, async () => { | |
| { common }, | ||
| ).sign(dummy.privKey) | ||
|
|
||
| await runBlockWithTxs(chain, execution, [tx1, tx2, tx3, tx4]) | ||
| let block = await runBlockWithTxs(chain, execution, [tx1, tx2, tx3, tx4]) | ||
|
|
||
| // compare the logs | ||
| let res = await rpc.request(method, [{ fromBlock: 'earliest', toBlock: 'latest' }]) | ||
|
|
@@ -100,6 +106,17 @@ describe(method, async () => { | |
| assert.fail(`should return the correct logs (fromBlock/toBlock as 'earliest' and 'latest')`) | ||
| } | ||
|
|
||
| if (hexToBigInt(res.result[0].blockTimestamp) === block.header.timestamp) { | ||
| assert.isTrue( | ||
| true, | ||
| `should return the correct blockTimestamp (fromBlock/toBlock as 'earliest' and 'latest')`, | ||
| ) | ||
| } else { | ||
| assert.fail( | ||
| `should return the correct blockTimestamp (fromBlock/toBlock as 'earliest' and 'latest')`, | ||
| ) | ||
| } | ||
|
|
||
| // get the logs using fromBlock/toBlock as numbers | ||
| res = await rpc.request(method, [{ fromBlock: '0x0', toBlock: '0x1' }]) | ||
| assert.strictEqual( | ||
|
|
@@ -206,6 +223,43 @@ describe(method, async () => { | |
| 20, | ||
| 'should return the correct logs (filter by blockHash)', | ||
| ) | ||
|
|
||
| // test adding more logs and checking timestamps against multiple blocks | ||
| const tx5 = createLegacyTx( | ||
| { | ||
| ...txData, | ||
| data, | ||
| to: contractAddr1, | ||
| nonce: 4, | ||
| }, | ||
| { common }, | ||
| ).sign(dummy.privKey) | ||
| const tx6 = createLegacyTx( | ||
| { | ||
| ...txData, | ||
| data, | ||
| to: contractAddr2, | ||
| nonce: 5, | ||
| }, | ||
| { common }, | ||
| ).sign(dummy.privKey) | ||
|
|
||
| const oldTimestamp = bigIntToHex(block.header.timestamp) | ||
| block = await runBlockWithTxs(chain, execution, [tx5, tx6]) | ||
| const newTimestamp = bigIntToHex(block.header.timestamp) | ||
|
|
||
| res = await rpc.request(method, [{ fromBlock: 'earliest', toBlock: 'latest' }]) | ||
|
|
||
| if ( | ||
| res.result[0].blockTimestamp === oldTimestamp && | ||
| res.result[10].blockTimestamp === oldTimestamp && | ||
| res.result[20].blockTimestamp === newTimestamp && | ||
| res.result[30].blockTimestamp === newTimestamp | ||
|
||
| ) { | ||
| assert.isTrue(true, 'should return the correct log timestamps across multiple blocks') | ||
| } else { | ||
| assert.fail('should return the correct log timestamps across multiple blocks') | ||
| } | ||
| }) | ||
|
|
||
| it('call with invalid params', async () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test should
assert.isEqualor something similar here, right? The if/else statement together withassert.fail/assert.isTrue(truesimulates the behavior of the equal checkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, was just following the style of the surrounding tests, which did this a fair bit