Skip to content

Commit c9bb826

Browse files
authored
chore: fix beacon proposer cache unit tests (#7335)
* chore: fix beacon proposer cache unit tests * Assign values to named constants
1 parent d41fb55 commit c9bb826

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {beforeEach, describe, expect, it} from "vitest";
2+
import {BeaconProposerCache} from "../../../src/chain/beaconProposerCache.js";
3+
4+
describe("BeaconProposerCache", () => {
5+
const suggestedFeeRecipient = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
6+
const feeRecipient1 = "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
7+
const feeRecipient2 = "0xcccccccccccccccccccccccccccccccccccccccc";
8+
9+
const validatorIndex1 = 23;
10+
const validatorIndex2 = 43;
11+
const unknownValidatorIndex = 32;
12+
13+
let cache: BeaconProposerCache;
14+
15+
beforeEach(() => {
16+
// max 2 items
17+
cache = new BeaconProposerCache({suggestedFeeRecipient});
18+
cache.add(1, {validatorIndex: validatorIndex1, feeRecipient: feeRecipient1});
19+
cache.add(3, {validatorIndex: validatorIndex2, feeRecipient: feeRecipient2});
20+
});
21+
22+
it("get default", () => {
23+
expect(cache.getOrDefault(unknownValidatorIndex)).toBe(suggestedFeeRecipient);
24+
});
25+
26+
it("get what has been set", () => {
27+
expect(cache.get(validatorIndex1)).toBe(feeRecipient1);
28+
});
29+
30+
it("override and get latest", () => {
31+
const newFeeRecipient = "0xdddddddddddddddddddddddddddddddddddddddd";
32+
cache.add(5, {validatorIndex: validatorIndex1, feeRecipient: newFeeRecipient});
33+
expect(cache.get(validatorIndex1)).toBe(newFeeRecipient);
34+
});
35+
36+
it("prune", () => {
37+
cache.prune(4);
38+
39+
// Default for what has been pruned
40+
expect(cache.getOrDefault(validatorIndex1)).toBe(suggestedFeeRecipient);
41+
42+
// Original for what hasn't been pruned
43+
expect(cache.get(validatorIndex2)).toBe(feeRecipient2);
44+
});
45+
});

packages/beacon-node/test/unit/chain/beaconProposerCache.ts

-37
This file was deleted.

0 commit comments

Comments
 (0)