diff --git a/baseapp/options.go b/baseapp/options.go index a94fda5aa5..5d7021bfa9 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -86,7 +86,7 @@ func SetAppConfig(config serverconfig.Config) func(*BaseApp) { return func(app *BaseApp) { app.setAppConfig(config) } } -// SetAppConfig sets the chain id. +// SetChainID sets the chain id. func SetChainID(chainID string) func(*BaseApp) { return func(app *BaseApp) { app.setChainID(chainID) } } diff --git a/server/grpc/server_test.go b/server/grpc/server_test.go index f55540c01e..d6956a7f45 100644 --- a/server/grpc/server_test.go +++ b/server/grpc/server_test.go @@ -47,7 +47,7 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.app = simapp.Setup(s.T(), false) + s.app = simapp.Setup(s.T(), false, true) cfg := network.DefaultConfig() cfg.NumValidators = 1 s.cfg = cfg diff --git a/simapp/app.go b/simapp/app.go index c959729744..e32f4003b1 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -344,6 +344,11 @@ func NewSimApp( // app.Logger().Info("upgrade to ", plan.Name) // return fromVM, nil // }, + + upgradetypes.EnablePublicDelegationUpgrade: func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + app.Logger().Info("upgrade to ", plan.Name) + return fromVM, nil + }, } upgradeInitlizier := map[string]upgradetypes.UpgradeInitializer{ @@ -353,6 +358,11 @@ func NewSimApp( // app.Logger().Info("Init BEP111") // return nil // }, + + upgradetypes.EnablePublicDelegationUpgrade: func() error { + app.Logger().Info("Init enable public delegation upgrade") + return nil + }, } var err error @@ -705,3 +715,13 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino return paramsKeeper } + +func InitUpgradeConfig() []config.UpgradeConfig { + return []config.UpgradeConfig{ + { + Name: upgradetypes.EnablePublicDelegationUpgrade, + Height: 2, + Info: "Enable public delegation, after this fork, anyone can delegate and redelegate to any validator.", + }, + } +} diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 9b7a5acbf5..cb721dfba8 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -25,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + srvconfig "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp/helpers" "github.com/cosmos/cosmos-sdk/simapp/params" @@ -68,10 +69,15 @@ type SetupOptions struct { AppOpts types.AppOptions } -func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { +func setup(withGenesis bool, invCheckPeriod uint, enableDefaultUpgrade bool) (*SimApp, GenesisState) { + appCfg := srvconfig.DefaultConfig() + if enableDefaultUpgrade { + appCfg.Upgrade = InitUpgradeConfig() + } + db := dbm.NewMemDB() encCdc := MakeTestEncodingConfig() - app := NewSimApp(log.NewNopLogger(), db, nil, true, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}) + app := NewSimApp(log.NewNopLogger(), db, nil, true, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}, bam.SetAppConfig(*appCfg)) if withGenesis { return app, NewDefaultGenesisState(encCdc.Codec) } @@ -120,7 +126,7 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio } // Setup initializes a new SimApp. A Nop logger is set in SimApp. -func Setup(t *testing.T, isCheckTx bool) *SimApp { +func Setup(t *testing.T, isCheckTx bool, enableDefaultUpgrade bool) *SimApp { t.Helper() privVal := mock.NewPV() @@ -139,7 +145,7 @@ func Setup(t *testing.T, isCheckTx bool) *SimApp { Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), } - app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) + app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, enableDefaultUpgrade, balance) return app } @@ -212,10 +218,10 @@ func genesisStateWithValSet(t *testing.T, // that also act as delegators. For simplicity, each validator is bonded with a delegation // of one consensus engine unit in the default token of the simapp from first genesis // account. A Nop logger is set in SimApp. -func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp { +func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, enableDefaultUpgrade bool, balances ...banktypes.Balance) *SimApp { t.Helper() - app, genesisState := setup(true, 5) + app, genesisState := setup(true, 5, enableDefaultUpgrade) genesisState = genesisStateWithValSet(t, app, genesisState, valSet, genAccs, balances...) stateBytes, err := json.MarshalIndent(genesisState, "", " ") @@ -257,7 +263,7 @@ func SetupWithGenesisAccounts(t *testing.T, genAccs []authtypes.GenesisAccount, validator := tmtypes.NewValidator(pubKey, 1) valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) - return SetupWithGenesisValSet(t, valSet, genAccs, balances...) + return SetupWithGenesisValSet(t, valSet, genAccs, true, balances...) } // GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts diff --git a/testutil/network/network.go b/testutil/network/network.go index c920f812f0..ebf5caca5a 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -64,6 +64,7 @@ func NewAppConstructor(encodingCfg params.EncodingConfig) AppConstructor { simapp.EmptyAppOptions{}, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), + baseapp.SetAppConfig(*val.AppConfig), ) } } @@ -234,6 +235,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { // generate private keys, node IDs, and initial transactions for i := 0; i < cfg.NumValidators; i++ { appCfg := srvconfig.DefaultConfig() + appCfg.Upgrade = simapp.InitUpgradeConfig() appCfg.Pruning = cfg.PruningStrategy appCfg.MinGasPrices = cfg.MinGasPrices appCfg.API.Enable = true diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index f1ef201046..0397fb3ff7 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -337,7 +337,7 @@ func ExamplePaginate(t *testing.T) { } func setupTest(t *testing.T) (*simapp.SimApp, sdk.Context, codec.Codec) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1}) appCodec := app.AppCodec() diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index c823adaa0b..fd29413cd4 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -43,7 +43,7 @@ type AnteTestSuite struct { // returns context and app with params set on account keeper func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, isCheckTx) + app := simapp.Setup(t, isCheckTx, true) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) diff --git a/x/auth/keeper/integration_test.go b/x/auth/keeper/integration_test.go index cbb9223b6f..bb9168f015 100644 --- a/x/auth/keeper/integration_test.go +++ b/x/auth/keeper/integration_test.go @@ -12,7 +12,7 @@ import ( // returns context and app with params set on account keeper func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, isCheckTx) + app := simapp.Setup(t, isCheckTx, true) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) diff --git a/x/auth/migrations/v046/store_test.go b/x/auth/migrations/v046/store_test.go index 48bd52d4b8..3e0e10aa63 100644 --- a/x/auth/migrations/v046/store_test.go +++ b/x/auth/migrations/v046/store_test.go @@ -16,7 +16,7 @@ import ( // TestMigrateMapAccAddressToAccNumberKey test cases for state migration of map to accAddr to accNum func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) // new base account senderPrivKey := secp256k1.GenPrivKey() diff --git a/x/auth/signing/verify_test.go b/x/auth/signing/verify_test.go index 7dc375f814..66820c9015 100644 --- a/x/auth/signing/verify_test.go +++ b/x/auth/signing/verify_test.go @@ -99,7 +99,7 @@ func TestVerifySignature(t *testing.T) { // returns context and app with params set on account keeper func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, isCheckTx) + app := simapp.Setup(t, isCheckTx, true) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) app.AccountKeeper.SetParams(ctx, types.DefaultParams()) diff --git a/x/auth/simulation/decoder_test.go b/x/auth/simulation/decoder_test.go index 95a966a005..23930e016d 100644 --- a/x/auth/simulation/decoder_test.go +++ b/x/auth/simulation/decoder_test.go @@ -21,7 +21,7 @@ var ( ) func TestDecodeStore(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) cdc := simapp.MakeTestEncodingConfig().Codec acc := types.NewBaseAccountWithAddress(delAddr1) dec := simulation.NewDecodeStore(app.AccountKeeper) diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 4a80585dba..b3a8ed2eb5 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -60,7 +60,7 @@ func TestBaseSequence(t *testing.T) { } func TestBaseAccountMarshal(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) _, pub, addr := testdata.KeyEthSecp256k1TestPubAddr() acc := types.NewBaseAccountWithAddress(addr) seq := uint64(7) diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 739e8eb678..fa5f6b4cd7 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -31,7 +31,7 @@ type VestingAccountTestSuite struct { func (s *VestingAccountTestSuite) SetupTest() { checkTx := false - s.app = simapp.Setup(s.T(), checkTx) + s.app = simapp.Setup(s.T(), checkTx, true) s.ctx = s.app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1}) } diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index 077d2a162b..8db9ef6c1b 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -23,7 +23,7 @@ type GenesisTestSuite struct { func (suite *GenesisTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1}) suite.keeper = app.AuthzKeeper diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index fdf8d5d081..c57bd852d4 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -33,7 +33,7 @@ type TestSuite struct { } func (s *TestSuite) SetupTest() { - app := simapp.Setup(s.T(), false) + app := simapp.Setup(s.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) now := tmtime.Now() ctx = ctx.WithBlockHeader(tmproto.Header{Time: now}) diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index 9b58c5eadb..62d5d306ae 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -15,7 +15,7 @@ import ( ) func TestExpiredGrantsQueue(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, types.Header{}) addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000)) granter := addrs[0] diff --git a/x/authz/simulation/genesis_test.go b/x/authz/simulation/genesis_test.go index 8f313be8ea..28157437d8 100644 --- a/x/authz/simulation/genesis_test.go +++ b/x/authz/simulation/genesis_test.go @@ -16,7 +16,7 @@ import ( ) func TestRandomizedGenState(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 0f9de86de8..347e79616a 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -27,7 +27,7 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 3fc4006540..957a40b70e 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -94,7 +94,7 @@ func (suite *IntegrationTestSuite) initKeepersWithmAccPerms(blockedAddrs map[str } func (suite *IntegrationTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 921b4b6138..36cedb0568 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -26,7 +26,7 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) } diff --git a/x/bank/types/send_authorization_test.go b/x/bank/types/send_authorization_test.go index 5e058317f1..1b849bff9e 100644 --- a/x/bank/types/send_authorization_test.go +++ b/x/bank/types/send_authorization_test.go @@ -19,7 +19,7 @@ var ( ) func TestSendAuthorization(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) authorization := types.NewSendAuthorization(coins1000) diff --git a/x/capability/capability_test.go b/x/capability/capability_test.go index 6dccd6e719..97c4f34ef2 100644 --- a/x/capability/capability_test.go +++ b/x/capability/capability_test.go @@ -29,7 +29,7 @@ type CapabilityTestSuite struct { func (suite *CapabilityTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) cdc := app.AppCodec() // create new keeper so we can define custom scoping before init and seal diff --git a/x/capability/keeper/keeper_test.go b/x/capability/keeper/keeper_test.go index 9757461db7..564e6a7d6e 100644 --- a/x/capability/keeper/keeper_test.go +++ b/x/capability/keeper/keeper_test.go @@ -25,7 +25,7 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) cdc := app.AppCodec() // create new keeper so we can define custom scoping before init and seal diff --git a/x/crisis/keeper/keeper_test.go b/x/crisis/keeper/keeper_test.go index f710a166a3..c90054ee22 100644 --- a/x/crisis/keeper/keeper_test.go +++ b/x/crisis/keeper/keeper_test.go @@ -13,7 +13,7 @@ import ( ) func TestLogger(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.NewContext(true, tmproto.Header{}) @@ -23,7 +23,7 @@ func TestLogger(t *testing.T) { } func TestInvariants(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) app.Commit() app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) @@ -36,7 +36,7 @@ func TestInvariants(t *testing.T) { } func TestAssertInvariants(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) app.Commit() app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}}) diff --git a/x/distribution/abci_test.go b/x/distribution/abci_test.go index bad340cc7b..2f5e70b598 100644 --- a/x/distribution/abci_test.go +++ b/x/distribution/abci_test.go @@ -33,7 +33,7 @@ type validator struct { // Context in https://github.com/cosmos/cosmos-sdk/issues/9161 func TestVerifyProposerRewardAssignement(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrsIncremental(app, ctx, totalValidators, valTokens) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index ce898b7f18..04978496d8 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -17,7 +17,7 @@ import ( ) func TestAllocateTokensToValidatorWithCommission(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 3, sdk.NewInt(1234)) @@ -46,7 +46,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { } func TestAllocateTokensToManyValidators(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // reset fee pool @@ -120,7 +120,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) { } func TestAllocateTokensTruncation(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // reset fee pool diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index 24027780ce..52b9110fa9 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/simapp" @@ -12,10 +13,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/upgrade" ) func TestCalculateRewardsBasic(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) @@ -72,7 +74,7 @@ func TestCalculateRewardsBasic(t *testing.T) { } func TestCalculateRewardsAfterSlash(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addr := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(100000000)) @@ -135,7 +137,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { } func TestCalculateRewardsAfterManySlashes(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) @@ -210,7 +212,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { } func TestCalculateRewardsMultiDelegator(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) @@ -225,7 +227,10 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { staking.EndBlocker(ctx, app.StakingKeeper) // next block - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 2) + + // upgrade public delegation + upgrade.BeginBlocker(app.UpgradeKeeper, ctx, abci.RequestBeginBlock{}) // fetch validator and delegation val := app.StakingKeeper.Validator(ctx, valAddrs[0]) @@ -273,7 +278,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { } func TestWithdrawDelegationRewardsBasic(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) @@ -346,7 +351,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { } func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addr := simapp.AddTestAddrs(app, ctx, 1, sdk.NewInt(1000000000)) @@ -414,7 +419,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { } func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) @@ -430,7 +435,11 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { staking.EndBlocker(ctx, app.StakingKeeper) // next block - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 2) + + // upgrade public delegation + upgrade.BeginBlocker(app.UpgradeKeeper, ctx, abci.RequestBeginBlock{}) + tstaking.Ctx = ctx // fetch validator and delegation val := app.StakingKeeper.Validator(ctx, valAddrs[0]) @@ -488,7 +497,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { } func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) @@ -513,7 +522,11 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { staking.EndBlocker(ctx, app.StakingKeeper) // next block - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 2) + + // upgrade public delegation + upgrade.BeginBlocker(app.UpgradeKeeper, ctx, abci.RequestBeginBlock{}) + tstaking.Ctx = ctx // fetch validator and delegation val := app.StakingKeeper.Validator(ctx, valAddrs[0]) @@ -635,7 +648,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { } func Test100PercentCommissionReward(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper) diff --git a/x/distribution/keeper/grpc_query_test.go b/x/distribution/keeper/grpc_query_test.go index 505bc9f179..f7983453b1 100644 --- a/x/distribution/keeper/grpc_query_test.go +++ b/x/distribution/keeper/grpc_query_test.go @@ -30,7 +30,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 9895e420bf..03310b775d 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -14,7 +14,7 @@ import ( ) func TestSetWithdrawAddr(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addr := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1000000000)) @@ -36,7 +36,7 @@ func TestSetWithdrawAddr(t *testing.T) { } func TestWithdrawValidatorCommission(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valCommission := sdk.DecCoins{ @@ -88,7 +88,7 @@ func TestWithdrawValidatorCommission(t *testing.T) { } func TestGetTotalRewards(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valCommission := sdk.DecCoins{ @@ -109,7 +109,7 @@ func TestGetTotalRewards(t *testing.T) { } func TestFundCommunityPool(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // reset fee pool diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index eda2175ed4..07f5a90322 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -221,7 +221,7 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) genesisVals := app.StakingKeeper.GetAllValidators(suite.ctx) diff --git a/x/distribution/simulation/proposals_test.go b/x/distribution/simulation/proposals_test.go index aec70fd832..c7a6ad6bf7 100644 --- a/x/distribution/simulation/proposals_test.go +++ b/x/distribution/simulation/proposals_test.go @@ -15,7 +15,7 @@ import ( ) func TestProposalContents(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // initialize parameters diff --git a/x/evidence/genesis_test.go b/x/evidence/genesis_test.go index 6f0ea79411..45148a9c40 100644 --- a/x/evidence/genesis_test.go +++ b/x/evidence/genesis_test.go @@ -26,7 +26,7 @@ type GenesisTestSuite struct { func (suite *GenesisTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1}) suite.keeper = app.EvidenceKeeper diff --git a/x/evidence/keeper/keeper_test.go b/x/evidence/keeper/keeper_test.go index eb5fdd974b..a135a7dc1b 100644 --- a/x/evidence/keeper/keeper_test.go +++ b/x/evidence/keeper/keeper_test.go @@ -80,7 +80,7 @@ type KeeperTestSuite struct { func (suite *KeeperTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) // recreate keeper in order to use custom testing types evidenceKeeper := keeper.NewKeeper( diff --git a/x/evidence/simulation/decoder_test.go b/x/evidence/simulation/decoder_test.go index d23d796a08..a483a3c105 100644 --- a/x/evidence/simulation/decoder_test.go +++ b/x/evidence/simulation/decoder_test.go @@ -16,7 +16,7 @@ import ( ) func TestDecodeStore(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) dec := simulation.NewDecodeStore(app.EvidenceKeeper) delPk1 := ed25519.GenPrivKey().PubKey() diff --git a/x/feegrant/basic_fee_test.go b/x/feegrant/basic_fee_test.go index 71d278fa40..05f13f0b3d 100644 --- a/x/feegrant/basic_fee_test.go +++ b/x/feegrant/basic_fee_test.go @@ -14,7 +14,7 @@ import ( ) func TestBasicFeeValidAllow(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) badTime := ctx.BlockTime().AddDate(0, 0, -1) diff --git a/x/feegrant/filtered_fee_test.go b/x/feegrant/filtered_fee_test.go index 6928bb562d..439187bb26 100644 --- a/x/feegrant/filtered_fee_test.go +++ b/x/feegrant/filtered_fee_test.go @@ -15,7 +15,7 @@ import ( ) func TestFilteredFeeValidAllow(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, ocproto.Header{ Time: time.Now(), diff --git a/x/feegrant/grant_test.go b/x/feegrant/grant_test.go index e30d7d046b..ce3f9f9faa 100644 --- a/x/feegrant/grant_test.go +++ b/x/feegrant/grant_test.go @@ -13,7 +13,7 @@ import ( ) func TestGrant(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) addr, err := sdk.AccAddressFromHexUnsafe("0x058b15d64f210480217ab50093b7373a41a86c33") require.NoError(t, err) addr2, err := sdk.AccAddressFromHexUnsafe("0x09417afda96ea6f066fc943bfadbc87e63eb67e5") diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index 0c80780da5..2db6119658 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -23,7 +23,7 @@ type GenesisTestSuite struct { func (suite *GenesisTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1}) suite.keeper = app.FeeGrantKeeper } diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index e8195951f9..439f824302 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -30,7 +30,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (suite *KeeperTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) suite.app = app diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 4c8aa03d41..486284e5f0 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -14,7 +14,7 @@ import ( ) func TestFeegrantPruning(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 4, sdk.NewInt(1000)) diff --git a/x/feegrant/periodic_fee_test.go b/x/feegrant/periodic_fee_test.go index 439ef19a01..3d90149fe9 100644 --- a/x/feegrant/periodic_fee_test.go +++ b/x/feegrant/periodic_fee_test.go @@ -14,7 +14,7 @@ import ( ) func TestPeriodicFeeValidAllow(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{ Time: time.Now(), }) diff --git a/x/feegrant/simulation/genesis_test.go b/x/feegrant/simulation/genesis_test.go index 44669c04be..389af0242a 100644 --- a/x/feegrant/simulation/genesis_test.go +++ b/x/feegrant/simulation/genesis_test.go @@ -16,7 +16,7 @@ import ( ) func TestRandomizedGenState(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 1a6b9a2397..ba432cfe57 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -27,7 +27,7 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{ Time: time.Now(), diff --git a/x/gashub/keeper/keeper_test.go b/x/gashub/keeper/keeper_test.go index 46bebb7217..3acd0df977 100644 --- a/x/gashub/keeper/keeper_test.go +++ b/x/gashub/keeper/keeper_test.go @@ -23,7 +23,7 @@ type IntegrationTestSuite struct { } func (suite *IntegrationTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index f9a40962d6..2c90600bdf 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -48,7 +48,7 @@ type GenTxTestSuite struct { func (suite *GenTxTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{ChainID: simapp.DefaultChainId}) suite.app = app suite.encodingConfig = simapp.MakeTestEncodingConfig() diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index f5934a6c67..20cddf3576 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -22,7 +22,7 @@ import ( ) func TestTickExpiredDepositPeriod(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) @@ -75,7 +75,7 @@ func TestTickExpiredDepositPeriod(t *testing.T) { } func TestTickMultipleExpiredDepositPeriod(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) @@ -154,7 +154,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) { } func TestTickPassedDepositPeriod(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) @@ -208,7 +208,7 @@ func TestTickPassedDepositPeriod(t *testing.T) { } func TestTickPassedVotingPeriod(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) @@ -274,7 +274,7 @@ func TestTickPassedVotingPeriod(t *testing.T) { } func TestProposalPassedEndblocker(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 10, valTokens) @@ -327,7 +327,7 @@ func TestProposalPassedEndblocker(t *testing.T) { } func TestEndBlockerProposalHandlerFailed(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 1, valTokens) diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index a592f0d7d8..f0a51d637d 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -22,7 +22,7 @@ import ( ) func TestImportExportQueues(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrs(app, ctx, 2, valTokens) @@ -117,7 +117,7 @@ func TestImportExportQueues(t *testing.T) { } func TestImportExportQueues_ErrorUnconsistentState(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) require.Panics(t, func() { gov.InitGenesis(ctx, app.AccountKeeper, app.BankKeeper, app.GovKeeper, &v1.GenesisState{ diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index 8d0a1986aa..1c326097eb 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -11,7 +11,7 @@ import ( ) func TestDeposits(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) TestAddrs := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(10000000)) diff --git a/x/gov/keeper/hooks_test.go b/x/gov/keeper/hooks_test.go index 19be117333..ba14e6e655 100644 --- a/x/gov/keeper/hooks_test.go +++ b/x/gov/keeper/hooks_test.go @@ -47,7 +47,7 @@ func (h *MockGovHooksReceiver) AfterProposalVotingPeriodEnded(ctx sdk.Context, p } func TestHooks(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) minDeposit := app.GovKeeper.GetDepositParams(ctx).MinDeposit diff --git a/x/gov/keeper/keeper_test.go b/x/gov/keeper/keeper_test.go index 95daf0797e..3f5b880e51 100644 --- a/x/gov/keeper/keeper_test.go +++ b/x/gov/keeper/keeper_test.go @@ -30,7 +30,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // Populate the gov account with some coins, as the TestProposal we have @@ -60,7 +60,7 @@ func (suite *KeeperTestSuite) SetupTest() { } func TestIncrementProposalNumber(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) tp := TestProposal @@ -81,7 +81,7 @@ func TestIncrementProposalNumber(t *testing.T) { } func TestProposalQueues(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // create test proposals diff --git a/x/gov/keeper/querier_test.go b/x/gov/keeper/querier_test.go index cfe3032f1d..f9e7c087ca 100644 --- a/x/gov/keeper/querier_test.go +++ b/x/gov/keeper/querier_test.go @@ -144,7 +144,7 @@ func getQueriedVotes(t *testing.T, ctx sdk.Context, cdc *codec.LegacyAmino, quer } func TestQueries(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) legacyQuerierCdc := app.LegacyAmino() querier := keeper.NewQuerier(app.GovKeeper, legacyQuerierCdc) @@ -305,7 +305,7 @@ func TestQueries(t *testing.T) { } func TestPaginatedVotesQuery(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) legacyQuerierCdc := app.LegacyAmino() diff --git a/x/gov/keeper/tally_test.go b/x/gov/keeper/tally_test.go index adb0d5a416..356260bde1 100644 --- a/x/gov/keeper/tally_test.go +++ b/x/gov/keeper/tally_test.go @@ -14,7 +14,7 @@ import ( ) func TestTallyNoOneVotes(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) createValidators(t, ctx, app, []int64{5, 5, 5}) @@ -36,7 +36,7 @@ func TestTallyNoOneVotes(t *testing.T) { } func TestTallyNoQuorum(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) createValidators(t, ctx, app, []int64{2, 5, 0}) @@ -61,7 +61,7 @@ func TestTallyNoQuorum(t *testing.T) { } func TestTallyOnlyValidatorsAllYes(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs, _ := createValidators(t, ctx, app, []int64{5, 5, 5}) @@ -87,7 +87,7 @@ func TestTallyOnlyValidatorsAllYes(t *testing.T) { } func TestTallyOnlyValidators51No(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valAccAddrs, _ := createValidators(t, ctx, app, []int64{5, 6, 0}) @@ -111,7 +111,7 @@ func TestTallyOnlyValidators51No(t *testing.T) { } func TestTallyOnlyValidators51Yes(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valAccAddrs, _ := createValidators(t, ctx, app, []int64{5, 6, 0}) @@ -136,7 +136,7 @@ func TestTallyOnlyValidators51Yes(t *testing.T) { } func TestTallyOnlyValidatorsVetoed(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valAccAddrs, _ := createValidators(t, ctx, app, []int64{6, 6, 7}) @@ -162,7 +162,7 @@ func TestTallyOnlyValidatorsVetoed(t *testing.T) { } func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valAccAddrs, _ := createValidators(t, ctx, app, []int64{6, 6, 7}) @@ -188,7 +188,7 @@ func TestTallyOnlyValidatorsAbstainPasses(t *testing.T) { } func TestTallyOnlyValidatorsAbstainFails(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valAccAddrs, _ := createValidators(t, ctx, app, []int64{6, 6, 7}) @@ -214,7 +214,7 @@ func TestTallyOnlyValidatorsAbstainFails(t *testing.T) { } func TestTallyOnlyValidatorsNonVoter(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) valAccAddrs, _ := createValidators(t, ctx, app, []int64{5, 6, 7}) @@ -240,7 +240,7 @@ func TestTallyOnlyValidatorsNonVoter(t *testing.T) { } func TestTallyDelgatorOverride(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs, valAddrs := createValidators(t, ctx, app, []int64{5, 6, 7}) @@ -276,7 +276,7 @@ func TestTallyDelgatorOverride(t *testing.T) { } func TestTallyDelgatorInherit(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7}) @@ -311,7 +311,7 @@ func TestTallyDelgatorInherit(t *testing.T) { } func TestTallyDelgatorMultipleOverride(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7}) @@ -351,7 +351,7 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) { } func TestTallyDelgatorMultipleInherit(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) createValidators(t, ctx, app, []int64{25, 6, 7}) @@ -392,7 +392,7 @@ func TestTallyDelgatorMultipleInherit(t *testing.T) { } func TestTallyJailedValidator(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs, valAddrs := createValidators(t, ctx, app, []int64{25, 6, 7}) @@ -435,7 +435,7 @@ func TestTallyJailedValidator(t *testing.T) { } func TestTallyValidatorMultipleDelegations(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs, valAddrs := createValidators(t, ctx, app, []int64{10, 10, 10}) diff --git a/x/gov/keeper/vote_test.go b/x/gov/keeper/vote_test.go index a1723c0f45..bd86949962 100644 --- a/x/gov/keeper/vote_test.go +++ b/x/gov/keeper/vote_test.go @@ -12,7 +12,7 @@ import ( ) func TestVotes(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000)) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 607ce8a9ea..5634807ec0 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -262,7 +262,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { // returns context and an app with updated mint keeper func createTestApp(t *testing.T, isCheckTx bool) (*simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, isCheckTx) + app := simapp.Setup(t, isCheckTx, true) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) app.MintKeeper.SetParams(ctx, minttypes.DefaultParams()) diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index 21b390be9b..d439bf8a29 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -13,7 +13,7 @@ import ( ) func TestQueryGroupsByMember(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) group.RegisterQueryServer(queryHelper, app.GroupKeeper) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 4df09ddf44..9e4220d7af 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -38,7 +38,7 @@ type TestSuite struct { } func (s *TestSuite) SetupTest() { - app := simapp.Setup(s.T(), false) + app := simapp.Setup(s.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) s.blockTime = tmtime.Now() diff --git a/x/group/module/abci_test.go b/x/group/module/abci_test.go index f1cd9f53a9..33c8a282b4 100644 --- a/x/group/module/abci_test.go +++ b/x/group/module/abci_test.go @@ -18,7 +18,7 @@ import ( ) func TestEndBlockerPruning(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(30000000)) addr1 := addrs[0] @@ -318,7 +318,7 @@ func TestEndBlockerPruning(t *testing.T) { } func TestEndBlockerTallying(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrs := simapp.AddTestAddrsIncremental(app, ctx, 4, sdk.NewInt(30000000)) diff --git a/x/group/simulation/genesis_test.go b/x/group/simulation/genesis_test.go index f87a5eb18f..f8f7823903 100644 --- a/x/group/simulation/genesis_test.go +++ b/x/group/simulation/genesis_test.go @@ -16,7 +16,7 @@ import ( ) func TestRandomizedGenState(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 1d3d6b31e2..9ff662af54 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -27,7 +27,7 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) } diff --git a/x/mint/keeper/grpc_query_test.go b/x/mint/keeper/grpc_query_test.go index cc2733d253..d1519d7ad2 100644 --- a/x/mint/keeper/grpc_query_test.go +++ b/x/mint/keeper/grpc_query_test.go @@ -22,7 +22,7 @@ type MintTestSuite struct { } func (suite *MintTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) diff --git a/x/mint/keeper/querier_test.go b/x/mint/keeper/querier_test.go index 2093da8751..5048537924 100644 --- a/x/mint/keeper/querier_test.go +++ b/x/mint/keeper/querier_test.go @@ -24,7 +24,7 @@ type MintKeeperTestSuite struct { } func (suite *MintKeeperTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), true) + app := simapp.Setup(suite.T(), true, true) ctx := app.BaseApp.NewContext(true, tmproto.Header{}) app.MintKeeper.SetParams(ctx, types.DefaultParams()) diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 5de7e2f7b2..b33f762de8 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -35,7 +35,7 @@ type TestSuite struct { } func (s *TestSuite) SetupTest() { - app := simapp.Setup(s.T(), false) + app := simapp.Setup(s.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) ctx = ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) diff --git a/x/nft/simulation/genesis_test.go b/x/nft/simulation/genesis_test.go index 3586229497..76462fa435 100644 --- a/x/nft/simulation/genesis_test.go +++ b/x/nft/simulation/genesis_test.go @@ -16,7 +16,7 @@ import ( ) func TestRandomizedGenState(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) s := rand.NewSource(1) r := rand.New(s) diff --git a/x/nft/simulation/operations_test.go b/x/nft/simulation/operations_test.go index 613ebea125..e7da1c4b4d 100644 --- a/x/nft/simulation/operations_test.go +++ b/x/nft/simulation/operations_test.go @@ -28,7 +28,7 @@ type SimTestSuite struct { func (suite *SimTestSuite) SetupTest() { checkTx := false - app := simapp.Setup(suite.T(), checkTx) + app := simapp.Setup(suite.T(), checkTx, true) suite.app = app suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{}) } diff --git a/x/params/keeper/keeper_test.go b/x/params/keeper/keeper_test.go index e22cb8b198..8ef433639c 100644 --- a/x/params/keeper/keeper_test.go +++ b/x/params/keeper/keeper_test.go @@ -27,7 +27,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - suite.app = simapp.Setup(suite.T(), false) + suite.app = simapp.Setup(suite.T(), false, true) suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) diff --git a/x/params/proposal_handler_test.go b/x/params/proposal_handler_test.go index 7b4bb36d63..da687de3cc 100644 --- a/x/params/proposal_handler_test.go +++ b/x/params/proposal_handler_test.go @@ -26,7 +26,7 @@ type HandlerTestSuite struct { } func (suite *HandlerTestSuite) SetupTest() { - suite.app = simapp.Setup(suite.T(), false) + suite.app = simapp.Setup(suite.T(), false, true) suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}) suite.govHandler = params.NewParamChangeProposalHandler(suite.app.ParamsKeeper) } diff --git a/x/slashing/abci_test.go b/x/slashing/abci_test.go index c1c8240603..6d81a3976c 100644 --- a/x/slashing/abci_test.go +++ b/x/slashing/abci_test.go @@ -17,7 +17,7 @@ import ( ) func TestBeginBlocker(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) pks := simapp.CreateTestPubKeys(1) diff --git a/x/slashing/keeper/genesis_test.go b/x/slashing/keeper/genesis_test.go index 3cea49ea38..4d65e14011 100644 --- a/x/slashing/keeper/genesis_test.go +++ b/x/slashing/keeper/genesis_test.go @@ -14,7 +14,7 @@ import ( ) func TestExportAndInitGenesis(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.SlashingKeeper.SetParams(ctx, testslashing.TestParams()) diff --git a/x/slashing/keeper/grpc_query_test.go b/x/slashing/keeper/grpc_query_test.go index 5a8733babe..64ec07f878 100644 --- a/x/slashing/keeper/grpc_query_test.go +++ b/x/slashing/keeper/grpc_query_test.go @@ -28,7 +28,7 @@ type SlashingTestSuite struct { } func (suite *SlashingTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) diff --git a/x/slashing/keeper/keeper_test.go b/x/slashing/keeper/keeper_test.go index 3b65eb9341..7a08c87336 100644 --- a/x/slashing/keeper/keeper_test.go +++ b/x/slashing/keeper/keeper_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/simapp" @@ -13,10 +14,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/teststaking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/upgrade" ) func TestUnJailNotBonded(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) p := app.StakingKeeper.GetParams(ctx) @@ -82,7 +84,7 @@ func TestUnJailNotBonded(t *testing.T) { // Ensure that SigningInfo.StartHeight is set correctly // and that they are not immediately jailed func TestHandleNewValidator(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200)) @@ -128,7 +130,7 @@ func TestHandleNewValidator(t *testing.T) { // Ensure that they're only slashed once func TestHandleAlreadyJailed(t *testing.T) { // initial setup - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200)) @@ -181,7 +183,7 @@ func TestHandleAlreadyJailed(t *testing.T) { func TestValidatorDippingInAndOut(t *testing.T) { // initial setup // TestParams set the SignedBlocksWindow to 1000 and MaxMissedBlocksPerWindow to 500 - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.SlashingKeeper.SetParams(ctx, testslashing.TestParams()) @@ -207,6 +209,8 @@ func TestValidatorDippingInAndOut(t *testing.T) { height := int64(0) for ; height < int64(100); height++ { ctx = ctx.WithBlockHeight(height) + // upgrade public delegation + upgrade.BeginBlocker(app.UpgradeKeeper, ctx, abci.RequestBeginBlock{}) app.SlashingKeeper.HandleValidatorSignature(ctx, val.Address(), power, true) } @@ -222,6 +226,7 @@ func TestValidatorDippingInAndOut(t *testing.T) { ctx = ctx.WithBlockHeight(height) // validator added back in + tstaking.Ctx = ctx tstaking.DelegateWithPower(sdk.AccAddress(pks[2].Address()), valAddr, 50) validatorUpdates = staking.EndBlocker(ctx, app.StakingKeeper) diff --git a/x/slashing/keeper/querier_test.go b/x/slashing/keeper/querier_test.go index 0b9fb6b51a..aac5842252 100644 --- a/x/slashing/keeper/querier_test.go +++ b/x/slashing/keeper/querier_test.go @@ -16,7 +16,7 @@ import ( ) func TestNewQuerier(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.SlashingKeeper.SetParams(ctx, testslashing.TestParams()) legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino()) @@ -34,7 +34,7 @@ func TestNewQuerier(t *testing.T) { func TestQueryParams(t *testing.T) { cdc := codec.NewLegacyAmino() legacyQuerierCdc := codec.NewAminoCodec(cdc) - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.SlashingKeeper.SetParams(ctx, testslashing.TestParams()) diff --git a/x/slashing/keeper/signing_info_test.go b/x/slashing/keeper/signing_info_test.go index cee32a0d54..167d717807 100644 --- a/x/slashing/keeper/signing_info_test.go +++ b/x/slashing/keeper/signing_info_test.go @@ -13,7 +13,7 @@ import ( ) func TestGetSetValidatorSigningInfo(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200)) @@ -37,7 +37,7 @@ func TestGetSetValidatorSigningInfo(t *testing.T) { } func TestGetSetValidatorMissedBlockBitArray(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200)) @@ -49,7 +49,7 @@ func TestGetSetValidatorMissedBlockBitArray(t *testing.T) { } func TestTombstoned(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200)) @@ -73,7 +73,7 @@ func TestTombstoned(t *testing.T) { } func TestJailUntil(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrDels := simapp.AddTestAddrsIncremental(app, ctx, 1, app.StakingKeeper.TokensFromConsensusPower(ctx, 200)) diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 043e2b6906..a3050c2c21 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -126,7 +126,7 @@ func createTestApp(t *testing.T, isCheckTx bool, r *rand.Rand, n int) (*simapp.S Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), } - app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) + app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, true, balance) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) initAmt := app.StakingKeeper.TokensFromConsensusPower(ctx, 200) diff --git a/x/staking/common_test.go b/x/staking/common_test.go index bec26d2525..070679ee09 100644 --- a/x/staking/common_test.go +++ b/x/staking/common_test.go @@ -38,7 +38,7 @@ var ( // getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper // to avoid messing with the hooks. func getBaseSimappWithCustomKeeper(t *testing.T) (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) appCodec := app.AppCodec() diff --git a/x/staking/keeper/common_test.go b/x/staking/keeper/common_test.go index 2356b27e3d..2be87c5784 100644 --- a/x/staking/keeper/common_test.go +++ b/x/staking/keeper/common_test.go @@ -22,7 +22,7 @@ func init() { // createTestInput Returns a simapp with custom StakingKeeper // to avoid messing with the hooks. func createTestInput(t *testing.T) (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.StakingKeeper = keeper.NewKeeper( diff --git a/x/staking/keeper/genesis_test.go b/x/staking/keeper/genesis_test.go index f502aeb105..a04324ee89 100644 --- a/x/staking/keeper/genesis_test.go +++ b/x/staking/keeper/genesis_test.go @@ -17,7 +17,7 @@ import ( ) func bootstrapGenesisTest(t *testing.T, numAddrs int) (*simapp.SimApp, sdk.Context, []sdk.AccAddress) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) addrDels, _ := generateAddresses(app, ctx, numAddrs) @@ -113,7 +113,7 @@ func TestInitGenesis(t *testing.T) { } func TestInitGenesis_PoolsBalanceMismatch(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.NewContext(false, tmproto.Header{}) consPub, err := codectypes.NewAnyWithValue(PKs[0]) diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 610acf4cb0..f970b7872c 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -27,7 +27,7 @@ type KeeperTestSuite struct { } func (suite *KeeperTestSuite) SetupTest() { - app := simapp.Setup(suite.T(), false) + app := simapp.Setup(suite.T(), false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) querier := keeper.Querier{Keeper: app.StakingKeeper} @@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) SetupTest() { } func TestParams(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) expParams := types.DefaultParams() diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 15479aafdf..c68b3c1b0f 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -17,6 +17,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" gov "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/staking/types" + upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) type msgServer struct { @@ -317,7 +318,12 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ return nil, err } - // TODO: And a hard fork to allow all delegations, before that fork, only self delegation allowed. + if !ctx.IsUpgraded(upgrade.EnablePublicDelegationUpgrade) { + selfDelAddress := validator.GetSelfDelegator() + if delegatorAddress.String() != selfDelAddress.String() { + return nil, types.ErrDelegationNotAllowed + } + } bondDenom := k.BondDenom(ctx) if msg.Amount.Denom != bondDenom { @@ -363,6 +369,10 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ // BeginRedelegate defines a method for performing a redelegation of coins from a delegator and source validator to a destination validator func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRedelegate) (*types.MsgBeginRedelegateResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + if !ctx.IsUpgraded(upgrade.EnablePublicDelegationUpgrade) { + return nil, types.ErrRedelegationNotAllowed + } + valSrcAddr, err := sdk.AccAddressFromHexUnsafe(msg.ValidatorSrcAddress) if err != nil { return nil, err @@ -378,8 +388,6 @@ func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRed return nil, err } - // TODO: And a hard fork to allow all redelegations - bondDenom := k.BondDenom(ctx) if msg.Amount.Denom != bondDenom { return nil, sdkerrors.Wrapf( diff --git a/x/staking/keeper/msg_server_test.go b/x/staking/keeper/msg_server_test.go index d0fa08e2e4..9b00cc6b01 100644 --- a/x/staking/keeper/msg_server_test.go +++ b/x/staking/keeper/msg_server_test.go @@ -15,7 +15,7 @@ import ( func TestCancelUnbondingDelegation(t *testing.T) { // setup the app - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) msgServer := keeper.NewMsgServerImpl(app.StakingKeeper) bondDenom := app.StakingKeeper.BondDenom(ctx) diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 8d556e813f..35132ce325 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -313,7 +313,7 @@ func createTestApp(t *testing.T, isCheckTx bool, r *rand.Rand, n int) (*simapp.S Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))), } - app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance) + app := simapp.SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, true, balance) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{ChainID: simapp.DefaultChainId}) app.MintKeeper.SetParams(ctx, minttypes.DefaultParams()) diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index faf6dce225..2518639014 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -22,7 +22,7 @@ var ( ) func TestAuthzAuthorizations(t *testing.T) { - app := simapp.Setup(t, false) + app := simapp.Setup(t, false, true) ctx := app.BaseApp.NewContext(false, tmproto.Header{}) // verify ValidateBasic returns error for the AUTHORIZATION_TYPE_UNSPECIFIED authorization type diff --git a/x/upgrade/client/testutil/suite.go b/x/upgrade/client/testutil/suite.go index d5e21ce47a..939efee524 100644 --- a/x/upgrade/client/testutil/suite.go +++ b/x/upgrade/client/testutil/suite.go @@ -29,7 +29,7 @@ type IntegrationTestSuite struct { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - app := simapp.Setup(s.T(), false) + app := simapp.Setup(s.T(), false, true) s.app = app s.ctx = app.BaseApp.NewContext(false, tmproto.Header{}) diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index dd0c8eb489..ea7636bd7a 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -24,7 +24,7 @@ type UpgradeTestSuite struct { } func (suite *UpgradeTestSuite) SetupTest() { - suite.app = simapp.Setup(suite.T(), false) + suite.app = simapp.Setup(suite.T(), false, false) suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{}) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index ee91bf1c31..b26b7b628f 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -26,7 +26,7 @@ type KeeperTestSuite struct { func (s *KeeperTestSuite) SetupTest() { var err error - app := simapp.Setup(s.T(), false) + app := simapp.Setup(s.T(), false, true) homeDir := filepath.Join(s.T().TempDir(), "x_upgrade_keeper_test") app.UpgradeKeeper, err = keeper.NewKeeper( // recreate keeper in order to use a custom home Path app.GetKey(types.StoreKey), app.AppCodec(), homeDir, diff --git a/x/upgrade/types/upgrade_config.go b/x/upgrade/types/upgrade_config.go index fc9612069a..ddbf16af45 100644 --- a/x/upgrade/types/upgrade_config.go +++ b/x/upgrade/types/upgrade_config.go @@ -9,6 +9,10 @@ import ( // BEP111 = "BEP111" // ) +const ( + EnablePublicDelegationUpgrade = "EnablePublicDelegationUpgrade" +) + var ( MainnetChainID = "inscription_9000-1" MainnetConfig = NewUpgradeConfig()