|
1 | 1 | import {describe, it, expect} from "vitest";
|
2 | 2 | import {toHexString} from "@chainsafe/ssz";
|
3 |
| -import {phase0} from "@lodestar/types"; |
4 |
| -import {getValidatorStatus, getStateValidatorIndex} from "../../../../../../src/api/impl/beacon/state/utils.js"; |
| 3 | +import {getStateValidatorIndex} from "../../../../../../src/api/impl/beacon/state/utils.js"; |
5 | 4 | import {generateCachedAltairState} from "../../../../../utils/state.js";
|
6 | 5 |
|
7 | 6 | describe("beacon state api utils", function () {
|
8 |
| - describe("getValidatorStatus", function () { |
9 |
| - it("should return PENDING_INITIALIZED", function () { |
10 |
| - const validator = { |
11 |
| - activationEpoch: 1, |
12 |
| - activationEligibilityEpoch: Infinity, |
13 |
| - } as phase0.Validator; |
14 |
| - const currentEpoch = 0; |
15 |
| - const status = getValidatorStatus(validator, currentEpoch); |
16 |
| - expect(status).toBe("pending_initialized"); |
17 |
| - }); |
18 |
| - it("should return PENDING_QUEUED", function () { |
19 |
| - const validator = { |
20 |
| - activationEpoch: 1, |
21 |
| - activationEligibilityEpoch: 101010101101010, |
22 |
| - } as phase0.Validator; |
23 |
| - const currentEpoch = 0; |
24 |
| - const status = getValidatorStatus(validator, currentEpoch); |
25 |
| - expect(status).toBe("pending_queued"); |
26 |
| - }); |
27 |
| - it("should return ACTIVE_ONGOING", function () { |
28 |
| - const validator = { |
29 |
| - activationEpoch: 1, |
30 |
| - exitEpoch: Infinity, |
31 |
| - } as phase0.Validator; |
32 |
| - const currentEpoch = 1; |
33 |
| - const status = getValidatorStatus(validator, currentEpoch); |
34 |
| - expect(status).toBe("active_ongoing"); |
35 |
| - }); |
36 |
| - it("should return ACTIVE_SLASHED", function () { |
37 |
| - const validator = { |
38 |
| - activationEpoch: 1, |
39 |
| - exitEpoch: 101010101101010, |
40 |
| - slashed: true, |
41 |
| - } as phase0.Validator; |
42 |
| - const currentEpoch = 1; |
43 |
| - const status = getValidatorStatus(validator, currentEpoch); |
44 |
| - expect(status).toBe("active_slashed"); |
45 |
| - }); |
46 |
| - it("should return ACTIVE_EXITING", function () { |
47 |
| - const validator = { |
48 |
| - activationEpoch: 1, |
49 |
| - exitEpoch: 101010101101010, |
50 |
| - slashed: false, |
51 |
| - } as phase0.Validator; |
52 |
| - const currentEpoch = 1; |
53 |
| - const status = getValidatorStatus(validator, currentEpoch); |
54 |
| - expect(status).toBe("active_exiting"); |
55 |
| - }); |
56 |
| - it("should return EXITED_SLASHED", function () { |
57 |
| - const validator = { |
58 |
| - exitEpoch: 1, |
59 |
| - withdrawableEpoch: 3, |
60 |
| - slashed: true, |
61 |
| - } as phase0.Validator; |
62 |
| - const currentEpoch = 2; |
63 |
| - const status = getValidatorStatus(validator, currentEpoch); |
64 |
| - expect(status).toBe("exited_slashed"); |
65 |
| - }); |
66 |
| - it("should return EXITED_UNSLASHED", function () { |
67 |
| - const validator = { |
68 |
| - exitEpoch: 1, |
69 |
| - withdrawableEpoch: 3, |
70 |
| - slashed: false, |
71 |
| - } as phase0.Validator; |
72 |
| - const currentEpoch = 2; |
73 |
| - const status = getValidatorStatus(validator, currentEpoch); |
74 |
| - expect(status).toBe("exited_unslashed"); |
75 |
| - }); |
76 |
| - it("should return WITHDRAWAL_POSSIBLE", function () { |
77 |
| - const validator = { |
78 |
| - withdrawableEpoch: 1, |
79 |
| - effectiveBalance: 32, |
80 |
| - } as phase0.Validator; |
81 |
| - const currentEpoch = 1; |
82 |
| - const status = getValidatorStatus(validator, currentEpoch); |
83 |
| - expect(status).toBe("withdrawal_possible"); |
84 |
| - }); |
85 |
| - it("should return WITHDRAWAL_DONE", function () { |
86 |
| - const validator = { |
87 |
| - withdrawableEpoch: 1, |
88 |
| - effectiveBalance: 0, |
89 |
| - } as phase0.Validator; |
90 |
| - const currentEpoch = 1; |
91 |
| - const status = getValidatorStatus(validator, currentEpoch); |
92 |
| - expect(status).toBe("withdrawal_done"); |
93 |
| - }); |
94 |
| - it("should error", function () { |
95 |
| - const validator = {} as phase0.Validator; |
96 |
| - const currentEpoch = 0; |
97 |
| - try { |
98 |
| - getValidatorStatus(validator, currentEpoch); |
99 |
| - } catch (error) { |
100 |
| - expect(error).toHaveProperty("message", "ValidatorStatus unknown"); |
101 |
| - } |
102 |
| - }); |
103 |
| - }); |
104 |
| - |
105 | 7 | describe("getStateValidatorIndex", () => {
|
106 | 8 | const state = generateCachedAltairState();
|
107 | 9 | const pubkey2index = state.epochCtx.pubkey2index;
|
|
0 commit comments