-
-
Notifications
You must be signed in to change notification settings - Fork 454
Expand file tree
/
Copy pathvalidatorStore.test.ts
More file actions
126 lines (111 loc) · 4.53 KB
/
validatorStore.test.ts
File metadata and controls
126 lines (111 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import {SecretKey} from "@chainsafe/blst";
import {fromHexString, toHexString} from "@chainsafe/ssz";
import {routes} from "@lodestar/api";
import {chainConfig} from "@lodestar/config/default";
import {bellatrix} from "@lodestar/types";
import {toBufferBE} from "bigint-buffer";
import {afterEach, beforeEach, describe, expect, it, vi} from "vitest";
import {ValidatorStore} from "../../src/services/validatorStore.js";
import {ValidatorProposerConfig} from "../../src/services/validatorStore.js";
import {getApiClientStub} from "../utils/apiStub.js";
import {initValidatorStore} from "../utils/validatorStore.js";
describe("ValidatorStore", () => {
const api = getApiClientStub();
let validatorStore: ValidatorStore;
let valProposerConfig: ValidatorProposerConfig;
beforeEach(async () => {
valProposerConfig = {
proposerConfig: {
[toHexString(pubkeys[0])]: {
graffiti: "graffiti",
strictFeeRecipientCheck: true,
feeRecipient: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
builder: {
gasLimit: 36000000,
selection: routes.validator.BuilderSelection.ExecutionOnly,
},
},
},
defaultConfig: {
graffiti: "default graffiti",
strictFeeRecipientCheck: false,
feeRecipient: "0xcccccccccccccccccccccccccccccccccccccccc",
builder: {
gasLimit: 35000000,
},
},
};
validatorStore = await initValidatorStore(secretKeys, api, chainConfig, valProposerConfig);
});
afterEach(() => {
vi.resetAllMocks();
});
it("Should validate graffiti,feeRecipient etc. from valProposerConfig and ValidatorStore", async () => {
//pubkeys[0] values
expect(validatorStore.getGraffiti(toHexString(pubkeys[0]))).toBe(
valProposerConfig.proposerConfig[toHexString(pubkeys[0])].graffiti
);
expect(validatorStore.getFeeRecipient(toHexString(pubkeys[0]))).toBe(
valProposerConfig.proposerConfig[toHexString(pubkeys[0])].feeRecipient
);
expect(validatorStore.strictFeeRecipientCheck(toHexString(pubkeys[0]))).toBe(
valProposerConfig.proposerConfig[toHexString(pubkeys[0])].strictFeeRecipientCheck
);
expect(validatorStore.getGasLimit(toHexString(pubkeys[0]))).toBe(
valProposerConfig.proposerConfig[toHexString(pubkeys[0])].builder?.gasLimit
);
// default values
expect(validatorStore.getGraffiti(toHexString(pubkeys[1]))).toBe(valProposerConfig.defaultConfig.graffiti);
expect(validatorStore.getFeeRecipient(toHexString(pubkeys[1]))).toBe(valProposerConfig.defaultConfig.feeRecipient);
expect(validatorStore.strictFeeRecipientCheck(toHexString(pubkeys[1]))).toBe(
valProposerConfig.defaultConfig.strictFeeRecipientCheck
);
expect(validatorStore.getGasLimit(toHexString(pubkeys[1]))).toBe(valProposerConfig.defaultConfig.builder?.gasLimit);
});
it("Should create/update builder data and return from cache next time", async () => {
let slot = 0;
const testCases: [bellatrix.SignedValidatorRegistrationV1, string, number][] = [
[valRegF00G100, "0x00", 100],
[valRegF10G100, "0x10", 100],
[valRegF10G200, "0x10", 200],
];
for (const [valReg, feeRecipient, gasLimit] of testCases) {
vi.spyOn(validatorStore, "signValidatorRegistration").mockResolvedValue(valReg);
const val1 = await validatorStore.getValidatorRegistration(pubkeys[0], {feeRecipient, gasLimit}, slot++);
expect(JSON.stringify(val1)).toEqual(JSON.stringify(valReg));
expect(validatorStore.signValidatorRegistration).toHaveBeenCalledOnce();
const val2 = await validatorStore.getValidatorRegistration(pubkeys[0], {feeRecipient, gasLimit}, slot++);
expect(JSON.stringify(val2)).toEqual(JSON.stringify(valReg));
expect(validatorStore.signValidatorRegistration).toHaveBeenCalledOnce();
}
});
});
const secretKeys = Array.from({length: 3}, (_, i) => SecretKey.fromBytes(toBufferBE(BigInt(i + 1), 32)));
const pubkeys = secretKeys.map((sk) => sk.toPublicKey().toBytes());
const valRegF00G100 = {
message: {
feeRecipient: fromHexString("0x00"),
gasLimit: 100,
timestamp: Date.now(),
pubkey: pubkeys[0],
},
signature: Buffer.alloc(96, 0),
};
const valRegF10G100 = {
message: {
feeRecipient: fromHexString("0x10"),
gasLimit: 100,
timestamp: Date.now(),
pubkey: pubkeys[0],
},
signature: Buffer.alloc(96, 0),
};
const valRegF10G200 = {
message: {
feeRecipient: fromHexString("0x10"),
gasLimit: 200,
timestamp: Date.now(),
pubkey: pubkeys[0],
},
signature: Buffer.alloc(96, 0),
};