-
Notifications
You must be signed in to change notification settings - Fork 199
/
nodesCoordinatorMock.go
181 lines (149 loc) · 5.18 KB
/
nodesCoordinatorMock.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package mock
import (
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/sharding"
)
// NodesCoordinatorMock -
type NodesCoordinatorMock struct {
ComputeValidatorsGroupCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]sharding.Validator, error)
GetValidatorsPublicKeysCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error)
GetValidatorsRewardsAddressesCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error)
GetAllEligibleValidatorsPublicKeysCalled func() (map[uint32][][]byte, error)
}
// GetAllLeavingValidatorsPublicKeys -
func (ncm *NodesCoordinatorMock) GetAllLeavingValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) {
return nil, nil
}
// GetAllEligibleValidatorsPublicKeys -
func (ncm *NodesCoordinatorMock) GetAllEligibleValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) {
if ncm.GetAllEligibleValidatorsPublicKeysCalled != nil {
return ncm.GetAllEligibleValidatorsPublicKeysCalled()
}
return nil, nil
}
// GetAllWaitingValidatorsPublicKeys -
func (ncm *NodesCoordinatorMock) GetAllWaitingValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) {
return nil, nil
}
// ComputeConsensusGroup -
func (ncm *NodesCoordinatorMock) ComputeConsensusGroup(
randomness []byte,
round uint64,
shardId uint32,
epoch uint32,
) (validatorsGroup []sharding.Validator, err error) {
if ncm.ComputeValidatorsGroupCalled != nil {
return ncm.ComputeValidatorsGroupCalled(randomness, round, shardId, epoch)
}
list := []sharding.Validator{
NewValidatorMock([]byte("A"), 1, 1),
NewValidatorMock([]byte("B"), 1, 1),
NewValidatorMock([]byte("C"), 1, 1),
NewValidatorMock([]byte("D"), 1, 1),
NewValidatorMock([]byte("E"), 1, 1),
NewValidatorMock([]byte("F"), 1, 1),
NewValidatorMock([]byte("G"), 1, 1),
NewValidatorMock([]byte("H"), 1, 1),
NewValidatorMock([]byte("I"), 1, 1),
}
return list, nil
}
// GetNumTotalEligible -
func (ncm *NodesCoordinatorMock) GetNumTotalEligible() uint64 {
return 1
}
// ConsensusGroupSize -
func (ncm *NodesCoordinatorMock) ConsensusGroupSize(uint32) int {
return 1
}
// GetConsensusValidatorsPublicKeys -
func (ncm *NodesCoordinatorMock) GetConsensusValidatorsPublicKeys(
randomness []byte,
round uint64,
shardId uint32,
epoch uint32,
) ([]string, error) {
if ncm.GetValidatorsPublicKeysCalled != nil {
return ncm.GetValidatorsPublicKeysCalled(randomness, round, shardId, epoch)
}
validators, err := ncm.ComputeConsensusGroup(randomness, round, shardId, epoch)
if err != nil {
return nil, err
}
pubKeys := make([]string, 0)
for _, v := range validators {
pubKeys = append(pubKeys, string(v.PubKey()))
}
return pubKeys, nil
}
// SetNodesPerShards -
func (ncm *NodesCoordinatorMock) SetNodesPerShards(
_ map[uint32][]sharding.Validator,
_ map[uint32][]sharding.Validator,
_ uint32,
) error {
return nil
}
// ComputeAdditionalLeaving -
func (ncm *NodesCoordinatorMock) ComputeAdditionalLeaving([]*state.ShardValidatorInfo) (map[uint32][]sharding.Validator, error) {
return make(map[uint32][]sharding.Validator), nil
}
// LoadState -
func (ncm *NodesCoordinatorMock) LoadState(_ []byte) error {
return nil
}
// GetSavedStateKey -
func (ncm *NodesCoordinatorMock) GetSavedStateKey() []byte {
return []byte("key")
}
// ShardIdForEpoch returns the nodesCoordinator configured ShardId for specified epoch if epoch configuration exists,
// otherwise error
func (ncm *NodesCoordinatorMock) ShardIdForEpoch(_ uint32) (uint32, error) {
panic("not implemented")
}
// ShuffleOutForEpoch verifies if the shards changed in the new epoch and calls the shuffleOutHandler
func (ncm *NodesCoordinatorMock) ShuffleOutForEpoch(_ uint32) {
panic("not implemented")
}
// GetConsensusWhitelistedNodes return the whitelisted nodes allowed to send consensus messages, for each of the shards
func (ncm *NodesCoordinatorMock) GetConsensusWhitelistedNodes(
_ uint32,
) (map[string]struct{}, error) {
return make(map[string]struct{}), nil
}
// SetConsensusGroupSize -
func (ncm *NodesCoordinatorMock) SetConsensusGroupSize(_ int) error {
panic("implement me")
}
// GetSelectedPublicKeys -
func (ncm *NodesCoordinatorMock) GetSelectedPublicKeys(_ []byte, _ uint32, _ uint32) (publicKeys []string, err error) {
panic("implement me")
}
// GetValidatorWithPublicKey -
func (ncm *NodesCoordinatorMock) GetValidatorWithPublicKey(_ []byte) (sharding.Validator, uint32, error) {
panic("implement me")
}
// GetValidatorsIndexes -
func (ncm *NodesCoordinatorMock) GetValidatorsIndexes(_ []string, _ uint32) ([]uint64, error) {
panic("implement me")
}
// GetOwnPublicKey -
func (ncm *NodesCoordinatorMock) GetOwnPublicKey() []byte {
panic("implement me")
}
// ValidatorsWeights -
func (ncm *NodesCoordinatorMock) ValidatorsWeights(validators []sharding.Validator) ([]uint32, error) {
weights := make([]uint32, len(validators))
for i := range validators {
weights[i] = 1
}
return weights, nil
}
// GetChance -
func (ncm *NodesCoordinatorMock) GetChance(uint32) uint32 {
return 1
}
// IsInterfaceNil returns true if there is no value under the interface
func (ncm *NodesCoordinatorMock) IsInterfaceNil() bool {
return ncm == nil
}