-
-
Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathdeposit.test.ts
99 lines (84 loc) · 3.5 KB
/
deposit.test.ts
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
import {describe, it, expect} from "vitest";
import {ssz} from "@lodestar/types";
import {createChainForkConfig} from "@lodestar/config";
import {MAX_DEPOSITS} from "@lodestar/params";
import {CachedBeaconStateElectra, getEth1DepositCount} from "../../../src/index.js";
import {createCachedBeaconStateTest} from "../../utils/state.js";
describe("getEth1DepositCount", () => {
it("Pre Electra", () => {
const stateView = ssz.altair.BeaconState.defaultViewDU();
const preElectraState = createCachedBeaconStateTest(stateView);
if (preElectraState.epochCtx.isAfterElectra()) {
throw Error("Not a pre-Electra state");
}
preElectraState.eth1Data.depositCount = 123;
// 1. Should get less than MAX_DEPOSIT
preElectraState.eth1DepositIndex = 120;
expect(getEth1DepositCount(preElectraState)).toBe(3);
// 2. Should get MAX_DEPOSIT
preElectraState.eth1DepositIndex = 100;
expect(getEth1DepositCount(preElectraState)).toBe(MAX_DEPOSITS);
});
it("Post Electra with eth1 deposit", () => {
const stateView = ssz.electra.BeaconState.defaultViewDU();
const postElectraState = createCachedBeaconStateTest(
stateView,
createChainForkConfig({
/* eslint-disable @typescript-eslint/naming-convention */
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: 0,
}),
{skipSyncCommitteeCache: true, skipSyncPubkeys: true}
) as CachedBeaconStateElectra;
if (!postElectraState.epochCtx.isAfterElectra()) {
throw Error("Not a post-Electra state");
}
postElectraState.depositRequestsStartIndex = 1000n;
postElectraState.eth1Data.depositCount = 995;
// 1. Should get less than MAX_DEPOSIT
postElectraState.eth1DepositIndex = 990;
expect(getEth1DepositCount(postElectraState)).toBe(5);
// 2. Should get MAX_DEPOSIT
postElectraState.eth1DepositIndex = 100;
expect(getEth1DepositCount(postElectraState)).toBe(MAX_DEPOSITS);
// 3. Should be 0
postElectraState.eth1DepositIndex = 1000;
expect(getEth1DepositCount(postElectraState)).toBe(0);
});
it("Post Electra without eth1 deposit", () => {
const stateView = ssz.electra.BeaconState.defaultViewDU();
const postElectraState = createCachedBeaconStateTest(
stateView,
createChainForkConfig({
/* eslint-disable @typescript-eslint/naming-convention */
ALTAIR_FORK_EPOCH: 0,
BELLATRIX_FORK_EPOCH: 0,
CAPELLA_FORK_EPOCH: 0,
DENEB_FORK_EPOCH: 0,
ELECTRA_FORK_EPOCH: 0,
}),
{skipSyncCommitteeCache: true, skipSyncPubkeys: true}
) as CachedBeaconStateElectra;
if (!postElectraState.epochCtx.isAfterElectra()) {
throw Error("Not a post-Electra state");
}
postElectraState.depositRequestsStartIndex = 1000n;
postElectraState.eth1Data.depositCount = 1005;
// Before eth1DepositIndex reaching the start index
// 1. Should get less than MAX_DEPOSIT
postElectraState.eth1DepositIndex = 990;
expect(getEth1DepositCount(postElectraState)).toBe(10);
// 2. Should get MAX_DEPOSIT
postElectraState.eth1DepositIndex = 983;
expect(getEth1DepositCount(postElectraState)).toBe(MAX_DEPOSITS);
// After eth1DepositIndex reaching the start index
// 1. Should be 0
postElectraState.eth1DepositIndex = 1000;
expect(getEth1DepositCount(postElectraState)).toBe(0);
postElectraState.eth1DepositIndex = 1003;
expect(getEth1DepositCount(postElectraState)).toBe(0);
});
});