From da97cd2ee283a4518a4bf0d785acc37ccd321616 Mon Sep 17 00:00:00 2001 From: Lucas Francisco Lopez Date: Wed, 12 Jun 2024 15:47:32 +0200 Subject: [PATCH] tests --- server/grpc/gogoreflection/fix_registration.go | 3 +-- simapp/mint_fn.go | 2 +- .../integration/distribution/keeper/msg_server_test.go | 2 +- tests/integration/gov/keeper/common_test.go | 7 +++---- tests/integration/staking/keeper/genesis_test.go | 2 -- tests/integration/staking/keeper/msg_server_test.go | 2 +- tests/integration/staking/keeper/validator_test.go | 3 +-- tests/sims/distribution/operations_test.go | 2 +- tests/sims/slashing/operations_test.go | 3 +-- x/distribution/keeper/allocation_test.go | 2 +- x/distribution/testutil/staking_helper.go | 3 +-- x/slashing/keeper/hooks_test.go | 3 +-- x/slashing/keeper/msg_server_test.go | 10 +++++----- 13 files changed, 18 insertions(+), 26 deletions(-) diff --git a/server/grpc/gogoreflection/fix_registration.go b/server/grpc/gogoreflection/fix_registration.go index ab1a18f592e9..086d9b0da6d1 100644 --- a/server/grpc/gogoreflection/fix_registration.go +++ b/server/grpc/gogoreflection/fix_registration.go @@ -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 ) diff --git a/simapp/mint_fn.go b/simapp/mint_fn.go index e34aca38f496..9f2ee70ca57b 100644 --- a/simapp/mint_fn.go +++ b/simapp/mint_fn.go @@ -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. diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 7be64650f965..89d31409ac11 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -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) diff --git a/tests/integration/gov/keeper/common_test.go b/tests/integration/gov/keeper/common_test.go index ca88fdf6cad1..38d7b964f753 100644 --- a/tests/integration/gov/keeper/common_test.go +++ b/tests/integration/gov/keeper/common_test.go @@ -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" ) @@ -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)) diff --git a/tests/integration/staking/keeper/genesis_test.go b/tests/integration/staking/keeper/genesis_test.go index be0bec67fa8e..95e34da18485 100644 --- a/tests/integration/staking/keeper/genesis_test.go +++ b/tests/integration/staking/keeper/genesis_test.go @@ -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" @@ -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 diff --git a/tests/integration/staking/keeper/msg_server_test.go b/tests/integration/staking/keeper/msg_server_test.go index d35880146f60..33653fe4a5bf 100644 --- a/tests/integration/staking/keeper/msg_server_test.go +++ b/tests/integration/staking/keeper/msg_server_test.go @@ -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)) diff --git a/tests/integration/staking/keeper/validator_test.go b/tests/integration/staking/keeper/validator_test.go index fa4efe24bae1..a19352f1cda6 100644 --- a/tests/integration/staking/keeper/validator_test.go +++ b/tests/integration/staking/keeper/validator_test.go @@ -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" @@ -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 } diff --git a/tests/sims/distribution/operations_test.go b/tests/sims/distribution/operations_test.go index 1fc107aaf8a5..a5451da0866b 100644 --- a/tests/sims/distribution/operations_test.go +++ b/tests/sims/distribution/operations_test.go @@ -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) diff --git a/tests/sims/slashing/operations_test.go b/tests/sims/slashing/operations_test.go index 55f4ba1ff9c3..b0df7052dab2 100644 --- a/tests/sims/slashing/operations_test.go +++ b/tests/sims/slashing/operations_test.go @@ -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" @@ -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) } diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index 24d3778804bf..1729a3982010 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -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() diff --git a/x/distribution/testutil/staking_helper.go b/x/distribution/testutil/staking_helper.go index 393ac1008d78..d84e92cc476c 100644 --- a/x/distribution/testutil/staking_helper.go +++ b/x/distribution/testutil/staking_helper.go @@ -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 diff --git a/x/slashing/keeper/hooks_test.go b/x/slashing/keeper/hooks_test.go index 8a35e6e906dc..2bb1b306b478 100644 --- a/x/slashing/keeper/hooks_test.go +++ b/x/slashing/keeper/hooks_test.go @@ -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" ) @@ -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) diff --git a/x/slashing/keeper/msg_server_test.go b/x/slashing/keeper/msg_server_test.go index 711103e5031d..39b04636328d 100644 --- a/x/slashing/keeper/msg_server_test.go +++ b/x/slashing/keeper/msg_server_test.go @@ -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) @@ -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 @@ -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 @@ -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 @@ -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)