Skip to content

Commit f46992e

Browse files
committed
Refactor: relocate evmd-specific configurations and add test counterparts
Moved evmd-specific app configurations under the evmd/ directory to improve modularity and maintain clearer separation between evmd and other components. Introduced corresponding configuration files under testutil/ to support test applications, since relocating the original files required new equivalents for testing purposes.
1 parent 34bfcc3 commit f46992e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+557
-122
lines changed

ante/evm/fee_checker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010

1111
"github.com/cosmos/evm/ante/evm"
1212
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
13-
"github.com/cosmos/evm/config"
1413
"github.com/cosmos/evm/encoding"
14+
"github.com/cosmos/evm/testutil/config"
1515
testconstants "github.com/cosmos/evm/testutil/constants"
1616
"github.com/cosmos/evm/types"
1717
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"

config/opendb.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

evmd/app.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
dbm "github.com/cosmos/cosmos-db"
1818
evmante "github.com/cosmos/evm/ante"
1919
cosmosevmante "github.com/cosmos/evm/ante/evm"
20-
evmconfig "github.com/cosmos/evm/config"
2120
evmosencoding "github.com/cosmos/evm/encoding"
21+
evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config"
2222
srvflags "github.com/cosmos/evm/server/flags"
2323
cosmosevmtypes "github.com/cosmos/evm/types"
2424
"github.com/cosmos/evm/x/erc20"
@@ -134,7 +134,7 @@ func init() {
134134
// manually update the power reduction by replacing micro (u) -> atto (a) evmos
135135
sdk.DefaultPowerReduction = cosmosevmtypes.AttoPowerReduction
136136

137-
defaultNodeHome = evmconfig.MustGetDefaultNodeHome()
137+
defaultNodeHome = evmdconfig.MustGetDefaultNodeHome()
138138
}
139139

