-
Notifications
You must be signed in to change notification settings - Fork 1k
/
getters_checkpoint.go
99 lines (75 loc) · 3.14 KB
/
getters_checkpoint.go
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
package testing
import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"testing"
)
func VerifyBeaconStateJustificationBitsNil(t *testing.T, factory getState) {
s, err := factory()
require.NoError(t, err)
require.DeepEqual(t, bitfield.Bitvector4{}.Bytes(), s.JustificationBits().Bytes())
}
type getStateWithJustificationBits = func(bitfield.Bitvector4) (state.BeaconState, error)
func VerifyBeaconStateJustificationBits(t *testing.T, factory getStateWithJustificationBits) {
s, err := factory(bitfield.Bitvector4{1, 2, 3, 4})
require.NoError(t, err)
require.DeepEqual(t, bitfield.Bitvector4{1, 2, 3, 4}.Bytes(), s.JustificationBits().Bytes())
}
func VerifyBeaconStatePreviousJustifiedCheckpointNil(t *testing.T, factory getState) {
s, err := factory()
require.NoError(t, err)
checkpoint := s.PreviousJustifiedCheckpoint()
require.Equal(t, (*ethpb.Checkpoint)(nil), checkpoint)
}
type getStateWithCheckpoint = func(checkpoint *ethpb.Checkpoint) (state.BeaconState, error)
func VerifyBeaconStatePreviousJustifiedCheckpoint(t *testing.T, factory getStateWithCheckpoint) {
orgCheckpoint := ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}
orgCheckpoint.Root[1] = 1
orgCheckpoint.Root[2] = 2
orgCheckpoint.Root[3] = 3
s, err := factory(orgCheckpoint)
require.NoError(t, err)
checkpoint := s.PreviousJustifiedCheckpoint()
require.DeepEqual(t, orgCheckpoint.Root, checkpoint.Root)
}
func VerifyBeaconStateCurrentJustifiedCheckpointNil(t *testing.T, factory getState) {
s, err := factory()
require.NoError(t, err)
checkpoint := s.CurrentJustifiedCheckpoint()
require.Equal(t, (*ethpb.Checkpoint)(nil), checkpoint)
}
func VerifyBeaconStateCurrentJustifiedCheckpoint(t *testing.T, factory getStateWithCheckpoint) {
orgCheckpoint := ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}
orgCheckpoint.Root[1] = 1
orgCheckpoint.Root[2] = 2
orgCheckpoint.Root[3] = 3
s, err := factory(orgCheckpoint)
require.NoError(t, err)
checkpoint := s.CurrentJustifiedCheckpoint()
require.DeepEqual(t, orgCheckpoint.Root, checkpoint.Root)
}
func VerifyBeaconStateFinalizedCheckpointNil(t *testing.T, factory getState) {
s, err := factory()
require.NoError(t, err)
checkpoint := s.FinalizedCheckpoint()
require.Equal(t, (*ethpb.Checkpoint)(nil), checkpoint)
epoch := s.FinalizedCheckpointEpoch()
require.Equal(t, primitives.Epoch(0), epoch)
}
func VerifyBeaconStateFinalizedCheckpoint(t *testing.T, factory getStateWithCheckpoint) {
orgCheckpoint := ðpb.Checkpoint{Root: make([]byte, fieldparams.RootLength)}
orgCheckpoint.Root[1] = 1
orgCheckpoint.Root[2] = 2
orgCheckpoint.Root[3] = 3
orgCheckpoint.Epoch = 123
s, err := factory(orgCheckpoint)
require.NoError(t, err)
checkpoint := s.FinalizedCheckpoint()
require.DeepEqual(t, orgCheckpoint.Root, checkpoint.Root)
epoch := s.FinalizedCheckpointEpoch()
require.Equal(t, orgCheckpoint.Epoch, epoch)
}