Skip to content

Commit

Permalink
Merge pull request #220 from terra-money/fix/v2.8/wasmconfig
Browse files Browse the repository at this point in the history
fix(v2.8): wasm config to use default config
  • Loading branch information
emidev98 authored Nov 28, 2023
2 parents bf22f10 + 23c5ebf commit cc362a0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 129 deletions.
5 changes: 2 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import (
"github.com/terra-money/core/v2/app/ante"
terraappconfig "github.com/terra-money/core/v2/app/config"
terraappparams "github.com/terra-money/core/v2/app/params"
"github.com/terra-money/core/v2/app/wasmconfig"

// unnamed import of statik for swagger UI support
_ "github.com/terra-money/core/v2/client/docs/statik"
Expand Down Expand Up @@ -190,7 +189,7 @@ func NewTerraApp(
invCheckPeriod uint,
encodingConfig terraappparams.EncodingConfig,
appOpts servertypes.AppOptions,
wasmConfig *wasmconfig.Config,
wasmConfig wasmtypes.WasmConfig,
baseAppOptions ...func(*baseapp.BaseApp),
) *TerraApp {
appCodec := encodingConfig.Marshaler
Expand Down Expand Up @@ -273,7 +272,7 @@ func NewTerraApp(
FeeShareKeeper: app.Keepers.FeeShareKeeper,
IBCkeeper: app.Keepers.IBCKeeper,
TxCounterStoreKey: app.keys[wasmtypes.StoreKey],
WasmConfig: wasmConfig.ToWasmConfig(),
WasmConfig: wasmConfig,
PobBuilderKeeper: app.Keepers.BuilderKeeper,
TxConfig: encodingConfig.TxConfig,
PobMempool: pobMempool,
Expand Down
18 changes: 9 additions & 9 deletions app/app_test/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/terra-money/alliance/x/alliance"
"github.com/terra-money/core/v2/app/wasmconfig"
"github.com/terra-money/core/v2/x/feeshare"
"github.com/terra-money/core/v2/x/tokenfactory"

Expand Down Expand Up @@ -54,6 +53,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
terra_app "github.com/terra-money/core/v2/app"
)

Expand All @@ -78,7 +78,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
app := terra_app.NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, terra_app.DefaultNodeHome, 0, encCfg,
simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())
simtestutil.EmptyAppOptions{}, wasmtypes.DefaultWasmConfig())

// generate validator private/public key
privVal := mocktestutils.NewPV()
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestSimAppExportAndBlockedAddrs(t *testing.T) {
app2 := terra_app.NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, terra_app.DefaultNodeHome, 0,
encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())
encCfg, simtestutil.EmptyAppOptions{}, wasmtypes.DefaultWasmConfig())
_, err = app2.ExportAppStateAndValidators(false, []string{}, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}
Expand All @@ -125,7 +125,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
app := terra_app.NewTerraApp(
logger, db, nil, true, map[int64]bool{},
terra_app.DefaultNodeHome, 0, encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())
terra_app.DefaultNodeHome, 0, encCfg, simtestutil.EmptyAppOptions{}, wasmtypes.DefaultWasmConfig())

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

Expand Down Expand Up @@ -215,7 +215,7 @@ func TestLegacyAmino(t *testing.T) {
app := terra_app.NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, terra_app.DefaultNodeHome, 0,
encCfg, simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig())
encCfg, simtestutil.EmptyAppOptions{}, wasmtypes.DefaultWasmConfig())

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

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

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

