Skip to content

Commit

Permalink
bump cosmos-sdk to v0.50
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Jan 4, 2024
1 parent 45259cb commit efc9ce3
Show file tree
Hide file tree
Showing 20 changed files with 677 additions and 698 deletions.
4 changes: 2 additions & 2 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

opchildante "github.com/initia-labs/OPinit/x/opchild/ante"
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
Expand Down
432 changes: 191 additions & 241 deletions app/app.go

Large diffs are not rendered by default.

42 changes: 20 additions & 22 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@ import (
"os"
"testing"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"cosmossdk.io/log"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"

"github.com/cosmos/cosmos-sdk/testutil/mock"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/consensus"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/ibc-go/modules/capability"

"cosmossdk.io/x/upgrade"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/x/params"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v8/modules/core"

opchild "github.com/initia-labs/OPinit/x/opchild"
"github.com/initia-labs/initia/x/bank"
Expand Down Expand Up @@ -66,10 +65,10 @@ func TestGetMaccPerms(t *testing.T) {

func TestInitGenesisOnMigration(t *testing.T) {
db := dbm.NewMemDB()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
logger := log.NewLogger(os.Stdout)
app := NewMinitiaApp(
logger, db, nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})

// Create a mock module. This module will serve as the new module we're
// adding during a migration.
Expand All @@ -78,14 +77,14 @@ func TestInitGenesisOnMigration(t *testing.T) {
mockModule := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockDefaultGenesis := json.RawMessage(`{"key": "value"}`)
mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis)
mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil)
mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1)
mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0))

app.mm.Modules["mock"] = mockModule
app.ModuleManager.Modules["mock"] = mockModule

// Run migrations only for "mock" module. We exclude it from
// the VersionMap to simulate upgrading with a new module.
_, err := app.mm.RunMigrations(ctx, app.configurator,
_, err := app.ModuleManager.RunMigrations(ctx, app.configurator,
module.VersionMap{
"bank": bank.AppModule{}.ConsensusVersion(),
"auth": auth.AppModule{}.ConsensusVersion(),
Expand All @@ -105,14 +104,15 @@ func TestInitGenesisOnMigration(t *testing.T) {
)
require.NoError(t, err)
}

func TestUpgradeStateOnGenesis(t *testing.T) {
app := SetupWithGenesisAccounts(nil, nil)

// make sure the upgrade keeper has version map in state
ctx := app.NewContext(false, tmproto.Header{})
vm := app.UpgradeKeeper.GetModuleVersionMap(ctx)
for v, i := range app.mm.Modules {
ctx := app.NewContext(true)
vm, err := app.UpgradeKeeper.GetModuleVersionMap(ctx)
require.NoError(t, err)

for v, i := range app.ModuleManager.Modules {
if i, ok := i.(module.HasConsensusVersion); ok {
require.Equal(t, vm[v], i.ConsensusVersion())
}
Expand All @@ -122,10 +122,8 @@ func TestUpgradeStateOnGenesis(t *testing.T) {
func TestGetKey(t *testing.T) {
db := dbm.NewMemDB()
app := NewMinitiaApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
log.NewLogger(os.Stdout),
db, nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})

require.NotEmpty(t, app.GetKey(banktypes.StoreKey))
require.NotEmpty(t, app.GetTKey(paramstypes.TStoreKey))
require.NotEmpty(t, app.GetMemKey(capabilitytypes.MemStoreKey))
}
59 changes: 42 additions & 17 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
package app

import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/std"
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"

moveconfig "github.com/initia-labs/initia/x/move/config"
"github.com/initia-labs/minimove/app/params"
)

var legacyCodecRegistered = false

// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)

if !legacyCodecRegistered {
// authz module use this codec to get signbytes.
// authz MsgExec can execute all message types,
// so legacy.Cdc need to register all amino messages to get proper signature
ModuleBasics.RegisterLegacyAminoCodec(legacy.Cdc)
legacyCodecRegistered = true
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
encodingConfig := params.EncodingConfig{
InterfaceRegistry: tempApp.InterfaceRegistry(),
Codec: tempApp.AppCodec(),
TxConfig: tempApp.TxConfig(),
Amino: tempApp.LegacyAmino(),
}

return encodingConfig
}

func AutoCliOpts() autocli.AppOptions {
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range tempApp.ModuleManager.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
moduleName := moduleWithName.Name()
if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
modules[moduleName] = appModule
}
}
}

return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(tempApp.ModuleManager.Modules),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}
}

func BasicManager() module.BasicManager {
tempApp := NewMinitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
return tempApp.BasicModuleManager
}
8 changes: 5 additions & 3 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"encoding/json"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/initia-labs/OPinit/x/opchild"

servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -15,7 +14,7 @@ func (app *MinitiaApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
) (servertypes.ExportedApp, error) {
// as if they could withdraw from the start of the next block
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContext(true)

// We export at last height + 1, because that's the height at which
// Tendermint will start InitChain.
Expand All @@ -24,7 +23,10 @@ func (app *MinitiaApp) ExportAppStateAndValidators(
height = 0
}

genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
genState, err := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
if err != nil {
return servertypes.ExportedApp{}, err
}
appState, err := json.MarshalIndent(genState, "", " ")
if err != nil {
return servertypes.ExportedApp{}, err
Expand Down
12 changes: 6 additions & 6 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icagenesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctypes "github.com/cosmos/ibc-go/v7/modules/core/types"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icagenesistypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/genesis/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctypes "github.com/cosmos/ibc-go/v8/modules/core/types"

opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
movetypes "github.com/initia-labs/initia/x/move/types"
Expand Down
11 changes: 7 additions & 4 deletions app/hook/move.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package hook

import (
"context"
"encoding/json"

"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"

movekeeper "github.com/initia-labs/initia/x/move/keeper"
Expand All @@ -12,14 +14,15 @@ import (

// bridge hook implementation for move
type MoveBridgeHook struct {
ac address.Codec
moveKeeper *movekeeper.Keeper
}

func NewMoveBridgeHook(moveKeeper *movekeeper.Keeper) MoveBridgeHook {
return MoveBridgeHook{moveKeeper}
func NewMoveBridgeHook(ac address.Codec, moveKeeper *movekeeper.Keeper) MoveBridgeHook {
return MoveBridgeHook{ac, moveKeeper}
}

func (mbh MoveBridgeHook) Hook(ctx sdk.Context, sender sdk.AccAddress, msgBytes []byte) error {
func (mbh MoveBridgeHook) Hook(ctx context.Context, sender sdk.AccAddress, msgBytes []byte) error {
msg := movetypes.MsgExecute{}
err := json.Unmarshal(msgBytes, &msg)
if err != nil {
Expand All @@ -31,7 +34,7 @@ func (mbh MoveBridgeHook) Hook(ctx sdk.Context, sender sdk.AccAddress, msgBytes
return err
}

moduleAddress, err := movetypes.AccAddressFromString(msg.ModuleAddress)
moduleAddress, err := movetypes.AccAddressFromString(mbh.ac, msg.ModuleAddress)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions app/lanes/free.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package lanes
import (
sdk "github.com/cosmos/cosmos-sdk/types"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"

"github.com/skip-mev/block-sdk/block/base"
)
Expand Down
2 changes: 1 addition & 1 deletion app/params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
6 changes: 3 additions & 3 deletions app/params/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
appCodec := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(appCodec, tx.DefaultSignModes)

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
Codec: appCodec,
TxConfig: txCfg,
Amino: amino,
}
Expand Down
24 changes: 17 additions & 7 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"encoding/json"
"time"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"

"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
Expand Down Expand Up @@ -64,7 +64,7 @@ func setup(db *dbm.DB, withGenesis bool) (*MinitiaApp, GenesisState) {
)

if withGenesis {
return app, NewDefaultGenesisState(encCdc.Marshaler, ModuleBasics, types.BaseDenom)
return app, NewDefaultGenesisState(encCdc.Codec, app.BasicModuleManager, types.BaseDenom)
}

return app, GenesisState{}
Expand Down Expand Up @@ -141,16 +141,26 @@ func SetupWithGenesisAccounts(
panic(err)
}

app.InitChain(
abci.RequestInitChain{
_, err = app.InitChain(
&abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: defaultConsensusParams,
AppStateBytes: stateBytes,
},
)
if err != nil {
panic(err)
}

_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: 1})
if err != nil {
panic(err)
}

app.Commit()
app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1}})
_, err = app.Commit()
if err != nil {
panic(err)
}

return app
}
9 changes: 5 additions & 4 deletions app/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// UpgradeHandler h for software upgrade proposal
Expand All @@ -17,7 +18,7 @@ func NewUpgradeHandler(app *MinitiaApp) UpgradeHandler {
}

func (h UpgradeHandler) CreateUpgradeHandler() upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return h.mm.RunMigrations(ctx, h.configurator, vm)
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return h.ModuleManager.RunMigrations(ctx, h.configurator, vm)
}
}
Loading

0 comments on commit efc9ce3

Please sign in to comment.