Skip to content

Commit

Permalink
chore: remove simapp imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Jul 23, 2024
1 parent e2b9e15 commit a8efba4
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 103 deletions.
3 changes: 1 addition & 2 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -84,7 +83,7 @@ func (suite *AnteTestSuite) SetupTest() {
suite.Require().NoError(err)
suite.priv = priv

suite.app = app.Setup(checkTx, func(app *app.EthermintApp, genesis simapp.GenesisState) simapp.GenesisState {
suite.app = app.Setup(checkTx, func(app *app.EthermintApp, genesis app.GenesisState) app.GenesisState {
if suite.enableFeemarket {
// setup feemarketGenesis params
feemarketGenesis := feemarkettypes.DefaultGenesisState()
Expand Down
46 changes: 36 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import (
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -123,8 +123,10 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

"github.com/cosmos/cosmos-sdk/server"
// unnamed import of statik for swagger UI support
_ "github.com/evmos/ethermint/client/docs/statik"
"github.com/evmos/ethermint/encoding"

"github.com/evmos/ethermint/app/ante"
"github.com/evmos/ethermint/ethereum/eip712"
Expand All @@ -140,7 +142,6 @@ import (
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"

simappparams "cosmossdk.io/simapp/params"
// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
Expand Down Expand Up @@ -225,6 +226,7 @@ type EthermintApp struct {
// encoding
cdc *codec.LegacyAmino
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry types.InterfaceRegistry

invCheckPeriod uint
Expand Down Expand Up @@ -282,15 +284,13 @@ func NewEthermintApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig simappparams.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *EthermintApp {
encodingConfig := encoding.MakeConfig(ModuleBasics)
appCodec := encodingConfig.Codec
cdc := encodingConfig.Amino
txConfig := encodingConfig.TxConfig
interfaceRegistry := encodingConfig.InterfaceRegistry

eip712.SetEncodingConfig(encodingConfig)
Expand All @@ -308,12 +308,13 @@ func NewEthermintApp(
appName,
logger,
db,
encodingConfig.TxConfig.TxDecoder(),
txConfig.TxDecoder(),
baseAppOptions...,
)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(txConfig.TxEncoder())

keys := sdk.NewKVStoreKeys(
// SDK keys
Expand All @@ -338,9 +339,11 @@ func NewEthermintApp(
os.Exit(1)
}

invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod))
app := &EthermintApp{
BaseApp: bApp,
cdc: cdc,
txConfig: txConfig,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
Expand Down Expand Up @@ -428,6 +431,16 @@ func NewEthermintApp(
keys[feegrant.StoreKey],
app.AccountKeeper)

// get skipUpgradeHeights from the app options
skipUpgradeHeights := map[int64]bool{}
for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) {
skipUpgradeHeights[int64(h)] = true
}
homePath := cast.ToString(appOpts.Get(flags.FlagHome))
if homePath == "" {
homePath = DefaultNodeHome
}

// set the governance module account as the authority for conducting upgrades
app.UpgradeKeeper = *upgradekeeper.NewKeeper(
skipUpgradeHeights,
Expand Down Expand Up @@ -543,7 +556,7 @@ func NewEthermintApp(
// SDK app modules
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
encodingConfig.TxConfig,
txConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
Expand Down Expand Up @@ -711,7 +724,7 @@ func NewEthermintApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
app.setAnteHandler(encodingConfig.TxConfig, cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)))
app.setAnteHandler(txConfig, cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)))
// In v0.46, the SDK introduces _postHandlers_. PostHandlers are like
// antehandlers, but are run _after_ the `runMsgs` execution. They are also
// defined as a chain, and have the same signature as antehandlers.
Expand Down Expand Up @@ -791,7 +804,7 @@ func (app *EthermintApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) a

// InitChainer updates at chain initialization
func (app *EthermintApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState simapp.GenesisState
var genesisState GenesisState
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
Expand Down Expand Up @@ -846,6 +859,19 @@ func (app *EthermintApp) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

func (app *EthermintApp) TxConfig() client.TxConfig {
return app.txConfig
}

func (app *EthermintApp) EncodingConfig() ethermint.EncodingConfig {
return ethermint.EncodingConfig{
InterfaceRegistry: app.InterfaceRegistry(),
Codec: app.AppCodec(),
TxConfig: app.TxConfig(),
Amino: app.LegacyAmino(),
}
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
Expand Down
5 changes: 0 additions & 5 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/evmos/ethermint/encoding"
)

func TestEthermintAppExport(t *testing.T) {
Expand All @@ -25,10 +24,6 @@ func TestEthermintAppExport(t *testing.T) {
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
0,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down
9 changes: 0 additions & 9 deletions app/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/baseapp"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/evmos/ethermint/encoding"
)

func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
Expand All @@ -20,10 +19,6 @@ func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
0,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down Expand Up @@ -53,10 +48,6 @@ func BenchmarkEthermintApp_ExportAppStateAndValidators(b *testing.B) {
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
0,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down
3 changes: 1 addition & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"

"cosmossdk.io/simapp"
servertypes "github.com/cosmos/cosmos-sdk/server/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -33,7 +32,7 @@ import (
)

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() simapp.GenesisState {
func NewDefaultGenesisState() GenesisState {
encCfg := encoding.MakeConfig(ModuleBasics)
return ModuleBasics.DefaultGenesis(encCfg.Codec)
}
Expand Down
19 changes: 7 additions & 12 deletions app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"encoding/json"
"time"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand All @@ -30,8 +29,6 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/evmos/ethermint/encoding"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
Expand All @@ -41,6 +38,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

type GenesisState map[string]json.RawMessage

// DefaultConsensusParams defines the default Tendermint consensus params used in
// EthermintApp testing.
var DefaultConsensusParams = &tmproto.ConsensusParams{
Expand All @@ -61,22 +60,18 @@ var DefaultConsensusParams = &tmproto.ConsensusParams{
}

// Setup initializes a new EthermintApp. A Nop logger is set in EthermintApp.
func Setup(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.GenesisState) simapp.GenesisState) *EthermintApp {
func Setup(isCheckTx bool, patchGenesis func(*EthermintApp, GenesisState) GenesisState) *EthermintApp {
return SetupWithDB(isCheckTx, patchGenesis, dbm.NewMemDB())
}

const ChainID = "ethermint_9000-1"

// SetupWithDB initializes a new EthermintApp. A Nop logger is set in EthermintApp.
func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.GenesisState) simapp.GenesisState, db dbm.DB) *EthermintApp {
func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, GenesisState) GenesisState, db dbm.DB) *EthermintApp {
app := NewEthermintApp(log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
DefaultNodeHome,
5,
encoding.MakeConfig(ModuleBasics),
simtestutil.NewAppOptionsWithFlagHome(DefaultNodeHome),
baseapp.SetChainID(ChainID),
)
Expand Down Expand Up @@ -108,7 +103,7 @@ func SetupWithDB(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.Genesis
}

// NewTestGenesisState generate genesis state with single validator
func NewTestGenesisState(codec codec.Codec) simapp.GenesisState {
func NewTestGenesisState(codec codec.Codec) GenesisState {
privVal := mock.NewPV()
pubKey, err := privVal.GetPubKey()
if err != nil {
Expand All @@ -130,10 +125,10 @@ func NewTestGenesisState(codec codec.Codec) simapp.GenesisState {
return genesisStateWithValSet(codec, genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
}

func genesisStateWithValSet(codec codec.Codec, genesisState simapp.GenesisState,
func genesisStateWithValSet(codec codec.Codec, genesisState GenesisState,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
) simapp.GenesisState {
) GenesisState {
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = codec.MustMarshalJSON(authGenesis)
Expand Down
14 changes: 5 additions & 9 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
tmcli "github.com/cometbft/cometbft/libs/cli"
tmlog "github.com/cometbft/cometbft/libs/log"

"cosmossdk.io/simapp/params"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand Down Expand Up @@ -66,7 +65,7 @@ const EnvPrefix = "ETHERMINT"

// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
Expand Down Expand Up @@ -210,7 +209,7 @@ func txCommand() *cobra.Command {
}

type appCreator struct {
encCfg params.EncodingConfig
encCfg ethermint.EncodingConfig
}

// newApp is an appCreator
Expand Down Expand Up @@ -267,10 +266,7 @@ func (a appCreator) newApp(logger tmlog.Logger, db dbm.DB, traceStore io.Writer,
chainID = conf.ChainID
}
ethermintApp := app.NewEthermintApp(
logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(sdkserver.FlagInvCheckPeriod)),
a.encCfg,
logger, db, traceStore, true,
appOpts,
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices))),
Expand Down Expand Up @@ -308,13 +304,13 @@ func (a appCreator) appExport(
}

if height != -1 {
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), a.encCfg, appOpts, baseapp.SetChainID(app.ChainID))
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, appOpts, baseapp.SetChainID(app.ChainID))

if err := ethermintApp.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err
}
} else {
ethermintApp = app.NewEthermintApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), a.encCfg, appOpts, baseapp.SetChainID(app.ChainID))
ethermintApp = app.NewEthermintApp(logger, db, traceStore, false, appOpts, baseapp.SetChainID(app.ChainID))
}

return ethermintApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
Expand Down
6 changes: 3 additions & 3 deletions encoding/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
package encoding

import (
"cosmossdk.io/simapp/params"
amino "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/tx"

enccodec "github.com/evmos/ethermint/encoding/codec"
ethermint "github.com/evmos/ethermint/types"
)

// MakeConfig creates an EncodingConfig for testing
func MakeConfig(mb module.BasicManager) params.EncodingConfig {
func MakeConfig(mb module.BasicManager) ethermint.EncodingConfig {
cdc := amino.NewLegacyAmino()
interfaceRegistry := types.NewInterfaceRegistry()
codec := amino.NewProtoCodec(interfaceRegistry)

encodingConfig := params.EncodingConfig{
encodingConfig := ethermint.EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
Expand Down
Loading

0 comments on commit a8efba4

Please sign in to comment.