require.NotEmpty(t, app.GetKey(banktypes.StoreKey))
require.NotEmpty(t, app.GetTKey(paramstypes.TStoreKey))
Expand All @@ -261,7 +261,7 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {
app := terra_app.NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db, nil, true, map[int64]bool{}, terra_app.DefaultNodeHome, 0, encCfg,
simtestutil.EmptyAppOptions{}, wasmconfig.DefaultConfig(),
simtestutil.EmptyAppOptions{}, wasmtypes.DefaultWasmConfig(),
)
genAccounts := authtypes.GenesisAccounts{
vestingtypes.NewContinuousVestingAccount(
Expand Down
8 changes: 3 additions & 5 deletions app/app_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/stretchr/testify/suite"
"github.com/terra-money/core/v2/app"
terra_app "github.com/terra-money/core/v2/app"
appparams "github.com/terra-money/core/v2/app/params"
"github.com/terra-money/core/v2/app/wasmconfig"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

Expand All @@ -36,7 +34,7 @@ import (
type AppTestSuite struct {
suite.Suite

App *app.TerraApp
App *terra_app.TerraApp
Ctx sdk.Context
QueryHelper *baseapp.QueryServiceTestHelper
TestAccs []sdk.AccAddress
Expand All @@ -47,7 +45,7 @@ type AppTestSuite struct {
func (s *AppTestSuite) Setup() {
appparams.RegisterAddressesConfig()
encCfg := terra_app.MakeEncodingConfig()
genesisState := app.NewDefaultGenesisState(encCfg.Marshaler)
genesisState := terra_app.NewDefaultGenesisState(encCfg.Marshaler)
genesisState.SetDefaultTerraConfig(encCfg.Marshaler)

db := dbm.NewMemDB()
Expand All @@ -61,7 +59,7 @@ func (s *AppTestSuite) Setup() {
0,
encCfg,
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
wasmtypes.DefaultWasmConfig(),
)
s.EncodingConfig = encCfg

Expand Down
6 changes: 3 additions & 3 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/app/keepers"
"github.com/terra-money/core/v2/app/wasmconfig"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
simulationtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
Expand Down Expand Up @@ -54,7 +54,7 @@ func BenchmarkSimulation(b *testing.B) {
0,
encoding,
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
wasmtypes.DefaultWasmConfig(),
)

// Run randomized simulations
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestSimulationManager(t *testing.T) {
0,
encoding,
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
wasmtypes.DefaultWasmConfig(),
)
sm := terraApp.SimulationManager()
require.NotNil(t, sm)
Expand Down
97 changes: 0 additions & 97 deletions app/wasmconfig/config.go

This file was deleted.

9 changes: 4 additions & 5 deletions cmd/terrad/config.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package main

import (
"github.com/terra-money/core/v2/app/wasmconfig"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
)

// TerraAppConfig terra specify app config
type TerraAppConfig struct {
serverconfig.Config

WASMConfig wasmconfig.Config `mapstructure:"wasm"`
WASMConfig wasmtypes.WasmConfig `mapstructure:"wasm"`
}

// initAppConfig helps to override default appConfig template and configs.
Expand Down Expand Up @@ -40,10 +39,10 @@ func initAppConfig() (string, interface{}) {

terraAppConfig := TerraAppConfig{
Config: *srvCfg,
WASMConfig: *wasmconfig.DefaultConfig(),
WASMConfig: wasmtypes.DefaultWasmConfig(),
}

terraAppTemplate := serverconfig.DefaultConfigTemplate + wasmconfig.DefaultConfigTemplate
terraAppTemplate := serverconfig.DefaultConfigTemplate + wasmtypes.DefaultConfigTemplate()

return terraAppTemplate, terraAppConfig
}
16 changes: 11 additions & 5 deletions cmd/terrad/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
dbm "github.com/cometbft/cometbft-db"
tmcli "github.com/cometbft/cometbft/libs/cli"
"github.com/cometbft/cometbft/libs/log"
Expand All @@ -32,9 +33,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"

wasm "github.com/CosmWasm/wasmd/x/wasm"
terraapp "github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/app/params"
"github.com/terra-money/core/v2/app/wasmconfig"
)

// NewRootCmd creates a new root command for terrad.
Expand Down Expand Up @@ -146,7 +147,7 @@ func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
wasmconfig.AddConfigFlags(startCmd)
wasm.AddModuleInitFlags(startCmd)
}

func queryCommand() *cobra.Command {
Expand Down Expand Up @@ -216,6 +217,11 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
skipUpgradeHeights[int64(h)] = true
}

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(err)
}

return terraapp.NewTerraApp(
logger,
db,
Expand All @@ -226,7 +232,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
a.encodingConfig,
appOpts,
wasmconfig.GetConfig(appOpts),
wasmConfig,
baseappOptions...,
)
}
Expand All @@ -252,13 +258,13 @@ func (a appCreator) appExport(

var terraApp *terraapp.TerraApp
if height != -1 {
terraApp = terraapp.NewTerraApp(logger, db, traceStore, false, map[int64]bool{}, homePath, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encodingConfig, appOpts, wasmconfig.DefaultConfig())
terraApp = terraapp.NewTerraApp(logger, db, traceStore, false, map[int64]bool{}, homePath, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encodingConfig, appOpts, wasmtypes.DefaultWasmConfig())

if err := terraApp.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err
}
} else {
terraApp = terraapp.NewTerraApp(logger, db, traceStore, true, map[int64]bool{}, homePath, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encodingConfig, appOpts, wasmconfig.DefaultConfig())
terraApp = terraapp.NewTerraApp(logger, db, traceStore, true, map[int64]bool{}, homePath, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), a.encodingConfig, appOpts, wasmtypes.DefaultWasmConfig())
}

return terraApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
Expand Down
3 changes: 1 addition & 2 deletions x/tokenfactory/bindings/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/app/wasmconfig"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -45,7 +44,7 @@ func CreateTestInput() (*app.TerraApp, sdk.Context) {
0,
encCfg,
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
wasmtypes.DefaultWasmConfig(),
)
ctx := terraApp.BaseApp.NewContext(true, tmproto.Header{Height: 1, ChainID: "phoenix-1", Time: time.Now()})
err := terraApp.Keepers.WasmKeeper.SetParams(ctx, wasmtypes.DefaultParams())
Expand Down

0 comments on commit cc362a0

Please sign in to comment.