Skip to content

Commit

Permalink
refactor: rename evmProvider to evmBlockNumberProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyaco committed Jul 24, 2024
1 parent 4a38c03 commit 711216d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const BINARY_SEARCH_DELTA_MULTIPLIER = 2n;

type BlockWithNumber = Omit<Block, "number"> & { number: bigint };

export class EvmProvider implements BlockNumberProvider {
export class EvmBlockNumberProvider implements BlockNumberProvider {
client: PublicClient;

constructor(client: PublicClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import { describe, expect, it, vi } from "vitest";
import { TimestampNotFound } from "../../src/exceptions/timestampNotFound.js";
import { UnsupportedBlockNumber } from "../../src/exceptions/unsupportedBlockNumber.js";
import { UnsupportedBlockTimestamps } from "../../src/exceptions/unsupportedBlockTimestamps.js";
import { EvmProvider } from "../../src/providers/evmProvider.js";
import { EvmBlockNumberProvider } from "../../src/providers/evmBlockNumberProvider.js";

describe("EvmProvider", () => {
describe("EvmBlockNumberProvider", () => {
describe("getEpochBlockNumber", () => {
let evmProvider: EvmProvider;
let evmProvider: EvmBlockNumberProvider;

it("returns the first of two consecutive blocks when their timestamp contains the searched timestamp", async () => {
const blockNumber = 10n;
const startTimestamp = Date.UTC(2024, 1, 1, 0, 0, 0, 0);
const endTimestamp = Date.UTC(2024, 1, 11, 0, 0, 0, 0);
const rpcProvider = mockRpcProvider(blockNumber, startTimestamp, endTimestamp);

evmProvider = new EvmProvider(rpcProvider);
evmProvider = new EvmBlockNumberProvider(rpcProvider);

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

evmProvider = new EvmProvider(rpcProvider);
evmProvider = new EvmBlockNumberProvider(rpcProvider);

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

evmProvider = new EvmProvider(rpcProvider);
evmProvider = new EvmBlockNumberProvider(rpcProvider);

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

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

evmProvider = new EvmProvider(rpcProvider);
evmProvider = new EvmBlockNumberProvider(rpcProvider);

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

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

evmProvider = new EvmProvider(rpcProvider);
evmProvider = new EvmBlockNumberProvider(rpcProvider);

expect(
evmProvider.getEpochBlockNumber(Number(timestamp), { blocksLookback: 2n }),
Expand All @@ -101,7 +101,7 @@ describe("EvmProvider", () => {
{ number: null, timestamp: BigInt(timestamp) },
]);

evmProvider = new EvmProvider(rpcProvider);
evmProvider = new EvmBlockNumberProvider(rpcProvider);

expect(
evmProvider.getEpochBlockNumber(Number(timestamp), { blocksLookback: 2n }),
Expand All @@ -113,7 +113,7 @@ describe("EvmProvider", () => {

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

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

expect(
Expand Down

0 comments on commit 711216d

Please sign in to comment.