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

Function TestEndBlockValidatorUpdates

state/execution_test.go:354–423  ·  view source on GitHub ↗

TestEndBlockValidatorUpdates ensures we update validator set and send an event.

(t *testing.T)

Source from the content-addressed store, hash-verified

352
353// TestEndBlockValidatorUpdates ensures we update validator set and send an event.
354func TestEndBlockValidatorUpdates(t *testing.T) {
355 app := &testApp{}
356 cc := proxy.NewLocalClientCreator(app)
357 proxyApp := proxy.NewAppConns(cc)
358 err := proxyApp.Start()
359 require.Nil(t, err)
360 defer proxyApp.Stop() //nolint:errcheck // ignore for tests
361
362 state, stateDB, _ := makeState(1, 1)
363 stateStore := sm.NewStore(stateDB, sm.StoreOptions{
364 DiscardABCIResponses: false,
365 })
366
367 blockExec := sm.NewBlockExecutor(
368 stateStore,
369 log.TestingLogger(),
370 proxyApp.Consensus(),
371 mmock.Mempool{},
372 sm.EmptyEvidencePool{},
373 )
374
375 eventBus := types.NewEventBus()
376 err = eventBus.Start()
377 require.NoError(t, err)
378 defer eventBus.Stop() //nolint:errcheck // ignore for tests
379
380 blockExec.SetEventBus(eventBus)
381
382 updatesSub, err := eventBus.Subscribe(
383 context.Background(),
384 "TestEndBlockValidatorUpdates",
385 types.EventQueryValidatorSetUpdates,
386 )
387 require.NoError(t, err)
388
389 block := makeBlock(state, 1)
390 blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
391
392 pubkey := ed25519.GenPrivKey().PubKey()
393 pk, err := cryptoenc.PubKeyToProto(pubkey)
394 require.NoError(t, err)
395 app.ValidatorUpdates = []abci.ValidatorUpdate{
396 {PubKey: pk, Power: 10},
397 }
398
399 state, _, err = blockExec.ApplyBlock(state, blockID, block)
400 require.Nil(t, err)
401 // test new validator was added to NextValidators
402 if assert.Equal(t, state.Validators.Size()+1, state.NextValidators.Size()) {
403 idx, _ := state.NextValidators.GetByAddress(pubkey.Address())
404 if idx < 0 {
405 t.Fatalf("can't find address %v in the set %v", pubkey.Address(), state.NextValidators)
406 }
407 }
408
409 // test we threw an event
410 select {
411 case msg := <-updatesSub.Out():

Callers

nothing calls this directly

Calls 15

ConsensusMethod · 0.95
SetEventBusMethod · 0.95
SubscribeMethod · 0.95
ApplyBlockMethod · 0.95
NewLocalClientCreatorFunction · 0.92
NewAppConnsFunction · 0.92
TestingLoggerFunction · 0.92
NewEventBusFunction · 0.92
GenPrivKeyFunction · 0.92
MakePartSetMethod · 0.80
DataMethod · 0.80
makeStateFunction · 0.70

Tested by

no test coverage detected