-
Notifications
You must be signed in to change notification settings - Fork 922
/
eth1_data_test.go
87 lines (80 loc) · 2.05 KB
/
eth1_data_test.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
package blocks_test
import (
"fmt"
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params"
)
func FakeDeposits(n uint64) []*ethpb.Eth1Data {
deposits := make([]*ethpb.Eth1Data, n)
for i := uint64(0); i < n; i++ {
deposits[i] = ðpb.Eth1Data{
DepositCount: 1,
DepositRoot: []byte("root"),
}
}
return deposits
}
func TestEth1DataHasEnoughSupport(t *testing.T) {
tests := []struct {
stateVotes []*ethpb.Eth1Data
data *ethpb.Eth1Data
hasSupport bool
votingPeriodLength uint64
}{
{
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
data: ðpb.Eth1Data{
DepositCount: 1,
DepositRoot: []byte("root"),
},
hasSupport: true,
votingPeriodLength: 7,
}, {
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
data: ðpb.Eth1Data{
DepositCount: 1,
DepositRoot: []byte("root"),
},
hasSupport: false,
votingPeriodLength: 8,
}, {
stateVotes: FakeDeposits(4 * params.BeaconConfig().SlotsPerEpoch),
data: ðpb.Eth1Data{
DepositCount: 1,
DepositRoot: []byte("root"),
},
hasSupport: false,
votingPeriodLength: 10,
},
}
params.SetupTestConfigCleanup(t)
for i, tt := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
c := params.BeaconConfig()
c.EpochsPerEth1VotingPeriod = tt.votingPeriodLength
params.OverrideBeaconConfig(c)
s, err := beaconstate.InitializeFromProto(&pb.BeaconState{
Eth1DataVotes: tt.stateVotes,
})
if err != nil {
t.Fatal(err)
}
result, err := blocks.Eth1DataHasEnoughSupport(s, tt.data)
if err != nil {
t.Fatal(err)
}
if result != tt.hasSupport {
t.Errorf(
"blocks.Eth1DataHasEnoughSupport(%+v) = %t, wanted %t",
tt.data,
result,
tt.hasSupport,
)
}
})
}
}