Skip to content

Commit

Permalink
fix: remove references from old logger
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyaco committed Jul 31, 2024
1 parent 557a073 commit 163669b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions packages/blocknumber/src/providers/evmBlockNumberProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
UnsupportedBlockNumber,
UnsupportedBlockTimestamps,
} from "../exceptions/index.js";
import logger from "../utils/logger.js";
import { BlockNumberProvider } from "./blockNumberProvider.js";

const BINARY_SEARCH_BLOCKS_LOOKBACK = 10_000n;
Expand Down Expand Up @@ -201,15 +200,15 @@ export class EvmBlockNumberProvider implements BlockNumberProvider {

if (low > high) throw new UnexpectedSearchRange(low, high);

logger.debug(`Starting block binary search for timestamp ${timestamp}...`);
this.logger.debug(`Starting block binary search for timestamp ${timestamp}...`);

while (low <= high) {
currentBlockNumber = (high + low) / 2n;

const currentBlock = await this.client.getBlock({ blockNumber: currentBlockNumber });
const nextBlock = await this.client.getBlock({ blockNumber: currentBlockNumber + 1n });

logger.debug(
this.logger.debug(
`Analyzing block number #${currentBlock.number} with timestamp ${currentBlock.timestamp}`,
);

Expand All @@ -223,7 +222,7 @@ export class EvmBlockNumberProvider implements BlockNumberProvider {
currentBlock.timestamp <= timestamp && nextBlock.timestamp > timestamp;

if (blockContainsTimestamp) {
logger.debug(`Block #${currentBlock.number} contains timestamp.`);
this.logger.debug(`Block #${currentBlock.number} contains timestamp.`);

return currentBlock.number;
} else if (currentBlock.timestamp <= timestamp) {
Expand Down
1 change: 0 additions & 1 deletion packages/blocknumber/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./caip/caip2.js";
export * from "./logger.js";
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger } from "@ebo-agent/shared";
import { Block, createPublicClient, GetBlockParameters, http } from "viem";
import { mainnet } from "viem/chains";
import { describe, expect, it, vi } from "vitest";
Expand All @@ -21,7 +22,7 @@ describe("EvmBlockNumberProvider", () => {
const endTimestamp = Date.UTC(2024, 1, 11, 0, 0, 0, 0);
const rpcProvider = mockRpcProvider(blockNumber, startTimestamp, endTimestamp);

evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig);
evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger);

const day5 = Date.UTC(2024, 1, 5, 2, 0, 0, 0);
const epochBlockNumber = await evmProvider.getEpochBlockNumber(day5);
Expand All @@ -35,7 +36,7 @@ describe("EvmBlockNumberProvider", () => {
const endTimestamp = Date.UTC(2024, 1, 1, 0, 0, 11, 0);
const rpcProvider = mockRpcProvider(lastBlockNumber, startTimestamp, endTimestamp);

evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig);
evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger);

const exactDay5 = Date.UTC(2024, 1, 1, 0, 0, 5, 0);
const epochBlockNumber = await evmProvider.getEpochBlockNumber(exactDay5);
Expand All @@ -49,7 +50,7 @@ describe("EvmBlockNumberProvider", () => {
const endTimestamp = Date.UTC(2024, 1, 1, 0, 0, 11, 0);
const rpcProvider = mockRpcProvider(lastBlockNumber, startTimestamp, endTimestamp);

evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig);
evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger);

const futureTimestamp = Date.UTC(2025, 1, 1, 0, 0, 0, 0);

Expand All @@ -64,7 +65,7 @@ describe("EvmBlockNumberProvider", () => {
const endTimestamp = Date.UTC(2024, 1, 1, 0, 0, 11, 0);
const rpcProvider = mockRpcProvider(lastBlockNumber, startTimestamp, endTimestamp);

evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig);
evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger);

const futureTimestamp = Date.UTC(1970, 1, 1, 0, 0, 0, 0);

Expand All @@ -84,7 +85,7 @@ describe("EvmBlockNumberProvider", () => {
{ number: 4n, timestamp: afterTimestamp },
]);

evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig);
evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger);

expect(evmProvider.getEpochBlockNumber(Number(timestamp))).rejects.toBeInstanceOf(
UnsupportedBlockTimestamps,
Expand All @@ -97,7 +98,7 @@ describe("EvmBlockNumberProvider", () => {
{ number: null, timestamp: BigInt(timestamp) },
]);

evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig);
evmProvider = new EvmBlockNumberProvider(rpcProvider, searchConfig, logger);

expect(evmProvider.getEpochBlockNumber(Number(timestamp))).rejects.toBeInstanceOf(
UnsupportedBlockNumber,
Expand All @@ -109,7 +110,7 @@ describe("EvmBlockNumberProvider", () => {

client.getBlock = vi.fn().mockRejectedValue(null);

evmProvider = new EvmBlockNumberProvider(client, searchConfig);
evmProvider = new EvmBlockNumberProvider(client, searchConfig, logger);
const timestamp = Date.UTC(2024, 1, 1, 0, 0, 0, 0);

expect(evmProvider.getEpochBlockNumber(timestamp)).rejects.toBeDefined();
Expand Down

0 comments on commit 163669b

Please sign in to comment.