Skip to content

Commit

Permalink
wip: upgrade 2.5 compile
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Aug 17, 2023
1 parent c0fb1c0 commit afe3937
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 253 deletions.
262 changes: 151 additions & 111 deletions app/app.go

Large diffs are not rendered by default.

37 changes: 18 additions & 19 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (
"os"
"testing"

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"
mocktestutils "github.com/cosmos/cosmos-sdk/testutil/mock"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
"github.com/terra-money/core/v2/app/wasmconfig"

"cosmossdk.io/simapp"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/tests/mocks"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand All @@ -43,7 +43,6 @@ import (
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"
"github.com/cosmos/ibc-go/v7/testing/mock"
"github.com/strangelove-ventures/packet-forward-middleware/v7/router"

"github.com/CosmWasm/wasmd/x/wasm"
Expand All @@ -69,11 +68,11 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
db := dbm.NewMemDB()
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, encCfg,
simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg,
simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())

// generate validator private/public key
privVal := mock.NewPV()
privVal := mocktestutils.NewPV()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err)

Expand Down Expand Up @@ -105,9 +104,9 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
// Making a new app object with the db, so that initchain hasn't been called
app2 := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0,
encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
_, err = app2.ExportAppStateAndValidators(false, []string{})
db, nil, true, map[int64]bool{}, DefaultNodeHome, 0,
encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())
_, err = app2.ExportAppStateAndValidators(false, []string{}, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

Expand All @@ -122,15 +121,15 @@ func TestInitGenesisOnMigration(t *testing.T) {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := NewTerraApp(
logger, db, nil, true, map[int64]bool{},
simapp.DefaultNodeHome, 0, encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
DefaultNodeHome, 0, encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())

ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})

// Create a mock module. This module will serve as the new module we're
// adding during a migration.
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockModule := mocks.NewMockAppModule(mockCtrl)
mockModule := mocktestutils.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)
Expand Down Expand Up @@ -174,7 +173,7 @@ func TestLegacyAmino(t *testing.T) {
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, DefaultNodeHome, 0,
encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())

require.Equal(t, encCfg.Amino, app.LegacyAmino())
}
Expand All @@ -185,7 +184,7 @@ func TestAppCodec(t *testing.T) {
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, DefaultNodeHome, 0,
encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())

require.Equal(t, encCfg.Marshaler, app.AppCodec())
}
Expand All @@ -196,7 +195,7 @@ func TestInterfaceRegistry(t *testing.T) {
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, DefaultNodeHome, 0,
encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())

require.Equal(t, encCfg.InterfaceRegistry, app.InterfaceRegistry())
}
Expand All @@ -207,7 +206,7 @@ func TestGetKey(t *testing.T) {
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, DefaultNodeHome, 0,
encCfg, simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig())
encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())

