Skip to content

Commit

Permalink
🐛 Fix: bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
William Cory authored and William Cory committed Aug 12, 2024
1 parent 044e7a1 commit 087b0f9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
5 changes: 1 addition & 4 deletions packages/actions/src/eth/ethGetLogsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ const parseBlockParam = async (blockchain, blockParam) => {
* @returns {import('./EthHandler.js').EthGetLogsHandler}
*/
export const ethGetLogsHandler = (client) => async (params) => {
params.filterParams.topics
params.filterParams.address

client.logger.debug(params, 'blockNumberHandler called with params')
const vm = await client.getVm()
const receiptsManager = await client.getReceiptsManager()
Expand Down Expand Up @@ -172,7 +169,7 @@ export const ethGetLogsHandler = (client) => async (params) => {
}

const cachedLogs = await receiptsManager.getLogs(
fetchFromRpc ? fromBlock : /** @type {import('@tevm/block').Block}*/ (forkedBlock),
fetchFromRpc ? /** @type {import('@tevm/block').Block}*/ (forkedBlock) : fromBlock,
toBlock,
params.filterParams.address !== undefined ? [createAddress(params.filterParams.address).bytes] : [],
params.filterParams.topics?.map((topic) => hexToBytes(topic)),
Expand Down
6 changes: 3 additions & 3 deletions packages/actions/src/eth/ethNewFilterHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { parseBlockTag } from './utils/parseBlockTag.js'
*/
export const ethNewFilterHandler = (tevmNode) => {
return async (params) => {
const { topics, address, toBlock = 'latest', fromBlock = 'latest' } = params
const { topics, address, toBlock = 'latest', fromBlock } = params
const vm = await tevmNode.getVm()
/**
* @param {typeof toBlock} tag
Expand Down Expand Up @@ -43,7 +43,7 @@ export const ethNewFilterHandler = (tevmNode) => {
if (!_toBlock) {
throw new UnknownBlockError(`Unknown block tag ${toBlock}`)
}
const _fromBlock = await getBlock(fromBlock)
const _fromBlock = await getBlock(fromBlock ?? 'latest')
if (!_fromBlock) {
throw new UnknownBlockError(`Unknown block tag ${fromBlock}`)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ export const ethNewFilterHandler = (tevmNode) => {
topics,
address,
toBlock: toBlock,
fromBlock: fromBlock,
fromBlock: fromBlock ?? _fromBlock.header.number,
},
installed: {},
err: undefined,
Expand Down
5 changes: 2 additions & 3 deletions packages/procedures/src/eth/ethGetFilterLogsProcedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const ethGetFilterLogsProcedure = (client) => {
try {
const ethGetLogsResult = await ethGetLogsHandler(client)({
filterParams: {
fromBlock: filter.logsCriteria.fromBlock,
toBlock: filter.logsCriteria.toBlock,
fromBlock: filter.logsCriteria.fromBlock?.header?.number ?? 0n,
toBlock: filter.logsCriteria.toBlock?.header?.number ?? 'latest',
address: filter.logsCriteria.address,
topics: filter.logsCriteria.topics,
},
Expand All @@ -50,7 +50,6 @@ export const ethGetFilterLogsProcedure = (client) => {
result: jsonRpcResult,
}
} catch (e) {
console.log(e)
return {
...(request.id ? { id: request.id } : {}),
method: request.method,
Expand Down
20 changes: 18 additions & 2 deletions packages/procedures/src/eth/ethGetFilterLogsProcedure.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createAddress, createContractAddress } from '@tevm/address'
import { type TevmNode, createTevmNode } from '@tevm/node'
import { SimpleContract } from '@tevm/contract'
import { PREFUNDED_ACCOUNTS, encodeDeployData, encodeFunctionData, numberToHex } from '@tevm/utils'
import { PREFUNDED_ACCOUNTS, encodeDeployData, encodeFunctionData, isHex, numberToHex } from '@tevm/utils'
import { beforeEach, describe, expect, it } from 'vitest'
import { callProcedure } from '../call/callProcedure.js'
import { mineProcedure } from '../mine/mineProcedure.js'
Expand Down Expand Up @@ -79,6 +79,22 @@ describe(ethGetFilterLogsProcedure.name, () => {
expect(error).toBeUndefined()

expect(result).toHaveLength(1)
expect(result).toMatchInlineSnapshot()
const { blockHash, ...deterministicResult } = result?.[0] ?? {}
expect(isHex(blockHash)).toBe(true)
expect(blockHash).toHaveLength(66)
expect(deterministicResult).toMatchInlineSnapshot(`
{
"address": "0x5fbdb2315678afecb367f032d93f642f64180aa3",
"blockNumber": "0x2",
"data": "0x0000000000000000000000000000000000000000000000000000000000000045",
"logIndex": "0x0",
"removed": false,
"topics": [
"0x012c78e2b84325878b1bd9d250d772cfe5bda7722d795f45036fa5e1e6e303fc",
],
"transactionHash": "0x26de6f137bcebaa05e276447f69158f66910b461e47afca6fe67360833698708",
"transactionIndex": "0x0",
}
`)
})
})

0 comments on commit 087b0f9

Please sign in to comment.