TestEndBlockValidatorUpdates ensures we update validator set and send an event.
(t *testing.T)
| 352 | |
| 353 | // TestEndBlockValidatorUpdates ensures we update validator set and send an event. |
| 354 | func 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(): |
nothing calls this directly
no test coverage detected