Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslopezf committed Jun 12, 2024
1 parent cd433e7 commit da97cd2
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 26 deletions.
3 changes: 1 addition & 2 deletions server/grpc/gogoreflection/fix_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package gogoreflection
import (
"reflect"

_ "github.com/cosmos/cosmos-proto" // look above
_ "github.com/cosmos/gogoproto/gogoproto" // required so it does register the gogoproto file descriptor
gogoproto "github.com/cosmos/gogoproto/proto"

_ "github.com/cosmos/cosmos-proto" // look above
"github.com/golang/protobuf/proto" //nolint:staticcheck // migrate in a future pr
)

Expand Down
2 changes: 1 addition & 1 deletion simapp/mint_fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

type MintBankKeeper interface {
MintCoins(ctx context.Context, moduleName string, coins sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule string, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
}

// ProvideExampleMintFn returns the function used in x/mint's endblocker to mint new tokens.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestMsgWithdrawDelegatorReward(t *testing.T) {
}

// setup staking validator
validator, err := stakingtypes.NewValidator(f.valAddr.String(), PKS[0], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
validator, err := stakingtypes.NewValidator(f.valAddr.String(), PKS[0], stakingtypes.Description{})
assert.NilError(t, err)
commission := stakingtypes.NewCommission(math.LegacyZeroDec(), math.LegacyOneDec(), math.LegacyOneDec())
validator, err = validator.SetInitialCommission(commission)
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"cosmossdk.io/x/gov/types/v1beta1"
stakingtypes "cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -42,11 +41,11 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
valAddrs := simtestutil.ConvertAddrsToValAddrs(addrs)
pks := simtestutil.CreateTestPubKeys(5)

val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{})
assert.NilError(t, err)
val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{})
assert.NilError(t, err)
val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{})
assert.NilError(t, err)

assert.NilError(t, f.stakingKeeper.SetValidator(f.ctx, val1))
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/staking/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"cosmossdk.io/x/staking"
"cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
Expand Down Expand Up @@ -197,7 +196,6 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
sdk.ValAddress(addrs[i]).String(),
PKs[i],
types.NewDescription(fmt.Sprintf("#%d", i), "", "", "", ""),
addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
)
assert.NilError(t, err)
validators[i].Status = types.Bonded
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
delegatorAddr := addrs[1]

// setup a new validator with bonded status
validator, err := types.NewValidator(valAddr.String(), PKs[0], types.NewDescription("Validator", "", "", "", ""), address.NewBech32Codec(sdk.Bech32PrefixConsAddr))
validator, err := types.NewValidator(valAddr.String(), PKs[0], types.NewDescription("Validator", "", "", "", ""))
validator.Status = types.Bonded
assert.NilError(t, err)
assert.NilError(t, f.stakingKeeper.SetValidator(ctx, validator))
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/staking/keeper/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"cosmossdk.io/x/staking/testutil"
"cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -21,7 +20,7 @@ import (

