Skip to content

Commit

Permalink
More UT fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-mena committed Jan 12, 2025
1 parent d53342f commit 4f7bd20
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
12 changes: 4 additions & 8 deletions internal/consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
cfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/crypto"
"github.com/cometbft/cometbft/crypto/bls12381"
cstypes "github.com/cometbft/cometbft/internal/consensus/types"
cmtos "github.com/cometbft/cometbft/internal/os"
"github.com/cometbft/cometbft/internal/test"
Expand Down Expand Up @@ -298,7 +297,7 @@ func signAddVotes(
_ bool,
vss ...*validatorStub,
) {
extEnabled := false // disable vote extensions in Bearchain
extEnabled := false // disable vote extensions in Berachain
votes := signVotes(voteType, chainID, blockID, extEnabled, vss...)
addVotes(to, votes...)
}
Expand Down Expand Up @@ -524,10 +523,10 @@ func randState(nValidators int) (*State, []*validatorStub) {
func randStateWithAppWithHeight(
nValidators int,
app abci.Application,
height int64,
_ int64,
) (*State, []*validatorStub) {
c := test.ConsensusParams()
//c.Feature.VoteExtensionsEnableHeight = height
c.Feature.VoteExtensionsEnableHeight = 0 // disable vote extensions in Berachain
return randStateWithAppImpl(nValidators, app, c)
}

Expand Down Expand Up @@ -891,10 +890,7 @@ func randConsensusNetWithPeers(
require.NoError(t, err)
tempStateFile, err := os.CreateTemp("", "priv_validator_state_")
require.NoError(t, err)
keyGen := func() (crypto.PrivKey, error) {
return bls12381.GenPrivKey()
}
privVal, err = privval.GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), keyGen)
privVal, err = privval.GenFilePV(tempKeyFile.Name(), tempStateFile.Name(), nil)
require.NoError(t, err)
}

