Skip to content
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

chore: fix beacon proposer cache unit tests #7335

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {beforeEach, describe, expect, it} from "vitest";
import {BeaconProposerCache} from "../../../src/chain/beaconProposerCache.js";

describe("BeaconProposerCache", () => {
const suggestedFeeRecipient = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
const feeRecipient1 = "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
const feeRecipient2 = "0xcccccccccccccccccccccccccccccccccccccccc";

const validatorIndex1 = 23;
const validatorIndex2 = 43;
const unknownValidatorIndex = 32;

let cache: BeaconProposerCache;

beforeEach(() => {
// max 2 items
cache = new BeaconProposerCache({suggestedFeeRecipient});
cache.add(1, {validatorIndex: validatorIndex1, feeRecipient: feeRecipient1});
cache.add(3, {validatorIndex: validatorIndex2, feeRecipient: feeRecipient2});
});

it("get default", () => {
expect(cache.getOrDefault(unknownValidatorIndex)).toBe(suggestedFeeRecipient);
});

it("get what has been set", () => {
expect(cache.get(validatorIndex1)).toBe(feeRecipient1);
});

it("override and get latest", () => {
const newFeeRecipient = "0xdddddddddddddddddddddddddddddddddddddddd";
cache.add(5, {validatorIndex: validatorIndex1, feeRecipient: newFeeRecipient});
expect(cache.get(validatorIndex1)).toBe(newFeeRecipient);
});

it("prune", () => {
cache.prune(4);

// Default for what has been pruned
expect(cache.getOrDefault(validatorIndex1)).toBe(suggestedFeeRecipient);

// Original for what hasn't been pruned
expect(cache.get(validatorIndex2)).toBe(feeRecipient2);
});
});
37 changes: 0 additions & 37 deletions packages/beacon-node/test/unit/chain/beaconProposerCache.ts

This file was deleted.

Loading