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

Function TestLargeGenesisValidator

state/state_test.go:730–910  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

728}
729
730func TestLargeGenesisValidator(t *testing.T) {
731 tearDown, _, state := setupTestCase(t)
732 defer tearDown(t)
733
734 genesisVotingPower := types.MaxTotalVotingPower / 1000
735 genesisPubKey := ed25519.GenPrivKey().PubKey()
736 // fmt.Println("genesis addr: ", genesisPubKey.Address())
737 genesisVal := &types.Validator{
738 Address: genesisPubKey.Address(),
739 PubKey: genesisPubKey,
740 VotingPower: genesisVotingPower,
741 }
742 // reset state validators to above validator
743 state.Validators = types.NewValidatorSet([]*types.Validator{genesisVal})
744 state.NextValidators = state.Validators
745 require.True(t, len(state.Validators.Validators) == 1)
746
747 // update state a few times with no validator updates
748 // asserts that the single validator's ProposerPrio stays the same
749 oldState := state
750 for i := 0; i < 10; i++ {
751 // no updates:
752 abciResponses := &tmstate.ABCIResponses{
753 BeginBlock: &abci.ResponseBeginBlock{},
754 EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil},
755 }
756 validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciResponses.EndBlock.ValidatorUpdates)
757 require.NoError(t, err)
758
759 block := makeBlock(oldState, oldState.LastBlockHeight+1)
760 blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
761
762 updatedState, err := sm.UpdateState(oldState, blockID, &block.Header, abciResponses, validatorUpdates)
763 require.NoError(t, err)
764 // no changes in voting power (ProposerPrio += VotingPower == Voting in 1st round; than shiftByAvg == 0,
765 // than -Total == -Voting)
766 // -> no change in ProposerPrio (stays zero):
767 assert.EqualValues(t, oldState.NextValidators, updatedState.NextValidators)
768 assert.EqualValues(t, 0, updatedState.NextValidators.Proposer.ProposerPriority)
769
770 oldState = updatedState
771 }
772 // add another validator, do a few iterations (create blocks),
773 // add more validators with same voting power as the 2nd
774 // let the genesis validator "unbond",
775 // see how long it takes until the effect wears off and both begin to alternate
776 // see: https://github.com/DeAI-Artist/Linkis/issues/2960
777 firstAddedValPubKey := ed25519.GenPrivKey().PubKey()
778 firstAddedValVotingPower := int64(10)
779 fvp, err := cryptoenc.PubKeyToProto(firstAddedValPubKey)
780 require.NoError(t, err)
781 firstAddedVal := abci.ValidatorUpdate{PubKey: fvp, Power: firstAddedValVotingPower}
782 validatorUpdates, err := types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{firstAddedVal})
783 assert.NoError(t, err)
784 abciResponses := &tmstate.ABCIResponses{
785 BeginBlock: &abci.ResponseBeginBlock{},
786 EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{firstAddedVal}},
787 }

Callers

nothing calls this directly

Calls 12

GenPrivKeyFunction · 0.92
NewValidatorSetFunction · 0.92
setupTestCaseFunction · 0.85
MakePartSetMethod · 0.80
makeBlockFunction · 0.70
PubKeyMethod · 0.65
AddressMethod · 0.65
HashMethod · 0.65
EqualMethod · 0.65
ValidatorUpdatesMethod · 0.45
HeaderMethod · 0.45
GetByAddressMethod · 0.45

Tested by

no test coverage detected