MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestUpdateValidators

Function TestUpdateValidators

state/execution_test.go:280–351  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

278}
279
280func TestUpdateValidators(t *testing.T) {
281 pubkey1 := ed25519.GenPrivKey().PubKey()
282 val1 := types.NewValidator(pubkey1, 10)
283 pubkey2 := ed25519.GenPrivKey().PubKey()
284 val2 := types.NewValidator(pubkey2, 20)
285
286 pk, err := cryptoenc.PubKeyToProto(pubkey1)
287 require.NoError(t, err)
288 pk2, err := cryptoenc.PubKeyToProto(pubkey2)
289 require.NoError(t, err)
290
291 testCases := []struct {
292 name string
293
294 currentSet *types.ValidatorSet
295 abciUpdates []abci.ValidatorUpdate
296
297 resultingSet *types.ValidatorSet
298 shouldErr bool
299 }{
300 {
301 "adding a validator is OK",
302 types.NewValidatorSet([]*types.Validator{val1}),
303 []abci.ValidatorUpdate{{PubKey: pk2, Power: 20}},
304 types.NewValidatorSet([]*types.Validator{val1, val2}),
305 false,
306 },
307 {
308 "updating a validator is OK",
309 types.NewValidatorSet([]*types.Validator{val1}),
310 []abci.ValidatorUpdate{{PubKey: pk, Power: 20}},
311 types.NewValidatorSet([]*types.Validator{types.NewValidator(pubkey1, 20)}),
312 false,
313 },
314 {
315 "removing a validator is OK",
316 types.NewValidatorSet([]*types.Validator{val1, val2}),
317 []abci.ValidatorUpdate{{PubKey: pk2, Power: 0}},
318 types.NewValidatorSet([]*types.Validator{val1}),
319 false,
320 },
321 {
322 "removing a non-existing validator results in error",
323 types.NewValidatorSet([]*types.Validator{val1}),
324 []abci.ValidatorUpdate{{PubKey: pk2, Power: 0}},
325 types.NewValidatorSet([]*types.Validator{val1}),
326 true,
327 },
328 }
329
330 for _, tc := range testCases {
331 tc := tc
332 t.Run(tc.name, func(t *testing.T) {
333 updates, err := types.PB2TM.ValidatorUpdates(tc.abciUpdates)
334 assert.NoError(t, err)
335 err = tc.currentSet.UpdateWithChangeSet(updates)
336 if tc.shouldErr {
337 assert.Error(t, err)

Callers

nothing calls this directly

Calls 11

GenPrivKeyFunction · 0.92
NewValidatorFunction · 0.92
NewValidatorSetFunction · 0.92
UpdateWithChangeSetMethod · 0.80
TotalVotingPowerMethod · 0.80
PubKeyMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.65
EqualMethod · 0.65
SizeMethod · 0.65
ValidatorUpdatesMethod · 0.45

Tested by

no test coverage detected