Expand Down
3 changes: 2 additions & 1 deletion internal/consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func TestReactorReceivePanicsIfInitPeerHasntBeenCalledYet(t *testing.T) {
// TestSwitchToConsensusVoteExtensions tests that the SwitchToConsensus correctly
// checks for vote extension data when required.
func TestSwitchToConsensusVoteExtensions(t *testing.T) {
t.Skip("No point in testing vote extensions in Berachain")
for _, testCase := range []struct {
name string
storedHeight int64
Expand Down Expand Up @@ -360,7 +361,7 @@ func TestSwitchToConsensusVoteExtensions(t *testing.T) {

cs.state.LastBlockHeight = testCase.storedHeight
cs.state.LastValidators = cs.state.Validators.Copy()
//cs.state.ConsensusParams.Feature.VoteExtensionsEnableHeight = testCase.initialRequiredHeight
cs.state.ConsensusParams.Feature.VoteExtensionsEnableHeight = testCase.initialRequiredHeight

propBlock, err := cs.createProposalBlock(ctx)
require.NoError(t, err)
Expand Down
7 changes: 5 additions & 2 deletions internal/consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,7 @@ func TestProcessProposalAccept(t *testing.T) {
// TestExtendVoteCalledWhenEnabled tests that the vote extension methods are called at the
// correct point in the consensus algorithm when vote extensions are enabled.
func TestExtendVoteCalledWhenEnabled(t *testing.T) {
t.Skip("No point in testing vote extensions in Berachain")
for _, testCase := range []struct {
name string
enabled bool
Expand Down Expand Up @@ -2239,6 +2240,7 @@ func TestExtendVoteCalledWhenEnabled(t *testing.T) {
// TestVerifyVoteExtensionNotCalledOnAbsentPrecommit tests that the VerifyVoteExtension
// method is not called for a validator's vote that is never delivered.
func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
t.Skip("No point in testing vote extensions in Berachain")
m := abcimocks.NewApplication(t)
m.On("PrepareProposal", mock.Anything, mock.Anything).Return(&abci.PrepareProposalResponse{}, nil)
m.On("ProcessProposal", mock.Anything, mock.Anything).Return(&abci.ProcessProposalResponse{Status: abci.PROCESS_PROPOSAL_STATUS_ACCEPT}, nil)
Expand All @@ -2252,7 +2254,7 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
m.On("Commit", mock.Anything, mock.Anything).Return(&abci.CommitResponse{}, nil).Maybe()
cs1, vss := randStateWithApp(4, m)
height, round, chainID := cs1.Height, cs1.Round, cs1.state.ChainID
//cs1.state.ConsensusParams.Feature.VoteExtensionsEnableHeight = cs1.Height
cs1.state.ConsensusParams.Feature.VoteExtensionsEnableHeight = cs1.Height

proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
Expand Down Expand Up @@ -2311,6 +2313,7 @@ func TestVerifyVoteExtensionNotCalledOnAbsentPrecommit(t *testing.T) {
// is the proposer again and ensures that the mock application receives the set of
// vote extensions from the previous consensus instance.
func TestPrepareProposalReceivesVoteExtensions(t *testing.T) {
t.Skip("No point in testing vote extensions in Berachain")
// create a list of vote extensions, one for each validator.
voteExtensions := [][]byte{
[]byte("extension 0"),
Expand Down Expand Up @@ -2555,7 +2558,7 @@ func TestVoteExtensionEnableHeight(t *testing.T) {
m.On("Commit", mock.Anything, mock.Anything).Return(&abci.CommitResponse{}, nil).Maybe()
cs1, vss := randStateWithAppWithHeight(numValidators, m, testCase.enableHeight)
height, round, chainID := cs1.Height, cs1.Round, cs1.state.ChainID
//cs1.state.ConsensusParams.Feature.VoteExtensionsEnableHeight = testCase.enableHeight
cs1.state.ConsensusParams.Feature.VoteExtensionsEnableHeight = 0 // disable vote extensions in Berachain

timeoutCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
Expand Down
4 changes: 2 additions & 2 deletions privval/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/crypto"
"github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cometbft/cometbft/crypto/bls12381"
cmtos "github.com/cometbft/cometbft/internal/os"
"github.com/cometbft/cometbft/internal/tempfile"
cmtbytes "github.com/cometbft/cometbft/libs/bytes"
Expand Down Expand Up @@ -186,7 +186,7 @@ func NewFilePV(privKey crypto.PrivKey, keyFilePath, stateFilePath string) *FileP
func GenFilePV(keyFilePath, stateFilePath string, keyGen func() (crypto.PrivKey, error)) (*FilePV, error) {
if keyGen == nil {
keyGen = func() (crypto.PrivKey, error) {
return ed25519.GenPrivKey(), nil
return bls12381.GenPrivKey()
}
}
key, err := keyGen()
Expand Down
3 changes: 2 additions & 1 deletion state/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ func TestPrepareProposalErrorOnPrepareProposalError(t *testing.T) {
// call correctly panics when the vote extension data is missing from the extended commit
// data that the method receives.
func TestCreateProposalAbsentVoteExtensions(t *testing.T) {
t.Skip("No point in testing vote extensions in Berachain")
for _, testCase := range []struct {
name string

Expand Down Expand Up @@ -1063,7 +1064,7 @@ func TestCreateProposalAbsentVoteExtensions(t *testing.T) {
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
// state.ConsensusParams.Feature.VoteExtensionsEnableHeight = testCase.extensionEnableHeight
state.ConsensusParams.Feature.VoteExtensionsEnableHeight = testCase.extensionEnableHeight
mp := &mpmocks.Mempool{}
mp.On("Lock").Return()
mp.On("Unlock").Return()
Expand Down
15 changes: 8 additions & 7 deletions types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"errors"
"flag"
"fmt"
"math"
"time"
Expand Down Expand Up @@ -177,10 +176,11 @@ func DefaultValidatorParams() ValidatorParams {
params := ValidatorParams{
PubKeyTypes: []string{ABCIPubKeyTypeBls12381},
}
// If we are running tests, enable ed25519.
if flag.Lookup("test.v") != nil {
params.PubKeyTypes = append(params.PubKeyTypes, ABCIPubKeyTypeEd25519)
}
// TODO Clean up
// // If we are running tests, enable ed25519.
// if flag.Lookup("test.v") != nil {
// params.PubKeyTypes = append(params.PubKeyTypes, ABCIPubKeyTypeEd25519)
// }
return params
}

Expand Down Expand Up @@ -285,7 +285,8 @@ func (params ConsensusParams) ValidateBasic() error {
}

// If we are running in production, we only allow BLS keys
if flag.Lookup("test.v") == nil {
// TODO Clean up
if true { // flag.Lookup("test.v") == nil {
if !(len(params.Validator.PubKeyTypes) == 1 && params.Validator.PubKeyTypes[0] == ABCIPubKeyTypeBls12381) {
return errors.New("only BLS key type is allowed")
}
Expand Down Expand Up @@ -444,7 +445,7 @@ func (params ConsensusParams) Update(params2 *cmtproto.ConsensusParams) Consensu
}
if params2.Feature != nil {
if params2.Feature.VoteExtensionsEnableHeight != nil {
res.Feature.VoteExtensionsEnableHeight = 0 //params2.Feature.GetVoteExtensionsEnableHeight().Value
res.Feature.VoteExtensionsEnableHeight = 0 // disable vote extensions in Berachain
}

if params2.Feature.PbtsEnableHeight != nil {
Expand Down

0 comments on commit 4f7bd20

Please sign in to comment.