140140
const appName = "evmd"
@@ -209,7 +209,7 @@ func NewExampleApp(
209209
loadLatest bool,
210210
appOpts servertypes.AppOptions,
211211
evmChainID uint64,
212-
evmAppOptions evmconfig.EVMOptionsFn,
212+
evmAppOptions evmdconfig.EVMOptionsFn,
213213
baseAppOptions ...func(*baseapp.BaseApp),
214214
) *EVMD {
215215
encodingConfig := evmosencoding.MakeConfig(evmChainID)
@@ -314,7 +314,7 @@ func NewExampleApp(
314314
// add keepers
315315
app.AccountKeeper = authkeeper.NewAccountKeeper(
316316
appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]),
317-
authtypes.ProtoBaseAccount, evmconfig.GetMaccPerms(),
317+
authtypes.ProtoBaseAccount, evmdconfig.GetMaccPerms(),
318318
authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
319319
sdk.GetConfig().GetBech32AccountAddrPrefix(),
320320
authAddr,
@@ -324,7 +324,7 @@ func NewExampleApp(
324324
appCodec,
325325
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
326326
app.AccountKeeper,
327-
evmconfig.BlockedAddresses(),
327+
evmdconfig.BlockedAddresses(),
328328
authAddr,
329329
logger,
330330
)
@@ -911,15 +911,15 @@ func (app *EVMD) TxConfig() client.TxConfig {
911911
func (app *EVMD) DefaultGenesis() map[string]json.RawMessage {
912912
genesis := app.BasicModuleManager.DefaultGenesis(app.appCodec)
913913

914-
mintGenState := evmconfig.NewMintGenesisState()
914+
mintGenState := NewMintGenesisState()
915915
genesis[minttypes.ModuleName] = app.appCodec.MustMarshalJSON(mintGenState)
916916

917-
evmGenState := evmconfig.NewEVMGenesisState()
917+
evmGenState := NewEVMGenesisState()
918918
genesis[evmtypes.ModuleName] = app.appCodec.MustMarshalJSON(evmGenState)
919919

920920
// NOTE: for the example chain implementation we are also adding a default token pair,
921921
// which is the base denomination of the chain (i.e. the WEVMOS contract)
922-
erc20GenState := evmconfig.NewErc20GenesisState()
922+
erc20GenState := NewErc20GenesisState()
923923
genesis[erc20types.ModuleName] = app.appCodec.MustMarshalJSON(erc20GenState)
924924

925925
return genesis

evmd/cmd/evmd/cmd/root.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414

1515
dbm "github.com/cosmos/cosmos-db"
1616
cosmosevmcmd "github.com/cosmos/evm/client"
17-
"github.com/cosmos/evm/config"
1817
cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring"
1918
"github.com/cosmos/evm/evmd"
19+
evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config"
2020
cosmosevmserver "github.com/cosmos/evm/server"
2121
srvflags "github.com/cosmos/evm/server/flags"
2222

@@ -63,7 +63,7 @@ func NewRootCmd() *cobra.Command {
6363
nil,
6464
true,
6565
simtestutil.EmptyAppOptions{},
66-
config.EVMChainID,
66+
evmdconfig.EVMChainID,
6767
noOpEvmAppOptions,
6868
)
6969

@@ -82,7 +82,7 @@ func NewRootCmd() *cobra.Command {
8282
WithInput(os.Stdin).
8383
WithAccountRetriever(authtypes.AccountRetriever{}).
8484
WithBroadcastMode(flags.FlagBroadcastMode).
85-
WithHomeDir(config.MustGetDefaultNodeHome()).
85+
WithHomeDir(evmdconfig.MustGetDefaultNodeHome()).
8686
WithViper(""). // In simapp, we don't use any prefix for env variables.
8787
// Cosmos EVM specific setup
8888
WithKeyringOptions(cosmosevmkeyring.Option()).
@@ -131,7 +131,7 @@ func NewRootCmd() *cobra.Command {
131131
return err
132132
}
133133

134-
customAppTemplate, customAppConfig := config.InitAppConfig(config.BaseDenom, config.EVMChainID)
134+
customAppTemplate, customAppConfig := evmdconfig.InitAppConfig(evmdconfig.BaseDenom, evmdconfig.EVMChainID)
135135
customTMConfig := initTendermintConfig()
136136

137137
return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig)
@@ -149,7 +149,7 @@ func NewRootCmd() *cobra.Command {
149149
}
150150

151151
if initClientCtx.ChainID != "" {
152-
if err := config.EvmAppOptions(config.EVMChainID); err != nil {
152+
if err := evmdconfig.EvmAppOptions(evmdconfig.EVMChainID); err != nil {
153153
panic(err)
154154
}
155155
}
@@ -173,7 +173,7 @@ func initRootCmd(rootCmd *cobra.Command, osApp *evmd.EVMD) {
173173
cfg := sdk.GetConfig()
174174
cfg.Seal()
175175

176-
defaultNodeHome := config.MustGetDefaultNodeHome()
176+
defaultNodeHome := evmdconfig.MustGetDefaultNodeHome()
177177
rootCmd.AddCommand(
178178
genutilcli.InitCmd(osApp.BasicModuleManager, defaultNodeHome),
179179
genutilcli.Commands(osApp.TxConfig(), osApp.BasicModuleManager, defaultNodeHome),
@@ -326,8 +326,8 @@ func newApp(
326326
return evmd.NewExampleApp(
327327
logger, db, traceStore, true,
328328
appOpts,
329-
config.EVMChainID,
330-
config.EvmAppOptions,
329+
evmdconfig.EVMChainID,
330+
evmdconfig.EvmAppOptions,
331331
baseappOptions...,
332332
)
333333
}
@@ -368,13 +368,13 @@ func appExport(
368368
}
369369

370370
if height != -1 {
371-
exampleApp = evmd.NewExampleApp(logger, db, traceStore, false, appOpts, config.EVMChainID, config.EvmAppOptions, baseapp.SetChainID(chainID))
371+
exampleApp = evmd.NewExampleApp(logger, db, traceStore, false, appOpts, evmdconfig.EVMChainID, evmdconfig.EvmAppOptions, baseapp.SetChainID(chainID))
372372

373373
if err := exampleApp.LoadHeight(height); err != nil {
374374
return servertypes.ExportedApp{}, err
375375
}
376376
} else {
377-
exampleApp = evmd.NewExampleApp(logger, db, traceStore, true, appOpts, config.EVMChainID, config.EvmAppOptions, baseapp.SetChainID(chainID))
377+
exampleApp = evmd.NewExampleApp(logger, db, traceStore, true, appOpts, evmdconfig.EVMChainID, evmdconfig.EvmAppOptions, baseapp.SetChainID(chainID))
378378
}
379379

380380
return exampleApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
@@ -389,7 +389,7 @@ func getChainIDFromOpts(appOpts servertypes.AppOptions) (chainID string, err err
389389
if chainID == "" {
390390
// If not available load from home
391391
homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
392-
chainID, err = config.GetChainIDFromHome(homeDir)
392+
chainID, err = evmdconfig.GetChainIDFromHome(homeDir)
393393
if err != nil {
394394
return "", err
395395
}

config/activators.go renamed to evmd/cmd/evmd/config/activators.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package config
33
import (
44
"github.com/ethereum/go-ethereum/core/vm"
55

6-
"github.com/cosmos/evm/config/eips"
6+
"github.com/cosmos/evm/evmd/eips"
77
)
88

99
// cosmosEVMActivators defines a map of opcode modifiers associated
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

evmd/cmd/evmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"os"
66

7-
evmdconfig "github.com/cosmos/evm/config"
87
"github.com/cosmos/evm/evmd/cmd/evmd/cmd"
8+
evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config"
99

1010
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
1111
sdk "github.com/cosmos/cosmos-sdk/types"
File renamed without changes.
File renamed without changes.

tests/integration/eips/test_eips.go renamed to evmd/eips/eips_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package eips
1+
package eips_test
22

33
import (
44
"fmt"
@@ -13,8 +13,9 @@ import (
1313
//nolint:revive,ST1001 // dot imports are fine for Ginkgo
1414
. "github.com/onsi/gomega"
1515

16-
"github.com/cosmos/evm/config/eips"
17-
"github.com/cosmos/evm/config/eips/testdata"
16+
"github.com/cosmos/evm/evmd/eips"
17+
"github.com/cosmos/evm/evmd/eips/testdata"
18+
"github.com/cosmos/evm/evmd/tests/integration"
1819
"github.com/cosmos/evm/testutil/integration/evm/factory"
1920
"github.com/cosmos/evm/testutil/integration/evm/grpc"
2021
"github.com/cosmos/evm/testutil/integration/evm/network"
@@ -33,7 +34,7 @@ import (
3334
// 3. Deploy and interact with contracts to compute the gas used AFTER enabling
3435
// the EIP.
3536

36-
func TestEIPs(t *testing.T, create network.CreateEvmApp, options ...network.ConfigOption) {
37+
func RunTests(t *testing.T, create network.CreateEvmApp, options ...network.ConfigOption) {
3738
_ = Describe("EIP-0000 - ", Ordered, func() {
3839
var (
3940
in network.Network
@@ -130,6 +131,8 @@ func TestEIPs(t *testing.T, create network.CreateEvmApp, options ...network.Conf
130131
})
131132

132133
It("should change CREATE opcode constant gas after enabling EIP", func() {
134+
qRes, err := gh.GetEvmParams()
135+
_ = qRes.Params
133136
gasCostPre := params.CreateGas
134137

135138
deploymentTxArgs, err := tf.GenerateDeployContractArgs(senderAddr2, evmtypes.EvmTxArgs{}, deploymentData)
@@ -443,3 +446,7 @@ func TestEIPs(t *testing.T, create network.CreateEvmApp, options ...network.Conf
443446
RegisterFailHandler(Fail)
444447
RunSpecs(t, "EIPs Suite")
445448
}
449+
450+
func TestEIPs(t *testing.T) {
451+
RunTests(t, integration.CreateEvmd)
452+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

evmd/genesis.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package evmd
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/cosmos/evm/evmd/cmd/evmd/config"
7+
testconstants "github.com/cosmos/evm/testutil/constants"
8+
erc20types "github.com/cosmos/evm/x/erc20/types"
9+
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
10+
evmtypes "github.com/cosmos/evm/x/vm/types"
11+
12+
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
13+
)
14+
15+
// GenesisState of the blockchain is represented here as a map of raw json
16+
// messages key'd by an identifier string.
17+
// The identifier is used to determine which module genesis information belongs
18+
// to so it may be appropriately routed during init chain.
19+
// Within this application default genesis information is retrieved from
20+
// the ModuleBasicManager which populates json from each BasicModule
21+
// object provided to it during init.
22+
type GenesisState map[string]json.RawMessage
23+
24+
// NewEVMGenesisState returns the default genesis state for the EVM module.
25+
//
26+
// NOTE: for the example chain implementation we need to set the default EVM denomination
27+
// and enable ALL precompiles.
28+
func NewEVMGenesisState() *evmtypes.GenesisState {
29+
evmGenState := evmtypes.DefaultGenesisState()
30+
evmGenState.Params.ActiveStaticPrecompiles = evmtypes.AvailableStaticPrecompiles
31+
32+
return evmGenState
33+
}
34+
35+
// NewErc20GenesisState returns the default genesis state for the ERC20 module.
36+
//
37+
// NOTE: for the example chain implementation we are also adding a default token pair,
38+
// which is the base denomination of the chain (i.e. the WEVMOS contract).
39+
func NewErc20GenesisState() *erc20types.GenesisState {
40+
erc20GenState := erc20types.DefaultGenesisState()
41+
erc20GenState.TokenPairs = testconstants.ExampleTokenPairs
42+
erc20GenState.Params.NativePrecompiles = append(erc20GenState.Params.NativePrecompiles, testconstants.WEVMOSContractMainnet)
43+
44+
return erc20GenState
45+
}
46+
47+
// NewMintGenesisState returns the default genesis state for the mint module.
48+
//
49+
// NOTE: for the example chain implementation we are also adding a default minter.
50+
func NewMintGenesisState() *minttypes.GenesisState {
51+
mintGenState := minttypes.DefaultGenesisState()
52+
mintGenState.Params.MintDenom = config.ExampleChainDenom
53+
54+
return mintGenState
55+
}
56+
57+
// NewFeeMarketGenesisState returns the default genesis state for the feemarket module.
58+
//
59+
// NOTE: for the example chain implementation we are disabling the base fee.
60+
func NewFeeMarketGenesisState() *feemarkettypes.GenesisState {
61+
feeMarketGenState := feemarkettypes.DefaultGenesisState()
62+
feeMarketGenState.Params.NoBaseFee = true
63+
64+
return feeMarketGenState
65+
}

evmd/test_helpers.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
cmttypes "github.com/cometbft/cometbft/types"
1212

1313
dbm "github.com/cosmos/cosmos-db"
14-
evmconfig "github.com/cosmos/evm/config"
14+
"github.com/cosmos/evm/evmd/cmd/evmd/config"
1515
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
1616
ibctesting "github.com/cosmos/ibc-go/v10/testing"
1717

@@ -43,23 +43,23 @@ func init() {
4343

4444
// Set the global SDK config for the tests
4545
cfg := sdk.GetConfig()
46-
evmconfig.SetBech32Prefixes(cfg)
47-
evmconfig.SetBip44CoinType(cfg)
46+
config.SetBech32Prefixes(cfg)
47+
config.SetBip44CoinType(cfg)
4848
}
4949

50-
func setup(withGenesis bool, invCheckPeriod uint, chainID string, evmChainID uint64) (*EVMD, evmconfig.GenesisState) {
50+
func setup(withGenesis bool, invCheckPeriod uint, chainID string, evmChainID uint64) (*EVMD, GenesisState) {
5151
db := dbm.NewMemDB()
5252

5353
appOptions := make(simtestutil.AppOptionsMap, 0)
5454
appOptions[flags.FlagHome] = defaultNodeHome
5555
appOptions[server.FlagInvCheckPeriod] = invCheckPeriod
5656

57-
app := NewExampleApp(log.NewNopLogger(), db, nil, true, appOptions, evmChainID, evmconfig.EvmAppOptions, baseapp.SetChainID(chainID))
57+
app := NewExampleApp(log.NewNopLogger(), db, nil, true, appOptions, evmChainID, config.EvmAppOptions, baseapp.SetChainID(chainID))
5858
if withGenesis {
5959
return app, app.DefaultGenesis()
6060
}
6161

62-
return app, evmconfig.GenesisState{}
62+
return app, GenesisState{}
6363
}
6464

6565
// Setup initializes a new EVMD. A Nop logger is set in EVMD.
@@ -131,7 +131,7 @@ func SetupTestingApp(chainID string, evmChainID uint64) func() (ibctesting.Testi
131131
db, nil, true,
132132
simtestutil.NewAppOptionsWithFlagHome(defaultNodeHome),
133133
evmChainID,
134-
evmconfig.EvmAppOptions,
134+
config.EvmAppOptions,
135135
baseapp.SetChainID(chainID),
136136
)
137137
return app, app.DefaultGenesis()

0 commit comments

Comments
 (0)