-
Notifications
You must be signed in to change notification settings - Fork 199
/
nodesCoordinatorMock.go
119 lines (94 loc) · 3.39 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
package mock
import (
"math/big"
"github.com/ElrondNetwork/elrond-go/sharding"
)
type NodesCoordinatorMock struct {
ComputeValidatorsGroupCalled func(randomness []byte, round uint64, shardId uint32) ([]sharding.Validator, error)
GetValidatorsPublicKeysCalled func(randomness []byte, round uint64, shardId uint32) ([]string, error)
GetValidatorsRewardsAddressesCalled func(randomness []byte, round uint64, shardId uint32) ([]string, error)
}
func (ncm *NodesCoordinatorMock) ComputeValidatorsGroup(
randomness []byte,
round uint64,
shardId uint32,
) (validatorsGroup []sharding.Validator, err error) {
if ncm.ComputeValidatorsGroupCalled != nil {
return ncm.ComputeValidatorsGroupCalled(randomness, round, shardId)
}
list := []sharding.Validator{
NewValidatorMock(big.NewInt(0), 0, []byte("A"), []byte("AA")),
NewValidatorMock(big.NewInt(0), 0, []byte("B"), []byte("BB")),
NewValidatorMock(big.NewInt(0), 0, []byte("C"), []byte("CC")),
NewValidatorMock(big.NewInt(0), 0, []byte("D"), []byte("DD")),
NewValidatorMock(big.NewInt(0), 0, []byte("E"), []byte("EE")),
NewValidatorMock(big.NewInt(0), 0, []byte("F"), []byte("FF")),
NewValidatorMock(big.NewInt(0), 0, []byte("G"), []byte("GG")),
NewValidatorMock(big.NewInt(0), 0, []byte("H"), []byte("HH")),
NewValidatorMock(big.NewInt(0), 0, []byte("I"), []byte("II")),
}
return list, nil
}
func (ncm *NodesCoordinatorMock) GetAllValidatorsPublicKeys() map[uint32][][]byte {
return nil
}
func (ncm *NodesCoordinatorMock) GetValidatorsIndexes(publicKeys []string) []uint64 {
return nil
}
func (ncm *NodesCoordinatorMock) GetValidatorsPublicKeys(randomness []byte, round uint64, shardId uint32) ([]string, error) {
if ncm.GetValidatorsPublicKeysCalled != nil {
return ncm.GetValidatorsPublicKeysCalled(randomness, round, shardId)
}
validators, err := ncm.ComputeValidatorsGroup(randomness, round, shardId)
if err != nil {
return nil, err
}
pubKeys := make([]string, 0)
for _, v := range validators {
pubKeys = append(pubKeys, string(v.PubKey()))
}
return pubKeys, nil
}
func (ncm *NodesCoordinatorMock) GetValidatorsRewardsAddresses(
randomness []byte,
round uint64,
shardId uint32,
) ([]string, error) {
if ncm.GetValidatorsPublicKeysCalled != nil {
return ncm.GetValidatorsRewardsAddressesCalled(randomness, round, shardId)
}
validators, err := ncm.ComputeValidatorsGroup(randomness, round, shardId)
if err != nil {
return nil, err
}
addresses := make([]string, 0)
for _, v := range validators {
addresses = append(addresses, string(v.Address()))
}
return addresses, nil
}
func (ncm *NodesCoordinatorMock) ConsensusGroupSize(shardId uint32) int {
panic("implement me")
}
func (ncm *NodesCoordinatorMock) SetNodesPerShards(map[uint32][]sharding.Validator) error {
return nil
}
func (ncm *NodesCoordinatorMock) SetConsensusGroupSize(int) error {
panic("implement me")
}
func (ncm *NodesCoordinatorMock) GetSelectedPublicKeys(selection []byte, shardId uint32) (publicKeys []string, err error) {
panic("implement me")
}
func (ncm *NodesCoordinatorMock) GetValidatorWithPublicKey(publicKey []byte) (sharding.Validator, uint32, error) {
panic("implement me")
}
func (ncm *NodesCoordinatorMock) GetOwnPublicKey() []byte {
panic("implement me")
}
// IsInterfaceNil returns true if there is no value under the interface
func (ncm *NodesCoordinatorMock) IsInterfaceNil() bool {
if ncm == nil {
return true
}
return false
}