Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: upgrade 2.5
Browse files Browse the repository at this point in the history
emidev98 committed Aug 17, 2023
1 parent c0fb1c0 commit 6b54e97
Showing 11 changed files with 227 additions and 168 deletions.
259 changes: 152 additions & 107 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
@@ -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"
@@ -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"
@@ -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)

@@ -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")
}

@@ -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)
@@ -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())
}
@@ -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())
}
@@ -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())
}
@@ -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))
@@ -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(
@@ -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)
6 changes: 4 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
@@ -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()})
@@ -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
}
40 changes: 21 additions & 19 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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() {
@@ -58,7 +60,7 @@ func BenchmarkSimulation(b *testing.B) {

encoding := app.MakeEncodingConfig()

simApp := app.NewTerraApp(
AppTest := app.NewTerraApp(
logger,
db,
nil,
@@ -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,
@@ -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
@@ -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": [
{
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:
4 changes: 2 additions & 2 deletions cmd/terrad/root.go
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@ import (
"os"
"path/filepath"

dbm "github.com/cometbft/cometbft-db"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cometbft/cometbft/libs/log"
"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/viper"
dbm "github.com/tendermint/tm-db"

tmcfg "github.com/cometbft/cometbft/config"
"github.com/cosmos/cosmos-sdk/baseapp"
@@ -278,5 +278,5 @@ func (a appCreator) appExport(
terraApp = terraapp.NewTerraApp(logger, db, traceStore, true, map[int64]bool{}, homePath, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encodingConfig, appOpts, wasmconfig.DefaultConfig())
}

return terraApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
return terraApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, []string{})
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ require (
cosmossdk.io/simapp v0.0.0-20230224204036-a6adb0821462
github.com/CosmWasm/wasmd v0.40.0
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.4
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79
@@ -21,7 +22,6 @@ require (
github.com/spf13/viper v1.16.0
github.com/strangelove-ventures/packet-forward-middleware/v7 v7.0.0-20230523193151-73dea436e53f
github.com/stretchr/testify v1.8.4
github.com/tendermint/tm-db v0.6.7
github.com/terra-money/alliance v0.2.3
)

@@ -58,13 +58,11 @@ require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/cometbft/cometbft-db v0.8.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
Loading

0 comments on commit 6b54e97

Please sign in to comment.