Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce enable public delegation upgrade #87

Merged
merged 5 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,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{
Expand All @@ -365,6 +370,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
Expand Down Expand Up @@ -719,3 +729,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.",
},
}
}
7 changes: 6 additions & 1 deletion simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"strings"
"testing"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

storetypes "github.com/cosmos/cosmos-sdk/store/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
"github.com/cosmos/cosmos-sdk/store"
Expand Down Expand Up @@ -315,6 +316,10 @@ func TestAppStateDeterminism(t *testing.T) {
db := dbm.NewMemDB()
app := NewSimApp(logger, db, nil, true, DefaultNodeHome, FlagPeriodValue, MakeTestEncodingConfig(), EmptyAppOptions{}, interBlockCacheOpt())

app.SetUpgradeChecker(func(context sdk.Context, s string) bool {
return true
})

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
Expand Down
20 changes: 13 additions & 7 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
Expand Down Expand Up @@ -213,10 +219,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, "", " ")
Expand Down Expand Up @@ -258,7 +264,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
Expand Down
2 changes: 2 additions & 0 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/query/pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion x/auth/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion x/auth/migrations/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func TestMigrateVestingAccounts(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
app := simapp.Setup(t, false)
app := simapp.Setup(t, false, true)
ctx := app.BaseApp.NewContext(false, tmproto.Header{
Time: time.Now(),
})
Expand Down
2 changes: 1 addition & 1 deletion x/auth/migrations/v046/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion x/auth/signing/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion x/auth/simulation/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/auth/vesting/types/vesting_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
2 changes: 1 addition & 1 deletion x/authz/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/authz/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion x/authz/module/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion x/authz/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/authz/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion x/bank/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
Expand Down
2 changes: 1 addition & 1 deletion x/bank/types/send_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion x/capability/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/capability/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions x/crisis/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand All @@ -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}})

Expand All @@ -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}})

Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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()})

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading