mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 04:41:22 +00:00
state: err if 0 power validator is added to the validator set
Closes #1893
This commit is contained in:
@ -149,6 +149,79 @@ func TestBeginBlockByzantineValidators(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateValidators(t *testing.T) {
|
||||
pubkey1 := crypto.GenPrivKeyEd25519().PubKey()
|
||||
val1 := types.NewValidator(pubkey1, 10)
|
||||
pubkey2 := crypto.GenPrivKeyEd25519().PubKey()
|
||||
val2 := types.NewValidator(pubkey2, 20)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
currentSet *types.ValidatorSet
|
||||
abciUpdates []abci.Validator
|
||||
|
||||
resultingSet *types.ValidatorSet
|
||||
shouldErr bool
|
||||
}{
|
||||
{
|
||||
"adding a validator is OK",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
[]abci.Validator{{[]byte{}, types.TM2PB.PubKey(pubkey2), 20}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1, val2}),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"updating a validator is OK",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
[]abci.Validator{{[]byte{}, types.TM2PB.PubKey(pubkey1), 20}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{types.NewValidator(pubkey1, 20)}),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"removing a validator is OK",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1, val2}),
|
||||
[]abci.Validator{{[]byte{}, types.TM2PB.PubKey(pubkey2), 0}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"removing a non-existing validator results in error",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
[]abci.Validator{{[]byte{}, types.TM2PB.PubKey(pubkey2), 0}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := updateValidators(tc.currentSet, tc.abciUpdates)
|
||||
if tc.shouldErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
require.Equal(t, tc.resultingSet.Size(), tc.currentSet.Size())
|
||||
|
||||
assert.Equal(t, tc.resultingSet.TotalVotingPower(), tc.currentSet.TotalVotingPower())
|
||||
|
||||
assert.Equal(t, tc.resultingSet.Validators[0].Address, tc.currentSet.Validators[0].Address)
|
||||
if tc.resultingSet.Size() > 1 {
|
||||
assert.Equal(t, tc.resultingSet.Validators[1].Address, tc.currentSet.Validators[1].Address)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// make some bogus txs
|
||||
|
Reference in New Issue
Block a user