func newMonikerValidator(tb testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator {
tb.Helper()
v, err := types.NewValidator(operator.String(), pubKey, types.Description{Moniker: moniker}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
v, err := types.NewValidator(operator.String(), pubKey, types.Description{Moniker: moniker})
assert.NilError(tb, err)
return v
}
Expand Down
2 changes: 1 addition & 1 deletion tests/sims/distribution/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (suite *SimTestSuite) getTestingValidator(accounts []simtypes.Account, comm
account := accounts[n]
valPubKey := account.PubKey
valAddr := sdk.ValAddress(account.PubKey.Address().Bytes())
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.Description{}, address.NewBech32Codec(sdk.Bech32PrefixConsAddr))
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.Description{})
require.NoError(err)
validator, err = validator.SetInitialCommission(commission)
require.NoError(err)
Expand Down
3 changes: 1 addition & 2 deletions tests/sims/slashing/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/runtime"
Expand Down Expand Up @@ -208,7 +207,7 @@ func getTestingValidator(ctx sdk.Context, stakingKeeper *stakingkeeper.Keeper, a
account := accounts[n]
valPubKey := account.ConsKey.PubKey()
valAddr := sdk.ValAddress(account.PubKey.Address().Bytes())
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
validator, err := stakingtypes.NewValidator(valAddr.String(), valPubKey, stakingtypes.Description{})
if err != nil {
return stakingtypes.Validator{}, fmt.Errorf("failed to create validator: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestAllocateTokensTruncation(t *testing.T) {
valAddr2 := sdk.ValAddress(valConsAddr2)
valAddr2Str, err := cdcOpts.GetValidatorCodec().BytesToString(valAddr2)
require.NoError(t, err)
val2, err := stakingtypes.NewValidator(valAddr2Str, valConsPk1, stakingtypes.Description{}, address.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val2, err := stakingtypes.NewValidator(valAddr2Str, valConsPk1, stakingtypes.Description{})
require.NoError(t, err)
val2.Commission = stakingtypes.NewCommission(math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDecWithPrec(1, 1), math.LegacyNewDec(0))
stakingKeeper.EXPECT().ValidatorByConsAddr(gomock.Any(), sdk.GetConsAddress(valConsPk2)).Return(val2, nil).AnyTimes()
Expand Down
3 changes: 1 addition & 2 deletions x/distribution/testutil/staking_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"cosmossdk.io/x/distribution/keeper"
stakingtypes "cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func CreateValidator(pk cryptotypes.PubKey, operator string, stake math.Int) (stakingtypes.Validator, error) {
val, err := stakingtypes.NewValidator(operator, pk, stakingtypes.Description{Moniker: "TestValidator"}, addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()))
val, err := stakingtypes.NewValidator(operator, pk, stakingtypes.Description{Moniker: "TestValidator"})
val.Tokens = stake
val.DelegatorShares = math.LegacyNewDecFromInt(val.Tokens)
return val, err
Expand Down
3 changes: 1 addition & 2 deletions x/slashing/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
stakingtypes "cosmossdk.io/x/staking/types"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -28,7 +27,7 @@ func (s *KeeperTestSuite) TestAfterValidatorCreatedOrRemoved() {

addStr, err := s.stakingKeeper.ValidatorAddressCodec().BytesToString(addr)
require.NoError(err)
validator, err := stakingtypes.NewValidator(addStr, pubKey, stakingtypes.Description{}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
validator, err := stakingtypes.NewValidator(addStr, pubKey, stakingtypes.Description{})
require.NoError(err)

s.stakingKeeper.EXPECT().Validator(ctx, valAddr).Return(validator, nil)
Expand Down
10 changes: 5 additions & 5 deletions x/slashing/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *KeeperTestSuite) TestUnjail() {
valStr, err := s.stakingKeeper.ValidatorAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
s.Require().NoError(err)

s.stakingKeeper.EXPECT().Validator(s.ctx, valAddr).Return(val, nil)
Expand Down Expand Up @@ -214,7 +214,7 @@ func (s *KeeperTestSuite) TestUnjail() {
consStr, err := s.stakingKeeper.ConsensusAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)
val.Jailed = false
Expand Down Expand Up @@ -249,7 +249,7 @@ func (s *KeeperTestSuite) TestUnjail() {
consStr, err := s.stakingKeeper.ConsensusAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)
val.Jailed = true
Expand Down Expand Up @@ -284,7 +284,7 @@ func (s *KeeperTestSuite) TestUnjail() {
addrStr, err := ac.BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)
val.Jailed = true
Expand Down Expand Up @@ -319,7 +319,7 @@ func (s *KeeperTestSuite) TestUnjail() {
consStr, err := s.stakingKeeper.ConsensusAddressCodec().BytesToString(addr)
s.Require().NoError(err)

val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"}, addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
val, err := types.NewValidator(valStr, pubKey, types.Description{Moniker: "test"})
val.Tokens = sdkmath.NewInt(1000)
val.DelegatorShares = sdkmath.LegacyNewDec(1)

Expand Down

0 comments on commit da97cd2

Please sign in to comment.