require.NotEmpty(t, app.GetKey(banktypes.StoreKey))
require.NotEmpty(t, app.GetTKey(paramstypes.TStoreKey))
Expand All @@ -219,8 +218,8 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {
db := dbm.NewMemDB()
app := NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, encCfg,
simapp.EmptyAppOptions{}, wasmconfig.DefaultConfig(),
db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, encCfg,
simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig(),
)
genAccounts := authtypes.GenesisAccounts{
vestingtypes.NewContinuousVestingAccount(
Expand Down Expand Up @@ -258,7 +257,7 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {
}

// generate validator private/public key
privVal := mock.NewPV()
privVal := mocktestutils.NewPV()
pubKey, err := privVal.GetPubKey()
require.NoError(t, err, "PubKey should not have an error")
validator := tmtypes.NewValidator(pubKey, 1)
Expand Down
6 changes: 4 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
// ExportAppStateAndValidators exports the state of the application for a genesis
// file.
func (app *TerraApp) ExportAppStateAndValidators(
forZeroHeight bool, jailAllowedAddrs []string,
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()})
Expand All @@ -35,7 +37,7 @@ func (app *TerraApp) ExportAppStateAndValidators(
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
validators, err := staking.WriteValidators(ctx, &app.StakingKeeper)
if err != nil {
return servertypes.ExportedApp{}, err
}
Expand Down
40 changes: 21 additions & 19 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,29 @@ import (
"os"
"testing"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
dbm "github.com/tendermint/tm-db"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/stretchr/testify/require"
"github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/app/wasmconfig"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
)

func init() {
simapp.GetSimulatorFlags()
simcli.GetSimulatorFlags()
}

type SimApp interface {
type AppTest interface {
app.TerraApp
GetBaseApp() *baseapp.BaseApp
AppCodec() codec.Codec
Expand All @@ -44,10 +45,11 @@ type SimApp interface {
// Running as go benchmark test:
// `go test -benchmem -run=^$ -bench ^BenchmarkSimulation ./app -NumBlocks=200 -BlockSize 50 -Commit=true -Verbose=true -Enabled=true`
func BenchmarkSimulation(b *testing.B) {
simapp.FlagEnabledValue = true
simapp.FlagCommitValue = true
config := simcli.NewConfigFromFlags()
simcli.FlagEnabledValue = true
simcli.FlagCommitValue = true

config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
db, dir, logger, _, err := simtestutil.SetupSimulation(config, "goleveldb-app-sim", "Simulation", true, false)
require.NoError(b, err, "simulation setup failed")

b.Cleanup(func() {
Expand All @@ -58,7 +60,7 @@ func BenchmarkSimulation(b *testing.B) {

encoding := app.MakeEncodingConfig()

simApp := app.NewTerraApp(
AppTest := app.NewTerraApp(
logger,
db,
nil,
Expand All @@ -67,38 +69,38 @@ func BenchmarkSimulation(b *testing.B) {
app.DefaultNodeHome,
0,
encoding,
simapp.EmptyAppOptions{},
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
)

// Run randomized simulations
_, simParams, simErr := simulation.SimulateFromSeed(
b,
os.Stdout,
simApp.BaseApp,
simapp.AppStateFn(simApp.AppCodec(), simApp.SimulationManager()),
AppTest.BaseApp,
simtestutil.AppStateFn(AppTest.AppCodec(), AppTest.SimulationManager(), app.DefaultGenesis()),
simulationtypes.RandomAccounts,
simapp.SimulationOperations(simApp, simApp.AppCodec(), config),
simApp.ModuleAccountAddrs(),
simtestutil.SimulationOperations(AppTest, AppTest.AppCodec(), config),
AppTest.ModuleAccountAddrs(),
config,
simApp.AppCodec(),
AppTest.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = simapp.CheckExportSimulation(simApp, config, simParams)
err = simtestutil.CheckExportSimulation(AppTest, config, simParams)
require.NoError(b, err)
require.NoError(b, simErr)

if config.Commit {
simapp.PrintStats(db)
simtestutil.PrintStats(db)
}
}

func TestSimulationManager(t *testing.T) {
db := dbm.NewMemDB()
encoding := app.MakeEncodingConfig()

simApp := app.NewTerraApp(
AppTest := app.NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
Expand All @@ -107,9 +109,9 @@ func TestSimulationManager(t *testing.T) {
app.DefaultNodeHome,
0,
encoding,
simapp.EmptyAppOptions{},
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
)
sm := simApp.SimulationManager()
sm := AppTest.SimulationManager()
require.NotNil(t, sm)
}
28 changes: 24 additions & 4 deletions app/upgrades/v2.5/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
package v2_5

import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
clientkeeper "github.com/cosmos/ibc-go/v7/modules/core/02-client/keeper"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations"
"github.com/terra-money/core/v2/app"
)

func CreateUpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
cdc codec.Codec,
clientKeeper clientkeeper.Keeper,
paramsKeeper paramskeeper.Keeper,
consensusParamsKeeper consensuskeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// prune expired tendermint consensus states to save storage space
_, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, app.Codec, app.IBCKeeper.ClientKeeper)

baseAppLegacySS := paramsKeeper.Subspace(baseapp.Paramspace).
WithKeyTable(paramstypes.ConsensusParamsKeyTable())
baseapp.MigrateParams(ctx, baseAppLegacySS, &consensusParamsKeeper)

// READ: https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v6-to-v7.md#chains
_, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper)
if err != nil {
return nil, err
}

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
// READ: https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v7-to-v7_1.md#chains
params := clientKeeper.GetParams(ctx)
params.AllowedClients = append(params.AllowedClients, ibcexported.Localhost)
clientKeeper.SetParams(ctx, params)

return mm.RunMigrations(ctx, cfg, fromVM)
}
}
4 changes: 2 additions & 2 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"swagger": "2.0",
"info": {
"title": "Terra Core Rest API",
"description": "Rest Interface for Terra Core v2.4 https://github.com/terra-money/core",
"version": "2.4"
"description": "Rest Interface for Terra Core v2.5 https://github.com/terra-money/core",
"version": "2.5"
},
"apis": [
{
Expand Down
4 changes: 2 additions & 2 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
swagger: '2.0'
info:
title: Terra Core Rest API
description: Rest Interface for Terra Core v2.4 https://github.com/terra-money/core
version: 2.4
description: Rest Interface for Terra Core v2.5 https://github.com/terra-money/core
version: 2.5
paths:
/terra/alliances:
get:
Expand Down
29 changes: 0 additions & 29 deletions cmd/terrad/genwasm.go

This file was deleted.

Loading

0 comments on commit afe3937

Please sign in to comment.