Skip to content

Commit

Permalink
refactor(x/staking)!: remove comet deps (#20728)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Jun 20, 2024
1 parent ae5fc15 commit ac77fc1
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 207 deletions.
1 change: 1 addition & 0 deletions x/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#17655](https://github.com/cosmos/cosmos-sdk/pull/17655) `QueryHistoricalInfo` was adjusted to return `HistoricalRecord` and marked `Hist` as deprecated.
* [#20295](https://github.com/cosmos/cosmos-sdk/pull/20295) `GetValidatorByConsAddr` now returns the Cosmos SDK `cryptotypes.Pubkey` instead of `cometcrypto.Publickey`. The caller is responsible to translate the returned value to the expected type.
* Remove `CmtConsPublicKey()` and `TmConsPublicKey()` from `Validator` interface and as methods on the `Validator` struct.
* [#20728](https://github.com/cosmos/cosmos-sdk/pull/20728) Remove `NewHistoricalInfo` and related functions to Historical Info & `GetCmtConsPubKey`, `ToCmtValidator` & `ToCmtValidators` as comet validator type is no longer used in the staking module.

### State Breaking changes

Expand Down
2 changes: 1 addition & 1 deletion x/staking/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io"
"testing"

abci "github.com/cometbft/cometbft/abci/types"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
"github.com/spf13/pflag"
"github.com/stretchr/testify/suite"
Expand Down
45 changes: 0 additions & 45 deletions x/staking/testutil/cmt.go

This file was deleted.

50 changes: 0 additions & 50 deletions x/staking/types/historical_info.go

This file was deleted.

56 changes: 0 additions & 56 deletions x/staking/types/historical_info_test.go

This file was deleted.

55 changes: 0 additions & 55 deletions x/staking/types/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import (
"sort"
"testing"

cmttypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"cosmossdk.io/math"
"cosmossdk.io/x/staking/testutil"
"cosmossdk.io/x/staking/types"

"github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/legacy"
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -256,58 +253,6 @@ func TestValidatorsSortDeterminism(t *testing.T) {
}
}

// Check SortCometBFT sorts the same as CometBFT
func TestValidatorsSortCometBFT(t *testing.T) {
vals := make([]types.Validator, 100)

for i := range vals {
pk := ed25519.GenPrivKey().PubKey()
pk2 := ed25519.GenPrivKey().PubKey()
vals[i] = newValidator(t, sdk.ValAddress(pk2.Address()), pk)
vals[i].Status = types.Bonded
vals[i].Tokens = math.NewInt(rand.Int63())
}
// create some validators with the same power
for i := 0; i < 10; i++ {
vals[i].Tokens = math.NewInt(1000000)
}

valz := types.Validators{Validators: vals, ValidatorCodec: address.NewBech32Codec("cosmosvaloper")}

// create expected CometBFT validators by converting to CometBFT then sorting
expectedVals, err := testutil.ToCmtValidators(valz, sdk.DefaultPowerReduction)
require.NoError(t, err)
sort.Sort(cmttypes.ValidatorsByVotingPower(expectedVals))

// sort in SDK and then convert to CometBFT
sort.SliceStable(valz.Validators, func(i, j int) bool {
return types.ValidatorsByVotingPower(valz.Validators).Less(i, j, sdk.DefaultPowerReduction)
})
actualVals, err := testutil.ToCmtValidators(valz, sdk.DefaultPowerReduction)
require.NoError(t, err)

require.Equal(t, expectedVals, actualVals, "sorting in SDK is not the same as sorting in CometBFT")
}

func TestValidatorToCmt(t *testing.T) {
vals := types.Validators{}
expected := make([]*cmttypes.Validator, 10)

for i := 0; i < 10; i++ {
pk := ed25519.GenPrivKey().PubKey()
val := newValidator(t, sdk.ValAddress(pk.Address()), pk)
val.Status = types.Bonded
val.Tokens = math.NewInt(rand.Int63())
vals.Validators = append(vals.Validators, val)
cmtPk, err := cryptocodec.ToCmtPubKeyInterface(pk)
require.NoError(t, err)
expected[i] = cmttypes.NewValidator(cmtPk, val.ConsensusPower(sdk.DefaultPowerReduction))
}
vs, err := testutil.ToCmtValidators(vals, sdk.DefaultPowerReduction)
require.NoError(t, err)
require.Equal(t, expected, vs)
}

func TestBondStatus(t *testing.T) {
require.False(t, types.Unbonded == types.Bonded)
require.False(t, types.Unbonded == types.Unbonding)
Expand Down

0 comments on commit ac77fc1

Please sign in to comment.