mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 22:23:11 +00:00
types: check if nil or empty valset (#5167)
Solves #5138 in the way that if a validatorSet is nil or empty it will not try to transform it to protobug Co-authored-by: Callum Michael Waters <cmwaters19@gmail.com>
This commit is contained in:
@@ -912,8 +912,8 @@ func (valz ValidatorsByAddress) Swap(i, j int) {
|
||||
|
||||
// ToProto converts ValidatorSet to protobuf
|
||||
func (vals *ValidatorSet) ToProto() (*tmproto.ValidatorSet, error) {
|
||||
if vals == nil {
|
||||
return nil, errors.New("nil validator set") // validator set should never be nil
|
||||
if vals.IsNilOrEmpty() {
|
||||
return &tmproto.ValidatorSet{}, nil // validator set should never be nil
|
||||
}
|
||||
|
||||
vp := new(tmproto.ValidatorSet)
|
||||
|
||||
@@ -1598,8 +1598,8 @@ func TestValidatorSetProtoBuf(t *testing.T) {
|
||||
{"fail valSet2, pubkey empty", valset2, false, false},
|
||||
{"fail nil Proposer", valset3, false, false},
|
||||
{"fail empty Proposer", valset4, false, false},
|
||||
{"fail empty valSet", &ValidatorSet{}, false, false},
|
||||
{"false nil", nil, false, false},
|
||||
{"fail empty valSet", &ValidatorSet{}, true, false},
|
||||
{"false nil", nil, true, false},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
protoValSet, err := tc.v1.ToProto()
|
||||
|
||||
Reference in New Issue
Block a user