Skip to content

Commit

Permalink
Merge pull request #144 from crescent-network/mm-order
Browse files Browse the repository at this point in the history
refactor!: modify mm order
  • Loading branch information
kingcre authored Feb 13, 2023
2 parents 2232323 + 9a55d05 commit fd1ccc2
Show file tree
Hide file tree
Showing 57 changed files with 7,720 additions and 45,025 deletions.
11 changes: 10 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import (
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
transfer "github.com/cosmos/ibc-go/v3/modules/apps/transfer"
"github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v3/modules/core"
Expand All @@ -110,6 +110,7 @@ import (
v2_0_0 "github.com/crescent-network/crescent/v4/app/upgrades/mainnet/v2.0.0"
v3 "github.com/crescent-network/crescent/v4/app/upgrades/mainnet/v3"
v4 "github.com/crescent-network/crescent/v4/app/upgrades/mainnet/v4"
v5 "github.com/crescent-network/crescent/v4/app/upgrades/mainnet/v5"
"github.com/crescent-network/crescent/v4/app/upgrades/testnet/rc4"
"github.com/crescent-network/crescent/v4/x/claim"
claimkeeper "github.com/crescent-network/crescent/v4/x/claim/keeper"
Expand Down Expand Up @@ -1010,6 +1011,10 @@ func (app *App) SetUpgradeStoreLoaders() {
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &v4.StoreUpgrades))
}
if upgradeInfo.Name == v5.UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &v5.StoreUpgrades))
}
}

func (app *App) SetUpgradeHandlers(mm *module.Manager, configurator module.Configurator) {
Expand All @@ -1028,4 +1033,8 @@ func (app *App) SetUpgradeHandlers(mm *module.Manager, configurator module.Confi
app.UpgradeKeeper.SetUpgradeHandler(
v4.UpgradeName, v4.UpgradeHandler(
mm, configurator, app.icaModule))

app.UpgradeKeeper.SetUpgradeHandler(
v5.UpgradeName, v5.UpgradeHandler(
mm, configurator))
}
19 changes: 19 additions & 0 deletions app/upgrades/mainnet/v5/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v5

import (
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const UpgradeName = "v5"

func UpgradeHandler(
mm *module.Manager, configurator module.Configurator) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, fromVM)
}
}

var StoreUpgrades = store.StoreUpgrades{}
80 changes: 80 additions & 0 deletions app/upgrades/mainnet/v5/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package v5_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

chain "github.com/crescent-network/crescent/v4/app"
v5 "github.com/crescent-network/crescent/v4/app/upgrades/mainnet/v5"
"github.com/crescent-network/crescent/v4/cmd/crescentd/cmd"
utils "github.com/crescent-network/crescent/v4/types"
liquiditytypes "github.com/crescent-network/crescent/v4/x/liquidity/types"
)

type UpgradeTestSuite struct {
suite.Suite
ctx sdk.Context
app *chain.App
}

func (s *UpgradeTestSuite) SetupTest() {
cmd.GetConfig()
s.app = chain.Setup(false)
s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{
Height: 1,
Time: utils.ParseTime("2023-03-01T00:00:00Z"),
})
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

const testUpgradeHeight = 10

func (s *UpgradeTestSuite) TestUpgradeV5() {
testCases := []struct {
title string
before func()
after func()
expPass bool
}{
{
"v5 upgrade liquidity",
func() {},
func() {
liquidityParams := s.app.LiquidityKeeper.GetParams(s.ctx)
s.Require().EqualValues(
liquidityParams.MaxNumMarketMakingOrdersPerPair, liquiditytypes.DefaultMaxNumMarketMakingOrdersPerPair)
},
true,
},
}

for _, tc := range testCases {
s.Run(tc.title, func() {
s.SetupTest()

tc.before()

s.ctx = s.ctx.WithBlockHeight(testUpgradeHeight - 1)
plan := upgradetypes.Plan{Name: v5.UpgradeName, Height: testUpgradeHeight}
err := s.app.UpgradeKeeper.ScheduleUpgrade(s.ctx, plan)
s.Require().NoError(err)
_, exists := s.app.UpgradeKeeper.GetUpgradePlan(s.ctx)
s.Require().True(exists)

s.ctx = s.ctx.WithBlockHeight(testUpgradeHeight)
s.Require().NotPanics(func() {
s.app.BeginBlocker(s.ctx, abci.RequestBeginBlock{})
})

tc.after()
})
}
}
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

Loading

0 comments on commit fd1ccc2

Please sign in to comment.