From feb4e7417e1ffebd660d764b5fe7297d0e6eb0e3 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 04:09:34 -0400 Subject: [PATCH 01/23] move sdk setup to root cmd from main --- evmd/cmd/evmd/cmd/root.go | 7 +++++++ evmd/cmd/evmd/main.go | 9 --------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/evmd/cmd/root.go index 8a540cf0a..70460c752 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/evmd/cmd/root.go @@ -51,6 +51,7 @@ import ( // NewRootCmd creates a new root command for evmd. It is called once in the // main function. func NewRootCmd() *cobra.Command { + setupSDKConfig() // we "pre"-instantiate the application for getting the injected/configured encoding configuration // and the CLI options for the modules // add keyring to autocli opts @@ -156,6 +157,12 @@ func NewRootCmd() *cobra.Command { return rootCmd } +func setupSDKConfig() { + config := sdk.GetConfig() + evmdconfig.SetBech32Prefixes(config) + config.Seal() +} + // initCometConfig helps to override default CometBFT Config values. // return cmtcfg.DefaultConfig if no custom configuration is required for the application. func initCometConfig() *cmtcfg.Config { diff --git a/evmd/cmd/evmd/main.go b/evmd/cmd/evmd/main.go index 0669a5891..cd63910e1 100644 --- a/evmd/cmd/evmd/main.go +++ b/evmd/cmd/evmd/main.go @@ -8,21 +8,12 @@ import ( evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - sdk "github.com/cosmos/cosmos-sdk/types" ) func main() { - setupSDKConfig() - rootCmd := cmd.NewRootCmd() if err := svrcmd.Execute(rootCmd, "evmd", evmdconfig.MustGetDefaultNodeHome()); err != nil { fmt.Fprintln(rootCmd.OutOrStderr(), err) os.Exit(1) } } - -func setupSDKConfig() { - config := sdk.GetConfig() - evmdconfig.SetBech32Prefixes(config) - config.Seal() -} From ad897410356a15fcc3300e684aed0bd7a42a31c2 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 04:32:08 -0400 Subject: [PATCH 02/23] refactor evmcoininfo and evmconfigurator --- x/vm/types/chain_config.go | 2 +- x/vm/types/coin_info.go | 78 +++++++++++++ x/vm/types/coin_info_test.go | 179 +++++++++++++++++++++++++++++ x/vm/types/config.go | 14 +-- x/vm/types/config_testing.go | 14 +-- x/vm/types/configurator.go | 24 ++-- x/vm/types/configurator_test.go | 36 +++--- x/vm/types/denom.go | 51 +++++--- x/vm/types/denom_config.go | 46 +++----- x/vm/types/denom_config_testing.go | 46 +++----- x/vm/types/msg_test.go | 4 +- x/vm/types/scaling_test.go | 42 +++---- x/vm/wrappers/bank_test.go | 172 +++++++++++++-------------- x/vm/wrappers/feemarket_test.go | 18 +-- 14 files changed, 486 insertions(+), 240 deletions(-) create mode 100644 x/vm/types/coin_info.go create mode 100644 x/vm/types/coin_info_test.go diff --git a/x/vm/types/chain_config.go b/x/vm/types/chain_config.go index 6a9877340..f81f19942 100644 --- a/x/vm/types/chain_config.go +++ b/x/vm/types/chain_config.go @@ -113,7 +113,7 @@ func DefaultChainConfig(evmChainID uint64) *ChainConfig { // setChainConfig allows to set the `chainConfig` variable modifying the // default values. The method is private because it should only be called once -// in the EVMConfigurator. +// in the EvmConfig. func setChainConfig(cc *ChainConfig) error { if chainConfig != nil { return errors.New("chainConfig already set. Cannot set again the chainConfig") diff --git a/x/vm/types/coin_info.go b/x/vm/types/coin_info.go new file mode 100644 index 000000000..d03b53e23 --- /dev/null +++ b/x/vm/types/coin_info.go @@ -0,0 +1,78 @@ +package types + +import ( + "errors" + "fmt" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// EvmCoinInfo struct holds the display name and decimal precisions of the EVM denom +type EvmCoinInfo struct { + // DisplayDenom defines the display denomination shown to users + DisplayDenom string `mapstructure:"display-denom"` + // Decimals defines the precision/decimals for the base denomination (1-18) + Decimals Decimals `mapstructure:"decimals"` + // ExtendedDecimals defines the precision/decimals for the extended denomination (typically 18 decimals for atto-denom) + ExtendedDecimals Decimals `mapstructure:"extended-decimals"` +} + +// Validate returns an error if the coin configuration fields are invalid. +func (c EvmCoinInfo) Validate() error { + if err := c.Decimals.Validate(); err != nil { + return fmt.Errorf("decimals validation failed: %w", err) + } + if err := c.ExtendedDecimals.Validate(); err != nil { + return fmt.Errorf("extended decimals validation failed: %w", err) + } + + denom := c.GetDenom() + if strings.HasPrefix(denom, "invalid") { + return errors.New("invalid denom, not a valid SI decimal, so denom cannot be derived") + } + if err := sdk.ValidateDenom(denom); err != nil { + return fmt.Errorf("invalid denom: %w", err) + } + + extendedDenom := c.GetExtendedDenom() + if strings.HasPrefix(extendedDenom, "invalid") { + return errors.New("invalid extended denom, not a valid SI decimal, so extended denom cannot be derived") + } + if err := sdk.ValidateDenom(extendedDenom); err != nil { + return fmt.Errorf("invalid extended denom: %w", err) + } + + if c.DisplayDenom == "" { + return errors.New("display-denom cannot be empty") + } + if err := sdk.ValidateDenom(c.DisplayDenom); err != nil { + return fmt.Errorf("invalid display denom: %w", err) + } + + // For 18 decimals, denom and extended denom should be the same, as higher decimals are not supported + if c.Decimals == EighteenDecimals { + if c.Decimals != c.ExtendedDecimals { + return errors.New("decimals and extended decimals must be the same for 18 decimals") + } + if c.GetDenom() != c.GetExtendedDenom() { + return errors.New("denom and extended denom must be the same for 18 decimals") + } + } + + return nil +} + +// GetDenom returns the base denomination used in the chain, derived by SI prefix +func (c EvmCoinInfo) GetDenom() string { + return CreateDenomStr(c.Decimals, c.DisplayDenom) +} + +// GetExtendedDenom returns the extended denomination used in the chain, derived by SI prefix +func (c EvmCoinInfo) GetExtendedDenom() string { + return CreateDenomStr(c.ExtendedDecimals, c.DisplayDenom) +} + +func CreateDenomStr(decimals Decimals, displayDenom string) string { + return decimals.GetSIPrefix() + displayDenom +} diff --git a/x/vm/types/coin_info_test.go b/x/vm/types/coin_info_test.go new file mode 100644 index 000000000..b4e8545a5 --- /dev/null +++ b/x/vm/types/coin_info_test.go @@ -0,0 +1,179 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEvmCoinInfoValidate(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + coinInfo EvmCoinInfo + expPass bool + errContains string + }{ + { + name: "valid 18 decimals config", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: EighteenDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: true, + }, + { + name: "valid 6 decimals config", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: SixDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: true, + }, + { + name: "valid 12 decimals config", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: TwelveDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: true, + }, + { + name: "valid 1 decimal config", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: OneDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: true, + }, + { + name: "empty display denom", + coinInfo: EvmCoinInfo{ + DisplayDenom: "", + Decimals: EighteenDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: false, + errContains: "invalid denom: a", + }, + { + name: "invalid denom format - starts with number", + coinInfo: EvmCoinInfo{ + DisplayDenom: "1test", + Decimals: EighteenDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: false, + errContains: "invalid denom", + }, + { + name: "invalid extended denom format - too short", + coinInfo: EvmCoinInfo{ + DisplayDenom: "t", + Decimals: SixDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: false, + errContains: "invalid denom: ut", + }, + { + name: "invalid display denom character", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test@", + Decimals: EighteenDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: false, + errContains: "invalid denom: atest@", + }, + { + name: "zero decimals is invalid", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: 0, + ExtendedDecimals: EighteenDecimals, + }, + expPass: false, + errContains: "decimals validation failed", + }, + { + name: "invalid si decimals", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: TenDecimals, + ExtendedDecimals: TenDecimals, + }, + expPass: false, + errContains: "received unsupported decimals: 10", + }, + { + name: "decimals out of valid range", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: Decimals(19), + ExtendedDecimals: Decimals(19), + }, + expPass: false, + errContains: "received unsupported decimals", + }, + { + name: "18 decimals with different extended decimals", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: EighteenDecimals, + ExtendedDecimals: TwelveDecimals, + }, + expPass: false, + errContains: "decimals and extended decimals must be the same for 18 decimals", + }, + { + name: "valid 6 decimals with different extended decimals", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test", + Decimals: SixDecimals, + ExtendedDecimals: NineDecimals, + }, + expPass: true, + }, + { + name: "display denom with valid special characters", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test-coin", + Decimals: SixDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: true, + }, + { + name: "display denom with valid numbers", + coinInfo: EvmCoinInfo{ + DisplayDenom: "test123", + Decimals: SixDecimals, + ExtendedDecimals: EighteenDecimals, + }, + expPass: true, + }, + } + + for _, tc := range testCases { + tc := tc //nolint:copyloopvar // Needed to work correctly with concurrent tests + + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + err := tc.coinInfo.Validate() + + if tc.expPass { + require.NoError(t, err, "expected validation to pass for %s", tc.name) + } else { + require.Error(t, err, "expected validation to fail for %s", tc.name) + require.Contains(t, err.Error(), tc.errContains, "error message should contain expected text") + } + }) + } +} diff --git a/x/vm/types/config.go b/x/vm/types/config.go index 34f87ffef..928c27881 100644 --- a/x/vm/types/config.go +++ b/x/vm/types/config.go @@ -1,7 +1,3 @@ -// -// The config package provides a convenient way to modify x/evm params and values. -// Its primary purpose is to be used during application initialization. - //go:build !test // +build !test @@ -14,12 +10,12 @@ import ( geth "github.com/ethereum/go-ethereum/params" ) -// Configure applies the changes to the virtual machine configuration. -func (ec *EVMConfigurator) Configure() error { - // If Configure method has been already used in the object, return +// Apply applies the changes to the virtual machine configuration. +func (ec *EvmConfig) Apply() error { + // If Apply method has been already used in the object, return // an error to avoid overriding configuration. if ec.sealed { - return fmt.Errorf("error configuring EVMConfigurator: already sealed and cannot be modified") + return fmt.Errorf("error applying EvmConfig: already sealed and cannot be modified") } if err := setChainConfig(ec.chainConfig); err != nil { @@ -45,7 +41,7 @@ func (ec *EVMConfigurator) Configure() error { return nil } -func (ec *EVMConfigurator) ResetTestConfig() { +func (ec *EvmConfig) ResetTestConfig() { panic("this is only implemented with the 'test' build flag. Make sure you're running your tests using the '-tags=test' flag.") } diff --git a/x/vm/types/config_testing.go b/x/vm/types/config_testing.go index 1440ccb86..dc95ff1e7 100644 --- a/x/vm/types/config_testing.go +++ b/x/vm/types/config_testing.go @@ -1,7 +1,3 @@ -// -// The config package provides a convenient way to modify x/evm params and values. -// Its primary purpose is to be used during application initialization. - //go:build test // +build test @@ -19,12 +15,12 @@ import ( // opcodes are active based on Ethereum upgrades. var testChainConfig *ChainConfig -// Configure applies the changes to the virtual machine configuration. -func (ec *EVMConfigurator) Configure() error { - // If Configure method has been already used in the object, return +// Apply applies the changes to the virtual machine configuration. +func (ec *EvmConfig) Apply() error { + // If Apply method has been already used in the object, return // an error to avoid overriding configuration. if ec.sealed { - return fmt.Errorf("error configuring EVMConfigurator: already sealed and cannot be modified") + return fmt.Errorf("error applying EvmConfig: already sealed and cannot be modified") } if err := setTestChainConfig(ec.chainConfig); err != nil { @@ -50,7 +46,7 @@ func (ec *EVMConfigurator) Configure() error { return nil } -func (ec *EVMConfigurator) ResetTestConfig() { +func (ec *EvmConfig) ResetTestConfig() { vm.ResetActivators() resetEVMCoinInfo() testChainConfig = nil diff --git a/x/vm/types/configurator.go b/x/vm/types/configurator.go index 44c1fd8ed..5c3c23a7f 100644 --- a/x/vm/types/configurator.go +++ b/x/vm/types/configurator.go @@ -1,7 +1,3 @@ -// -// The config package provides a convenient way to modify x/evm params and values. -// Its primary purpose is to be used during application initialization. - package types import ( @@ -11,10 +7,10 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) -// EVMConfigurator allows to extend x/evm module configurations. The configurator modifies +// EvmConfig allows to extend x/evm module configurations. The configurator modifies // the EVM before starting the node. This means that all init genesis validations will be // applied to each change. -type EVMConfigurator struct { +type EvmConfig struct { sealed bool extendedEIPs map[int]func(*vm.JumpTable) extendedDefaultExtraEIPs []int64 @@ -22,35 +18,35 @@ type EVMConfigurator struct { evmCoinInfo EvmCoinInfo } -// NewEVMConfigurator returns a pointer to a new EVMConfigurator object. -func NewEVMConfigurator() *EVMConfigurator { - return &EVMConfigurator{} +// NewEvmConfig returns a pointer to a new EvmConfig object. +func NewEvmConfig() *EvmConfig { + return &EvmConfig{} } // WithExtendedEips allows to add to the go-ethereum activators map the provided // EIP activators. -func (ec *EVMConfigurator) WithExtendedEips(extendedEIPs map[int]func(*vm.JumpTable)) *EVMConfigurator { +func (ec *EvmConfig) WithExtendedEips(extendedEIPs map[int]func(*vm.JumpTable)) *EvmConfig { ec.extendedEIPs = extendedEIPs return ec } // WithExtendedDefaultExtraEIPs update the x/evm DefaultExtraEIPs params // by adding provided EIP numbers. -func (ec *EVMConfigurator) WithExtendedDefaultExtraEIPs(eips ...int64) *EVMConfigurator { +func (ec *EvmConfig) WithExtendedDefaultExtraEIPs(eips ...int64) *EvmConfig { ec.extendedDefaultExtraEIPs = eips return ec } // WithChainConfig allows to define a custom `chainConfig` to be used in the // EVM. -func (ec *EVMConfigurator) WithChainConfig(cc *ChainConfig) *EVMConfigurator { +func (ec *EvmConfig) WithChainConfig(cc *ChainConfig) *EvmConfig { ec.chainConfig = cc return ec } // WithEVMCoinInfo allows to define the denom and decimals of the token used as the // EVM token. -func (ec *EVMConfigurator) WithEVMCoinInfo(coinInfo EvmCoinInfo) *EVMConfigurator { +func (ec *EvmConfig) WithEVMCoinInfo(coinInfo EvmCoinInfo) *EvmConfig { ec.evmCoinInfo = coinInfo return ec } @@ -58,7 +54,7 @@ func (ec *EVMConfigurator) WithEVMCoinInfo(coinInfo EvmCoinInfo) *EVMConfigurato func extendDefaultExtraEIPs(extraEIPs []int64) error { for _, eip := range extraEIPs { if slices.Contains(DefaultExtraEIPs, eip) { - return fmt.Errorf("error configuring EVMConfigurator: EIP %d is already present in the default list: %v", eip, DefaultExtraEIPs) + return fmt.Errorf("error applying EvmConfig: EIP %d is already present in the default list: %v", eip, DefaultExtraEIPs) } DefaultExtraEIPs = append(DefaultExtraEIPs, eip) diff --git a/x/vm/types/configurator_test.go b/x/vm/types/configurator_test.go index 8ba74f536..16d621348 100644 --- a/x/vm/types/configurator_test.go +++ b/x/vm/types/configurator_test.go @@ -10,13 +10,13 @@ import ( "github.com/cosmos/evm/x/vm/types" ) -func TestEVMConfigurator(t *testing.T) { - evmConfigurator := types.NewEVMConfigurator(). +func TestEvmConfigApply(t *testing.T) { + evmConfigurator := types.NewEvmConfig(). WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]) - err := evmConfigurator.Configure() + err := evmConfigurator.Apply() require.NoError(t, err) - err = evmConfigurator.Configure() + err = evmConfigurator.Apply() require.Error(t, err) require.Contains(t, err.Error(), "sealed", "expected different error") } @@ -24,17 +24,17 @@ func TestEVMConfigurator(t *testing.T) { func TestExtendedEips(t *testing.T) { testCases := []struct { name string - malleate func() *types.EVMConfigurator + malleate func() *types.EvmConfig expPass bool errContains string }{ { "fail - eip already present in activators return an error", - func() *types.EVMConfigurator { + func() *types.EvmConfig { extendedEIPs := map[int]func(*vm.JumpTable){ 3855: func(_ *vm.JumpTable) {}, } - ec := types.NewEVMConfigurator(). + ec := types.NewEvmConfig(). WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). WithExtendedEips(extendedEIPs) return ec @@ -44,11 +44,11 @@ func TestExtendedEips(t *testing.T) { }, { "success - new default extra eips without duplication added", - func() *types.EVMConfigurator { + func() *types.EvmConfig { extendedEIPs := map[int]func(*vm.JumpTable){ 0o000: func(_ *vm.JumpTable) {}, } - ec := types.NewEVMConfigurator(). + ec := types.NewEvmConfig(). WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). WithExtendedEips(extendedEIPs) return ec @@ -61,7 +61,7 @@ func TestExtendedEips(t *testing.T) { for _, tc := range testCases { ec := tc.malleate() ec.ResetTestConfig() - err := ec.Configure() + err := ec.Apply() if tc.expPass { require.NoError(t, err) @@ -76,17 +76,17 @@ func TestExtendedDefaultExtraEips(t *testing.T) { defaultExtraEIPsSnapshot := types.DefaultExtraEIPs testCases := []struct { name string - malleate func() *types.EVMConfigurator + malleate func() *types.EvmConfig postCheck func() expPass bool errContains string }{ { "fail - duplicate default EIP entiries", - func() *types.EVMConfigurator { + func() *types.EvmConfig { extendedDefaultExtraEIPs := []int64{1000} types.DefaultExtraEIPs = append(types.DefaultExtraEIPs, 1000) - ec := types.NewEVMConfigurator(). + ec := types.NewEvmConfig(). WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). WithExtendedDefaultExtraEIPs(extendedDefaultExtraEIPs...) return ec @@ -100,9 +100,9 @@ func TestExtendedDefaultExtraEips(t *testing.T) { }, { "success - empty default extra eip", - func() *types.EVMConfigurator { + func() *types.EvmConfig { var extendedDefaultExtraEIPs []int64 - ec := types.NewEVMConfigurator(). + ec := types.NewEvmConfig(). WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). WithExtendedDefaultExtraEIPs(extendedDefaultExtraEIPs...) return ec @@ -115,9 +115,9 @@ func TestExtendedDefaultExtraEips(t *testing.T) { }, { "success - extra default eip added", - func() *types.EVMConfigurator { + func() *types.EvmConfig { extendedDefaultExtraEIPs := []int64{1001} - ec := types.NewEVMConfigurator(). + ec := types.NewEvmConfig(). WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). WithExtendedDefaultExtraEIPs(extendedDefaultExtraEIPs...) return ec @@ -135,7 +135,7 @@ func TestExtendedDefaultExtraEips(t *testing.T) { t.Run(tc.name, func(t *testing.T) { ec := tc.malleate() ec.ResetTestConfig() - err := ec.Configure() + err := ec.Apply() if tc.expPass { require.NoError(t, err) diff --git a/x/vm/types/denom.go b/x/vm/types/denom.go index b4d5d68dc..0119ce460 100644 --- a/x/vm/types/denom.go +++ b/x/vm/types/denom.go @@ -1,11 +1,8 @@ -// -// The config package provides a convenient way to modify x/evm params and values. -// Its primary purpose is to be used during application initialization. - package types import ( "fmt" + "slices" "cosmossdk.io/math" ) @@ -57,9 +54,19 @@ var ConversionFactor = map[Decimals]math.Int{ type Decimals uint8 // Validate checks if the Decimals instance represent a supported decimals value -// or not. func (d Decimals) Validate() error { - if 0 < d && d <= EighteenDecimals { + validDecimals := []Decimals{ + OneDecimals, + TwoDecimals, + ThreeDecimals, + SixDecimals, + NineDecimals, + TwelveDecimals, + FifteenDecimals, + EighteenDecimals, + } + + if slices.Contains(validDecimals, d) { return nil } @@ -77,13 +84,27 @@ func (d Decimals) ConversionFactor() math.Int { return ConversionFactor[d] } -// EvmCoinInfo struct holds the name and decimals of the EVM denom. The EVM denom -// is the token used to pay fees in the EVM. -// -// TODO: move to own file? at least rename file because it's unclear to use "denom" -type EvmCoinInfo struct { - Denom string - ExtendedDenom string - DisplayDenom string - Decimals Decimals +// GetSIPrefix returns the SI prefix for the decimals +func (d Decimals) GetSIPrefix() string { + switch d { + case OneDecimals: + return "d" + case TwoDecimals: + return "c" + case ThreeDecimals: + return "m" + case SixDecimals: + return "u" + case NineDecimals: + return "n" + case TwelveDecimals: + return "p" + case FifteenDecimals: + return "f" + case EighteenDecimals: + return "a" + default: + // decimals must be one of 1, 2, 3, 6, 9, 12, 15, 18 to have a valid prefix + return "invalid" + } } diff --git a/x/vm/types/denom_config.go b/x/vm/types/denom_config.go index 04ff3fe8b..f32c29df6 100644 --- a/x/vm/types/denom_config.go +++ b/x/vm/types/denom_config.go @@ -1,7 +1,3 @@ -// -// The config package provides a convenient way to modify x/evm params and values. -// Its primary purpose is to be used during application initialization. - //go:build !test // +build !test @@ -15,7 +11,7 @@ import ( ) // evmCoinInfo hold the information of the coin used in the EVM as gas token. It -// can only be set via `EVMConfigurator` before starting the app. +// can only be set via `EvmConfig.Apply` before starting the app. var evmCoinInfo *EvmCoinInfo // setEVMCoinDecimals allows to define the decimals used in the representation @@ -29,21 +25,12 @@ func setEVMCoinDecimals(d Decimals) error { return nil } -// setEVMCoinDenom allows to define the denom of the coin used in the EVM. -func setEVMCoinDenom(denom string) error { - if err := sdk.ValidateDenom(denom); err != nil { - return fmt.Errorf("setting EVM coin denom: %w", err) - } - evmCoinInfo.Denom = denom - return nil -} - -// setEVMCoinExtendedDenom allows to define the extended denom of the coin used in the EVM. -func setEVMCoinExtendedDenom(extendedDenom string) error { - if err := sdk.ValidateDenom(extendedDenom); err != nil { +// setEVMCoinExtendedDecimals allows to define the extended denom of the coin used in the EVM. +func setEVMCoinExtendedDecimals(d Decimals) error { + if err := d.Validate(); err != nil { return err } - evmCoinInfo.ExtendedDenom = extendedDenom + evmCoinInfo.ExtendedDecimals = d return nil } @@ -61,14 +48,20 @@ func GetEVMCoinDecimals() Decimals { return evmCoinInfo.Decimals } +// GetEVMCoinExtendedDecimals returns the extended decimals used in the +// representation of the EVM coin. +func GetEVMCoinExtendedDecimals() Decimals { + return evmCoinInfo.ExtendedDecimals +} + // GetEVMCoinDenom returns the denom used for the EVM coin. func GetEVMCoinDenom() string { - return evmCoinInfo.Denom + return evmCoinInfo.GetDenom() } // GetEVMCoinExtendedDenom returns the extended denom used for the EVM coin. func GetEVMCoinExtendedDenom() string { - return evmCoinInfo.ExtendedDenom + return evmCoinInfo.GetExtendedDenom() } // GetEVMCoinDisplayDenom returns the display denom used for the EVM coin. @@ -83,21 +76,18 @@ func setEVMCoinInfo(eci EvmCoinInfo) error { } if eci.Decimals == EighteenDecimals { - if eci.Denom != eci.ExtendedDenom { - return errors.New("EVM coin denom and extended denom must be the same for 18 decimals") + if eci.Decimals != eci.ExtendedDecimals { + return errors.New("EVM coin decimals and extended decimals must be the same for 18 decimals") } } evmCoinInfo = new(EvmCoinInfo) - if err := setEVMCoinDenom(eci.Denom); err != nil { - return err - } - if err := setEVMCoinExtendedDenom(eci.ExtendedDenom); err != nil { + if err := setEVMCoinDecimals(eci.Decimals); err != nil { return err } - if err := setDisplayDenom(eci.DisplayDenom); err != nil { + if err := setEVMCoinExtendedDecimals(eci.ExtendedDecimals); err != nil { return err } - return setEVMCoinDecimals(eci.Decimals) + return setDisplayDenom(eci.DisplayDenom) } diff --git a/x/vm/types/denom_config_testing.go b/x/vm/types/denom_config_testing.go index 66b849c0c..8633fdaf2 100644 --- a/x/vm/types/denom_config_testing.go +++ b/x/vm/types/denom_config_testing.go @@ -1,7 +1,3 @@ -// -// The config package provides a convenient way to modify x/evm params and values. -// Its primary purpose is to be used during application initialization. - //go:build test // +build test @@ -15,7 +11,7 @@ import ( ) // testingEvmCoinInfo hold the information of the coin used in the EVM as gas token. It -// can only be set via `EVMConfigurator` before starting the app. +// can only be set via `EvmConfig.Apply` before starting the app. var testingEvmCoinInfo *EvmCoinInfo // setEVMCoinDecimals allows to define the decimals used in the representation @@ -29,21 +25,12 @@ func setEVMCoinDecimals(d Decimals) error { return nil } -// setEVMCoinDenom allows to define the denom of the coin used in the EVM. -func setEVMCoinDenom(denom string) error { - if err := sdk.ValidateDenom(denom); err != nil { - return err - } - testingEvmCoinInfo.Denom = denom - return nil -} - -// setEVMCoinExtendedDenom allows to define the extended denom of the coin used in the EVM. -func setEVMCoinExtendedDenom(extendedDenom string) error { - if err := sdk.ValidateDenom(extendedDenom); err != nil { +// setEVMCoinExtendedDecimals allows to define the extended denom of the coin used in the EVM. +func setEVMCoinExtendedDecimals(d Decimals) error { + if err := d.Validate(); err != nil { return err } - testingEvmCoinInfo.ExtendedDenom = extendedDenom + testingEvmCoinInfo.ExtendedDecimals = d return nil } @@ -61,14 +48,20 @@ func GetEVMCoinDecimals() Decimals { return testingEvmCoinInfo.Decimals } +// GetEVMCoinExtendedDecimals returns the extended decimals used in the +// representation of the EVM coin. +func GetEVMCoinExtendedDecimals() Decimals { + return testingEvmCoinInfo.ExtendedDecimals +} + // GetEVMCoinDenom returns the denom used for the EVM coin. func GetEVMCoinDenom() string { - return testingEvmCoinInfo.Denom + return testingEvmCoinInfo.GetDenom() } // GetEVMCoinExtendedDenom returns the extended denom used for the EVM coin. func GetEVMCoinExtendedDenom() string { - return testingEvmCoinInfo.ExtendedDenom + return testingEvmCoinInfo.GetExtendedDenom() } // GetEVMCoinDisplayDenom returns the display denom used for the EVM coin. @@ -83,23 +76,20 @@ func setTestingEVMCoinInfo(eci EvmCoinInfo) error { } if eci.Decimals == EighteenDecimals { - if eci.Denom != eci.ExtendedDenom { - return errors.New("EVM coin denom and extended denom must be the same for 18 decimals") + if eci.Decimals != eci.ExtendedDecimals { + return errors.New("EVM coin decimals and extended decimals must be the same for 18 decimals") } } testingEvmCoinInfo = new(EvmCoinInfo) - if err := setEVMCoinDenom(eci.Denom); err != nil { - return err - } - if err := setEVMCoinExtendedDenom(eci.ExtendedDenom); err != nil { + if err := setEVMCoinDecimals(eci.Decimals); err != nil { return err } - if err := setDisplayDenom(eci.DisplayDenom); err != nil { + if err := setEVMCoinExtendedDecimals(eci.ExtendedDecimals); err != nil { return err } - return setEVMCoinDecimals(eci.Decimals) + return setDisplayDenom(eci.DisplayDenom) } // resetEVMCoinInfo resets to nil the testingEVMCoinInfo diff --git a/x/vm/types/msg_test.go b/x/vm/types/msg_test.go index 2692b3edb..a16dd0762 100644 --- a/x/vm/types/msg_test.go +++ b/x/vm/types/msg_test.go @@ -116,9 +116,9 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_BuildTx() { testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], } { for _, tc := range testCases { - configurator := types.NewEVMConfigurator() + configurator := types.NewEvmConfig() configurator.ResetTestConfig() - suite.Require().NoError(configurator.WithEVMCoinInfo(coinInfo).Configure()) + suite.Require().NoError(configurator.WithEVMCoinInfo(coinInfo).Apply()) baseDenom := types.GetEVMCoinDenom() extendedDenom := types.GetEVMCoinExtendedDenom() diff --git a/x/vm/types/scaling_test.go b/x/vm/types/scaling_test.go index 421914fe1..7eb47cf76 100644 --- a/x/vm/types/scaling_test.go +++ b/x/vm/types/scaling_test.go @@ -20,8 +20,8 @@ func TestConvertEvmCoinFrom18Decimals(t *testing.T) { eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] - eighteenDecimalsBaseCoinZero := sdk.Coin{Denom: eighteenDecimalsCoinInfo.Denom, Amount: math.NewInt(0)} - sixDecimalsBaseCoinZero := sdk.Coin{Denom: sixDecimalsCoinInfo.Denom, Amount: math.NewInt(0)} + eighteenDecimalsBaseCoinZero := sdk.Coin{Denom: eighteenDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(0)} + sixDecimalsBaseCoinZero := sdk.Coin{Denom: sixDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(0)} testCases := []struct { name string @@ -42,28 +42,28 @@ func TestConvertEvmCoinFrom18Decimals(t *testing.T) { evmCoinInfo: sixDecimalsCoinInfo, coin: sixDecimalsBaseCoinZero, expErr: false, - expCoin: sdk.Coin{Denom: sixDecimalsCoinInfo.ExtendedDenom, Amount: math.NewInt(0)}, + expCoin: sdk.Coin{Denom: sixDecimalsCoinInfo.GetExtendedDenom(), Amount: math.NewInt(0)}, }, { name: "pass - no conversion with 18 decimals", evmCoinInfo: eighteenDecimalsCoinInfo, - coin: sdk.Coin{Denom: eighteenDecimalsCoinInfo.Denom, Amount: math.NewInt(10)}, + coin: sdk.Coin{Denom: eighteenDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(10)}, expErr: false, - expCoin: sdk.Coin{Denom: eighteenDecimalsCoinInfo.Denom, Amount: math.NewInt(10)}, + expCoin: sdk.Coin{Denom: eighteenDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(10)}, }, { name: "pass - conversion with 6 decimals", evmCoinInfo: sixDecimalsCoinInfo, - coin: sdk.Coin{Denom: sixDecimalsCoinInfo.Denom, Amount: math.NewInt(1e12)}, + coin: sdk.Coin{Denom: sixDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(1e12)}, expErr: false, - expCoin: sdk.Coin{Denom: sixDecimalsCoinInfo.ExtendedDenom, Amount: math.NewInt(1e12)}, + expCoin: sdk.Coin{Denom: sixDecimalsCoinInfo.GetExtendedDenom(), Amount: math.NewInt(1e12)}, }, { name: "pass - conversion with amount less than conversion factor", evmCoinInfo: sixDecimalsCoinInfo, - coin: sdk.Coin{Denom: sixDecimalsCoinInfo.Denom, Amount: math.NewInt(1e11)}, + coin: sdk.Coin{Denom: sixDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(1e11)}, expErr: false, - expCoin: sdk.Coin{Denom: sixDecimalsCoinInfo.ExtendedDenom, Amount: math.NewInt(1e11)}, + expCoin: sdk.Coin{Denom: sixDecimalsCoinInfo.GetExtendedDenom(), Amount: math.NewInt(1e11)}, }, { name: "fail - not evm denom", @@ -75,9 +75,9 @@ func TestConvertEvmCoinFrom18Decimals(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - require.NoError(t, configurator.WithEVMCoinInfo(tc.evmCoinInfo).Configure()) + require.NoError(t, configurator.WithEVMCoinInfo(tc.evmCoinInfo).Apply()) coinConverted, err := evmtypes.ConvertEvmCoinDenomToExtendedDenom(tc.coin) @@ -96,8 +96,8 @@ func TestConvertCoinsFrom18Decimals(t *testing.T) { sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] nonBaseCoin := sdk.Coin{Denom: "btc", Amount: math.NewInt(10)} - eighteenDecimalsBaseCoin := sdk.Coin{Denom: eighteenDecimalsCoinInfo.Denom, Amount: math.NewInt(10)} - sixDecimalsBaseCoin := sdk.Coin{Denom: sixDecimalsCoinInfo.Denom, Amount: math.NewInt(10)} + eighteenDecimalsBaseCoin := sdk.Coin{Denom: eighteenDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(10)} + sixDecimalsBaseCoin := sdk.Coin{Denom: sixDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(10)} testCases := []struct { name string @@ -121,7 +121,7 @@ func TestConvertCoinsFrom18Decimals(t *testing.T) { name: "pass - only base denom 6 decimals", evmCoinInfo: sixDecimalsCoinInfo, coins: sdk.Coins{sixDecimalsBaseCoin}, - expCoins: sdk.Coins{sdk.Coin{Denom: sixDecimalsCoinInfo.ExtendedDenom, Amount: math.NewInt(10)}}, + expCoins: sdk.Coins{sdk.Coin{Denom: sixDecimalsCoinInfo.GetExtendedDenom(), Amount: math.NewInt(10)}}, }, { name: "pass - multiple coins and base denom 18 decimals", @@ -133,15 +133,15 @@ func TestConvertCoinsFrom18Decimals(t *testing.T) { name: "pass - multiple coins and base denom 6 decimals", evmCoinInfo: sixDecimalsCoinInfo, coins: sdk.Coins{nonBaseCoin, sixDecimalsBaseCoin}.Sort(), - expCoins: sdk.Coins{nonBaseCoin, sdk.Coin{Denom: sixDecimalsCoinInfo.ExtendedDenom, Amount: math.NewInt(10)}}.Sort(), + expCoins: sdk.Coins{nonBaseCoin, sdk.Coin{Denom: sixDecimalsCoinInfo.GetExtendedDenom(), Amount: math.NewInt(10)}}.Sort(), }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - require.NoError(t, configurator.WithEVMCoinInfo(tc.evmCoinInfo).Configure()) + require.NoError(t, configurator.WithEVMCoinInfo(tc.evmCoinInfo).Apply()) coinConverted := evmtypes.ConvertCoinsDenomToExtendedDenom(tc.coins) require.Equal(t, tc.expCoins, coinConverted, "expected a different coin") @@ -188,9 +188,9 @@ func TestConvertAmountTo18DecimalsLegacy(t *testing.T) { } { for _, tc := range testCases { t.Run(fmt.Sprintf("%d dec - %s", coinInfo.Decimals, tc.name), func(t *testing.T) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - require.NoError(t, configurator.WithEVMCoinInfo(coinInfo).Configure()) + require.NoError(t, configurator.WithEVMCoinInfo(coinInfo).Apply()) res := evmtypes.ConvertBigIntFrom18DecimalsToLegacyDec(tc.amt.ToBig()) exp := math.LegacyNewDecFromBigInt(tc.amt.ToBig()) if coinInfo.Decimals == evmtypes.SixDecimals { @@ -226,9 +226,9 @@ func TestConvertAmountTo18DecimalsBigInt(t *testing.T) { } { for _, tc := range testCases { t.Run(fmt.Sprintf("%d dec - %s", coinInfo.Decimals, tc.name), func(t *testing.T) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - require.NoError(t, configurator.WithEVMCoinInfo(coinInfo).Configure()) + require.NoError(t, configurator.WithEVMCoinInfo(coinInfo).Apply()) res := evmtypes.ConvertAmountTo18DecimalsBigInt(tc.amt) exp := tc.amt if coinInfo.Decimals == evmtypes.SixDecimals { diff --git a/x/vm/wrappers/bank_test.go b/x/vm/wrappers/bank_test.go index 590da9908..8a6ff4a0b 100644 --- a/x/vm/wrappers/bank_test.go +++ b/x/vm/wrappers/bank_test.go @@ -38,12 +38,12 @@ func TestMintAmountToAccount(t *testing.T) { { name: "success - convert evm coin denom to extended denom", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, + evmDenom: sixDecimalsCoinInfo.GetDenom(), amount: big.NewInt(1e18), // 1 token in 18 decimals recipient: sdk.AccAddress([]byte("test_address")), expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)) // 1 token in 18 decimals + expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)) // 1 token in 18 decimals expectedCoins := sdk.NewCoins(expectedCoin) mbk.EXPECT(). @@ -62,12 +62,12 @@ func TestMintAmountToAccount(t *testing.T) { { name: "success - 18 decimals amount not modified", coinInfo: eighteenDecimalsCoinInfo, - evmDenom: eighteenDecimalsCoinInfo.Denom, + evmDenom: eighteenDecimalsCoinInfo.GetDenom(), amount: big.NewInt(1e18), // 1 token in 18 decimals recipient: sdk.AccAddress([]byte("test_address")), expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - expectedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)) + expectedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)) expectedCoins := sdk.NewCoins(expectedCoin) mbk.EXPECT(). @@ -86,12 +86,12 @@ func TestMintAmountToAccount(t *testing.T) { { name: "fail - mint coins error", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, + evmDenom: sixDecimalsCoinInfo.GetDenom(), amount: big.NewInt(1e18), recipient: sdk.AccAddress([]byte("test_address")), expectErr: "failed to mint coins to account in bank wrapper", mockSetup: func(mbk *testutil.MockBankWrapper) { - expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)) + expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)) expectedCoins := sdk.NewCoins(expectedCoin) mbk.EXPECT(). @@ -104,10 +104,10 @@ func TestMintAmountToAccount(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") // Setup mock controller ctrl := gomock.NewController(t) @@ -146,7 +146,7 @@ func TestBurnAmountFromAccount(t *testing.T) { amount: big.NewInt(1e18), expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)) + expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)) expectedCoins := sdk.NewCoins(expectedCoin) mbk.EXPECT(). @@ -168,7 +168,7 @@ func TestBurnAmountFromAccount(t *testing.T) { amount: big.NewInt(1e18), expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - expectedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)) + expectedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)) expectedCoins := sdk.NewCoins(expectedCoin) mbk.EXPECT(). @@ -190,7 +190,7 @@ func TestBurnAmountFromAccount(t *testing.T) { amount: big.NewInt(1e18), expectErr: "failed to burn coins from account in bank wrapper", mockSetup: func(mbk *testutil.MockBankWrapper) { - expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)) + expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)) expectedCoins := sdk.NewCoins(expectedCoin) mbk.EXPECT(). @@ -208,7 +208,7 @@ func TestBurnAmountFromAccount(t *testing.T) { amount: big.NewInt(1e18), expectErr: "burn error", mockSetup: func(mbk *testutil.MockBankWrapper) { - expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)) + expectedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)) expectedCoins := sdk.NewCoins(expectedCoin) mbk.EXPECT(). @@ -225,10 +225,10 @@ func TestBurnAmountFromAccount(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") // Setup mock controller ctrl := gomock.NewController(t) @@ -266,14 +266,14 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { coinInfo: eighteenDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), }...) return coins }, expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), }...) mbk.EXPECT(). @@ -290,14 +290,14 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { coinInfo: sixDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), }...) return coins }, expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)), }...) mbk.EXPECT(). @@ -314,7 +314,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { coinInfo: eighteenDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) return coins @@ -322,7 +322,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) @@ -340,7 +340,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { coinInfo: sixDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) return coins @@ -348,7 +348,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) @@ -366,7 +366,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { coinInfo: sixDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.Denom, sdkmath.ZeroInt()), + sdk.NewCoin(sixDecimalsCoinInfo.GetDenom(), sdkmath.ZeroInt()), }...) return coins }, @@ -386,10 +386,10 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") // Setup mock controller ctrl := gomock.NewController(t) @@ -427,14 +427,14 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { coinInfo: eighteenDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), }...) return coins }, expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), }...) mbk.EXPECT(). @@ -451,14 +451,14 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { coinInfo: sixDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), }...) return coins }, expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)), }...) mbk.EXPECT(). @@ -475,7 +475,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { coinInfo: eighteenDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) return coins @@ -483,7 +483,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) @@ -501,7 +501,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { coinInfo: sixDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) return coins @@ -509,7 +509,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { expectErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { expectedCoins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)), + sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)), sdk.NewCoin("something", sdkmath.NewInt(3e18)), }...) @@ -527,7 +527,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { coinInfo: sixDecimalsCoinInfo, coins: func() sdk.Coins { coins := sdk.NewCoins([]sdk.Coin{ - sdk.NewCoin(sixDecimalsCoinInfo.Denom, sdkmath.ZeroInt()), + sdk.NewCoin(sixDecimalsCoinInfo.GetDenom(), sdkmath.ZeroInt()), }...) return coins }, @@ -547,10 +547,10 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") // Setup mock controller ctrl := gomock.NewController(t) @@ -591,85 +591,85 @@ func TestGetBalance(t *testing.T) { { name: "success - convert 6 decimals amount to 18 decimals", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)), + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)) + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)) mbk.EXPECT(). GetBalance( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, { name: "success - convert max int 6 decimals amount to 18 decimals", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e12).MulRaw(maxInt64)), + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e12).MulRaw(maxInt64)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e12).MulRaw(maxInt64)) + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e12).MulRaw(maxInt64)) mbk.EXPECT(). GetBalance( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, { name: "success - does not convert 18 decimals amount", coinInfo: eighteenDecimalsCoinInfo, - evmDenom: eighteenDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + evmDenom: eighteenDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)) + returnedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)) mbk.EXPECT(). GetBalance( gomock.Any(), account, - eighteenDecimalsCoinInfo.Denom, + eighteenDecimalsCoinInfo.GetDenom(), ).Return(returnedCoin) }, }, { name: "success - zero balance", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(0)), + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(0)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(0)) + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(0)) mbk.EXPECT(). GetBalance( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, { name: "success - small amount (less than 1 full token)", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e14)), // 0.0001 token in 18 decimals + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e14)), // 0.0001 token in 18 decimals expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e14)) // 0.0001 token in 6 decimals + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e14)) // 0.0001 token in 6 decimals mbk.EXPECT(). GetBalance( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, @@ -685,10 +685,10 @@ func TestGetBalance(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") // Setup mock controller ctrl := gomock.NewController(t) @@ -738,85 +738,85 @@ func TestSppendableCoin(t *testing.T) { { name: "success - convert 6 decimals amount to 18 decimals", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)), + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e18)) + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e18)) mbk.EXPECT(). SpendableCoin( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, { name: "success - convert max int 6 decimals amount to 18 decimals", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e12).MulRaw(maxInt64)), + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e12).MulRaw(maxInt64)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e12).MulRaw(maxInt64)) + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e12).MulRaw(maxInt64)) mbk.EXPECT(). SpendableCoin( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, { name: "success - does not convert 18 decimals amount", coinInfo: eighteenDecimalsCoinInfo, - evmDenom: eighteenDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)), + evmDenom: eighteenDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.Denom, sdkmath.NewInt(1e18)) + returnedCoin := sdk.NewCoin(eighteenDecimalsCoinInfo.GetDenom(), sdkmath.NewInt(1e18)) mbk.EXPECT(). SpendableCoin( gomock.Any(), account, - eighteenDecimalsCoinInfo.Denom, + eighteenDecimalsCoinInfo.GetDenom(), ).Return(returnedCoin) }, }, { name: "success - zero balance", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(0)), + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(0)), expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(0)) + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(0)) mbk.EXPECT(). SpendableCoin( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, { name: "success - small amount (less than 1 full token)", coinInfo: sixDecimalsCoinInfo, - evmDenom: sixDecimalsCoinInfo.Denom, - expCoin: sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e14)), // 0.0001 token in 18 decimals + evmDenom: sixDecimalsCoinInfo.GetDenom(), + expCoin: sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e14)), // 0.0001 token in 18 decimals expErr: "", mockSetup: func(mbk *testutil.MockBankWrapper) { - returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.ExtendedDenom, sdkmath.NewInt(1e14)) // 0.0001 token in 6 decimals + returnedCoin := sdk.NewCoin(sixDecimalsCoinInfo.GetExtendedDenom(), sdkmath.NewInt(1e14)) // 0.0001 token in 6 decimals mbk.EXPECT(). SpendableCoin( gomock.Any(), account, - sixDecimalsCoinInfo.ExtendedDenom, + sixDecimalsCoinInfo.GetExtendedDenom(), ).Return(returnedCoin) }, }, @@ -832,10 +832,10 @@ func TestSppendableCoin(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") // Setup mock controller ctrl := gomock.NewController(t) diff --git a/x/vm/wrappers/feemarket_test.go b/x/vm/wrappers/feemarket_test.go index 710f905ff..6486e51f2 100644 --- a/x/vm/wrappers/feemarket_test.go +++ b/x/vm/wrappers/feemarket_test.go @@ -90,10 +90,10 @@ func TestGetBaseFee(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") ctrl := gomock.NewController(t) mockFeeMarketKeeper := testutil.NewMockFeeMarketKeeper(ctrl) @@ -180,10 +180,10 @@ func TestCalculateBaseFee(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") ctrl := gomock.NewController(t) mockFeeMarketKeeper := testutil.NewMockFeeMarketKeeper(ctrl) @@ -255,10 +255,10 @@ func TestGetParams(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Setup EVM configurator to have access to the EVM coin info. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - err := configurator.WithEVMCoinInfo(tc.coinInfo).Configure() - require.NoError(t, err, "failed to configure EVMConfigurator") + err := configurator.WithEVMCoinInfo(tc.coinInfo).Apply() + require.NoError(t, err, "failed to apply EvmConfig") ctrl := gomock.NewController(t) mockFeeMarketKeeper := testutil.NewMockFeeMarketKeeper(ctrl) From 4d0136cd6b10cbffd26a23cab411a4f7403c1967 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 04:32:31 -0400 Subject: [PATCH 03/23] update evmcoininfo usage --- ante/cosmos/authz_test.go | 4 +- config/evm_app_options.go | 8 +-- ethereum/eip712/preprocess_test.go | 4 +- evmd/cmd/evmd/config/config.go | 21 ++++---- evmd/eips/README.md | 10 ++-- evmd/tests/integration/x_vm_test.go | 14 +++--- precompiles/common/balance_handler_test.go | 4 +- tests/integration/ante/ante_test_suite.go | 14 +++--- .../ante/test_evm_unit_04_validate.go | 4 +- .../precompiles/werc20/test_integration.go | 4 +- .../x/precisebank/test_burn_integration.go | 4 +- .../x/precisebank/test_mint_integration.go | 4 +- .../x/precisebank/test_send_integration.go | 4 +- tests/integration/x/vm/keeper_test_suite.go | 14 +++--- tests/integration/x/vm/test_grpc_query.go | 15 +++--- testutil/config/config.go | 14 +++--- testutil/config/config_testing.go | 49 ++++++++----------- testutil/constants/constants.go | 28 +++++------ .../evm/network/chain_id_modifiers.go | 2 +- testutil/integration/evm/network/coins.go | 2 +- testutil/integration/evm/network/config.go | 4 +- utils/utils_test.go | 4 +- x/precisebank/types/extended_balance_test.go | 4 +- x/precisebank/types/genesis_test.go | 8 +-- 24 files changed, 110 insertions(+), 133 deletions(-) diff --git a/ante/cosmos/authz_test.go b/ante/cosmos/authz_test.go index aee72f910..1930f2077 100644 --- a/ante/cosmos/authz_test.go +++ b/ante/cosmos/authz_test.go @@ -21,9 +21,9 @@ import ( ) func TestAuthzLimiterDecorator(t *testing.T) { - evmConfigurator := evmtypes.NewEVMConfigurator(). + evmConfigurator := evmtypes.NewEvmConfig(). WithEVMCoinInfo(constants.ExampleChainCoinInfo[constants.ExampleChainID]) - err := evmConfigurator.Configure() + err := evmConfigurator.Apply() require.NoError(t, err) encodingCfg := encoding.MakeConfig(constants.ExampleChainID.EVMChainID) diff --git a/config/evm_app_options.go b/config/evm_app_options.go index 63b06dbc6..3c95e91db 100644 --- a/config/evm_app_options.go +++ b/config/evm_app_options.go @@ -53,7 +53,7 @@ func EvmAppOptionsWithConfigWithReset( } ethCfg := evmtypes.DefaultChainConfig(chainID) - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() if withReset { // reset configuration to set the new one configurator.ResetTestConfig() @@ -63,7 +63,7 @@ func EvmAppOptionsWithConfigWithReset( WithChainConfig(ethCfg). // NOTE: we're using the 18 decimals default for the example chain WithEVMCoinInfo(coinInfo). - Configure() + Apply() if err != nil { return err } @@ -79,7 +79,7 @@ func setBaseDenom(ci evmtypes.EvmCoinInfo) (err error) { // So when failing because the denom was already registered, we ignore it and set // the corresponding denom to be base denom defer func() { - err = sdk.SetBaseDenom(ci.Denom) + err = sdk.SetBaseDenom(ci.GetDenom()) }() if err := sdk.RegisterDenom(ci.DisplayDenom, math.LegacyOneDec()); err != nil { return err @@ -87,5 +87,5 @@ func setBaseDenom(ci evmtypes.EvmCoinInfo) (err error) { // sdk.RegisterDenom will automatically overwrite the base denom when the // new setBaseDenom() units are lower than the current base denom's units. - return sdk.RegisterDenom(ci.Denom, math.LegacyNewDecWithPrec(1, int64(ci.Decimals))) + return sdk.RegisterDenom(ci.GetDenom(), math.LegacyNewDecWithPrec(1, int64(ci.Decimals))) } diff --git a/ethereum/eip712/preprocess_test.go b/ethereum/eip712/preprocess_test.go index c0376fda0..e355d6787 100644 --- a/ethereum/eip712/preprocess_test.go +++ b/ethereum/eip712/preprocess_test.go @@ -56,9 +56,9 @@ type TestCaseStruct struct { func TestLedgerPreprocessing(t *testing.T) { // Update bech32 prefix sdk.GetConfig().SetBech32PrefixForAccount(constants.ExampleBech32Prefix, "") - evmConfigurator := evmtypes.NewEVMConfigurator(). + evmConfigurator := evmtypes.NewEvmConfig(). WithEVMCoinInfo(constants.ExampleChainCoinInfo[constants.ExampleChainID]) - err := evmConfigurator.Configure() + err := evmConfigurator.Apply() require.NoError(t, err) testCases := []TestCaseStruct{ diff --git a/evmd/cmd/evmd/config/config.go b/evmd/cmd/evmd/config/config.go index 2699ca0b6..a5b042d07 100644 --- a/evmd/cmd/evmd/config/config.go +++ b/evmd/cmd/evmd/config/config.go @@ -12,24 +12,21 @@ import ( // chain id var ChainsCoinInfo = map[uint64]evmtypes.EvmCoinInfo{ EighteenDecimalsChainID: { - Denom: ExampleChainDenom, - ExtendedDenom: ExampleChainDenom, - DisplayDenom: ExampleDisplayDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleDisplayDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, // SixDecimalsChainID provides a chain ID which is being set up with 6 decimals SixDecimalsChainID: { - Denom: "utest", - ExtendedDenom: "atest", - DisplayDenom: "test", - Decimals: evmtypes.SixDecimals, + DisplayDenom: "test", + Decimals: evmtypes.SixDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, // EVMChainID provides a chain ID used for internal testing EVMChainID: { - Denom: "atest", - ExtendedDenom: "atest", - DisplayDenom: "test", - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: "test", + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, } diff --git a/evmd/eips/README.md b/evmd/eips/README.md index ac498503e..93f5572d8 100644 --- a/evmd/eips/README.md +++ b/evmd/eips/README.md @@ -134,7 +134,7 @@ In this way, even though the custom activators defined $3$ new EIPs, we are goin The EVM configuration is the type used to modify the EVM configuration before starting a node. The type is defined as: ```go -type EVMConfigurator struct { +type EvmConfig struct { extendedEIPs map[int]func(*vm.JumpTable) extendedDefaultExtraEIPs []int64 sealed bool @@ -151,18 +151,18 @@ It is important to notice that the configurator will only allow to append new en **Cosmos EVM**. The reason behind this choice is to ensure the correct and safe execution of the virtual machine but still allowing partners to customize their implementation. -The `EVMConfigurator` type should be constructed using the builder pattern inside the `init()` function of the file so +The `EvmConfig` type should be constructed using the builder pattern inside the `init()` function of the file so that it is run during the creation of the application. An example of the usage of the configurator is reported below: ```go -configurator := evmconfig.NewEVMConfigurator(). +configurator := evmconfig.NewEvmConfig(). WithExtendedEips(customActivators). WithExtendedDefaultExtraEIPs(defaultEnabledEIPs...). - Configure() + Apply() -err := configurator.Configure() +err := configurator.Apply() ``` Errors are raised when the configurator tries to append an item with the same name of one of the default one. Since diff --git a/evmd/tests/integration/x_vm_test.go b/evmd/tests/integration/x_vm_test.go index c1aec6e9f..a95c07391 100644 --- a/evmd/tests/integration/x_vm_test.go +++ b/evmd/tests/integration/x_vm_test.go @@ -35,22 +35,20 @@ func BenchmarkGasEstimation(b *testing.B) { chainConfig := types.DefaultChainConfig(nw.GetEIP155ChainID().Uint64()) // get the denom and decimals set on chain initialization // because we'll need to set them again when resetting the chain config - denom := types.GetEVMCoinDenom() - extendedDenom := types.GetEVMCoinExtendedDenom() displayDenom := types.GetEVMCoinDisplayDenom() decimals := types.GetEVMCoinDecimals() + extendedDecimals := types.GetEVMCoinExtendedDecimals() - configurator := types.NewEVMConfigurator() + configurator := types.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(types.EvmCoinInfo{ - Denom: denom, - ExtendedDenom: extendedDenom, - DisplayDenom: displayDenom, - Decimals: decimals, + DisplayDenom: displayDenom, + Decimals: decimals, + ExtendedDecimals: extendedDecimals, }). - Configure() + Apply() require.NoError(b, err) // Use simple transaction args for consistent benchmarking diff --git a/precompiles/common/balance_handler_test.go b/precompiles/common/balance_handler_test.go index c0ea5fe0b..c00e74fb2 100644 --- a/precompiles/common/balance_handler_test.go +++ b/precompiles/common/balance_handler_test.go @@ -30,9 +30,9 @@ func setupBalanceHandlerTest(t *testing.T) { t.Helper() sdk.GetConfig().SetBech32PrefixForAccount(testconstants.ExampleBech32Prefix, "") - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - require.NoError(t, configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]).Configure()) + require.NoError(t, configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]).Apply()) } func TestParseAddress(t *testing.T) { diff --git a/tests/integration/ante/ante_test_suite.go b/tests/integration/ante/ante_test_suite.go index d6a72cfa3..0fb9db71c 100644 --- a/tests/integration/ante/ante_test_suite.go +++ b/tests/integration/ante/ante_test_suite.go @@ -114,22 +114,20 @@ func (s *AnteTestSuite) SetupTest() { // get the denom and decimals set when initialized the chain // to set them again // when resetting the chain config - denom := evmtypes.GetEVMCoinDenom() - extendedDenom := evmtypes.GetEVMCoinExtendedDenom() displayDenom := evmtypes.GetEVMCoinDisplayDenom() decimals := evmtypes.GetEVMCoinDecimals() + extendedDecimals := evmtypes.GetEVMCoinExtendedDecimals() - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(evmtypes.EvmCoinInfo{ - Denom: denom, - ExtendedDenom: extendedDenom, - DisplayDenom: displayDenom, - Decimals: decimals, + DisplayDenom: displayDenom, + Decimals: decimals, + ExtendedDecimals: extendedDecimals, }). - Configure() + Apply() s.Require().NoError(err) } diff --git a/tests/integration/ante/test_evm_unit_04_validate.go b/tests/integration/ante/test_evm_unit_04_validate.go index 8e87308cd..81e06a937 100644 --- a/tests/integration/ante/test_evm_unit_04_validate.go +++ b/tests/integration/ante/test_evm_unit_04_validate.go @@ -244,9 +244,9 @@ func (s *EvmUnitAnteTestSuite) TestCheckTxFee() { s.Run(fmt.Sprintf("%s, %s", chainID.ChainID, tc.name), func() { // Call the configurator to set the EVM coin required for the // function to be tested. - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - s.Require().NoError(configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[chainID]).Configure()) + s.Require().NoError(configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[chainID]).Apply()) // If decimals is not 18 decimals, we have to convert txFeeInfo to original // decimals representation. diff --git a/tests/integration/precompiles/werc20/test_integration.go b/tests/integration/precompiles/werc20/test_integration.go index 686bdb65f..ebcd75f5a 100644 --- a/tests/integration/precompiles/werc20/test_integration.go +++ b/tests/integration/precompiles/werc20/test_integration.go @@ -108,11 +108,11 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp customGenesis[feemarkettypes.ModuleName] = feemarketGenesis // Reset evm config here for the standard case - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() Expect(configurator. WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[chainId]). - Configure()).To(BeNil(), "expected no error setting the evm configurator") + Apply()).To(BeNil(), "expected no error setting the evm configurator") opts := []network.ConfigOption{ network.WithChainID(chainId), diff --git a/tests/integration/x/precisebank/test_burn_integration.go b/tests/integration/x/precisebank/test_burn_integration.go index 65b57f5da..852b60f59 100644 --- a/tests/integration/x/precisebank/test_burn_integration.go +++ b/tests/integration/x/precisebank/test_burn_integration.go @@ -498,10 +498,10 @@ func (s *KeeperIntegrationTestSuite) TestBurnCoinsRandomValueMultiDecimals() { } func FuzzBurnCoins(f *testing.F) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) - err := configurator.Configure() + err := configurator.Apply() require.NoError(f, err) f.Add(int64(0)) diff --git a/tests/integration/x/precisebank/test_mint_integration.go b/tests/integration/x/precisebank/test_mint_integration.go index 0458f1299..de411877d 100644 --- a/tests/integration/x/precisebank/test_mint_integration.go +++ b/tests/integration/x/precisebank/test_mint_integration.go @@ -415,10 +415,10 @@ func (s *KeeperIntegrationTestSuite) TestMintCoinsRandomValueMultiDecimals() { } func FuzzMintCoins(f *testing.F) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) - err := configurator.Configure() + err := configurator.Apply() require.NoError(f, err) f.Add(int64(0)) diff --git a/tests/integration/x/precisebank/test_send_integration.go b/tests/integration/x/precisebank/test_send_integration.go index d819bf650..b09919497 100644 --- a/tests/integration/x/precisebank/test_send_integration.go +++ b/tests/integration/x/precisebank/test_send_integration.go @@ -796,10 +796,10 @@ func (s *KeeperIntegrationTestSuite) TestSendCoinsRandomValueMultiDecimals() { } func FuzzSendCoins(f *testing.F) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) - err := configurator.Configure() + err := configurator.Apply() require.NoError(f, err) f.Add(uint64(100), uint64(0), uint64(2)) diff --git a/tests/integration/x/vm/keeper_test_suite.go b/tests/integration/x/vm/keeper_test_suite.go index 8f3f3b39a..5347cdf4f 100644 --- a/tests/integration/x/vm/keeper_test_suite.go +++ b/tests/integration/x/vm/keeper_test_suite.go @@ -101,21 +101,19 @@ func (s *KeeperTestSuite) SetupTest() { } // get the denom and decimals set on chain initialization // because we'll need to set them again when resetting the chain config - denom := evmtypes.GetEVMCoinDenom() - extendedDenom := evmtypes.GetEVMCoinExtendedDenom() displayDenom := evmtypes.GetEVMCoinDisplayDenom() decimals := evmtypes.GetEVMCoinDecimals() + extendedDecimals := evmtypes.GetEVMCoinExtendedDecimals() - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(evmtypes.EvmCoinInfo{ - Denom: denom, - ExtendedDenom: extendedDenom, - DisplayDenom: displayDenom, - Decimals: decimals, + DisplayDenom: displayDenom, + Decimals: decimals, + ExtendedDecimals: extendedDecimals, }). - Configure() + Apply() s.Require().NoError(err) } diff --git a/tests/integration/x/vm/test_grpc_query.go b/tests/integration/x/vm/test_grpc_query.go index f9b55fac3..59f874d9b 100644 --- a/tests/integration/x/vm/test_grpc_query.go +++ b/tests/integration/x/vm/test_grpc_query.go @@ -1602,12 +1602,12 @@ func (s *KeeperTestSuite) TestQueryBaseFee() { chainConfig.CancunTime = &maxInt chainConfig.PragueTime = &maxInt - configurator := types.NewEVMConfigurator() + configurator := types.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). - Configure() + Apply() s.Require().NoError(err) }, true, @@ -1632,10 +1632,9 @@ func (s *KeeperTestSuite) TestQueryBaseFee() { // Save initial configure to restore it between tests coinInfo := types.EvmCoinInfo{ - Denom: types.GetEVMCoinDenom(), - ExtendedDenom: types.GetEVMCoinExtendedDenom(), - DisplayDenom: types.GetEVMCoinDisplayDenom(), - Decimals: types.GetEVMCoinDecimals(), + DisplayDenom: types.GetEVMCoinDisplayDenom(), + Decimals: types.GetEVMCoinDecimals(), + ExtendedDecimals: types.GetEVMCoinExtendedDecimals(), } chainConfig := types.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64()) @@ -1658,12 +1657,12 @@ func (s *KeeperTestSuite) TestQueryBaseFee() { s.Require().Error(err) } s.Require().NoError(s.Network.NextBlock()) - configurator := types.NewEVMConfigurator() + configurator := types.NewEvmConfig() configurator.ResetTestConfig() err = configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(coinInfo). - Configure() + Apply() s.Require().NoError(err) }) } diff --git a/testutil/config/config.go b/testutil/config/config.go index 7ea385bdb..54fcdd69b 100644 --- a/testutil/config/config.go +++ b/testutil/config/config.go @@ -12,16 +12,14 @@ import ( // chain id var ChainsCoinInfo = map[uint64]evmtypes.EvmCoinInfo{ EighteenDecimalsChainID: { - Denom: ExampleChainDenom, - ExtendedDenom: ExampleChainDenom, - DisplayDenom: ExampleDisplayDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleDisplayDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, EVMChainID: { - Denom: ExampleChainDenom, - ExtendedDenom: ExampleChainDenom, - DisplayDenom: ExampleDisplayDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleDisplayDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, } diff --git a/testutil/config/config_testing.go b/testutil/config/config_testing.go index e37568c2b..9781099fa 100644 --- a/testutil/config/config_testing.go +++ b/testutil/config/config_testing.go @@ -13,46 +13,39 @@ import ( // chain id var TestChainsCoinInfo = map[uint64]evmtypes.EvmCoinInfo{ EighteenDecimalsChainID: { - Denom: ExampleChainDenom, - ExtendedDenom: ExampleChainDenom, - DisplayDenom: ExampleDisplayDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleDisplayDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, SixDecimalsChainID: { - Denom: "utest", - ExtendedDenom: "atest", - DisplayDenom: "test", - Decimals: evmtypes.SixDecimals, + DisplayDenom: "test", + Decimals: evmtypes.SixDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, TwelveDecimalsChainID: { - Denom: "ptest2", - ExtendedDenom: "atest2", - DisplayDenom: "test2", - Decimals: evmtypes.TwelveDecimals, + DisplayDenom: "test2", + Decimals: evmtypes.TwelveDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, TwoDecimalsChainID: { - Denom: "ctest3", - ExtendedDenom: "atest3", - DisplayDenom: "test3", - Decimals: evmtypes.TwoDecimals, + DisplayDenom: "test3", + Decimals: evmtypes.TwoDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, TestChainID1: { - Denom: ExampleChainDenom, - ExtendedDenom: ExampleChainDenom, - DisplayDenom: ExampleChainDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleChainDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, TestChainID2: { - Denom: ExampleChainDenom, - ExtendedDenom: ExampleChainDenom, - DisplayDenom: ExampleChainDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleChainDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, EVMChainID: { - Denom: ExampleChainDenom, - ExtendedDenom: ExampleChainDenom, - DisplayDenom: ExampleDisplayDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleChainDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, } diff --git a/testutil/constants/constants.go b/testutil/constants/constants.go index 1b2cf732a..caba3030c 100644 --- a/testutil/constants/constants.go +++ b/testutil/constants/constants.go @@ -76,28 +76,24 @@ var ( // chain id ExampleChainCoinInfo = map[ChainID]evmtypes.EvmCoinInfo{ ExampleChainID: { - Denom: ExampleAttoDenom, - ExtendedDenom: ExampleAttoDenom, - DisplayDenom: ExampleDisplayDenom, - Decimals: evmtypes.EighteenDecimals, + DisplayDenom: ExampleDisplayDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, SixDecimalsChainID: { - Denom: "utest", - ExtendedDenom: "atest", - DisplayDenom: "test", - Decimals: evmtypes.SixDecimals, + DisplayDenom: "test", + Decimals: evmtypes.SixDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, TwelveDecimalsChainID: { - Denom: "ptest2", - ExtendedDenom: "atest2", - DisplayDenom: "test2", - Decimals: evmtypes.TwelveDecimals, + DisplayDenom: "test2", + Decimals: evmtypes.TwelveDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, TwoDecimalsChainID: { - Denom: "ctest3", - ExtendedDenom: "atest3", - DisplayDenom: "test3", - Decimals: evmtypes.TwoDecimals, + DisplayDenom: "test3", + Decimals: evmtypes.TwoDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, }, } diff --git a/testutil/integration/evm/network/chain_id_modifiers.go b/testutil/integration/evm/network/chain_id_modifiers.go index 736c14e5c..94b4714e4 100644 --- a/testutil/integration/evm/network/chain_id_modifiers.go +++ b/testutil/integration/evm/network/chain_id_modifiers.go @@ -91,7 +91,7 @@ func updateErc20TokenPairs(chainID testconstants.ChainID, tokenPairs []erc20type if tokenPair.Erc20Address == mainnetAddress { updatedTokenPairs[i] = erc20types.TokenPair{ Erc20Address: testnetAddress, - Denom: coinInfo.Denom, + Denom: coinInfo.GetDenom(), Enabled: tokenPair.Enabled, ContractOwner: tokenPair.ContractOwner, } diff --git a/testutil/integration/evm/network/coins.go b/testutil/integration/evm/network/coins.go index 022a5d55f..363d21491 100644 --- a/testutil/integration/evm/network/coins.go +++ b/testutil/integration/evm/network/coins.go @@ -39,7 +39,7 @@ func DefaultChainCoins() ChainCoins { func getCoinInfo(coinInfo evmtypes.EvmCoinInfo) CoinInfo { return CoinInfo{ - Denom: coinInfo.Denom, + Denom: coinInfo.GetDenom(), Decimals: coinInfo.Decimals, } } diff --git a/testutil/integration/evm/network/config.go b/testutil/integration/evm/network/config.go index ed612f75f..2ad976fb8 100644 --- a/testutil/integration/evm/network/config.go +++ b/testutil/integration/evm/network/config.go @@ -132,10 +132,10 @@ func WithChainID(chainID testconstants.ChainID) ConfigOption { cfg.eip155ChainID = big.NewInt(int64(chainID.EVMChainID)) //nolint:gosec // G115 // won't exceed uint64 if cfg.chainCoins.IsBaseEqualToEVM() { - cfg.chainCoins.baseCoin.Denom = evmCoinInfo.Denom + cfg.chainCoins.baseCoin.Denom = evmCoinInfo.GetDenom() cfg.chainCoins.baseCoin.Decimals = evmCoinInfo.Decimals } - cfg.chainCoins.evmCoin.Denom = evmCoinInfo.Denom + cfg.chainCoins.evmCoin.Denom = evmCoinInfo.GetDenom() cfg.chainCoins.evmCoin.Decimals = evmCoinInfo.Decimals } } diff --git a/utils/utils_test.go b/utils/utils_test.go index c6d7d331f..a70b4ce63 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -489,10 +489,10 @@ func TestAccountEquivalence(t *testing.T) { func TestCalcBaseFee(t *testing.T) { for _, chainID := range []constants.ChainID{constants.ExampleChainID, constants.TwelveDecimalsChainID, constants.SixDecimalsChainID} { t.Run(chainID.ChainID, func(t *testing.T) { - evmConfigurator := evmtypes.NewEVMConfigurator(). + evmConfigurator := evmtypes.NewEvmConfig(). WithEVMCoinInfo(constants.ExampleChainCoinInfo[chainID]) evmConfigurator.ResetTestConfig() - err := evmConfigurator.Configure() + err := evmConfigurator.Apply() require.NoError(t, err) config := ¶ms.ChainConfig{ diff --git a/x/precisebank/types/extended_balance_test.go b/x/precisebank/types/extended_balance_test.go index d0a013f1b..8c92b5dea 100644 --- a/x/precisebank/types/extended_balance_test.go +++ b/x/precisebank/types/extended_balance_test.go @@ -16,10 +16,10 @@ import ( func TestSumExtendedCoin(t *testing.T) { coinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() err := configurator. WithEVMCoinInfo(coinInfo). - Configure() + Apply() require.NoError(t, err) tests := []struct { diff --git a/x/precisebank/types/genesis_test.go b/x/precisebank/types/genesis_test.go index bd92f3e07..41a5ee80e 100644 --- a/x/precisebank/types/genesis_test.go +++ b/x/precisebank/types/genesis_test.go @@ -256,10 +256,10 @@ func TestGenesisState_TotalAmountWithRemainder(t *testing.T) { } func FuzzGenesisStateValidate_NonZeroRemainder(f *testing.F) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) - err := configurator.Configure() + err := configurator.Apply() require.NoError(f, err) f.Add(5) @@ -283,10 +283,10 @@ func FuzzGenesisStateValidate_NonZeroRemainder(f *testing.F) { } func FuzzGenesisStateValidate_ZeroRemainder(f *testing.F) { - configurator := evmtypes.NewEVMConfigurator() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) - err := configurator.Configure() + err := configurator.Apply() require.NoError(f, err) f.Add(5) From 4c1b44f46c5dbc4435b8b45be5d25c1d4eed60d9 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 04:45:46 -0400 Subject: [PATCH 04/23] fix test --- config/chain_config.go | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 config/chain_config.go diff --git a/config/chain_config.go b/config/chain_config.go new file mode 100644 index 000000000..e0c06c0d1 --- /dev/null +++ b/config/chain_config.go @@ -0,0 +1,10 @@ +package config + +import ( + evmtypes "github.com/cosmos/evm/x/vm/types" +) + +type ChainConfig struct { + ChainID string + EvmConfig *evmtypes.EvmConfig +} From 5e5311ab7ae1db2e6578f999a6a33350d36c91ef Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 04:48:33 -0400 Subject: [PATCH 05/23] remove unnecessaty vars --- tests/integration/ante/ante_test_suite.go | 10 +++------- tests/integration/testutil/test_config.go | 2 +- tests/integration/x/vm/keeper_test_suite.go | 10 +++------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/tests/integration/ante/ante_test_suite.go b/tests/integration/ante/ante_test_suite.go index 0fb9db71c..b5d14131c 100644 --- a/tests/integration/ante/ante_test_suite.go +++ b/tests/integration/ante/ante_test_suite.go @@ -114,18 +114,14 @@ func (s *AnteTestSuite) SetupTest() { // get the denom and decimals set when initialized the chain // to set them again // when resetting the chain config - displayDenom := evmtypes.GetEVMCoinDisplayDenom() - decimals := evmtypes.GetEVMCoinDecimals() - extendedDecimals := evmtypes.GetEVMCoinExtendedDecimals() - configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(evmtypes.EvmCoinInfo{ - DisplayDenom: displayDenom, - Decimals: decimals, - ExtendedDecimals: extendedDecimals, + DisplayDenom: evmtypes.GetEVMCoinDisplayDenom(), + Decimals: evmtypes.GetEVMCoinDecimals(), + ExtendedDecimals: evmtypes.GetEVMCoinExtendedDecimals(), }). Apply() s.Require().NoError(err) diff --git a/tests/integration/testutil/test_config.go b/tests/integration/testutil/test_config.go index dac835b44..dc57266be 100644 --- a/tests/integration/testutil/test_config.go +++ b/tests/integration/testutil/test_config.go @@ -74,7 +74,7 @@ func (s *TestSuite) TestWithChainID() { ) // Bank balance should always be in the original amount. - cReq, err := handler.GetBalanceFromBank(keyring.GetAccAddr(0), tc.coinInfo.Denom) + cReq, err := handler.GetBalanceFromBank(keyring.GetAccAddr(0), tc.coinInfo.GetDenom()) s.NoError(err, "error getting balances") s.Equal( tc.expCosmosAmount.String(), diff --git a/tests/integration/x/vm/keeper_test_suite.go b/tests/integration/x/vm/keeper_test_suite.go index 5347cdf4f..2a68fef21 100644 --- a/tests/integration/x/vm/keeper_test_suite.go +++ b/tests/integration/x/vm/keeper_test_suite.go @@ -101,18 +101,14 @@ func (s *KeeperTestSuite) SetupTest() { } // get the denom and decimals set on chain initialization // because we'll need to set them again when resetting the chain config - displayDenom := evmtypes.GetEVMCoinDisplayDenom() - decimals := evmtypes.GetEVMCoinDecimals() - extendedDecimals := evmtypes.GetEVMCoinExtendedDecimals() - configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(evmtypes.EvmCoinInfo{ - DisplayDenom: displayDenom, - Decimals: decimals, - ExtendedDecimals: extendedDecimals, + DisplayDenom: evmtypes.GetEVMCoinDisplayDenom(), + Decimals: evmtypes.GetEVMCoinDecimals(), + ExtendedDecimals: evmtypes.GetEVMCoinExtendedDecimals(), }). Apply() s.Require().NoError(err) From ec249498dc066e687bf6af7008c2cc95ceada476 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 04:59:25 -0400 Subject: [PATCH 06/23] var assignments are actually necessary --- tests/integration/ante/ante_test_suite.go | 10 +++++++--- tests/integration/x/vm/keeper_test_suite.go | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/integration/ante/ante_test_suite.go b/tests/integration/ante/ante_test_suite.go index b5d14131c..0fb9db71c 100644 --- a/tests/integration/ante/ante_test_suite.go +++ b/tests/integration/ante/ante_test_suite.go @@ -114,14 +114,18 @@ func (s *AnteTestSuite) SetupTest() { // get the denom and decimals set when initialized the chain // to set them again // when resetting the chain config + displayDenom := evmtypes.GetEVMCoinDisplayDenom() + decimals := evmtypes.GetEVMCoinDecimals() + extendedDecimals := evmtypes.GetEVMCoinExtendedDecimals() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(evmtypes.EvmCoinInfo{ - DisplayDenom: evmtypes.GetEVMCoinDisplayDenom(), - Decimals: evmtypes.GetEVMCoinDecimals(), - ExtendedDecimals: evmtypes.GetEVMCoinExtendedDecimals(), + DisplayDenom: displayDenom, + Decimals: decimals, + ExtendedDecimals: extendedDecimals, }). Apply() s.Require().NoError(err) diff --git a/tests/integration/x/vm/keeper_test_suite.go b/tests/integration/x/vm/keeper_test_suite.go index 2a68fef21..5347cdf4f 100644 --- a/tests/integration/x/vm/keeper_test_suite.go +++ b/tests/integration/x/vm/keeper_test_suite.go @@ -101,14 +101,18 @@ func (s *KeeperTestSuite) SetupTest() { } // get the denom and decimals set on chain initialization // because we'll need to set them again when resetting the chain config + displayDenom := evmtypes.GetEVMCoinDisplayDenom() + decimals := evmtypes.GetEVMCoinDecimals() + extendedDecimals := evmtypes.GetEVMCoinExtendedDecimals() + configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). WithEVMCoinInfo(evmtypes.EvmCoinInfo{ - DisplayDenom: evmtypes.GetEVMCoinDisplayDenom(), - Decimals: evmtypes.GetEVMCoinDecimals(), - ExtendedDecimals: evmtypes.GetEVMCoinExtendedDecimals(), + DisplayDenom: displayDenom, + Decimals: decimals, + ExtendedDecimals: extendedDecimals, }). Apply() s.Require().NoError(err) From 5596af56f1dd8fc8a372962118135307e98d127d Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 06:59:00 -0400 Subject: [PATCH 07/23] add coin info to toml --- server/config/config.go | 20 ++++++++++++++++++- server/config/toml.go | 11 ++++++++++ server/flags/flags.go | 3 +++ server/start.go | 3 +++ x/vm/types/{configurator.go => evm_config.go} | 0 ...onfigurator_test.go => evm_config_test.go} | 0 6 files changed, 36 insertions(+), 1 deletion(-) rename x/vm/types/{configurator.go => evm_config.go} (100%) rename x/vm/types/{configurator_test.go => evm_config_test.go} (100%) diff --git a/server/config/config.go b/server/config/config.go index cabd79181..3abe522f1 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -6,6 +6,8 @@ import ( "path" "time" + evmtypes "github.com/cosmos/evm/x/vm/types" + "github.com/spf13/viper" "github.com/cometbft/cometbft/libs/strings" @@ -63,9 +65,18 @@ const ( // DefaultMaxTxGasWanted is the default gas wanted for each eth tx returned in ante handler in check tx mode DefaultMaxTxGasWanted = 0 - // DefaultEVMChainID is the default EVM Chain ID if one is not provided + // DefaultEVMChainID is the default EVM Chain ID if one is not provided, should match the value in evmd config DefaultEVMChainID = 262144 + // DefaultEvmCoinInfoDisplayDenom is the default display denomination for the chain + DefaultEvmCoinInfoDisplayDenom = "atom" + + // DefaultEvmCoinInfoDecimals is the default decimals for the base denomination + DefaultEvmCoinInfoDecimals = evmtypes.EighteenDecimals + + // DefaultEvmCoinInfoExtendedDecimals is the default decimals for the extended denomination + DefaultEvmCoinInfoExtendedDecimals = evmtypes.EighteenDecimals + // DefaultEVMMinTip is the default minimum priority fee for the mempool DefaultEVMMinTip = 0 @@ -148,6 +159,8 @@ type EVMConfig struct { EVMChainID uint64 `mapstructure:"evm-chain-id"` // MinTip defines the minimum priority fee for the mempool MinTip uint64 `mapstructure:"min-tip"` + // CoinInfo defines the coin configuration for the chain + CoinInfo evmtypes.EvmCoinInfo `mapstructure:"coin-info"` } // JSONRPCConfig defines configuration for the EVM RPC server. @@ -218,6 +231,11 @@ func DefaultEVMConfig() *EVMConfig { EVMChainID: DefaultEVMChainID, EnablePreimageRecording: DefaultEnablePreimageRecording, MinTip: DefaultEVMMinTip, + CoinInfo: evmtypes.EvmCoinInfo{ + DisplayDenom: DefaultEvmCoinInfoDisplayDenom, + Decimals: DefaultEvmCoinInfoDecimals, + ExtendedDecimals: DefaultEvmCoinInfoExtendedDecimals, + }, } } diff --git a/server/config/toml.go b/server/config/toml.go index 1e9d4689a..52ce9c29c 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -25,6 +25,17 @@ evm-chain-id = {{ .EVM.EVMChainID }} # MinTip defines the minimum priority fee for the mempool. min-tip = {{ .EVM.MinTip }} +[evm.coin-info] + +# DisplayDenom defines the display denomination shown to users +display-denom = "{{ .EVM.CoinInfo.DisplayDenom }}" + +# Decimals defines the precision/decimals for the base denomination (1-18) +decimals = {{ .EVM.CoinInfo.Decimals }} + +# ExtendedDecimals defines the precision/decimals for the extended denomination (typically 18 decimals for atto-denom) +extended-decimals = {{ .EVM.CoinInfo.ExtendedDecimals }} + ############################################################################### ### JSON RPC Configuration ### ############################################################################### diff --git a/server/flags/flags.go b/server/flags/flags.go index 3844fc7df..704d6d2e0 100644 --- a/server/flags/flags.go +++ b/server/flags/flags.go @@ -71,6 +71,9 @@ const ( EVMEnablePreimageRecording = "evm.cache-preimage" EVMChainID = "evm.evm-chain-id" EVMMinTip = "evm.min-tip" + EVMDisplayDenom = "evm.coin-info.display-denom" + EVMDecimals = "evm.coin-info.decimals" + EVMExtendedDecimals = "evm.coin-info.extended-decimals" ) // TLS flags diff --git a/server/start.go b/server/start.go index 85ba9dad6..14742e17d 100644 --- a/server/start.go +++ b/server/start.go @@ -220,6 +220,9 @@ which accepts a path for the resulting pprof file. cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll cmd.Flags().Uint64(srvflags.EVMChainID, cosmosevmserverconfig.DefaultEVMChainID, "the EIP-155 compatible replay protection chain ID") cmd.Flags().Uint64(srvflags.EVMMinTip, cosmosevmserverconfig.DefaultEVMMinTip, "the minimum priority fee for the mempool") + cmd.Flags().String(srvflags.EVMDisplayDenom, cosmosevmserverconfig.DefaultEvmCoinInfoDisplayDenom, "the display denomination for the chain") + cmd.Flags().Uint8(srvflags.EVMDecimals, uint8(cosmosevmserverconfig.DefaultEvmCoinInfoDecimals), "the decimals for the base denomination") + cmd.Flags().Uint8(srvflags.EVMExtendedDecimals, uint8(cosmosevmserverconfig.DefaultEvmCoinInfoExtendedDecimals), "the decimals for the extended denomination") cmd.Flags().String(srvflags.TLSCertPath, "", "the cert.pem file path for the server TLS configuration") cmd.Flags().String(srvflags.TLSKeyPath, "", "the key.pem file path for the server TLS configuration") diff --git a/x/vm/types/configurator.go b/x/vm/types/evm_config.go similarity index 100% rename from x/vm/types/configurator.go rename to x/vm/types/evm_config.go diff --git a/x/vm/types/configurator_test.go b/x/vm/types/evm_config_test.go similarity index 100% rename from x/vm/types/configurator_test.go rename to x/vm/types/evm_config_test.go From 02d01f732214aac5691660b1d8786dc1cc25988d Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 07:30:05 -0400 Subject: [PATCH 08/23] add fallback for missing chain id in client.toml --- evmd/cmd/evmd/cmd/root.go | 15 +++++++++------ evmd/config/client.toml | 6 +++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/evmd/cmd/root.go index 70460c752..5b899141d 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/evmd/cmd/root.go @@ -4,6 +4,7 @@ import ( "errors" "io" "os" + "strconv" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/spf13/cast" @@ -140,18 +141,20 @@ func NewRootCmd() *cobra.Command { initRootCmd(rootCmd, tempApp) - autoCliOpts := tempApp.AutoCliOpts() + if initClientCtx.ChainID == "" { + // if the chain id is not set in client.toml, set it to the default chain id + initClientCtx = initClientCtx.WithChainID(strconv.FormatUint(evmdconfig.EVMChainID, 10)) + } initClientCtx, _ = clientcfg.ReadFromClientConfig(initClientCtx) - autoCliOpts.ClientCtx = initClientCtx + autoCliOpts := tempApp.AutoCliOpts() + autoCliOpts.ClientCtx = initClientCtx if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { panic(err) } - if initClientCtx.ChainID != "" { - if err := evmdconfig.EvmAppOptions(evmdconfig.EVMChainID); err != nil { - panic(err) - } + if err := evmdconfig.EvmAppOptions(evmdconfig.EVMChainID); err != nil { + panic(err) } return rootCmd diff --git a/evmd/config/client.toml b/evmd/config/client.toml index 2a8569c81..02df72407 100644 --- a/evmd/config/client.toml +++ b/evmd/config/client.toml @@ -7,11 +7,15 @@ # The network chain ID chain-id = "" + # The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory) keyring-backend = "os" + # CLI output format (text|json) output = "text" + # : to CometBFT RPC interface for this chain node = "tcp://localhost:26657" + # Transaction broadcasting mode (sync|async) -broadcast-mode = "sync" +broadcast-mode = "sync" \ No newline at end of file From 91edb754aa442ec9ed26e624ff8bd338c86e682f Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 08:38:48 -0400 Subject: [PATCH 09/23] refactor server options --- config/server_app_options.go | 94 --------- config/server_app_options_test.go | 332 ------------------------------ evmd/app.go | 10 +- evmd/cmd/evmd/cmd/root.go | 24 +-- evmd/cmd/evmd/config/chain_id.go | 29 --- evmd/cmd/evmd/config/config.go | 19 ++ evmd/cmd/evmd/config/constants.go | 31 --- 7 files changed, 27 insertions(+), 512 deletions(-) delete mode 100644 config/server_app_options.go delete mode 100644 config/server_app_options_test.go delete mode 100644 evmd/cmd/evmd/config/chain_id.go delete mode 100644 evmd/cmd/evmd/config/constants.go diff --git a/config/server_app_options.go b/config/server_app_options.go deleted file mode 100644 index cac9cc7a1..000000000 --- a/config/server_app_options.go +++ /dev/null @@ -1,94 +0,0 @@ -package config - -import ( - "math" - "path/filepath" - - "github.com/holiman/uint256" - "github.com/spf13/cast" - - srvflags "github.com/cosmos/evm/server/flags" - - "cosmossdk.io/log" - - "github.com/cosmos/cosmos-sdk/client/flags" - sdkserver "github.com/cosmos/cosmos-sdk/server" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" -) - -// GetBlockGasLimit reads the genesis json file using AppGenesisFromFile -// to extract the consensus block gas limit before InitChain is called. -func GetBlockGasLimit(appOpts servertypes.AppOptions, logger log.Logger) uint64 { - homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) - if homeDir == "" { - logger.Error("home directory not found in app options, using zero block gas limit") - return math.MaxUint64 - } - genesisPath := filepath.Join(homeDir, "config", "genesis.json") - - appGenesis, err := genutiltypes.AppGenesisFromFile(genesisPath) - if err != nil { - logger.Error("failed to load genesis using SDK AppGenesisFromFile, using zero block gas limit", "path", genesisPath, "error", err) - return 0 - } - genDoc, err := appGenesis.ToGenesisDoc() - if err != nil { - logger.Error("failed to convert AppGenesis to GenesisDoc, using zero block gas limit", "path", genesisPath, "error", err) - return 0 - } - - if genDoc.ConsensusParams == nil { - logger.Error("consensus parameters not found in genesis (nil), using zero block gas limit") - return 0 - } - - maxGas := genDoc.ConsensusParams.Block.MaxGas - if maxGas == -1 { - logger.Warn("genesis max_gas is unlimited (-1), using max uint64") - return math.MaxUint64 - } - if maxGas < -1 { - logger.Error("invalid max_gas value in genesis, using zero block gas limit") - return 0 - } - blockGasLimit := uint64(maxGas) // #nosec G115 -- maxGas >= 0 checked above - - logger.Debug( - "extracted block gas limit from genesis using SDK AppGenesisFromFile", - "genesis_path", genesisPath, - "max_gas", maxGas, - "block_gas_limit", blockGasLimit, - ) - - return blockGasLimit -} - -// GetMinGasPrices reads the min gas prices from the app options, set from app.toml -// This is currently not used, but is kept in case this is useful for the mempool, -// in addition to the min tip flag -func GetMinGasPrices(appOpts servertypes.AppOptions, logger log.Logger) sdk.DecCoins { - minGasPricesStr := cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices)) - minGasPrices, err := sdk.ParseDecCoins(minGasPricesStr) - if err != nil { - logger.With("error", err).Info("failed to parse min gas prices, using empty DecCoins") - minGasPrices = sdk.DecCoins{} - } - - return minGasPrices -} - -// GetMinTip reads the min tip from the app options, set from app.toml -// This field is also known as the minimum priority fee -func GetMinTip(appOpts servertypes.AppOptions, logger log.Logger) *uint256.Int { - minTipUint64 := cast.ToUint64(appOpts.Get(srvflags.EVMMinTip)) - minTip := uint256.NewInt(minTipUint64) - - if minTip.Cmp(uint256.NewInt(0)) >= 0 { // zero or positive - return minTip - } - - logger.Error("invalid min tip value in app.toml or flag, falling back to nil", "min_tip", minTipUint64) - return nil -} diff --git a/config/server_app_options_test.go b/config/server_app_options_test.go deleted file mode 100644 index ee4ed2ff1..000000000 --- a/config/server_app_options_test.go +++ /dev/null @@ -1,332 +0,0 @@ -package config - -import ( - "encoding/json" - "fmt" - "math" - "os" - "path/filepath" - "testing" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/log" - sdkmath "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/client/flags" - sdkserver "github.com/cosmos/cosmos-sdk/server" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type mockAppOptions struct { - values map[string]interface{} -} - -func newMockAppOptions() *mockAppOptions { - return &mockAppOptions{ - values: make(map[string]interface{}), - } -} - -func (m *mockAppOptions) Get(key string) interface{} { - return m.values[key] -} - -func (m *mockAppOptions) Set(key string, value interface{}) { - m.values[key] = value -} - -func TestGetBlockGasLimit(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - setupFn func() servertypes.AppOptions - expected uint64 - }{ - { - name: "empty home directory returns max uint64", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - return opts - }, - expected: math.MaxUint64, - }, - { - name: "genesis file not found returns 0", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(flags.FlagHome, "/non/existent/directory") - return opts - }, - expected: 0, - }, - { - name: "valid genesis with max_gas = -1 returns max uint64", - setupFn: func() servertypes.AppOptions { - homeDir := createGenesisWithMaxGas(t, -1) - opts := newMockAppOptions() - opts.Set(flags.FlagHome, homeDir) - return opts - }, - expected: math.MaxUint64, - }, - { - name: "valid genesis with max_gas < -1 returns 0", - setupFn: func() servertypes.AppOptions { - homeDir := createGenesisWithMaxGas(t, -5) - opts := newMockAppOptions() - opts.Set(flags.FlagHome, homeDir) - return opts - }, - expected: 0, - }, - { - name: "valid genesis with max_gas = 0 returns 0", - setupFn: func() servertypes.AppOptions { - homeDir := createGenesisWithMaxGas(t, 0) - opts := newMockAppOptions() - opts.Set(flags.FlagHome, homeDir) - return opts - }, - expected: 0, - }, - { - name: "valid genesis with max_gas = 1000000 returns 1000000", - setupFn: func() servertypes.AppOptions { - homeDir := createGenesisWithMaxGas(t, 1000000) - opts := newMockAppOptions() - opts.Set(flags.FlagHome, homeDir) - return opts - }, - expected: 1000000, - }, - { - name: "genesis without consensus params returns 0", - setupFn: func() servertypes.AppOptions { - homeDir := createGenesisWithoutConsensusParams(t) - opts := newMockAppOptions() - opts.Set(flags.FlagHome, homeDir) - return opts - }, - expected: 0, - }, - { - name: "invalid genesis JSON returns 0", - setupFn: func() servertypes.AppOptions { - homeDir := createInvalidGenesis(t) - opts := newMockAppOptions() - opts.Set(flags.FlagHome, homeDir) - return opts - }, - expected: 0, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(_ *testing.T) { - appOpts := tc.setupFn() - logger := log.NewNopLogger() - - result := GetBlockGasLimit(appOpts, logger) - require.Equal(t, tc.expected, result, "GetBlockGasLimit returned unexpected value") - }) - } -} - -func TestGetMinGasPrices(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - setupFn func() servertypes.AppOptions - expected sdk.DecCoins - }{ - { - name: "valid single gas price", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(sdkserver.FlagMinGasPrices, "0.025uatom") - return opts - }, - expected: sdk.DecCoins{sdk.NewDecCoinFromDec("uatom", sdkmath.LegacyMustNewDecFromStr("0.025"))}, - }, - { - name: "valid multiple gas prices", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(sdkserver.FlagMinGasPrices, "0.025uatom,0.001stake") - return opts - }, - expected: sdk.DecCoins{ - sdk.NewDecCoinFromDec("stake", sdkmath.LegacyMustNewDecFromStr("0.001")), - sdk.NewDecCoinFromDec("uatom", sdkmath.LegacyMustNewDecFromStr("0.025")), - }, - }, - { - name: "empty gas prices returns empty DecCoins", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(sdkserver.FlagMinGasPrices, "") - return opts - }, - expected: nil, - }, - { - name: "missing gas prices flag returns empty DecCoins", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - return opts - }, - expected: nil, - }, - { - name: "invalid gas price format returns empty DecCoins", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(sdkserver.FlagMinGasPrices, "invalid-format") - return opts - }, - expected: sdk.DecCoins{}, - }, - { - name: "malformed coin denomination returns empty DecCoins", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(sdkserver.FlagMinGasPrices, "0.025") - return opts - }, - expected: sdk.DecCoins{}, - }, - { - name: "zero amount gas price", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(sdkserver.FlagMinGasPrices, "0uatom") - return opts - }, - expected: sdk.DecCoins{}, - }, - { - name: "large decimal precision gas price", - setupFn: func() servertypes.AppOptions { - opts := newMockAppOptions() - opts.Set(sdkserver.FlagMinGasPrices, "0.000000000000000001uatom") - return opts - }, - expected: sdk.DecCoins{sdk.NewDecCoinFromDec("uatom", sdkmath.LegacyMustNewDecFromStr("0.000000000000000001"))}, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(_ *testing.T) { - appOpts := tc.setupFn() - logger := log.NewNopLogger() - - result := GetMinGasPrices(appOpts, logger) - require.Equal(t, tc.expected, result, "GetMinGasPrices returned unexpected value") - }) - } -} - -func createGenesisWithMaxGas(t *testing.T, maxGas int64) string { - t.Helper() - tempDir := t.TempDir() - configDir := filepath.Join(tempDir, "config") - require.NoError(t, os.MkdirAll(configDir, 0o755)) - - genesis := map[string]interface{}{ - "app_name": "evmd", - "app_version": "test", - "chain_id": "test-chain", - "initial_height": 1, - "genesis_time": "2024-01-01T00:00:00Z", - "app_hash": nil, - "app_state": map[string]interface{}{ - "auth": map[string]interface{}{ - "params": map[string]interface{}{ - "max_memo_characters": "256", - "tx_sig_limit": "7", - "tx_size_cost_per_byte": "10", - "sig_verify_cost_ed25519": "590", - "sig_verify_cost_secp256k1": "1000", - }, - "accounts": []interface{}{}, - }, - }, - "consensus": map[string]interface{}{ - "params": map[string]interface{}{ - "block": map[string]interface{}{ - "max_bytes": "22020096", - "max_gas": fmt.Sprintf("%d", maxGas), - }, - "evidence": map[string]interface{}{ - "max_age_num_blocks": "100000", - "max_age_duration": "172800000000000", - "max_bytes": "1048576", - }, - "validator": map[string]interface{}{ - "pub_key_types": []string{"ed25519"}, - }, - "version": map[string]interface{}{ - "app": "0", - }, - }, - }, - } - - genesisBytes, err := json.MarshalIndent(genesis, "", " ") - require.NoError(t, err) - - genesisPath := filepath.Join(configDir, "genesis.json") - require.NoError(t, os.WriteFile(genesisPath, genesisBytes, 0o600)) - - return tempDir -} - -func createGenesisWithoutConsensusParams(t *testing.T) string { - t.Helper() - tempDir := t.TempDir() - configDir := filepath.Join(tempDir, "config") - require.NoError(t, os.MkdirAll(configDir, 0o755)) - - genesis := map[string]interface{}{ - "app_name": "evmd", - "app_version": "test", - "chain_id": "test-chain", - "initial_height": 1, - "genesis_time": "2024-01-01T00:00:00Z", - "app_hash": nil, - "app_state": map[string]interface{}{ - "auth": map[string]interface{}{ - "params": map[string]interface{}{}, - "accounts": []interface{}{}, - }, - }, - "consensus": map[string]interface{}{ - "params": nil, - }, - } - - genesisBytes, err := json.MarshalIndent(genesis, "", " ") - require.NoError(t, err) - - genesisPath := filepath.Join(configDir, "genesis.json") - require.NoError(t, os.WriteFile(genesisPath, genesisBytes, 0o600)) - - return tempDir -} - -func createInvalidGenesis(t *testing.T) string { - t.Helper() - tempDir := t.TempDir() - configDir := filepath.Join(tempDir, "config") - require.NoError(t, os.MkdirAll(configDir, 0o755)) - - invalidJSON := `{"invalid": json}` - genesisPath := filepath.Join(configDir, "genesis.json") - require.NoError(t, os.WriteFile(genesisPath, []byte(invalidJSON), 0o600)) - - return tempDir -} diff --git a/evmd/app.go b/evmd/app.go index d4ec9ebe3..6f9d41f45 100644 --- a/evmd/app.go +++ b/evmd/app.go @@ -85,7 +85,7 @@ import ( runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" sdkserver "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" - "github.com/cosmos/cosmos-sdk/server/config" + servercfg "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" testdata_pulsar "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" sdk "github.com/cosmos/cosmos-sdk/types" @@ -755,9 +755,9 @@ func NewExampleApp( // If you wish to use the noop mempool, remove this codeblock if evmtypes.GetChainConfig() != nil { // Get the block gas limit from genesis file - blockGasLimit := evmconfig.GetBlockGasLimit(appOpts, logger) + blockGasLimit := evmdconfig.GetBlockGasLimit(appOpts, logger) // Get GetMinTip from app.toml or cli flag configuration - mipTip := evmconfig.GetMinTip(appOpts, logger) + mipTip := evmdconfig.GetMinTip(appOpts, logger) mempoolConfig := &evmmempool.EVMMempoolConfig{ AnteHandler: app.GetAnteHandler(), @@ -981,7 +981,7 @@ func (app *EVMD) SimulationManager() *module.SimulationManager { // RegisterAPIRoutes registers all application module routes with the provided // API server. -func (app *EVMD) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { +func (app *EVMD) RegisterAPIRoutes(apiSvr *api.Server, apiConfig servercfg.APIConfig) { clientCtx := apiSvr.ClientCtx // Register new tx routes from grpc-gateway. authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) @@ -1016,7 +1016,7 @@ func (app *EVMD) RegisterTendermintService(clientCtx client.Context) { ) } -func (app *EVMD) RegisterNodeService(clientCtx client.Context, cfg config.Config) { +func (app *EVMD) RegisterNodeService(clientCtx client.Context, cfg servercfg.Config) { node.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg) } diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/evmd/cmd/root.go index 5b899141d..ea3e33f34 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/evmd/cmd/root.go @@ -142,7 +142,7 @@ func NewRootCmd() *cobra.Command { initRootCmd(rootCmd, tempApp) if initClientCtx.ChainID == "" { - // if the chain id is not set in client.toml, set it to the default chain id + // if the chain id is not set in client.toml, populate it with the default evm chain id initClientCtx = initClientCtx.WithChainID(strconv.FormatUint(evmdconfig.EVMChainID, 10)) } initClientCtx, _ = clientcfg.ReadFromClientConfig(initClientCtx) @@ -296,7 +296,7 @@ func newApp( } // get the chain id - chainID, err := getChainIDFromOpts(appOpts) + chainID, err := evmdconfig.GetEvmChainID(appOpts) if err != nil { panic(err) } @@ -365,7 +365,7 @@ func appExport( appOpts = viperAppOpts // get the chain id - chainID, err := getChainIDFromOpts(appOpts) + chainID, err := evmdconfig.GetEvmChainID(appOpts) if err != nil { return servertypes.ExportedApp{}, err } @@ -382,21 +382,3 @@ func appExport( return exampleApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) } - -// getChainIDFromOpts returns the chain Id from app Opts -// It first tries to get from the chainId flag, if not available -// it will load from home -func getChainIDFromOpts(appOpts servertypes.AppOptions) (chainID string, err error) { - // Get the chain Id from appOpts - chainID = cast.ToString(appOpts.Get(flags.FlagChainID)) - if chainID == "" { - // If not available load from home - homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) - chainID, err = evmdconfig.GetChainIDFromHome(homeDir) - if err != nil { - return "", err - } - } - - return -} diff --git a/evmd/cmd/evmd/config/chain_id.go b/evmd/cmd/evmd/config/chain_id.go deleted file mode 100644 index 8de2e4543..000000000 --- a/evmd/cmd/evmd/config/chain_id.go +++ /dev/null @@ -1,29 +0,0 @@ -package config - -import ( - "path/filepath" - - "github.com/spf13/viper" - - "github.com/cosmos/cosmos-sdk/client/config" -) - -// GetChainIDFromHome returns the chain ID from the client configuration -// in the given home directory. -func GetChainIDFromHome(home string) (string, error) { - v := viper.New() - v.AddConfigPath(filepath.Join(home, "config")) - v.SetConfigName("client") - v.SetConfigType("toml") - - if err := v.ReadInConfig(); err != nil { - return "", err - } - conf := new(config.ClientConfig) - - if err := v.Unmarshal(conf); err != nil { - return "", err - } - - return conf.ChainID, nil -} diff --git a/evmd/cmd/evmd/config/config.go b/evmd/cmd/evmd/config/config.go index a5b042d07..6c49bbcd9 100644 --- a/evmd/cmd/evmd/config/config.go +++ b/evmd/cmd/evmd/config/config.go @@ -53,6 +53,25 @@ const ( BaseDenomUnit = 18 // EVMChainID defines the EIP-155 replay-protection chain id for the current ethereum chain config. EVMChainID = 262144 + // ExampleChainDenom is the denomination of the Cosmos EVM example chain's base coin. + ExampleChainDenom = "aatom" + // ExampleDisplayDenom is the display denomination of the Cosmos EVM example chain's base coin. + ExampleDisplayDenom = "atom" + // EighteenDecimalsChainID is the chain ID for the 18 decimals chain. + EighteenDecimalsChainID = 9001 + // SixDecimalsChainID is the chain ID for the 6 decimals chain. + SixDecimalsChainID = 9002 + // TwelveDecimalsChainID is the chain ID for the 12 decimals chain. + TwelveDecimalsChainID = 9003 + // TwoDecimalsChainID is the chain ID for the 2 decimals chain. + TwoDecimalsChainID = 9004 + CosmosChainID = 262144 + // TestChainID1 is test chain IDs for IBC E2E test + TestChainID1 = 9005 + // TestChainID2 is test chain IDs for IBC E2E test + TestChainID2 = 9006 + // WEVMOSContractMainnet is the WEVMOS contract address for mainnet + WEVMOSContractMainnet = "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517" ) // SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings. diff --git a/evmd/cmd/evmd/config/constants.go b/evmd/cmd/evmd/config/constants.go deleted file mode 100644 index fb9bdbe4b..000000000 --- a/evmd/cmd/evmd/config/constants.go +++ /dev/null @@ -1,31 +0,0 @@ -package config - -const ( - // ExampleChainDenom is the denomination of the Cosmos EVM example chain's base coin. - ExampleChainDenom = "aatom" - - // ExampleDisplayDenom is the display denomination of the Cosmos EVM example chain's base coin. - ExampleDisplayDenom = "atom" - - // EighteenDecimalsChainID is the chain ID for the 18 decimals chain. - EighteenDecimalsChainID = 9001 - - // SixDecimalsChainID is the chain ID for the 6 decimals chain. - SixDecimalsChainID = 9002 - - // TwelveDecimalsChainID is the chain ID for the 12 decimals chain. - TwelveDecimalsChainID = 9003 - - // TwoDecimalsChainID is the chain ID for the 2 decimals chain. - TwoDecimalsChainID = 9004 - - CosmosChainID = 262144 - - // TestChainID1 is test chain IDs for IBC E2E test - TestChainID1 = 9005 - // TestChainID2 is test chain IDs for IBC E2E test - TestChainID2 = 9006 - - // WEVMOSContractMainnet is the WEVMOS contract address for mainnet - WEVMOSContractMainnet = "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517" -) From 24c6f42876979b9f86cd9bd5458dc7eda61f0776 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 08:41:29 -0400 Subject: [PATCH 10/23] lint --- evmd/cmd/evmd/config/server_app_options.go | 112 ++++++ .../evmd/config/server_app_options_test.go | 332 ++++++++++++++++++ server/config/config.go | 4 +- 3 files changed, 446 insertions(+), 2 deletions(-) create mode 100644 evmd/cmd/evmd/config/server_app_options.go create mode 100644 evmd/cmd/evmd/config/server_app_options_test.go diff --git a/evmd/cmd/evmd/config/server_app_options.go b/evmd/cmd/evmd/config/server_app_options.go new file mode 100644 index 000000000..0ca0c3c47 --- /dev/null +++ b/evmd/cmd/evmd/config/server_app_options.go @@ -0,0 +1,112 @@ +package config + +import ( + "math" + "path/filepath" + + "github.com/holiman/uint256" + "github.com/spf13/cast" + + "cosmossdk.io/log" + srvflags "github.com/cosmos/evm/server/flags" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/config" + "github.com/cosmos/cosmos-sdk/client/flags" + sdkserver "github.com/cosmos/cosmos-sdk/server" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" +) + +// GetBlockGasLimit reads the genesis json file using AppGenesisFromFile +// to extract the consensus block gas limit before InitChain is called. +func GetBlockGasLimit(appOpts servertypes.AppOptions, logger log.Logger) uint64 { + homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) + if homeDir == "" { + logger.Error("home directory not found in app options, using zero block gas limit") + return math.MaxUint64 + } + genesisPath := filepath.Join(homeDir, "config", "genesis.json") + + appGenesis, err := genutiltypes.AppGenesisFromFile(genesisPath) + if err != nil { + logger.Error("failed to load genesis using SDK AppGenesisFromFile, using zero block gas limit", "path", genesisPath, "error", err) + return 0 + } + genDoc, err := appGenesis.ToGenesisDoc() + if err != nil { + logger.Error("failed to convert AppGenesis to GenesisDoc, using zero block gas limit", "path", genesisPath, "error", err) + return 0 + } + + if genDoc.ConsensusParams == nil { + logger.Error("consensus parameters not found in genesis (nil), using zero block gas limit") + return 0 + } + + maxGas := genDoc.ConsensusParams.Block.MaxGas + if maxGas == -1 { + logger.Warn("genesis max_gas is unlimited (-1), using max uint64") + return math.MaxUint64 + } + if maxGas < -1 { + logger.Error("invalid max_gas value in genesis, using zero block gas limit") + return 0 + } + blockGasLimit := uint64(maxGas) // #nosec G115 -- maxGas >= 0 checked above + + logger.Debug( + "extracted block gas limit from genesis using SDK AppGenesisFromFile", + "genesis_path", genesisPath, + "max_gas", maxGas, + "block_gas_limit", blockGasLimit, + ) + + return blockGasLimit +} + +// GetMinGasPrices reads the min gas prices from the app options, set from app.toml +// This is currently not used, but is kept in case this is useful for the mempool, +// in addition to the min tip flag +func GetMinGasPrices(appOpts servertypes.AppOptions, logger log.Logger) sdk.DecCoins { + minGasPricesStr := cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices)) + minGasPrices, err := sdk.ParseDecCoins(minGasPricesStr) + if err != nil { + logger.With("error", err).Info("failed to parse min gas prices, using empty DecCoins") + minGasPrices = sdk.DecCoins{} + } + + return minGasPrices +} + +// GetMinTip reads the min tip from the app options, set from app.toml +// This field is also known as the minimum priority fee +func GetMinTip(appOpts servertypes.AppOptions, logger log.Logger) *uint256.Int { + minTipUint64 := cast.ToUint64(appOpts.Get(srvflags.EVMMinTip)) + minTip := uint256.NewInt(minTipUint64) + + if minTip.Cmp(uint256.NewInt(0)) >= 0 { // zero or positive + return minTip + } + + logger.Error("invalid min tip value in app.toml or flag, falling back to nil", "min_tip", minTipUint64) + return nil +} + +// GetEvmChainID returns the EVM chain ID from the app options, set from +// If not available, it will load from client.toml +func GetEvmChainID(appOpts servertypes.AppOptions) (string, error) { + chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) + if chainID == "" { + // if not available, load from client.toml + clientCtx := client.Context{}.WithHomeDir(MustGetDefaultNodeHome()) + clientCtx, err := config.ReadFromClientConfig(clientCtx) + if err != nil { + return "", err + } + chainID = clientCtx.ChainID + } + + return chainID, nil +} diff --git a/evmd/cmd/evmd/config/server_app_options_test.go b/evmd/cmd/evmd/config/server_app_options_test.go new file mode 100644 index 000000000..ee4ed2ff1 --- /dev/null +++ b/evmd/cmd/evmd/config/server_app_options_test.go @@ -0,0 +1,332 @@ +package config + +import ( + "encoding/json" + "fmt" + "math" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + + "cosmossdk.io/log" + sdkmath "cosmossdk.io/math" + + "github.com/cosmos/cosmos-sdk/client/flags" + sdkserver "github.com/cosmos/cosmos-sdk/server" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type mockAppOptions struct { + values map[string]interface{} +} + +func newMockAppOptions() *mockAppOptions { + return &mockAppOptions{ + values: make(map[string]interface{}), + } +} + +func (m *mockAppOptions) Get(key string) interface{} { + return m.values[key] +} + +func (m *mockAppOptions) Set(key string, value interface{}) { + m.values[key] = value +} + +func TestGetBlockGasLimit(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + setupFn func() servertypes.AppOptions + expected uint64 + }{ + { + name: "empty home directory returns max uint64", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + return opts + }, + expected: math.MaxUint64, + }, + { + name: "genesis file not found returns 0", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(flags.FlagHome, "/non/existent/directory") + return opts + }, + expected: 0, + }, + { + name: "valid genesis with max_gas = -1 returns max uint64", + setupFn: func() servertypes.AppOptions { + homeDir := createGenesisWithMaxGas(t, -1) + opts := newMockAppOptions() + opts.Set(flags.FlagHome, homeDir) + return opts + }, + expected: math.MaxUint64, + }, + { + name: "valid genesis with max_gas < -1 returns 0", + setupFn: func() servertypes.AppOptions { + homeDir := createGenesisWithMaxGas(t, -5) + opts := newMockAppOptions() + opts.Set(flags.FlagHome, homeDir) + return opts + }, + expected: 0, + }, + { + name: "valid genesis with max_gas = 0 returns 0", + setupFn: func() servertypes.AppOptions { + homeDir := createGenesisWithMaxGas(t, 0) + opts := newMockAppOptions() + opts.Set(flags.FlagHome, homeDir) + return opts + }, + expected: 0, + }, + { + name: "valid genesis with max_gas = 1000000 returns 1000000", + setupFn: func() servertypes.AppOptions { + homeDir := createGenesisWithMaxGas(t, 1000000) + opts := newMockAppOptions() + opts.Set(flags.FlagHome, homeDir) + return opts + }, + expected: 1000000, + }, + { + name: "genesis without consensus params returns 0", + setupFn: func() servertypes.AppOptions { + homeDir := createGenesisWithoutConsensusParams(t) + opts := newMockAppOptions() + opts.Set(flags.FlagHome, homeDir) + return opts + }, + expected: 0, + }, + { + name: "invalid genesis JSON returns 0", + setupFn: func() servertypes.AppOptions { + homeDir := createInvalidGenesis(t) + opts := newMockAppOptions() + opts.Set(flags.FlagHome, homeDir) + return opts + }, + expected: 0, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(_ *testing.T) { + appOpts := tc.setupFn() + logger := log.NewNopLogger() + + result := GetBlockGasLimit(appOpts, logger) + require.Equal(t, tc.expected, result, "GetBlockGasLimit returned unexpected value") + }) + } +} + +func TestGetMinGasPrices(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + setupFn func() servertypes.AppOptions + expected sdk.DecCoins + }{ + { + name: "valid single gas price", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(sdkserver.FlagMinGasPrices, "0.025uatom") + return opts + }, + expected: sdk.DecCoins{sdk.NewDecCoinFromDec("uatom", sdkmath.LegacyMustNewDecFromStr("0.025"))}, + }, + { + name: "valid multiple gas prices", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(sdkserver.FlagMinGasPrices, "0.025uatom,0.001stake") + return opts + }, + expected: sdk.DecCoins{ + sdk.NewDecCoinFromDec("stake", sdkmath.LegacyMustNewDecFromStr("0.001")), + sdk.NewDecCoinFromDec("uatom", sdkmath.LegacyMustNewDecFromStr("0.025")), + }, + }, + { + name: "empty gas prices returns empty DecCoins", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(sdkserver.FlagMinGasPrices, "") + return opts + }, + expected: nil, + }, + { + name: "missing gas prices flag returns empty DecCoins", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + return opts + }, + expected: nil, + }, + { + name: "invalid gas price format returns empty DecCoins", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(sdkserver.FlagMinGasPrices, "invalid-format") + return opts + }, + expected: sdk.DecCoins{}, + }, + { + name: "malformed coin denomination returns empty DecCoins", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(sdkserver.FlagMinGasPrices, "0.025") + return opts + }, + expected: sdk.DecCoins{}, + }, + { + name: "zero amount gas price", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(sdkserver.FlagMinGasPrices, "0uatom") + return opts + }, + expected: sdk.DecCoins{}, + }, + { + name: "large decimal precision gas price", + setupFn: func() servertypes.AppOptions { + opts := newMockAppOptions() + opts.Set(sdkserver.FlagMinGasPrices, "0.000000000000000001uatom") + return opts + }, + expected: sdk.DecCoins{sdk.NewDecCoinFromDec("uatom", sdkmath.LegacyMustNewDecFromStr("0.000000000000000001"))}, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(_ *testing.T) { + appOpts := tc.setupFn() + logger := log.NewNopLogger() + + result := GetMinGasPrices(appOpts, logger) + require.Equal(t, tc.expected, result, "GetMinGasPrices returned unexpected value") + }) + } +} + +func createGenesisWithMaxGas(t *testing.T, maxGas int64) string { + t.Helper() + tempDir := t.TempDir() + configDir := filepath.Join(tempDir, "config") + require.NoError(t, os.MkdirAll(configDir, 0o755)) + + genesis := map[string]interface{}{ + "app_name": "evmd", + "app_version": "test", + "chain_id": "test-chain", + "initial_height": 1, + "genesis_time": "2024-01-01T00:00:00Z", + "app_hash": nil, + "app_state": map[string]interface{}{ + "auth": map[string]interface{}{ + "params": map[string]interface{}{ + "max_memo_characters": "256", + "tx_sig_limit": "7", + "tx_size_cost_per_byte": "10", + "sig_verify_cost_ed25519": "590", + "sig_verify_cost_secp256k1": "1000", + }, + "accounts": []interface{}{}, + }, + }, + "consensus": map[string]interface{}{ + "params": map[string]interface{}{ + "block": map[string]interface{}{ + "max_bytes": "22020096", + "max_gas": fmt.Sprintf("%d", maxGas), + }, + "evidence": map[string]interface{}{ + "max_age_num_blocks": "100000", + "max_age_duration": "172800000000000", + "max_bytes": "1048576", + }, + "validator": map[string]interface{}{ + "pub_key_types": []string{"ed25519"}, + }, + "version": map[string]interface{}{ + "app": "0", + }, + }, + }, + } + + genesisBytes, err := json.MarshalIndent(genesis, "", " ") + require.NoError(t, err) + + genesisPath := filepath.Join(configDir, "genesis.json") + require.NoError(t, os.WriteFile(genesisPath, genesisBytes, 0o600)) + + return tempDir +} + +func createGenesisWithoutConsensusParams(t *testing.T) string { + t.Helper() + tempDir := t.TempDir() + configDir := filepath.Join(tempDir, "config") + require.NoError(t, os.MkdirAll(configDir, 0o755)) + + genesis := map[string]interface{}{ + "app_name": "evmd", + "app_version": "test", + "chain_id": "test-chain", + "initial_height": 1, + "genesis_time": "2024-01-01T00:00:00Z", + "app_hash": nil, + "app_state": map[string]interface{}{ + "auth": map[string]interface{}{ + "params": map[string]interface{}{}, + "accounts": []interface{}{}, + }, + }, + "consensus": map[string]interface{}{ + "params": nil, + }, + } + + genesisBytes, err := json.MarshalIndent(genesis, "", " ") + require.NoError(t, err) + + genesisPath := filepath.Join(configDir, "genesis.json") + require.NoError(t, os.WriteFile(genesisPath, genesisBytes, 0o600)) + + return tempDir +} + +func createInvalidGenesis(t *testing.T) string { + t.Helper() + tempDir := t.TempDir() + configDir := filepath.Join(tempDir, "config") + require.NoError(t, os.MkdirAll(configDir, 0o755)) + + invalidJSON := `{"invalid": json}` + genesisPath := filepath.Join(configDir, "genesis.json") + require.NoError(t, os.WriteFile(genesisPath, []byte(invalidJSON), 0o600)) + + return tempDir +} diff --git a/server/config/config.go b/server/config/config.go index 3abe522f1..9450a39c1 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -6,12 +6,12 @@ import ( "path" "time" - evmtypes "github.com/cosmos/evm/x/vm/types" - "github.com/spf13/viper" "github.com/cometbft/cometbft/libs/strings" + evmtypes "github.com/cosmos/evm/x/vm/types" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/server/config" From 517ae7d5808e51c84c4dd8adbd5fc43aa3f29ac8 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 12:06:44 -0400 Subject: [PATCH 11/23] add appOptions refactor --- ante/evm/mono_decorator_test.go | 8 +- config/chain_config.go | 10 --- config/evm_app_options.go | 91 --------------------- evmd/app.go | 9 +- evmd/cmd/evmd/cmd/creator.go | 16 +++- evmd/cmd/evmd/cmd/root.go | 38 +++++---- evmd/cmd/evmd/cmd/testnet.go | 6 +- evmd/cmd/evmd/config/chain_config.go | 84 +++++++++++++++++++ evmd/cmd/evmd/config/config.go | 29 +++++-- evmd/cmd/evmd/config/config_testing.go | 15 ---- evmd/cmd/evmd/config/server_app_options.go | 69 +++++++++++++++- tests/integration/x/vm/keeper_test_suite.go | 4 +- tests/integration/x/vm/test_grpc_query.go | 3 +- testutil/config/constants.go | 2 - testutil/config/evm_app_options.go | 14 ---- x/vm/types/chain_config.go | 24 ++---- x/vm/types/evm_config.go | 8 ++ 17 files changed, 243 insertions(+), 187 deletions(-) delete mode 100644 config/chain_config.go delete mode 100644 config/evm_app_options.go create mode 100644 evmd/cmd/evmd/config/chain_config.go delete mode 100644 evmd/cmd/evmd/config/config_testing.go delete mode 100644 testutil/config/evm_app_options.go diff --git a/ante/evm/mono_decorator_test.go b/ante/evm/mono_decorator_test.go index 295415734..0c1fed7ed 100644 --- a/ante/evm/mono_decorator_test.go +++ b/ante/evm/mono_decorator_test.go @@ -17,9 +17,9 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/evm/ante/evm" + evmconfig "github.com/cosmos/evm/config" "github.com/cosmos/evm/crypto/ethsecp256k1" "github.com/cosmos/evm/encoding" - "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" "github.com/cosmos/evm/x/vm/statedb" @@ -144,9 +144,9 @@ func toMsgSlice(msgs []*evmsdktypes.MsgEthereumTx) []sdk.Msg { } func TestMonoDecorator(t *testing.T) { - chainID := uint64(config.EighteenDecimalsChainID) - require.NoError(t, config.EvmAppOptions(chainID)) - cfg := encoding.MakeConfig(chainID) + chainConfig := evmconfig.DefaultChainConfig + require.NoError(t, chainConfig.ApplyChainConfig()) + cfg := encoding.MakeConfig(chainConfig.EvmChainID) testCases := []struct { name string diff --git a/config/chain_config.go b/config/chain_config.go deleted file mode 100644 index e0c06c0d1..000000000 --- a/config/chain_config.go +++ /dev/null @@ -1,10 +0,0 @@ -package config - -import ( - evmtypes "github.com/cosmos/evm/x/vm/types" -) - -type ChainConfig struct { - ChainID string - EvmConfig *evmtypes.EvmConfig -} diff --git a/config/evm_app_options.go b/config/evm_app_options.go deleted file mode 100644 index 3c95e91db..000000000 --- a/config/evm_app_options.go +++ /dev/null @@ -1,91 +0,0 @@ -package config - -import ( - "fmt" - - "github.com/ethereum/go-ethereum/core/vm" - - evmtypes "github.com/cosmos/evm/x/vm/types" - - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// EVMOptionsFn defines a function type for setting app options specifically for -// the Cosmos EVM app. The function should receive the chainID and return an error if -// any. -type EVMOptionsFn func(uint64) error - -var sealed = false - -func EvmAppOptionsWithConfig( - chainID uint64, - chainsCoinInfo map[uint64]evmtypes.EvmCoinInfo, - cosmosEVMActivators map[int]func(*vm.JumpTable), -) error { - if sealed { - return nil - } - - if err := EvmAppOptionsWithConfigWithReset(chainID, chainsCoinInfo, cosmosEVMActivators, false); err != nil { - return err - } - - sealed = true - return nil -} - -func EvmAppOptionsWithConfigWithReset( - chainID uint64, - chainsCoinInfo map[uint64]evmtypes.EvmCoinInfo, - cosmosEVMActivators map[int]func(*vm.JumpTable), - withReset bool, -) error { - coinInfo, found := chainsCoinInfo[chainID] - if !found { - return fmt.Errorf("unknown chain id: %d", chainID) - } - - // set the denom info for the chain - if err := setBaseDenom(coinInfo); err != nil { - return err - } - - ethCfg := evmtypes.DefaultChainConfig(chainID) - configurator := evmtypes.NewEvmConfig() - if withReset { - // reset configuration to set the new one - configurator.ResetTestConfig() - } - err := configurator. - WithExtendedEips(cosmosEVMActivators). - WithChainConfig(ethCfg). - // NOTE: we're using the 18 decimals default for the example chain - WithEVMCoinInfo(coinInfo). - Apply() - if err != nil { - return err - } - - return nil -} - -// setBaseDenom registers the display denom and base denom and sets the -// base denom for the chain. The function registered different values based on -// the EvmCoinInfo to allow different configurations in mainnet and testnet. -func setBaseDenom(ci evmtypes.EvmCoinInfo) (err error) { - // Defer setting the base denom, and capture any potential error from it. - // So when failing because the denom was already registered, we ignore it and set - // the corresponding denom to be base denom - defer func() { - err = sdk.SetBaseDenom(ci.GetDenom()) - }() - if err := sdk.RegisterDenom(ci.DisplayDenom, math.LegacyOneDec()); err != nil { - return err - } - - // sdk.RegisterDenom will automatically overwrite the base denom when the - // new setBaseDenom() units are lower than the current base denom's units. - return sdk.RegisterDenom(ci.GetDenom(), math.LegacyNewDecWithPrec(1, int64(ci.Decimals))) -} diff --git a/evmd/app.go b/evmd/app.go index 6f9d41f45..fb3fb790d 100644 --- a/evmd/app.go +++ b/evmd/app.go @@ -20,7 +20,7 @@ import ( dbm "github.com/cosmos/cosmos-db" evmante "github.com/cosmos/evm/ante" cosmosevmante "github.com/cosmos/evm/ante/evm" - evmconfig "github.com/cosmos/evm/config" + "github.com/cosmos/evm/config" evmosencoding "github.com/cosmos/evm/encoding" "github.com/cosmos/evm/evmd/ante" evmmempool "github.com/cosmos/evm/mempool" @@ -212,11 +212,10 @@ func NewExampleApp( traceStore io.Writer, loadLatest bool, appOpts servertypes.AppOptions, - evmChainID uint64, - evmAppOptions evmconfig.EVMOptionsFn, + chainConfig config.ChainConfig, baseAppOptions ...func(*baseapp.BaseApp), ) *EVMD { - encodingConfig := evmosencoding.MakeConfig(evmChainID) + encodingConfig := evmosencoding.MakeConfig(chainConfig.EvmChainID) appCodec := encodingConfig.Codec legacyAmino := encodingConfig.Amino @@ -263,7 +262,7 @@ func NewExampleApp( bApp.SetTxEncoder(txConfig.TxEncoder()) // initialize the Cosmos EVM application configuration - if err := evmAppOptions(evmChainID); err != nil { + if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } diff --git a/evmd/cmd/evmd/cmd/creator.go b/evmd/cmd/evmd/cmd/creator.go index c6238998d..77b067381 100644 --- a/evmd/cmd/evmd/cmd/creator.go +++ b/evmd/cmd/evmd/cmd/creator.go @@ -88,14 +88,18 @@ func (a appCreator) newApp( baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), } + chainConfig, err := evmdconfig.CreateChainConfig(appOpts) + if err != nil { + panic(err) + } + return evmd.NewExampleApp( logger, db, traceStore, true, simtestutil.EmptyAppOptions{}, - evmdconfig.EVMChainID, - evmdconfig.EvmAppOptions, + *chainConfig, baseappOptions..., ) } @@ -131,14 +135,18 @@ func (a appCreator) appExport( loadLatest = true } + chainConfig, err := evmdconfig.CreateChainConfig(appOpts) + if err != nil { + return servertypes.ExportedApp{}, err + } + evmApp = evmd.NewExampleApp( logger, db, traceStore, loadLatest, appOpts, - evmdconfig.EVMChainID, - evmdconfig.EvmAppOptions, + *chainConfig, ) if height != -1 { diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/evmd/cmd/root.go index ea3e33f34..c42358a04 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/evmd/cmd/root.go @@ -16,6 +16,7 @@ import ( dbm "github.com/cosmos/cosmos-db" cosmosevmcmd "github.com/cosmos/evm/client" + evmconfig "github.com/cosmos/evm/config" cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring" "github.com/cosmos/evm/evmd" evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" @@ -56,17 +57,14 @@ func NewRootCmd() *cobra.Command { // we "pre"-instantiate the application for getting the injected/configured encoding configuration // and the CLI options for the modules // add keyring to autocli opts - noOpEvmAppOptions := func(_ uint64) error { - return nil - } + tempApp := evmd.NewExampleApp( log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{}, - evmdconfig.EVMChainID, - noOpEvmAppOptions, + evmconfig.ChainConfig{}, ) encodingConfig := sdktestutil.TestEncodingConfig{ @@ -132,7 +130,7 @@ func NewRootCmd() *cobra.Command { return err } - customAppTemplate, customAppConfig := evmdconfig.InitAppConfig(evmdconfig.BaseDenom, evmdconfig.EVMChainID) + customAppTemplate, customAppConfig := evmdconfig.InitAppConfig(evmdconfig.BaseDenom, evmdconfig.DefaultEvmChainID) customTMConfig := initCometConfig() return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) @@ -143,7 +141,7 @@ func NewRootCmd() *cobra.Command { if initClientCtx.ChainID == "" { // if the chain id is not set in client.toml, populate it with the default evm chain id - initClientCtx = initClientCtx.WithChainID(strconv.FormatUint(evmdconfig.EVMChainID, 10)) + initClientCtx = initClientCtx.WithChainID(strconv.FormatUint(evmdconfig.DefaultEvmChainID, 10)) } initClientCtx, _ = clientcfg.ReadFromClientConfig(initClientCtx) @@ -153,7 +151,9 @@ func NewRootCmd() *cobra.Command { panic(err) } - if err := evmdconfig.EvmAppOptions(evmdconfig.EVMChainID); err != nil { + chainConfig := evmdconfig.DefaultChainConfig + + if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } @@ -296,7 +296,7 @@ func newApp( } // get the chain id - chainID, err := evmdconfig.GetEvmChainID(appOpts) + chainID, err := evmdconfig.GetChainID(appOpts) if err != nil { panic(err) } @@ -326,11 +326,15 @@ func newApp( baseapp.SetChainID(chainID), } + chainConfig, err := evmdconfig.CreateChainConfig(appOpts) + if err != nil { + panic(err) + } + return evmd.NewExampleApp( logger, db, traceStore, true, appOpts, - evmdconfig.EVMChainID, - evmdconfig.EvmAppOptions, + *chainConfig, baseappOptions..., ) } @@ -365,19 +369,25 @@ func appExport( appOpts = viperAppOpts // get the chain id - chainID, err := evmdconfig.GetEvmChainID(appOpts) + chainID, err := evmdconfig.GetChainID(appOpts) + if err != nil { + return servertypes.ExportedApp{}, err + } + + // create the chain config + chainConfig, err := evmdconfig.CreateChainConfig(appOpts) if err != nil { return servertypes.ExportedApp{}, err } if height != -1 { - exampleApp = evmd.NewExampleApp(logger, db, traceStore, false, appOpts, evmdconfig.EVMChainID, evmdconfig.EvmAppOptions, baseapp.SetChainID(chainID)) + exampleApp = evmd.NewExampleApp(logger, db, traceStore, false, appOpts, *chainConfig, baseapp.SetChainID(chainID)) if err := exampleApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - exampleApp = evmd.NewExampleApp(logger, db, traceStore, true, appOpts, evmdconfig.EVMChainID, evmdconfig.EvmAppOptions, baseapp.SetChainID(chainID)) + exampleApp = evmd.NewExampleApp(logger, db, traceStore, true, appOpts, *chainConfig, baseapp.SetChainID(chainID)) } return exampleApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) diff --git a/evmd/cmd/evmd/cmd/testnet.go b/evmd/cmd/evmd/cmd/testnet.go index c90690cb0..af5a66417 100644 --- a/evmd/cmd/evmd/cmd/testnet.go +++ b/evmd/cmd/evmd/cmd/testnet.go @@ -268,7 +268,7 @@ func initTestnetFiles( appConfig.Telemetry.EnableHostnameLabel = false appConfig.Telemetry.GlobalLabels = [][]string{{"chain_id", args.chainID}} evm := cosmosevmserverconfig.DefaultEVMConfig() - evm.EVMChainID = evmdconfig.EVMChainID + evm.EVMChainID = evmdconfig.DefaultEvmChainID evmCfg := evmdconfig.EVMAppConfig{ Config: *appConfig, EVM: *evm, @@ -683,7 +683,7 @@ func NewTestNetworkFixture() network.TestFixture { nil, true, simtestutil.EmptyAppOptions{}, - evmdconfig.EVMChainID, + evmdconfig.DefaultEvmChainID, evmdconfig.EvmAppOptions, ) @@ -694,7 +694,7 @@ func NewTestNetworkFixture() network.TestFixture { nil, true, simtestutil.EmptyAppOptions{}, - evmdconfig.EVMChainID, + evmdconfig.DefaultEvmChainID, evmdconfig.EvmAppOptions, ) } diff --git a/evmd/cmd/evmd/config/chain_config.go b/evmd/cmd/evmd/config/chain_config.go new file mode 100644 index 000000000..6827dc93c --- /dev/null +++ b/evmd/cmd/evmd/config/chain_config.go @@ -0,0 +1,84 @@ +package config + +import ( + "fmt" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/evm/x/vm/types" + "github.com/ethereum/go-ethereum/core/vm" +) + +type ChainConfig struct { + ChainID string + EvmChainID uint64 + EvmConfig *types.EvmConfig +} + +// NewChainConfig creates a chain config with custom parameters, using defaults if not provided +func NewChainConfig( + chainID string, + evmChainID uint64, + evmActivators map[int]func(*vm.JumpTable), + evmExtraEIPs []int64, + evmChainConfig *types.ChainConfig, + evmCoinInfo types.EvmCoinInfo, + reset bool, +) ChainConfig { + if evmChainConfig == nil { + evmChainConfig = types.DefaultChainConfig(evmChainID, evmCoinInfo) + } + + evmConfig := types.NewEvmConfig(). + WithChainConfig(evmChainConfig). + WithEVMCoinInfo(evmCoinInfo). + WithExtendedEips(evmActivators). + WithExtendedDefaultExtraEIPs(evmExtraEIPs...) + + if reset { + evmConfig.ResetTestConfig() + } + + return ChainConfig{ + ChainID: chainID, + EvmChainID: evmChainID, + EvmConfig: evmConfig, + } +} + +// ApplyEvmConfig applies the evm config to the global singleton chain config and coin info +func (cc *ChainConfig) ApplyChainConfig() error { + if cc.EvmConfig == nil { + return nil // no op if evm config is nil + } + if cc.EvmConfig == nil { + return fmt.Errorf("evm config is nil, cannot apply chain config") + } + if cc.EvmConfig.GetChainConfig() == nil { + return fmt.Errorf("chain config is nil, cannot apply chain config") + } + + if err := setBaseDenom(cc.EvmConfig.GetEVMCoinInfo()); err != nil { + return err + } + return cc.EvmConfig.Apply() +} + +// setBaseDenom registers the display denom and base denom and sets the +// base denom for the chain. The function registered different values based on +// the EvmCoinInfo to allow different configurations in mainnet and testnet. +func setBaseDenom(ci types.EvmCoinInfo) (err error) { + // defer setting the base denom, and capture any potential error from it. + // when failing because the denom was already registered, we ignore it and set + // the corresponding denom to be base denom + defer func() { + err = sdk.SetBaseDenom(ci.GetDenom()) + }() + if err := sdk.RegisterDenom(ci.DisplayDenom, math.LegacyOneDec()); err != nil { + return err + } + + // sdk.RegisterDenom will automatically overwrite the base denom when the + // new setBaseDenom() units are lower than the current base denom's units. + return sdk.RegisterDenom(ci.GetDenom(), math.LegacyNewDecWithPrec(1, int64(ci.Decimals))) +} diff --git a/evmd/cmd/evmd/config/config.go b/evmd/cmd/evmd/config/config.go index 6c49bbcd9..5f76b2c4d 100644 --- a/evmd/cmd/evmd/config/config.go +++ b/evmd/cmd/evmd/config/config.go @@ -7,6 +7,23 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +// DefaultChainConfig provides a standard 18-decimal cosmos/atom test configuration +var ( + DefaultChainConfig = NewChainConfig( + DefaultChainID, + DefaultEvmChainID, + cosmosEVMActivators, + nil, + nil, + evmtypes.EvmCoinInfo{ + DisplayDenom: DisplayDenom, + Decimals: Decimals, + ExtendedDecimals: ExtendedDecimals, + }, + false, + ) +) + // ChainsCoinInfo is a map of the chain id and its corresponding EvmCoinInfo // that allows initializing the app with different coin info based on the // chain id @@ -23,7 +40,7 @@ var ChainsCoinInfo = map[uint64]evmtypes.EvmCoinInfo{ ExtendedDecimals: evmtypes.EighteenDecimals, }, // EVMChainID provides a chain ID used for internal testing - EVMChainID: { + DefaultEvmChainID: { DisplayDenom: "test", Decimals: evmtypes.EighteenDecimals, ExtendedDecimals: evmtypes.EighteenDecimals, @@ -49,10 +66,11 @@ const ( DisplayDenom = "atom" // BaseDenom defines to the default denomination used in the Cosmos EVM example chain. BaseDenom = "aatom" - // BaseDenomUnit defines the precision of the base denomination. - BaseDenomUnit = 18 - // EVMChainID defines the EIP-155 replay-protection chain id for the current ethereum chain config. - EVMChainID = 262144 + // Decimals defines the precision of the base denomination. + Decimals = evmtypes.EighteenDecimals + ExtendedDecimals = evmtypes.EighteenDecimals + // DefaultEvmChainID defines the EIP-155 replay-protection chain id for the current ethereum chain config. + DefaultEvmChainID = 262144 // ExampleChainDenom is the denomination of the Cosmos EVM example chain's base coin. ExampleChainDenom = "aatom" // ExampleDisplayDenom is the display denomination of the Cosmos EVM example chain's base coin. @@ -65,6 +83,7 @@ const ( TwelveDecimalsChainID = 9003 // TwoDecimalsChainID is the chain ID for the 2 decimals chain. TwoDecimalsChainID = 9004 + DefaultChainID = "cosmos" CosmosChainID = 262144 // TestChainID1 is test chain IDs for IBC E2E test TestChainID1 = 9005 diff --git a/evmd/cmd/evmd/config/config_testing.go b/evmd/cmd/evmd/config/config_testing.go deleted file mode 100644 index 504d57427..000000000 --- a/evmd/cmd/evmd/config/config_testing.go +++ /dev/null @@ -1,15 +0,0 @@ -//go:build test -// +build test - -package config - -import ( - evmconfig "github.com/cosmos/evm/config" - testconfig "github.com/cosmos/evm/testutil/config" -) - -// EvmAppOptions allows to setup the global configuration -// for the Cosmos EVM chain. -func EvmAppOptions(chainID uint64) error { - return evmconfig.EvmAppOptionsWithConfigWithReset(chainID, testconfig.TestChainsCoinInfo, cosmosEVMActivators, true) -} diff --git a/evmd/cmd/evmd/config/server_app_options.go b/evmd/cmd/evmd/config/server_app_options.go index 0ca0c3c47..8731fa594 100644 --- a/evmd/cmd/evmd/config/server_app_options.go +++ b/evmd/cmd/evmd/config/server_app_options.go @@ -1,6 +1,7 @@ package config import ( + "errors" "math" "path/filepath" @@ -8,7 +9,9 @@ import ( "github.com/spf13/cast" "cosmossdk.io/log" + evmconfig "github.com/cosmos/evm/config" srvflags "github.com/cosmos/evm/server/flags" + evmtypes "github.com/cosmos/evm/x/vm/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -94,9 +97,9 @@ func GetMinTip(appOpts servertypes.AppOptions, logger log.Logger) *uint256.Int { return nil } -// GetEvmChainID returns the EVM chain ID from the app options, set from +// GetChainID returns the EVM chain ID from the app options, set from // If not available, it will load from client.toml -func GetEvmChainID(appOpts servertypes.AppOptions) (string, error) { +func GetChainID(appOpts servertypes.AppOptions) (string, error) { chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) if chainID == "" { // if not available, load from client.toml @@ -110,3 +113,65 @@ func GetEvmChainID(appOpts servertypes.AppOptions) (string, error) { return chainID, nil } + +// GetEvmChainID returns the EVM chain ID from the app options, set from flags or app.toml +func GetEvmChainID(appOpts servertypes.AppOptions) (uint64, error) { + evmChainID := cast.ToUint64(appOpts.Get(srvflags.EVMChainID)) + if evmChainID == 0 { + return 0, errors.New("evm chain id flag not found in app options") + } + return evmChainID, nil +} + +func GetEvmCoinInfo(appOpts servertypes.AppOptions) (*evmtypes.EvmCoinInfo, error) { + displayDenom := cast.ToString(appOpts.Get(srvflags.EVMDisplayDenom)) + if displayDenom == "" { + return nil, errors.New("display denom flag not found in app options") + } + decimals := cast.ToUint8(appOpts.Get(srvflags.EVMDecimals)) + if decimals == 0 { + return nil, errors.New("decimals flag not found in app options") + } + extendedDecimals := cast.ToUint8(appOpts.Get(srvflags.EVMExtendedDecimals)) + if extendedDecimals == 0 { + return nil, errors.New("extended decimals flag not found in app options") + } + + evmCoinInfo := evmtypes.EvmCoinInfo{ + DisplayDenom: displayDenom, + Decimals: evmtypes.Decimals(decimals), + ExtendedDecimals: evmtypes.Decimals(extendedDecimals), + } + if err := evmCoinInfo.Validate(); err != nil { + return nil, err + } + + return &evmCoinInfo, nil +} + +func CreateChainConfig(appOpts servertypes.AppOptions) (*evmconfig.ChainConfig, error) { + chainID, err := GetChainID(appOpts) + if err != nil { + return nil, err + } + evmChainID, err := GetEvmChainID(appOpts) + if err != nil { + return nil, err + } + evmCoinInfo, err := GetEvmCoinInfo(appOpts) + if err != nil { + return nil, err + } + + chainConfig := evmconfig.NewChainConfig( + chainID, + evmChainID, + cosmosEVMActivators, + nil, + nil, + *evmCoinInfo, + false, + ) + + return &chainConfig, nil +} diff --git a/tests/integration/x/vm/keeper_test_suite.go b/tests/integration/x/vm/keeper_test_suite.go index 5347cdf4f..60893608d 100644 --- a/tests/integration/x/vm/keeper_test_suite.go +++ b/tests/integration/x/vm/keeper_test_suite.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/stretchr/testify/suite" + testconstants "github.com/cosmos/evm/testutil/constants" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -88,7 +89,8 @@ func (s *KeeperTestSuite) SetupTest() { s.Handler = gh s.Keyring = keys - chainConfig := evmtypes.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64()) + coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + chainConfig := evmtypes.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64(), coinInfo) if !s.EnableLondonHF { maxInt := sdkmath.NewInt(math.MaxInt64) chainConfig.LondonBlock = &maxInt diff --git a/tests/integration/x/vm/test_grpc_query.go b/tests/integration/x/vm/test_grpc_query.go index 59f874d9b..f5c65f9c5 100644 --- a/tests/integration/x/vm/test_grpc_query.go +++ b/tests/integration/x/vm/test_grpc_query.go @@ -1592,7 +1592,8 @@ func (s *KeeperTestSuite) TestQueryBaseFee() { feemarketDefault := feemarkettypes.DefaultParams() s.Require().NoError(s.Network.App.GetFeeMarketKeeper().SetParams(s.Network.GetContext(), feemarketDefault)) - chainConfig := types.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64()) + coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + chainConfig := types.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64(), coinInfo) maxInt := sdkmath.NewInt(math.MaxInt64) chainConfig.LondonBlock = &maxInt chainConfig.ArrowGlacierBlock = &maxInt diff --git a/testutil/config/constants.go b/testutil/config/constants.go index fb9bdbe4b..3a7354cd9 100644 --- a/testutil/config/constants.go +++ b/testutil/config/constants.go @@ -19,8 +19,6 @@ const ( // TwoDecimalsChainID is the chain ID for the 2 decimals chain. TwoDecimalsChainID = 9004 - CosmosChainID = 262144 - // TestChainID1 is test chain IDs for IBC E2E test TestChainID1 = 9005 // TestChainID2 is test chain IDs for IBC E2E test diff --git a/testutil/config/evm_app_options.go b/testutil/config/evm_app_options.go deleted file mode 100644 index 07e73107d..000000000 --- a/testutil/config/evm_app_options.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build !test -// +build !test - -package config - -import ( - evmconfig "github.com/cosmos/evm/config" -) - -// EvmAppOptions allows to setup the global configuration -// for the Cosmos EVM chain. -func EvmAppOptions(chainID uint64) error { - return evmconfig.EvmAppOptionsWithConfig(chainID, ChainsCoinInfo, cosmosEVMActivators) -} diff --git a/x/vm/types/chain_config.go b/x/vm/types/chain_config.go index f81f19942..a674675dc 100644 --- a/x/vm/types/chain_config.go +++ b/x/vm/types/chain_config.go @@ -10,9 +10,6 @@ import ( sdkmath "cosmossdk.io/math" ) -// testChainID represents the ChainID used for the purpose of testing. -const testChainID uint64 = 262144 - // chainConfig is the chain configuration used in the EVM to defined which // opcodes are active based on Ethereum upgrades. var chainConfig *ChainConfig @@ -58,11 +55,7 @@ func (cc ChainConfig) EthereumConfig(chainID *big.Int) *gethparams.ChainConfig { } } -func DefaultChainConfig(evmChainID uint64) *ChainConfig { - if evmChainID == 0 { - evmChainID = testChainID - } - +func DefaultChainConfig(evmChainID uint64, coinInfo EvmCoinInfo) *ChainConfig { homesteadBlock := sdkmath.ZeroInt() daoForkBlock := sdkmath.ZeroInt() eip150Block := sdkmath.ZeroInt() @@ -84,8 +77,8 @@ func DefaultChainConfig(evmChainID uint64) *ChainConfig { cfg := &ChainConfig{ ChainId: evmChainID, - Denom: DefaultEVMDenom, - Decimals: DefaultEVMDecimals, + Denom: coinInfo.GetDenom(), + Decimals: uint64(coinInfo.Decimals), HomesteadBlock: &homesteadBlock, DAOForkBlock: &daoForkBlock, DAOForkSupport: true, @@ -116,17 +109,16 @@ func DefaultChainConfig(evmChainID uint64) *ChainConfig { // in the EvmConfig. func setChainConfig(cc *ChainConfig) error { if chainConfig != nil { - return errors.New("chainConfig already set. Cannot set again the chainConfig") + return errors.New("chainConfig already set, cannot set again") } - config := DefaultChainConfig(0) - if cc != nil { - config = cc + if cc == nil { + return errors.New("chain config is nil") } - if err := config.Validate(); err != nil { + if err := cc.Validate(); err != nil { return err } - chainConfig = config + chainConfig = cc return nil } diff --git a/x/vm/types/evm_config.go b/x/vm/types/evm_config.go index 5c3c23a7f..d2d26c2bb 100644 --- a/x/vm/types/evm_config.go +++ b/x/vm/types/evm_config.go @@ -23,6 +23,14 @@ func NewEvmConfig() *EvmConfig { return &EvmConfig{} } +func (ec *EvmConfig) GetChainConfig() *ChainConfig { + return ec.chainConfig +} + +func (ec *EvmConfig) GetEVMCoinInfo() EvmCoinInfo { + return ec.evmCoinInfo +} + // WithExtendedEips allows to add to the go-ethereum activators map the provided // EIP activators. func (ec *EvmConfig) WithExtendedEips(extendedEIPs map[int]func(*vm.JumpTable)) *EvmConfig { From fc87a641be39cfc6f1b1c12eb7083221a2bffb38 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 14:49:29 -0400 Subject: [PATCH 12/23] add chainconfig replacement --- ante/evm/fee_checker_test.go | 9 ++--- ante/evm/mono_decorator_test.go | 2 +- .../evmd/config => config}/chain_config.go | 0 {evmd/cmd/evmd/config => config}/config.go | 23 +++++++++++- {evmd => config}/eips/README.md | 0 config/eips/activators.go | 15 ++++++++ {evmd => config}/eips/eips.go | 0 .../config => config}/server_app_options.go | 14 +++++--- .../server_app_options_test.go | 0 evmd/app.go | 5 +-- evmd/cmd/evmd/cmd/creator.go | 6 ++-- evmd/cmd/evmd/cmd/root.go | 16 ++++----- evmd/cmd/evmd/cmd/testnet.go | 11 +++--- evmd/cmd/evmd/config/activators.go | 15 -------- evmd/cmd/evmd/config/evm_app_options.go | 14 -------- evmd/cmd/evmd/main.go | 4 +-- evmd/genesis.go | 2 +- evmd/test_helpers.go | 17 +++++---- evmd/{ => tests}/eips/eips_test.go | 4 +-- evmd/{ => tests}/eips/testdata/Counter.json | 0 evmd/{ => tests}/eips/testdata/Counter.sol | 0 .../eips/testdata/CounterFactory.json | 0 .../eips/testdata/CounterFactory.sol | 0 evmd/{ => tests}/eips/testdata/contracts.go | 0 evmd/tests/integration/create_app.go | 35 +++++++++++++++---- evmd/tests/integration/x_vm_test.go | 4 ++- evmd/tests/network/network.go | 33 ++++++++++++++--- rpc/backend/call_tx.go | 7 +++- tests/integration/ante/ante_test_suite.go | 4 ++- tests/integration/x/vm/test_grpc_query.go | 2 +- testutil/config/config_testing.go | 19 +++++++++- testutil/ibc/coordinator.go | 5 +-- x/precisebank/keeper/keeper_test.go | 5 +-- x/vm/types/chain_config_test.go | 2 +- x/vm/types/config_testing.go | 18 +++++++--- x/vm/types/msg_test.go | 5 +-- 36 files changed, 196 insertions(+), 100 deletions(-) rename {evmd/cmd/evmd/config => config}/chain_config.go (100%) rename {evmd/cmd/evmd/config => config}/config.go (89%) rename {evmd => config}/eips/README.md (100%) create mode 100644 config/eips/activators.go rename {evmd => config}/eips/eips.go (100%) rename {evmd/cmd/evmd/config => config}/server_app_options.go (93%) rename {evmd/cmd/evmd/config => config}/server_app_options_test.go (100%) delete mode 100644 evmd/cmd/evmd/config/activators.go delete mode 100644 evmd/cmd/evmd/config/evm_app_options.go rename evmd/{ => tests}/eips/eips_test.go (99%) rename evmd/{ => tests}/eips/testdata/Counter.json (100%) rename evmd/{ => tests}/eips/testdata/Counter.sol (100%) rename evmd/{ => tests}/eips/testdata/CounterFactory.json (100%) rename evmd/{ => tests}/eips/testdata/CounterFactory.sol (100%) rename evmd/{ => tests}/eips/testdata/contracts.go (100%) diff --git a/ante/evm/fee_checker_test.go b/ante/evm/fee_checker_test.go index a5cbc3734..b75c0c1a9 100644 --- a/ante/evm/fee_checker_test.go +++ b/ante/evm/fee_checker_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/evm/ante/evm" anteinterfaces "github.com/cosmos/evm/ante/interfaces" + evmconfig "github.com/cosmos/evm/config" "github.com/cosmos/evm/encoding" - "github.com/cosmos/evm/testutil/config" testconstants "github.com/cosmos/evm/testutil/constants" "github.com/cosmos/evm/types" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" @@ -57,9 +57,10 @@ func TestSDKTxFeeChecker(t *testing.T) { // with extension option // without extension option // london hardfork enableness - chainID := uint64(config.EighteenDecimalsChainID) - encodingConfig := encoding.MakeConfig(chainID) - err := config.EvmAppOptions(chainID) + + chainConfig := evmconfig.NewTestChainConfig(evmconfig.DefaultEvmChainID) + encodingConfig := encoding.MakeConfig(chainConfig.EvmChainID) + err := chainConfig.ApplyChainConfig() require.NoError(t, err) evmDenom := evmtypes.GetEVMCoinDenom() diff --git a/ante/evm/mono_decorator_test.go b/ante/evm/mono_decorator_test.go index 0c1fed7ed..bc0178fe3 100644 --- a/ante/evm/mono_decorator_test.go +++ b/ante/evm/mono_decorator_test.go @@ -144,7 +144,7 @@ func toMsgSlice(msgs []*evmsdktypes.MsgEthereumTx) []sdk.Msg { } func TestMonoDecorator(t *testing.T) { - chainConfig := evmconfig.DefaultChainConfig + chainConfig := evmconfig.NewTestChainConfig(evmconfig.DefaultEvmChainID) require.NoError(t, chainConfig.ApplyChainConfig()) cfg := encoding.MakeConfig(chainConfig.EvmChainID) diff --git a/evmd/cmd/evmd/config/chain_config.go b/config/chain_config.go similarity index 100% rename from evmd/cmd/evmd/config/chain_config.go rename to config/chain_config.go diff --git a/evmd/cmd/evmd/config/config.go b/config/config.go similarity index 89% rename from evmd/cmd/evmd/config/config.go rename to config/config.go index 5f76b2c4d..4f76b7a1a 100644 --- a/evmd/cmd/evmd/config/config.go +++ b/config/config.go @@ -1,6 +1,7 @@ package config import ( + "github.com/cosmos/evm/config/eips" "github.com/cosmos/evm/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -12,7 +13,7 @@ var ( DefaultChainConfig = NewChainConfig( DefaultChainID, DefaultEvmChainID, - cosmosEVMActivators, + eips.CosmosEVMActivators, nil, nil, evmtypes.EvmCoinInfo{ @@ -106,3 +107,23 @@ func SetBip44CoinType(config *sdk.Config) { config.SetPurpose(sdk.Purpose) // Shared config.SetFullFundraiserPath(types.BIP44HDPath) //nolint: staticcheck } + +// NewTestChainConfig creates a fresh chain config for testing purposes +// This avoids the issue of shared EvmConfig instances being sealed +func NewTestChainConfig(evmChainID uint64) ChainConfig { + coinInfo := evmtypes.EvmCoinInfo{ + DisplayDenom: DisplayDenom, + Decimals: Decimals, + ExtendedDecimals: ExtendedDecimals, + } + + return NewChainConfig( + DefaultChainID, + evmChainID, + eips.CosmosEVMActivators, + nil, + nil, + coinInfo, + true, // reset = true for testing + ) +} diff --git a/evmd/eips/README.md b/config/eips/README.md similarity index 100% rename from evmd/eips/README.md rename to config/eips/README.md diff --git a/config/eips/activators.go b/config/eips/activators.go new file mode 100644 index 000000000..6536179e4 --- /dev/null +++ b/config/eips/activators.go @@ -0,0 +1,15 @@ +package eips + +import ( + "github.com/ethereum/go-ethereum/core/vm" +) + +var ( + // CosmosEVMActivators defines a map of opcode modifiers associated + // with a key defining the corresponding EIP. + CosmosEVMActivators = map[int]func(*vm.JumpTable){ + 0o000: Enable0000, + 0o001: Enable0001, + 0o002: Enable0002, + } +) diff --git a/evmd/eips/eips.go b/config/eips/eips.go similarity index 100% rename from evmd/eips/eips.go rename to config/eips/eips.go diff --git a/evmd/cmd/evmd/config/server_app_options.go b/config/server_app_options.go similarity index 93% rename from evmd/cmd/evmd/config/server_app_options.go rename to config/server_app_options.go index 8731fa594..47551f902 100644 --- a/evmd/cmd/evmd/config/server_app_options.go +++ b/config/server_app_options.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cast" "cosmossdk.io/log" - evmconfig "github.com/cosmos/evm/config" + "github.com/cosmos/evm/config/eips" srvflags "github.com/cosmos/evm/server/flags" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -103,7 +103,11 @@ func GetChainID(appOpts servertypes.AppOptions) (string, error) { chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) if chainID == "" { // if not available, load from client.toml - clientCtx := client.Context{}.WithHomeDir(MustGetDefaultNodeHome()) + homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) + if homeDir == "" { + return "", errors.New("home directory flag not found in app options") + } + clientCtx := client.Context{}.WithHomeDir(homeDir) clientCtx, err := config.ReadFromClientConfig(clientCtx) if err != nil { return "", err @@ -149,7 +153,7 @@ func GetEvmCoinInfo(appOpts servertypes.AppOptions) (*evmtypes.EvmCoinInfo, erro return &evmCoinInfo, nil } -func CreateChainConfig(appOpts servertypes.AppOptions) (*evmconfig.ChainConfig, error) { +func CreateChainConfig(appOpts servertypes.AppOptions) (*ChainConfig, error) { chainID, err := GetChainID(appOpts) if err != nil { return nil, err @@ -163,10 +167,10 @@ func CreateChainConfig(appOpts servertypes.AppOptions) (*evmconfig.ChainConfig, return nil, err } - chainConfig := evmconfig.NewChainConfig( + chainConfig := NewChainConfig( chainID, evmChainID, - cosmosEVMActivators, + eips.CosmosEVMActivators, nil, nil, *evmCoinInfo, diff --git a/evmd/cmd/evmd/config/server_app_options_test.go b/config/server_app_options_test.go similarity index 100% rename from evmd/cmd/evmd/config/server_app_options_test.go rename to config/server_app_options_test.go diff --git a/evmd/app.go b/evmd/app.go index fb3fb790d..54859ff43 100644 --- a/evmd/app.go +++ b/evmd/app.go @@ -21,6 +21,7 @@ import ( evmante "github.com/cosmos/evm/ante" cosmosevmante "github.com/cosmos/evm/ante/evm" "github.com/cosmos/evm/config" + evmconfig "github.com/cosmos/evm/config" evmosencoding "github.com/cosmos/evm/encoding" "github.com/cosmos/evm/evmd/ante" evmmempool "github.com/cosmos/evm/mempool" @@ -754,9 +755,9 @@ func NewExampleApp( // If you wish to use the noop mempool, remove this codeblock if evmtypes.GetChainConfig() != nil { // Get the block gas limit from genesis file - blockGasLimit := evmdconfig.GetBlockGasLimit(appOpts, logger) + blockGasLimit := evmconfig.GetBlockGasLimit(appOpts, logger) // Get GetMinTip from app.toml or cli flag configuration - mipTip := evmdconfig.GetMinTip(appOpts, logger) + mipTip := evmconfig.GetMinTip(appOpts, logger) mempoolConfig := &evmmempool.EVMMempoolConfig{ AnteHandler: app.GetAnteHandler(), diff --git a/evmd/cmd/evmd/cmd/creator.go b/evmd/cmd/evmd/cmd/creator.go index 77b067381..73aac47ad 100644 --- a/evmd/cmd/evmd/cmd/creator.go +++ b/evmd/cmd/evmd/cmd/creator.go @@ -12,8 +12,8 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + evmconfig "github.com/cosmos/evm/config" "github.com/cosmos/evm/evmd" - evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" "github.com/spf13/cast" "github.com/spf13/viper" @@ -88,7 +88,7 @@ func (a appCreator) newApp( baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), } - chainConfig, err := evmdconfig.CreateChainConfig(appOpts) + chainConfig, err := evmconfig.CreateChainConfig(appOpts) if err != nil { panic(err) } @@ -135,7 +135,7 @@ func (a appCreator) appExport( loadLatest = true } - chainConfig, err := evmdconfig.CreateChainConfig(appOpts) + chainConfig, err := evmconfig.CreateChainConfig(appOpts) if err != nil { return servertypes.ExportedApp{}, err } diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/evmd/cmd/root.go index c42358a04..da63597c3 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/evmd/cmd/root.go @@ -130,7 +130,7 @@ func NewRootCmd() *cobra.Command { return err } - customAppTemplate, customAppConfig := evmdconfig.InitAppConfig(evmdconfig.BaseDenom, evmdconfig.DefaultEvmChainID) + customAppTemplate, customAppConfig := evmdconfig.InitAppConfig(evmconfig.BaseDenom, evmconfig.DefaultEvmChainID) customTMConfig := initCometConfig() return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) @@ -141,7 +141,7 @@ func NewRootCmd() *cobra.Command { if initClientCtx.ChainID == "" { // if the chain id is not set in client.toml, populate it with the default evm chain id - initClientCtx = initClientCtx.WithChainID(strconv.FormatUint(evmdconfig.DefaultEvmChainID, 10)) + initClientCtx = initClientCtx.WithChainID(strconv.FormatUint(evmconfig.DefaultEvmChainID, 10)) } initClientCtx, _ = clientcfg.ReadFromClientConfig(initClientCtx) @@ -151,7 +151,7 @@ func NewRootCmd() *cobra.Command { panic(err) } - chainConfig := evmdconfig.DefaultChainConfig + chainConfig := evmconfig.NewTestChainConfig(evmconfig.DefaultEvmChainID) if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) @@ -162,7 +162,7 @@ func NewRootCmd() *cobra.Command { func setupSDKConfig() { config := sdk.GetConfig() - evmdconfig.SetBech32Prefixes(config) + evmconfig.SetBech32Prefixes(config) config.Seal() } @@ -296,7 +296,7 @@ func newApp( } // get the chain id - chainID, err := evmdconfig.GetChainID(appOpts) + chainID, err := evmconfig.GetChainID(appOpts) if err != nil { panic(err) } @@ -326,7 +326,7 @@ func newApp( baseapp.SetChainID(chainID), } - chainConfig, err := evmdconfig.CreateChainConfig(appOpts) + chainConfig, err := evmconfig.CreateChainConfig(appOpts) if err != nil { panic(err) } @@ -369,13 +369,13 @@ func appExport( appOpts = viperAppOpts // get the chain id - chainID, err := evmdconfig.GetChainID(appOpts) + chainID, err := evmconfig.GetChainID(appOpts) if err != nil { return servertypes.ExportedApp{}, err } // create the chain config - chainConfig, err := evmdconfig.CreateChainConfig(appOpts) + chainConfig, err := evmconfig.CreateChainConfig(appOpts) if err != nil { return servertypes.ExportedApp{}, err } diff --git a/evmd/cmd/evmd/cmd/testnet.go b/evmd/cmd/evmd/cmd/testnet.go index af5a66417..8ee891b07 100644 --- a/evmd/cmd/evmd/cmd/testnet.go +++ b/evmd/cmd/evmd/cmd/testnet.go @@ -12,7 +12,6 @@ import ( cosmosevmhd "github.com/cosmos/evm/crypto/hd" cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring" "github.com/cosmos/evm/evmd" - evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" cosmosevmserverconfig "github.com/cosmos/evm/server/config" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -20,6 +19,8 @@ import ( cmtconfig "github.com/cometbft/cometbft/config" "github.com/cometbft/cometbft/types" tmtime "github.com/cometbft/cometbft/types/time" + evmconfig "github.com/cosmos/evm/config" + evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" dbm "github.com/cosmos/cosmos-db" @@ -268,7 +269,7 @@ func initTestnetFiles( appConfig.Telemetry.EnableHostnameLabel = false appConfig.Telemetry.GlobalLabels = [][]string{{"chain_id", args.chainID}} evm := cosmosevmserverconfig.DefaultEVMConfig() - evm.EVMChainID = evmdconfig.DefaultEvmChainID + evm.EVMChainID = evmconfig.DefaultEvmChainID evmCfg := evmdconfig.EVMAppConfig{ Config: *appConfig, EVM: *evm, @@ -683,8 +684,7 @@ func NewTestNetworkFixture() network.TestFixture { nil, true, simtestutil.EmptyAppOptions{}, - evmdconfig.DefaultEvmChainID, - evmdconfig.EvmAppOptions, + evmconfig.DefaultChainConfig, ) appCtr := func(val network.ValidatorI) servertypes.Application { @@ -694,8 +694,7 @@ func NewTestNetworkFixture() network.TestFixture { nil, true, simtestutil.EmptyAppOptions{}, - evmdconfig.DefaultEvmChainID, - evmdconfig.EvmAppOptions, + evmconfig.DefaultChainConfig, ) } diff --git a/evmd/cmd/evmd/config/activators.go b/evmd/cmd/evmd/config/activators.go deleted file mode 100644 index 136f1f2b8..000000000 --- a/evmd/cmd/evmd/config/activators.go +++ /dev/null @@ -1,15 +0,0 @@ -package config - -import ( - "github.com/ethereum/go-ethereum/core/vm" - - "github.com/cosmos/evm/evmd/eips" -) - -// cosmosEVMActivators defines a map of opcode modifiers associated -// with a key defining the corresponding EIP. -var cosmosEVMActivators = map[int]func(*vm.JumpTable){ - 0o000: eips.Enable0000, - 0o001: eips.Enable0001, - 0o002: eips.Enable0002, -} diff --git a/evmd/cmd/evmd/config/evm_app_options.go b/evmd/cmd/evmd/config/evm_app_options.go deleted file mode 100644 index 07e73107d..000000000 --- a/evmd/cmd/evmd/config/evm_app_options.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build !test -// +build !test - -package config - -import ( - evmconfig "github.com/cosmos/evm/config" -) - -// EvmAppOptions allows to setup the global configuration -// for the Cosmos EVM chain. -func EvmAppOptions(chainID uint64) error { - return evmconfig.EvmAppOptionsWithConfig(chainID, ChainsCoinInfo, cosmosEVMActivators) -} diff --git a/evmd/cmd/evmd/main.go b/evmd/cmd/evmd/main.go index cd63910e1..3dad66a57 100644 --- a/evmd/cmd/evmd/main.go +++ b/evmd/cmd/evmd/main.go @@ -5,14 +5,14 @@ import ( "os" "github.com/cosmos/evm/evmd/cmd/evmd/cmd" - evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" + evmconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" ) func main() { rootCmd := cmd.NewRootCmd() - if err := svrcmd.Execute(rootCmd, "evmd", evmdconfig.MustGetDefaultNodeHome()); err != nil { + if err := svrcmd.Execute(rootCmd, "evmd", evmconfig.MustGetDefaultNodeHome()); err != nil { fmt.Fprintln(rootCmd.OutOrStderr(), err) os.Exit(1) } diff --git a/evmd/genesis.go b/evmd/genesis.go index 7d656730b..a21b03423 100644 --- a/evmd/genesis.go +++ b/evmd/genesis.go @@ -3,7 +3,7 @@ package evmd import ( "encoding/json" - "github.com/cosmos/evm/evmd/cmd/evmd/config" + "github.com/cosmos/evm/config" testconstants "github.com/cosmos/evm/testutil/constants" erc20types "github.com/cosmos/evm/x/erc20/types" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" diff --git a/evmd/test_helpers.go b/evmd/test_helpers.go index b7e77d9b3..54c08d721 100644 --- a/evmd/test_helpers.go +++ b/evmd/test_helpers.go @@ -5,14 +5,13 @@ import ( "fmt" "testing" - "github.com/cosmos/evm/evmd/cmd/evmd/config" - testconfig "github.com/cosmos/evm/testutil/config" "github.com/stretchr/testify/require" abci "github.com/cometbft/cometbft/abci/types" cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" + evmconfig "github.com/cosmos/evm/config" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" ibctesting "github.com/cosmos/ibc-go/v10/testing" @@ -44,8 +43,8 @@ func init() { // Set the global SDK config for the tests cfg := sdk.GetConfig() - config.SetBech32Prefixes(cfg) - config.SetBip44CoinType(cfg) + evmconfig.SetBech32Prefixes(cfg) + evmconfig.SetBip44CoinType(cfg) } func setup(withGenesis bool, invCheckPeriod uint, chainID string, evmChainID uint64) (*EVMD, GenesisState) { @@ -55,7 +54,8 @@ func setup(withGenesis bool, invCheckPeriod uint, chainID string, evmChainID uin appOptions[flags.FlagHome] = defaultNodeHome appOptions[server.FlagInvCheckPeriod] = invCheckPeriod - app := NewExampleApp(log.NewNopLogger(), db, nil, true, appOptions, evmChainID, testconfig.EvmAppOptions, baseapp.SetChainID(chainID)) + chainConfig := evmconfig.DefaultChainConfig + app := NewExampleApp(log.NewNopLogger(), db, nil, true, appOptions, chainConfig, baseapp.SetChainID(chainID)) if withGenesis { return app, app.DefaultGenesis() } @@ -124,16 +124,15 @@ func SetupWithGenesisValSet(t *testing.T, chainID string, evmChainID uint64, val // SetupTestingApp initializes the IBC-go testing application // need to keep this design to comply with the ibctesting SetupTestingApp func // and be able to set the chainID for the tests properly -func SetupTestingApp(chainID string, evmChainID uint64) func() (ibctesting.TestingApp, map[string]json.RawMessage) { +func SetupTestingApp(chainConfig evmconfig.ChainConfig) func() (ibctesting.TestingApp, map[string]json.RawMessage) { return func() (ibctesting.TestingApp, map[string]json.RawMessage) { db := dbm.NewMemDB() app := NewExampleApp( log.NewNopLogger(), db, nil, true, simtestutil.NewAppOptionsWithFlagHome(defaultNodeHome), - evmChainID, - testconfig.EvmAppOptions, - baseapp.SetChainID(chainID), + chainConfig, + baseapp.SetChainID(chainConfig.ChainID), ) return app, app.DefaultGenesis() } diff --git a/evmd/eips/eips_test.go b/evmd/tests/eips/eips_test.go similarity index 99% rename from evmd/eips/eips_test.go rename to evmd/tests/eips/eips_test.go index 512881342..151853b17 100644 --- a/evmd/eips/eips_test.go +++ b/evmd/tests/eips/eips_test.go @@ -1,4 +1,4 @@ -package eips_test +package eips import ( "fmt" @@ -13,7 +13,7 @@ import ( //nolint:revive // dot imports are fine for Ginkgo . "github.com/onsi/gomega" - "github.com/cosmos/evm/evmd/eips/testdata" + "github.com/cosmos/evm/evmd/tests/eips/testdata" "github.com/cosmos/evm/evmd/tests/integration" testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" diff --git a/evmd/eips/testdata/Counter.json b/evmd/tests/eips/testdata/Counter.json similarity index 100% rename from evmd/eips/testdata/Counter.json rename to evmd/tests/eips/testdata/Counter.json diff --git a/evmd/eips/testdata/Counter.sol b/evmd/tests/eips/testdata/Counter.sol similarity index 100% rename from evmd/eips/testdata/Counter.sol rename to evmd/tests/eips/testdata/Counter.sol diff --git a/evmd/eips/testdata/CounterFactory.json b/evmd/tests/eips/testdata/CounterFactory.json similarity index 100% rename from evmd/eips/testdata/CounterFactory.json rename to evmd/tests/eips/testdata/CounterFactory.json diff --git a/evmd/eips/testdata/CounterFactory.sol b/evmd/tests/eips/testdata/CounterFactory.sol similarity index 100% rename from evmd/eips/testdata/CounterFactory.sol rename to evmd/tests/eips/testdata/CounterFactory.sol diff --git a/evmd/eips/testdata/contracts.go b/evmd/tests/eips/testdata/contracts.go similarity index 100% rename from evmd/eips/testdata/contracts.go rename to evmd/tests/eips/testdata/contracts.go diff --git a/evmd/tests/integration/create_app.go b/evmd/tests/integration/create_app.go index fd05c278f..d6b52c21c 100644 --- a/evmd/tests/integration/create_app.go +++ b/evmd/tests/integration/create_app.go @@ -5,9 +5,8 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/evm" + "github.com/cosmos/evm/config" "github.com/cosmos/evm/evmd" - "github.com/cosmos/evm/evmd/cmd/evmd/config" - testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/constants" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" ibctesting "github.com/cosmos/ibc-go/v10/testing" @@ -36,14 +35,26 @@ func CreateEvmd(chainID string, evmChainID uint64, customBaseAppOptions ...func( baseAppOptions := append(customBaseAppOptions, baseapp.SetChainID(chainID)) + coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + chainConfig := config.NewChainConfig( + constants.ExampleChainID.ChainID, + evmChainID, + nil, + nil, + nil, + coinInfo, + false, + ) + if err := chainConfig.ApplyChainConfig(); err != nil { + panic(err) + } return evmd.NewExampleApp( logger, db, nil, loadLatest, appOptions, - evmChainID, - testconfig.EvmAppOptions, + chainConfig, baseAppOptions..., ) } @@ -51,14 +62,26 @@ func CreateEvmd(chainID string, evmChainID uint64, customBaseAppOptions ...func( // SetupEvmd initializes a new evmd app with default genesis state. // It is used in IBC integration tests to create a new evmd app instance. func SetupEvmd() (ibctesting.TestingApp, map[string]json.RawMessage) { + coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + chainConfig := config.NewChainConfig( + constants.ExampleChainID.ChainID, + constants.ExampleEIP155ChainID, + nil, + nil, + nil, + coinInfo, + false, + ) + if err := chainConfig.ApplyChainConfig(); err != nil { + panic(err) + } app := evmd.NewExampleApp( log.NewNopLogger(), dbm.NewMemDB(), nil, true, simutils.EmptyAppOptions{}, - constants.ExampleEIP155ChainID, - testconfig.EvmAppOptions, + chainConfig, ) // disable base fee for testing genesisState := app.DefaultGenesis() diff --git a/evmd/tests/integration/x_vm_test.go b/evmd/tests/integration/x_vm_test.go index a95c07391..47a2de85e 100644 --- a/evmd/tests/integration/x_vm_test.go +++ b/evmd/tests/integration/x_vm_test.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/evm/server/config" "github.com/cosmos/evm/tests/integration/x/vm" + "github.com/cosmos/evm/testutil/constants" "github.com/cosmos/evm/testutil/integration/evm/network" "github.com/cosmos/evm/testutil/keyring" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" @@ -32,7 +33,8 @@ func BenchmarkGasEstimation(b *testing.B) { // gh := grpc.NewIntegrationHandler(nw) // tf := factory.New(nw, gh) - chainConfig := types.DefaultChainConfig(nw.GetEIP155ChainID().Uint64()) + coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + chainConfig := types.DefaultChainConfig(nw.GetEIP155ChainID().Uint64(), coinInfo) // get the denom and decimals set on chain initialization // because we'll need to set them again when resetting the chain config displayDenom := types.GetEVMCoinDisplayDenom() diff --git a/evmd/tests/network/network.go b/evmd/tests/network/network.go index 51fb9133f..11702ef65 100644 --- a/evmd/tests/network/network.go +++ b/evmd/tests/network/network.go @@ -27,11 +27,11 @@ import ( cmtclient "github.com/cometbft/cometbft/rpc/client" dbm "github.com/cosmos/cosmos-db" + evmconfig "github.com/cosmos/evm/config" "github.com/cosmos/evm/crypto/hd" "github.com/cosmos/evm/evmd" evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" "github.com/cosmos/evm/server/config" - testconfig "github.com/cosmos/evm/testutil/config" testconstants "github.com/cosmos/evm/testutil/constants" cosmosevmtypes "github.com/cosmos/evm/types" @@ -110,7 +110,20 @@ func DefaultConfig() Config { panic(fmt.Sprintf("failed creating temporary directory: %v", err)) } defer os.RemoveAll(dir) - tempApp := evmd.NewExampleApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simutils.NewAppOptionsWithFlagHome(dir), evmChainID, testconfig.EvmAppOptions, baseapp.SetChainID(chainID)) + coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + chainConfig := evmconfig.NewChainConfig( + chainID, + evmChainID, + nil, + nil, + nil, + coinInfo, + false, + ) + if err := chainConfig.ApplyChainConfig(); err != nil { + panic(err) + } + tempApp := evmd.NewExampleApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simutils.NewAppOptionsWithFlagHome(dir), chainConfig, baseapp.SetChainID(chainID)) cfg := Config{ Codec: tempApp.AppCodec(), @@ -140,11 +153,23 @@ func DefaultConfig() Config { // NewAppConstructor returns a new Cosmos EVM AppConstructor func NewAppConstructor(chainID string, evmChainID uint64) AppConstructor { return func(val Validator) servertypes.Application { + coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + chainConfig := evmconfig.NewChainConfig( + chainID, + evmChainID, + nil, + nil, + nil, + coinInfo, + false, + ) + if err := chainConfig.ApplyChainConfig(); err != nil { + panic(err) + } return evmd.NewExampleApp( val.Ctx.Logger, dbm.NewMemDB(), nil, true, simutils.NewAppOptionsWithFlagHome(val.Ctx.Config.RootDir), - evmChainID, - testconfig.EvmAppOptions, + chainConfig, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), baseapp.SetChainID(chainID), diff --git a/rpc/backend/call_tx.go b/rpc/backend/call_tx.go index e444cc9b2..bb2d29b75 100644 --- a/rpc/backend/call_tx.go +++ b/rpc/backend/call_tx.go @@ -42,7 +42,12 @@ func (b *Backend) Resend(args evmtypes.TransactionArgs, gasPrice *hexutil.Big, g // signers to be backwards-compatible with old transactions. cfg := b.ChainConfig() if cfg == nil { - cfg = evmtypes.DefaultChainConfig(b.EvmChainID.Uint64()).EthereumConfig(nil) + coinInfo := evmtypes.EvmCoinInfo{ + DisplayDenom: evmtypes.GetEVMCoinDisplayDenom(), + Decimals: evmtypes.GetEVMCoinDecimals(), + ExtendedDecimals: evmtypes.GetEVMCoinExtendedDecimals(), + } + cfg = evmtypes.DefaultChainConfig(b.EvmChainID.Uint64(), coinInfo).EthereumConfig(nil) } signer := ethtypes.LatestSigner(cfg) diff --git a/tests/integration/ante/ante_test_suite.go b/tests/integration/ante/ante_test_suite.go index 0fb9db71c..03d5cf70d 100644 --- a/tests/integration/ante/ante_test_suite.go +++ b/tests/integration/ante/ante_test_suite.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/suite" + "github.com/cosmos/evm/testutil/constants" "github.com/cosmos/evm/testutil/integration" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" @@ -99,7 +100,8 @@ func (s *AnteTestSuite) SetupTest() { s.Require().NotNil(s.network.App.AppCodec()) - chainConfig := evmtypes.DefaultChainConfig(s.network.GetEIP155ChainID().Uint64()) + coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + chainConfig := evmtypes.DefaultChainConfig(s.network.GetEIP155ChainID().Uint64(), coinInfo) if !s.enableLondonHF { maxInt := sdkmath.NewInt(math.MaxInt64) chainConfig.LondonBlock = &maxInt diff --git a/tests/integration/x/vm/test_grpc_query.go b/tests/integration/x/vm/test_grpc_query.go index f5c65f9c5..89aa28ff6 100644 --- a/tests/integration/x/vm/test_grpc_query.go +++ b/tests/integration/x/vm/test_grpc_query.go @@ -1637,7 +1637,7 @@ func (s *KeeperTestSuite) TestQueryBaseFee() { Decimals: types.GetEVMCoinDecimals(), ExtendedDecimals: types.GetEVMCoinExtendedDecimals(), } - chainConfig := types.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64()) + chainConfig := types.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64(), coinInfo) for _, tc := range testCases { s.Run(tc.name, func() { diff --git a/testutil/config/config_testing.go b/testutil/config/config_testing.go index 9781099fa..a0cd819e5 100644 --- a/testutil/config/config_testing.go +++ b/testutil/config/config_testing.go @@ -52,5 +52,22 @@ var TestChainsCoinInfo = map[uint64]evmtypes.EvmCoinInfo{ // EvmAppOptions allows to setup the global configuration // for the Cosmos EVM chain. func EvmAppOptions(chainID uint64) error { - return evmconfig.EvmAppOptionsWithConfigWithReset(chainID, TestChainsCoinInfo, cosmosEVMActivators, true) + coinInfo, exists := TestChainsCoinInfo[chainID] + if !exists { + coinInfo = evmtypes.EvmCoinInfo{ + DisplayDenom: "test", + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, + } + } + chainConfig := evmconfig.NewChainConfig( + "test", + chainID, + cosmosEVMActivators, + nil, + nil, + coinInfo, + true, + ) + return chainConfig.ApplyChainConfig() } diff --git a/testutil/ibc/coordinator.go b/testutil/ibc/coordinator.go index c4823df48..e424727bb 100644 --- a/testutil/ibc/coordinator.go +++ b/testutil/ibc/coordinator.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/evm/testutil/config" + evmconfig "github.com/cosmos/evm/config" ibctesting "github.com/cosmos/ibc-go/v10/testing" ) @@ -41,8 +41,9 @@ func NewCoordinator(t *testing.T, nEVMChains, mCosmosChains int, evmAppCreator i for i := 1; i <= nEVMChains; i++ { chainID := GetChainID(i) evmChainID, err := strconv.ParseUint(GetEvmChainID(i), 10, 64) + chainConfig := evmconfig.NewTestChainConfig(evmChainID) require.NoError(t, err) - require.NoError(t, config.EvmAppOptions(evmChainID)) + require.NoError(t, chainConfig.ApplyChainConfig()) // setup EVM chains chains[strconv.FormatUint(evmChainID, 10)] = NewTestChain(t, true, coord, chainID) } diff --git a/x/precisebank/keeper/keeper_test.go b/x/precisebank/keeper/keeper_test.go index 75a4656ef..f1ce34828 100644 --- a/x/precisebank/keeper/keeper_test.go +++ b/x/precisebank/keeper/keeper_test.go @@ -3,8 +3,8 @@ package keeper_test import ( "testing" + evmconfig "github.com/cosmos/evm/config" evmosencoding "github.com/cosmos/evm/encoding" - "github.com/cosmos/evm/testutil/config" testconstants "github.com/cosmos/evm/testutil/constants" "github.com/cosmos/evm/x/precisebank/keeper" "github.com/cosmos/evm/x/precisebank/types" @@ -44,7 +44,8 @@ func newMockedTestData(t *testing.T) testData { cfg := evmosencoding.MakeConfig(chainID) cdc := cfg.Codec k := keeper.NewKeeper(cdc, storeKey, bk, ak) - err := config.EvmAppOptions(chainID) + chainConfig := evmconfig.NewTestChainConfig(chainID) + err := chainConfig.ApplyChainConfig() if err != nil { return testData{} } diff --git a/x/vm/types/chain_config_test.go b/x/vm/types/chain_config_test.go index 827fcd31d..18b106a5c 100644 --- a/x/vm/types/chain_config_test.go +++ b/x/vm/types/chain_config_test.go @@ -21,7 +21,7 @@ func TestChainConfigValidate(t *testing.T) { config types.ChainConfig expError bool }{ - {"default", *types.DefaultChainConfig(0), false}, + {"default", *types.DefaultChainConfig(0, types.EvmCoinInfo{DisplayDenom: "test", Decimals: types.EighteenDecimals, ExtendedDecimals: types.EighteenDecimals}), false}, { "valid", types.ChainConfig{ diff --git a/x/vm/types/config_testing.go b/x/vm/types/config_testing.go index dc95ff1e7..8ed238984 100644 --- a/x/vm/types/config_testing.go +++ b/x/vm/types/config_testing.go @@ -56,14 +56,22 @@ func setTestChainConfig(cc *ChainConfig) error { if testChainConfig != nil { return errors.New("chainConfig already set. Cannot set again the chainConfig. Call the configurators ResetTestConfig method before configuring a new chain.") } - config := DefaultChainConfig(0) - if cc != nil { - config = cc + + // If no chain config is provided, create a default one for testing + if cc == nil { + config := DefaultChainConfig(0, EvmCoinInfo{ + DisplayDenom: "test", + Decimals: EighteenDecimals, + ExtendedDecimals: EighteenDecimals, + }) + cc = config } - if err := config.Validate(); err != nil { + + if err := cc.Validate(); err != nil { return err } - testChainConfig = config + + testChainConfig = cc return nil } diff --git a/x/vm/types/msg_test.go b/x/vm/types/msg_test.go index a16dd0762..4684ef741 100644 --- a/x/vm/types/msg_test.go +++ b/x/vm/types/msg_test.go @@ -13,8 +13,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/suite" + evmconfig "github.com/cosmos/evm/config" "github.com/cosmos/evm/encoding" - "github.com/cosmos/evm/testutil/config" testconstants "github.com/cosmos/evm/testutil/constants" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/vm/types" @@ -54,7 +54,8 @@ func (suite *MsgsTestSuite) SetupTest() { encodingConfig := encoding.MakeConfig(suite.chainID.Uint64()) suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig) - err := config.EvmAppOptions(9001) + chainConfig := evmconfig.NewTestChainConfig(9001) + err := chainConfig.ApplyChainConfig() suite.Require().NoError(err) } From b80b4b7b9a1c47f2cd027c9bdb2128762c78436b Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 16:25:56 -0400 Subject: [PATCH 13/23] move constants to config --- config/chain_config.go | 7 +- config/server_app_options.go | 3 +- testutil/config/activators.go | 13 --- testutil/config/config.go | 21 +++++ testutil/config/config_testing.go | 24 ----- testutil/config/constants.go | 132 +++++++++++++++++++++++---- testutil/config/eips.go | 33 ------- testutil/constants/constants.go | 127 -------------------------- testutil/constants/constants_test.go | 34 ------- 9 files changed, 143 insertions(+), 251 deletions(-) delete mode 100644 testutil/config/activators.go delete mode 100644 testutil/config/eips.go delete mode 100644 testutil/constants/constants.go delete mode 100644 testutil/constants/constants_test.go diff --git a/config/chain_config.go b/config/chain_config.go index 6827dc93c..996e6ebb0 100644 --- a/config/chain_config.go +++ b/config/chain_config.go @@ -3,10 +3,13 @@ package config import ( "fmt" + "github.com/ethereum/go-ethereum/core/vm" + + "github.com/cosmos/evm/x/vm/types" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/evm/x/vm/types" - "github.com/ethereum/go-ethereum/core/vm" ) type ChainConfig struct { diff --git a/config/server_app_options.go b/config/server_app_options.go index 47551f902..89d4db633 100644 --- a/config/server_app_options.go +++ b/config/server_app_options.go @@ -8,11 +8,12 @@ import ( "github.com/holiman/uint256" "github.com/spf13/cast" - "cosmossdk.io/log" "github.com/cosmos/evm/config/eips" srvflags "github.com/cosmos/evm/server/flags" evmtypes "github.com/cosmos/evm/x/vm/types" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/testutil/config/activators.go b/testutil/config/activators.go deleted file mode 100644 index a88b99e69..000000000 --- a/testutil/config/activators.go +++ /dev/null @@ -1,13 +0,0 @@ -package config - -import ( - "github.com/ethereum/go-ethereum/core/vm" -) - -// cosmosEVMActivators defines a map of opcode modifiers associated -// with a key defining the corresponding EIP. -var cosmosEVMActivators = map[int]func(*vm.JumpTable){ - 0o000: Enable0000, - 0o001: Enable0001, - 0o002: Enable0002, -} diff --git a/testutil/config/config.go b/testutil/config/config.go index 54fcdd69b..01d343669 100644 --- a/testutil/config/config.go +++ b/testutil/config/config.go @@ -48,6 +48,27 @@ const ( EVMChainID = 262144 ) +const ( + // ExampleChainDenom is the denomination of the Cosmos EVM example chain's base coin. + ExampleChainDenom = "aatom" + // ExampleDisplayDenom is the display denomination of the Cosmos EVM example chain's base coin. + ExampleDisplayDenom = "atom" + // EighteenDecimalsChainID is the chain ID for the 18 decimals chain. + EighteenDecimalsChainID = 9001 + // SixDecimalsChainID is the chain ID for the 6 decimals chain. + SixDecimalsChainID = 9002 + // TwelveDecimalsChainID is the chain ID for the 12 decimals chain. + TwelveDecimalsChainID = 9003 + // TwoDecimalsChainID is the chain ID for the 2 decimals chain. + TwoDecimalsChainID = 9004 + // TestChainID1 is test chain IDs for IBC E2E test + TestChainID1 = 9005 + // TestChainID2 is test chain IDs for IBC E2E test + TestChainID2 = 9006 + // WEVMOSContractMainnet is the WEVMOS contract address for mainnet + WEVMOSContractMainnet = "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517" +) + // SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings. func SetBech32Prefixes(config *sdk.Config) { config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub) diff --git a/testutil/config/config_testing.go b/testutil/config/config_testing.go index a0cd819e5..408647968 100644 --- a/testutil/config/config_testing.go +++ b/testutil/config/config_testing.go @@ -4,7 +4,6 @@ package config import ( - evmconfig "github.com/cosmos/evm/config" evmtypes "github.com/cosmos/evm/x/vm/types" ) @@ -48,26 +47,3 @@ var TestChainsCoinInfo = map[uint64]evmtypes.EvmCoinInfo{ ExtendedDecimals: evmtypes.EighteenDecimals, }, } - -// EvmAppOptions allows to setup the global configuration -// for the Cosmos EVM chain. -func EvmAppOptions(chainID uint64) error { - coinInfo, exists := TestChainsCoinInfo[chainID] - if !exists { - coinInfo = evmtypes.EvmCoinInfo{ - DisplayDenom: "test", - Decimals: evmtypes.EighteenDecimals, - ExtendedDecimals: evmtypes.EighteenDecimals, - } - } - chainConfig := evmconfig.NewChainConfig( - "test", - chainID, - cosmosEVMActivators, - nil, - nil, - coinInfo, - true, - ) - return chainConfig.ApplyChainConfig() -} diff --git a/testutil/config/constants.go b/testutil/config/constants.go index 3a7354cd9..c600c34f1 100644 --- a/testutil/config/constants.go +++ b/testutil/config/constants.go @@ -1,29 +1,127 @@ package config -const ( - // ExampleChainDenom is the denomination of the Cosmos EVM example chain's base coin. - ExampleChainDenom = "aatom" +import ( + erc20types "github.com/cosmos/evm/x/erc20/types" + evmtypes "github.com/cosmos/evm/x/vm/types" - // ExampleDisplayDenom is the display denomination of the Cosmos EVM example chain's base coin. - ExampleDisplayDenom = "atom" + "cosmossdk.io/math" +) - // EighteenDecimalsChainID is the chain ID for the 18 decimals chain. - EighteenDecimalsChainID = 9001 +const ( + // DefaultGasPrice is used in testing as the default to use for transactions + DefaultGasPrice = 20 - // SixDecimalsChainID is the chain ID for the 6 decimals chain. - SixDecimalsChainID = 9002 + // ExampleAttoDenom provides an example denom for use in tests + ExampleAttoDenom = "aatom" - // TwelveDecimalsChainID is the chain ID for the 12 decimals chain. - TwelveDecimalsChainID = 9003 + // ExampleMicroDenom provides an example denom for use in tests + ExampleMicroDenom = "uatom" - // TwoDecimalsChainID is the chain ID for the 2 decimals chain. - TwoDecimalsChainID = 9004 + // ExampleDisplayDenom provides an example display denom for use in tests + ExampleDisplayDenom = "atom" - // TestChainID1 is test chain IDs for IBC E2E test - TestChainID1 = 9005 - // TestChainID2 is test chain IDs for IBC E2E test - TestChainID2 = 9006 + // ExampleBech32Prefix provides an example Bech32 prefix for use in tests + ExampleBech32Prefix = "cosmos" + + // ExampleEIP155ChainID provides an example EIP-155 chain ID for use in tests + ExampleEIP155ChainID = 9001 // WEVMOSContractMainnet is the WEVMOS contract address for mainnet WEVMOSContractMainnet = "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517" + // WEVMOSContractTestnet is the WEVMOS contract address for testnet + WEVMOSContractTestnet = "0xcc491f589b45d4a3c679016195b3fb87d7848210" + // ExampleEvmAddress1 is the example EVM address + ExampleEvmAddressAlice = "0x1e0DE5DB1a39F99cBc67B00fA3415181b3509e42" + // ExampleEvmAddress2 is the example EVM address + ExampleEvmAddressBob = "0x0AFc8e15F0A74E98d0AEC6C67389D2231384D4B2" +) + +type ChainID struct { + ChainID string `json:"chain_id"` + EVMChainID uint64 `json:"evm_chain_id"` +} + +var ( + // ExampleChainIDPrefix provides a chain ID prefix for EIP-155 that can be used in tests + ExampleChainIDPrefix = "cosmos" + + // ExampleChainID provides a chain ID that can be used in tests + ExampleChainID = ChainID{ + ChainID: ExampleChainIDPrefix + "-1", + EVMChainID: 9001, + } + + // SixDecimalsChainID provides a chain ID which is being set up with 6 decimals + ExampleSixDecimalsChainID = ChainID{ + ChainID: "ossix-2", + EVMChainID: 9002, + } + + // TwelveDecimalsChainID provides a chain ID which is being set up with 12 decimals + ExampleTwelveDecimalsChainID = ChainID{ + ChainID: "ostwelve-3", + EVMChainID: 9003, + } + + // TwoDecimalsChainID provides a chain ID which is being set up with 2 decimals + ExampleTwoDecimalsChainID = ChainID{ + ChainID: "ostwo-4", + EVMChainID: 9004, + } + + // ExampleChainCoinInfo provides the coin info for the example chain + // + // It is a map of the chain id and its corresponding EvmCoinInfo + // that allows initializing the app with different coin info based on the + // chain id + ExampleChainCoinInfo = map[ChainID]evmtypes.EvmCoinInfo{ + ExampleChainID: { + DisplayDenom: ExampleDisplayDenom, + Decimals: evmtypes.EighteenDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, + }, + ExampleSixDecimalsChainID: { + DisplayDenom: "test", + Decimals: evmtypes.SixDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, + }, + ExampleTwelveDecimalsChainID: { + DisplayDenom: "test2", + Decimals: evmtypes.TwelveDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, + }, + ExampleTwoDecimalsChainID: { + DisplayDenom: "test3", + Decimals: evmtypes.TwoDecimals, + ExtendedDecimals: evmtypes.EighteenDecimals, + }, + } + + // OtherCoinDenoms provides a list of other coin denoms that can be used in tests + OtherCoinDenoms = []string{ + "foo", + "bar", + } + + // ExampleTokenPairs creates a slice of token pairs, that contains a pair for the native denom of the example chain + // implementation. + ExampleTokenPairs = []erc20types.TokenPair{ + { + Erc20Address: WEVMOSContractMainnet, + Denom: ExampleAttoDenom, + Enabled: true, + ContractOwner: erc20types.OWNER_MODULE, + }, + } + + // ExampleAllowances creates a slice of allowances, that contains an allowance for the native denom of the example chain + // implementation. + ExampleAllowances = []erc20types.Allowance{ + { + Erc20Address: WEVMOSContractMainnet, + Owner: ExampleEvmAddressAlice, + Spender: ExampleEvmAddressBob, + Value: math.NewInt(100), + }, + } ) diff --git a/testutil/config/eips.go b/testutil/config/eips.go deleted file mode 100644 index a1157805e..000000000 --- a/testutil/config/eips.go +++ /dev/null @@ -1,33 +0,0 @@ -package config - -import ( - "github.com/ethereum/go-ethereum/core/vm" -) - -var ( - Multiplier = uint64(10) - SstoreConstantGas = uint64(500) -) - -// enable0000 contains the logic to modify the CREATE and CREATE2 opcodes -// constant gas value. -func Enable0000(jt *vm.JumpTable) { - currentValCreate := jt[vm.CREATE].GetConstantGas() - jt[vm.CREATE].SetConstantGas(currentValCreate * Multiplier) - - currentValCreate2 := jt[vm.CREATE2].GetConstantGas() - jt[vm.CREATE2].SetConstantGas(currentValCreate2 * Multiplier) -} - -// enable0001 contains the logic to modify the CALL opcode -// constant gas value. -func Enable0001(jt *vm.JumpTable) { - currentVal := jt[vm.CALL].GetConstantGas() - jt[vm.CALL].SetConstantGas(currentVal * Multiplier) -} - -// enable0002 contains the logic to modify the SSTORE opcode -// constant gas value. -func Enable0002(jt *vm.JumpTable) { - jt[vm.SSTORE].SetConstantGas(SstoreConstantGas) -} diff --git a/testutil/constants/constants.go b/testutil/constants/constants.go deleted file mode 100644 index caba3030c..000000000 --- a/testutil/constants/constants.go +++ /dev/null @@ -1,127 +0,0 @@ -package constants - -import ( - erc20types "github.com/cosmos/evm/x/erc20/types" - evmtypes "github.com/cosmos/evm/x/vm/types" - - "cosmossdk.io/math" -) - -const ( - // DefaultGasPrice is used in testing as the default to use for transactions - DefaultGasPrice = 20 - - // ExampleAttoDenom provides an example denom for use in tests - ExampleAttoDenom = "aatom" - - // ExampleMicroDenom provides an example denom for use in tests - ExampleMicroDenom = "uatom" - - // ExampleDisplayDenom provides an example display denom for use in tests - ExampleDisplayDenom = "atom" - - // ExampleBech32Prefix provides an example Bech32 prefix for use in tests - ExampleBech32Prefix = "cosmos" - - // ExampleEIP155ChainID provides an example EIP-155 chain ID for use in tests - ExampleEIP155ChainID = 9001 - - // WEVMOSContractMainnet is the WEVMOS contract address for mainnet - WEVMOSContractMainnet = "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517" - // WEVMOSContractTestnet is the WEVMOS contract address for testnet - WEVMOSContractTestnet = "0xcc491f589b45d4a3c679016195b3fb87d7848210" - // ExampleEvmAddress1 is the example EVM address - ExampleEvmAddressAlice = "0x1e0DE5DB1a39F99cBc67B00fA3415181b3509e42" - // ExampleEvmAddress2 is the example EVM address - ExampleEvmAddressBob = "0x0AFc8e15F0A74E98d0AEC6C67389D2231384D4B2" -) - -type ChainID struct { - ChainID string `json:"chain_id"` - EVMChainID uint64 `json:"evm_chain_id"` -} - -var ( - // ExampleChainIDPrefix provides a chain ID prefix for EIP-155 that can be used in tests - ExampleChainIDPrefix = "cosmos" - - // ExampleChainID provides a chain ID that can be used in tests - ExampleChainID = ChainID{ - ChainID: ExampleChainIDPrefix + "-1", - EVMChainID: 9001, - } - - // SixDecimalsChainID provides a chain ID which is being set up with 6 decimals - SixDecimalsChainID = ChainID{ - ChainID: "ossix-2", - EVMChainID: 9002, - } - - // TwelveDecimalsChainID provides a chain ID which is being set up with 12 decimals - TwelveDecimalsChainID = ChainID{ - ChainID: "ostwelve-3", - EVMChainID: 9003, - } - - // TwoDecimalsChainID provides a chain ID which is being set up with 2 decimals - TwoDecimalsChainID = ChainID{ - ChainID: "ostwo-4", - EVMChainID: 9004, - } - - // ExampleChainCoinInfo provides the coin info for the example chain - // - // It is a map of the chain id and its corresponding EvmCoinInfo - // that allows initializing the app with different coin info based on the - // chain id - ExampleChainCoinInfo = map[ChainID]evmtypes.EvmCoinInfo{ - ExampleChainID: { - DisplayDenom: ExampleDisplayDenom, - Decimals: evmtypes.EighteenDecimals, - ExtendedDecimals: evmtypes.EighteenDecimals, - }, - SixDecimalsChainID: { - DisplayDenom: "test", - Decimals: evmtypes.SixDecimals, - ExtendedDecimals: evmtypes.EighteenDecimals, - }, - TwelveDecimalsChainID: { - DisplayDenom: "test2", - Decimals: evmtypes.TwelveDecimals, - ExtendedDecimals: evmtypes.EighteenDecimals, - }, - TwoDecimalsChainID: { - DisplayDenom: "test3", - Decimals: evmtypes.TwoDecimals, - ExtendedDecimals: evmtypes.EighteenDecimals, - }, - } - - // OtherCoinDenoms provides a list of other coin denoms that can be used in tests - OtherCoinDenoms = []string{ - "foo", - "bar", - } - - // ExampleTokenPairs creates a slice of token pairs, that contains a pair for the native denom of the example chain - // implementation. - ExampleTokenPairs = []erc20types.TokenPair{ - { - Erc20Address: WEVMOSContractMainnet, - Denom: ExampleAttoDenom, - Enabled: true, - ContractOwner: erc20types.OWNER_MODULE, - }, - } - - // ExampleAllowances creates a slice of allowances, that contains an allowance for the native denom of the example chain - // implementation. - ExampleAllowances = []erc20types.Allowance{ - { - Erc20Address: WEVMOSContractMainnet, - Owner: ExampleEvmAddressAlice, - Spender: ExampleEvmAddressBob, - Value: math.NewInt(100), - }, - } -) diff --git a/testutil/constants/constants_test.go b/testutil/constants/constants_test.go deleted file mode 100644 index 30c951cd4..000000000 --- a/testutil/constants/constants_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package constants_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/evm/testutil/config" - "github.com/cosmos/evm/testutil/constants" -) - -func TestRequireSameTestDenom(t *testing.T) { - require.Equal(t, - constants.ExampleAttoDenom, - config.ExampleChainDenom, - "test denoms should be the same across the repo", - ) -} - -func TestRequireSameTestBech32Prefix(t *testing.T) { - require.Equal(t, - constants.ExampleBech32Prefix, - config.Bech32Prefix, - "bech32 prefixes should be the same across the repo", - ) -} - -func TestRequireSameWEVMOSMainnet(t *testing.T) { - require.Equal(t, - constants.WEVMOSContractMainnet, - config.WEVMOSContractMainnet, - "wevmos contract addresses should be the same across the repo", - ) -} From db26c466723a3ee93c254e09f3261cd1d3dba865 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 17:34:25 -0400 Subject: [PATCH 14/23] consolidate testutil constants package into config --- ante/cosmos/authz_test.go | 6 +- ante/evm/fee_checker_test.go | 14 +-- config/eips/activators.go | 16 ++- ethereum/eip712/preprocess_test.go | 10 +- evmd/genesis.go | 6 +- evmd/tests/eips/eips_test.go | 8 +- evmd/tests/integration/create_app.go | 12 +-- evmd/tests/integration/x_vm_test.go | 4 +- evmd/tests/ledger/evmosd_suite_test.go | 6 +- evmd/tests/network/network.go | 12 +-- ibc/utils_test.go | 4 +- precompiles/common/balance_handler_test.go | 6 +- precompiles/common/types_test.go | 6 +- rpc/backend/node_info.go | 4 +- rpc/backend/tx_info_test.go | 12 +-- server/config/config_test.go | 6 +- tests/integration/ante/ante_test_suite.go | 4 +- tests/integration/ante/evm_ante_test_suite.go | 10 +- .../ante/evm_unit_ante_test_suite.go | 6 +- tests/integration/ante/test_evm_ante.go | 54 +++++----- tests/integration/ante/test_evm_fee_market.go | 8 +- .../ante/test_evm_unit_04_validate.go | 10 +- .../test_evm_unit_06_account_verification.go | 4 +- .../ante/test_evm_unit_08_gas_consume.go | 6 +- .../test_evm_unit_09_increment_sequence.go | 4 +- .../ante/test_evm_unit_10_gas_wanted.go | 4 +- tests/integration/ante/test_integration.go | 4 +- tests/integration/ante/test_min_gas_price.go | 4 +- tests/integration/eip712/test_eip712.go | 6 +- tests/integration/indexer/test_kv_indexer.go | 4 +- tests/integration/mempool/test_setup.go | 6 +- .../distribution/test_distribution.go | 18 ++-- .../precompiles/distribution/test_event.go | 24 ++--- .../distribution/test_integration.go | 8 +- .../precompiles/distribution/test_setup.go | 12 +-- .../precompiles/distribution/test_tx.go | 46 ++++----- .../precompiles/erc20/test_integration.go | 6 +- .../integration/precompiles/gov/test_query.go | 4 +- .../integration/precompiles/gov/test_setup.go | 10 +- .../precompiles/staking/test_integration.go | 6 +- .../precompiles/staking/test_setup.go | 4 +- .../precompiles/staking/test_staking.go | 10 +- .../precompiles/werc20/test_events.go | 16 +-- .../precompiles/werc20/test_integration.go | 20 ++-- .../rpc/backend/test_backend_suite.go | 4 +- tests/integration/rpc/backend/test_call_tx.go | 4 +- .../rpc/backend/test_chain_info.go | 4 +- .../rpc/backend/test_evm_query_client.go | 10 +- .../integration/rpc/backend/test_node_info.go | 8 +- tests/integration/testutil/test_config.go | 16 +-- .../integration/wallets/test_ledger_suite.go | 6 +- tests/integration/x/erc20/test_grpc_query.go | 8 +- tests/integration/x/erc20/test_precompiles.go | 10 +- tests/integration/x/erc20/test_token_pairs.go | 8 +- .../x/precisebank/test_burn_integration.go | 12 +-- .../integration/x/precisebank/test_genesis.go | 6 +- .../x/precisebank/test_integration.go | 26 ++--- .../x/precisebank/test_mint_integration.go | 12 +-- .../x/precisebank/test_send_integration.go | 20 ++-- tests/integration/x/precisebank/test_setup.go | 6 +- tests/integration/x/vm/keeper_test_suite.go | 4 +- tests/integration/x/vm/test_benchmark.go | 6 +- tests/integration/x/vm/test_call_evm.go | 6 +- tests/integration/x/vm/test_grpc_query.go | 6 +- .../x/vm/test_iterate_contracts.go | 4 +- tests/integration/x/vm/test_statedb.go | 4 +- testutil/config/config.go | 2 - testutil/config/constants.go | 3 - testutil/config/genesis.go | 5 +- testutil/integration/evm/network/amounts.go | 6 +- .../evm/network/chain_id_modifiers.go | 10 +- testutil/integration/evm/network/coins.go | 4 +- testutil/integration/evm/network/config.go | 14 +-- .../evm/network/example_contracts.go | 10 +- testutil/integration/evm/network/setup.go | 8 +- testutil/integration/evm/utils/genesis.go | 10 +- testutil/tx/cosmos.go | 6 +- utils/utils_test.go | 6 +- x/erc20/types/genesis_test.go | 98 +++++++++---------- x/precisebank/keeper/keeper_test.go | 4 +- x/precisebank/types/extended_balance_test.go | 4 +- x/precisebank/types/genesis_test.go | 6 +- x/vm/types/evm_config_test.go | 14 +-- x/vm/types/msg_test.go | 6 +- x/vm/types/scaling_test.go | 18 ++-- x/vm/wrappers/bank_test.go | 26 ++--- x/vm/wrappers/feemarket_test.go | 32 +++--- 87 files changed, 462 insertions(+), 470 deletions(-) diff --git a/ante/cosmos/authz_test.go b/ante/cosmos/authz_test.go index 1930f2077..52e62a184 100644 --- a/ante/cosmos/authz_test.go +++ b/ante/cosmos/authz_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/evm/ante/cosmos" "github.com/cosmos/evm/encoding" "github.com/cosmos/evm/testutil" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" evmtypes "github.com/cosmos/evm/x/vm/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -22,11 +22,11 @@ import ( func TestAuthzLimiterDecorator(t *testing.T) { evmConfigurator := evmtypes.NewEvmConfig(). - WithEVMCoinInfo(constants.ExampleChainCoinInfo[constants.ExampleChainID]) + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]) err := evmConfigurator.Apply() require.NoError(t, err) - encodingCfg := encoding.MakeConfig(constants.ExampleChainID.EVMChainID) + encodingCfg := encoding.MakeConfig(testconfig.ExampleChainID.EVMChainID) txCfg := encodingCfg.TxConfig testPrivKeys, testAddresses, err := testutil.GeneratePrivKeyAddressPairs(5) require.NoError(t, err) diff --git a/ante/evm/fee_checker_test.go b/ante/evm/fee_checker_test.go index b75c0c1a9..903f6e8cf 100644 --- a/ante/evm/fee_checker_test.go +++ b/ante/evm/fee_checker_test.go @@ -12,7 +12,7 @@ import ( anteinterfaces "github.com/cosmos/evm/ante/interfaces" evmconfig "github.com/cosmos/evm/config" "github.com/cosmos/evm/encoding" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/types" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -111,7 +111,7 @@ func TestSDKTxFeeChecker(t *testing.T) { func() sdk.FeeTx { txBuilder := encodingConfig.TxConfig.NewTxBuilder() txBuilder.SetGasLimit(1) - txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(10)))) + txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(10)))) return txBuilder.GetTx() }, false, @@ -156,7 +156,7 @@ func TestSDKTxFeeChecker(t *testing.T) { func() sdk.FeeTx { txBuilder := encodingConfig.TxConfig.NewTxBuilder() txBuilder.SetGasLimit(1) - txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(10)))) + txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(10)))) return txBuilder.GetTx() }, true, @@ -173,7 +173,7 @@ func TestSDKTxFeeChecker(t *testing.T) { func() sdk.FeeTx { txBuilder := encodingConfig.TxConfig.NewTxBuilder() txBuilder.SetGasLimit(1) - txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction).Add(math.NewInt(10))))) + txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction).Add(math.NewInt(10))))) return txBuilder.GetTx() }, true, @@ -190,7 +190,7 @@ func TestSDKTxFeeChecker(t *testing.T) { func() sdk.FeeTx { txBuilder := encodingConfig.TxConfig.NewTxBuilder().(authtx.ExtensionOptionsTxBuilder) txBuilder.SetGasLimit(1) - txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction)))) + txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction)))) option, err := codectypes.NewAnyWithValue(&types.ExtensionOptionDynamicFeeTx{}) require.NoError(t, err) @@ -211,7 +211,7 @@ func TestSDKTxFeeChecker(t *testing.T) { func() sdk.FeeTx { txBuilder := encodingConfig.TxConfig.NewTxBuilder().(authtx.ExtensionOptionsTxBuilder) txBuilder.SetGasLimit(1) - txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction).Add(math.NewInt(10))))) + txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction).Add(math.NewInt(10))))) option, err := codectypes.NewAnyWithValue(&types.ExtensionOptionDynamicFeeTx{ MaxPriorityPrice: math.LegacyNewDec(5).MulInt(evmtypes.DefaultPriorityReduction), @@ -234,7 +234,7 @@ func TestSDKTxFeeChecker(t *testing.T) { func() sdk.FeeTx { txBuilder := encodingConfig.TxConfig.NewTxBuilder().(authtx.ExtensionOptionsTxBuilder) txBuilder.SetGasLimit(1) - txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction).Add(math.NewInt(10))))) + txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(10).Mul(evmtypes.DefaultPriorityReduction).Add(math.NewInt(10))))) // set negative priority fee option, err := codectypes.NewAnyWithValue(&types.ExtensionOptionDynamicFeeTx{ diff --git a/config/eips/activators.go b/config/eips/activators.go index 6536179e4..f349cddea 100644 --- a/config/eips/activators.go +++ b/config/eips/activators.go @@ -4,12 +4,10 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) -var ( - // CosmosEVMActivators defines a map of opcode modifiers associated - // with a key defining the corresponding EIP. - CosmosEVMActivators = map[int]func(*vm.JumpTable){ - 0o000: Enable0000, - 0o001: Enable0001, - 0o002: Enable0002, - } -) +// CosmosEVMActivators defines a map of opcode modifiers associated +// with a key defining the corresponding EIP. +var CosmosEVMActivators = map[int]func(*vm.JumpTable){ + 0o000: Enable0000, + 0o001: Enable0001, + 0o002: Enable0002, +} diff --git a/ethereum/eip712/preprocess_test.go b/ethereum/eip712/preprocess_test.go index e355d6787..1a9ffbdec 100644 --- a/ethereum/eip712/preprocess_test.go +++ b/ethereum/eip712/preprocess_test.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/evm/encoding" "github.com/cosmos/evm/ethereum/eip712" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -30,7 +30,7 @@ import ( // Testing Constants var ( // chainID is used in EIP-712 tests. - chainID = uint64(constants.ExampleEIP155ChainID) + chainID = uint64(testconfig.ExampleEIP155ChainID) ctx = client.Context{}.WithTxConfig( encoding.MakeConfig(chainID).TxConfig, @@ -39,7 +39,7 @@ var ( // feePayerAddress is the address of the fee payer used in EIP-712 tests. feePayerAddress = fmt.Sprintf( "%s17xpfvakm2amg962yls6f84z3kell8c5lserqta", - constants.ExampleBech32Prefix, + testconfig.ExampleBech32Prefix, ) ) @@ -55,9 +55,9 @@ type TestCaseStruct struct { func TestLedgerPreprocessing(t *testing.T) { // Update bech32 prefix - sdk.GetConfig().SetBech32PrefixForAccount(constants.ExampleBech32Prefix, "") + sdk.GetConfig().SetBech32PrefixForAccount(testconfig.ExampleBech32Prefix, "") evmConfigurator := evmtypes.NewEvmConfig(). - WithEVMCoinInfo(constants.ExampleChainCoinInfo[constants.ExampleChainID]) + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]) err := evmConfigurator.Apply() require.NoError(t, err) diff --git a/evmd/genesis.go b/evmd/genesis.go index a21b03423..01ef01b32 100644 --- a/evmd/genesis.go +++ b/evmd/genesis.go @@ -4,7 +4,7 @@ import ( "encoding/json" "github.com/cosmos/evm/config" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" erc20types "github.com/cosmos/evm/x/erc20/types" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -39,8 +39,8 @@ func NewEVMGenesisState() *evmtypes.GenesisState { // which is the base denomination of the chain (i.e. the WEVMOS contract). func NewErc20GenesisState() *erc20types.GenesisState { erc20GenState := erc20types.DefaultGenesisState() - erc20GenState.TokenPairs = testconstants.ExampleTokenPairs - erc20GenState.NativePrecompiles = []string{testconstants.WEVMOSContractMainnet} + erc20GenState.TokenPairs = testconfig.ExampleTokenPairs + erc20GenState.NativePrecompiles = []string{testconfig.WEVMOSContractMainnet} return erc20GenState } diff --git a/evmd/tests/eips/eips_test.go b/evmd/tests/eips/eips_test.go index 151853b17..8e0cc7ae4 100644 --- a/evmd/tests/eips/eips_test.go +++ b/evmd/tests/eips/eips_test.go @@ -13,9 +13,9 @@ import ( //nolint:revive // dot imports are fine for Ginkgo . "github.com/onsi/gomega" + "github.com/cosmos/evm/config/eips" "github.com/cosmos/evm/evmd/tests/eips/testdata" "github.com/cosmos/evm/evmd/tests/integration" - testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -107,7 +107,7 @@ func RunTests(t *testing.T, create network.CreateEvmApp, options ...network.Conf }) It("should enable the new EIP", func() { - testconfig.Multiplier = eipMultiplier + eips.Multiplier = eipMultiplier newEIP := 0o000 qRes, err := gh.GetEvmParams() @@ -259,7 +259,7 @@ func RunTests(t *testing.T, create network.CreateEvmApp, options ...network.Conf Expect(counter.String()).To(Equal(fmt.Sprintf("%d", initialCounterValue+1)), "counter is not correct") }) It("should enable the new EIP", func() { - testconfig.Multiplier = eipMultiplier + eips.Multiplier = eipMultiplier newEIP := 0o001 qRes, err := gh.GetEvmParams() @@ -403,7 +403,7 @@ func RunTests(t *testing.T, create network.CreateEvmApp, options ...network.Conf }) It("should enable the new EIP", func() { - testconfig.SstoreConstantGas = constantGas + eips.SstoreConstantGas = constantGas newEIP := 0o002 qRes, err := gh.GetEvmParams() diff --git a/evmd/tests/integration/create_app.go b/evmd/tests/integration/create_app.go index d6b52c21c..0f8e501ce 100644 --- a/evmd/tests/integration/create_app.go +++ b/evmd/tests/integration/create_app.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/evm" "github.com/cosmos/evm/config" "github.com/cosmos/evm/evmd" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" ibctesting "github.com/cosmos/ibc-go/v10/testing" @@ -35,9 +35,9 @@ func CreateEvmd(chainID string, evmChainID uint64, customBaseAppOptions ...func( baseAppOptions := append(customBaseAppOptions, baseapp.SetChainID(chainID)) - coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := config.NewChainConfig( - constants.ExampleChainID.ChainID, + testconfig.ExampleChainID.ChainID, evmChainID, nil, nil, @@ -62,10 +62,10 @@ func CreateEvmd(chainID string, evmChainID uint64, customBaseAppOptions ...func( // SetupEvmd initializes a new evmd app with default genesis state. // It is used in IBC integration tests to create a new evmd app instance. func SetupEvmd() (ibctesting.TestingApp, map[string]json.RawMessage) { - coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := config.NewChainConfig( - constants.ExampleChainID.ChainID, - constants.ExampleEIP155ChainID, + testconfig.ExampleChainID.ChainID, + testconfig.ExampleEIP155ChainID, nil, nil, nil, diff --git a/evmd/tests/integration/x_vm_test.go b/evmd/tests/integration/x_vm_test.go index 47a2de85e..228defde2 100644 --- a/evmd/tests/integration/x_vm_test.go +++ b/evmd/tests/integration/x_vm_test.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/evm/server/config" "github.com/cosmos/evm/tests/integration/x/vm" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" "github.com/cosmos/evm/testutil/keyring" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" @@ -33,7 +33,7 @@ func BenchmarkGasEstimation(b *testing.B) { // gh := grpc.NewIntegrationHandler(nw) // tf := factory.New(nw, gh) - coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := types.DefaultChainConfig(nw.GetEIP155ChainID().Uint64(), coinInfo) // get the denom and decimals set on chain initialization // because we'll need to set them again when resetting the chain config diff --git a/evmd/tests/ledger/evmosd_suite_test.go b/evmd/tests/ledger/evmosd_suite_test.go index 200a8a5da..47c803257 100644 --- a/evmd/tests/ledger/evmosd_suite_test.go +++ b/evmd/tests/ledger/evmosd_suite_test.go @@ -29,7 +29,7 @@ import ( "github.com/cosmos/evm/encoding" "github.com/cosmos/evm/evmd" "github.com/cosmos/evm/evmd/tests/ledger/mocks" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/cosmos-sdk/client" @@ -87,7 +87,7 @@ func (suite *LedgerTestSuite) SetupEvmosApp() { consAddress := sdk.ConsAddress(utiltx.GenerateAddress().Bytes()) // init app - chainID := constants.ExampleChainID + chainID := testconfig.ExampleChainID suite.app = evmd.Setup(suite.T(), chainID.ChainID, chainID.EVMChainID) suite.ctx = suite.app.NewContextLegacy(false, tmproto.Header{ Height: 1, @@ -136,7 +136,7 @@ func (suite *LedgerTestSuite) NewKeyringAndCtxs(krHome string, input io.Reader, WithUseLedger(true). WithKeyring(kr). WithClient(mocks.MockCometRPC{Client: rpcclientmock.Client{}}). - WithChainID(constants.ExampleChainIDPrefix + "-13"). + WithChainID(testconfig.ExampleChainIDPrefix + "-13"). WithSignModeStr(flags.SignModeLegacyAminoJSON) srvCtx := server.NewDefaultContext() diff --git a/evmd/tests/network/network.go b/evmd/tests/network/network.go index 11702ef65..50981c3fc 100644 --- a/evmd/tests/network/network.go +++ b/evmd/tests/network/network.go @@ -32,7 +32,7 @@ import ( "github.com/cosmos/evm/evmd" evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" "github.com/cosmos/evm/server/config" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" cosmosevmtypes "github.com/cosmos/evm/types" "cosmossdk.io/log" @@ -110,7 +110,7 @@ func DefaultConfig() Config { panic(fmt.Sprintf("failed creating temporary directory: %v", err)) } defer os.RemoveAll(dir) - coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := evmconfig.NewChainConfig( chainID, evmChainID, @@ -136,8 +136,8 @@ func DefaultConfig() Config { TimeoutCommit: 3 * time.Second, ChainID: chainID, NumValidators: 4, - BondDenom: testconstants.ExampleAttoDenom, - MinGasPrices: fmt.Sprintf("0.000006%s", testconstants.ExampleAttoDenom), + BondDenom: testconfig.ExampleAttoDenom, + MinGasPrices: fmt.Sprintf("0.000006%s", testconfig.ExampleAttoDenom), AccountTokens: sdk.TokensFromConsensusPower(1000000000000000000, cosmosevmtypes.AttoPowerReduction), StakingTokens: sdk.TokensFromConsensusPower(500000000000000000, cosmosevmtypes.AttoPowerReduction), BondedTokens: sdk.TokensFromConsensusPower(100000000000000000, cosmosevmtypes.AttoPowerReduction), @@ -153,7 +153,7 @@ func DefaultConfig() Config { // NewAppConstructor returns a new Cosmos EVM AppConstructor func NewAppConstructor(chainID string, evmChainID uint64) AppConstructor { return func(val Validator) servertypes.Application { - coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := evmconfig.NewChainConfig( chainID, evmChainID, @@ -501,7 +501,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { return nil, err } - customAppTemplate, _ := evmdconfig.InitAppConfig(testconstants.ExampleAttoDenom, testconstants.ExampleEIP155ChainID) + customAppTemplate, _ := evmdconfig.InitAppConfig(testconfig.ExampleAttoDenom, testconfig.ExampleEIP155ChainID) srvconfig.SetConfigTemplate(customAppTemplate) srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg) diff --git a/ibc/utils_test.go b/ibc/utils_test.go index 586ecd259..fb52a0959 100644 --- a/ibc/utils_test.go +++ b/ibc/utils_test.go @@ -7,7 +7,7 @@ import ( cosmosevmibc "github.com/cosmos/evm/ibc" precompilestestutil "github.com/cosmos/evm/precompiles/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" transfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v10/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v10/testing" @@ -297,7 +297,7 @@ func TestGetReceivedCoin(t *testing.T) { } func TestGetSentCoin(t *testing.T) { - baseDenom := testconstants.ExampleAttoDenom + baseDenom := testconfig.ExampleAttoDenom testCases := []struct { name string diff --git a/precompiles/common/balance_handler_test.go b/precompiles/common/balance_handler_test.go index c00e74fb2..919c62eaa 100644 --- a/precompiles/common/balance_handler_test.go +++ b/precompiles/common/balance_handler_test.go @@ -12,7 +12,7 @@ import ( cmn "github.com/cosmos/evm/precompiles/common" cmnmocks "github.com/cosmos/evm/precompiles/common/mocks" testutil "github.com/cosmos/evm/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" precisebanktypes "github.com/cosmos/evm/x/precisebank/types" "github.com/cosmos/evm/x/vm/statedb" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -29,10 +29,10 @@ import ( func setupBalanceHandlerTest(t *testing.T) { t.Helper() - sdk.GetConfig().SetBech32PrefixForAccount(testconstants.ExampleBech32Prefix, "") + sdk.GetConfig().SetBech32PrefixForAccount(testconfig.ExampleBech32Prefix, "") configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - require.NoError(t, configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]).Apply()) + require.NoError(t, configurator.WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]).Apply()) } func TestParseAddress(t *testing.T) { diff --git a/precompiles/common/types_test.go b/precompiles/common/types_test.go index 2ccbf868e..f824209a3 100644 --- a/precompiles/common/types_test.go +++ b/precompiles/common/types_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/evm/precompiles/common" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "cosmossdk.io/math" @@ -24,7 +24,7 @@ func TestNewCoinsResponse(t *testing.T) { } for _, tc := range testCases { - coin := sdk.NewCoin(constants.ExampleAttoDenom, tc.amount) + coin := sdk.NewCoin(testconfig.ExampleAttoDenom, tc.amount) coins := sdk.NewCoins(coin) res := common.NewCoinsResponse(coins) require.Equal(t, 1, len(res)) @@ -41,7 +41,7 @@ func TestNewDecCoinsResponse(t *testing.T) { } for _, tc := range testCases { - coin := sdk.NewDecCoin(constants.ExampleAttoDenom, tc.amount) + coin := sdk.NewDecCoin(testconfig.ExampleAttoDenom, tc.amount) coins := sdk.NewDecCoins(coin) res := common.NewDecCoinsResponse(coins) require.Equal(t, 1, len(res)) diff --git a/rpc/backend/node_info.go b/rpc/backend/node_info.go index dcdf28a68..5fb388bc5 100644 --- a/rpc/backend/node_info.go +++ b/rpc/backend/node_info.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/evm/crypto/ethsecp256k1" rpctypes "github.com/cosmos/evm/rpc/types" "github.com/cosmos/evm/server/config" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" evmtypes "github.com/cosmos/evm/x/vm/types" errorsmod "cosmossdk.io/errors" @@ -345,7 +345,7 @@ func (b *Backend) RPCMinGasPrice() *big.Int { minGasPrice := b.Cfg.GetMinGasPrices() amt := minGasPrice.AmountOf(baseDenom) if amt.IsNil() || amt.IsZero() { - return big.NewInt(constants.DefaultGasPrice) + return big.NewInt(testconfig.DefaultGasPrice) } return evmtypes.ConvertAmountTo18DecimalsLegacy(amt).TruncateInt().BigInt() diff --git a/rpc/backend/tx_info_test.go b/rpc/backend/tx_info_test.go index 834b6f2ca..b6a9707ff 100644 --- a/rpc/backend/tx_info_test.go +++ b/rpc/backend/tx_info_test.go @@ -22,7 +22,7 @@ import ( "github.com/cosmos/evm/indexer" "github.com/cosmos/evm/rpc/backend/mocks" rpctypes "github.com/cosmos/evm/rpc/types" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -36,7 +36,7 @@ func setupMockBackend(t *testing.T) *Backend { t.Helper() ctx := server.NewDefaultContext() ctx.Viper.Set("telemetry.global-labels", []interface{}{}) - ctx.Viper.Set("evm.evm-chain-id", constants.ExampleChainID.EVMChainID) + ctx.Viper.Set("evm.evm-chain-id", testconfig.ExampleChainID.EVMChainID) baseDir := t.TempDir() nodeDirName := "node" @@ -52,8 +52,8 @@ func setupMockBackend(t *testing.T) *Backend { Seq: uint64(1), } - encodingConfig := encoding.MakeConfig(constants.ExampleChainID.EVMChainID) - clientCtx := client.Context{}.WithChainID(constants.ExampleChainID.ChainID). + encodingConfig := encoding.MakeConfig(testconfig.ExampleChainID.EVMChainID) + clientCtx := client.Context{}.WithChainID(testconfig.ExampleChainID.ChainID). WithHeight(1). WithTxConfig(encodingConfig.TxConfig). WithKeyringDir(clientDir). @@ -69,7 +69,7 @@ func setupMockBackend(t *testing.T) *Backend { backend.Cfg.JSONRPC.GasCap = 25000000 backend.Cfg.JSONRPC.EVMTimeout = 0 backend.Cfg.JSONRPC.AllowInsecureUnlock = true - backend.Cfg.EVM.EVMChainID = constants.ExampleChainID.EVMChainID + backend.Cfg.EVM.EVMChainID = testconfig.ExampleChainID.EVMChainID mockEVMQueryClient := mocks.NewEVMQueryClient(t) mockFeeMarketQueryClient := mocks.NewFeeMarketQueryClient(t) backend.QueryClient.QueryClient = mockEVMQueryClient @@ -86,7 +86,7 @@ func setupMockBackend(t *testing.T) *Backend { mockHeader := &tmtypes.Header{ Height: 1, Time: time.Now(), - ChainID: constants.ExampleChainID.ChainID, + ChainID: testconfig.ExampleChainID.ChainID, } mockBlock := &tmtypes.Block{ Header: *mockHeader, diff --git a/server/config/config_test.go b/server/config/config_test.go index e5920a986..8ffd1224a 100644 --- a/server/config/config_test.go +++ b/server/config/config_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" serverconfig "github.com/cosmos/evm/server/config" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" ) func TestDefaultConfig(t *testing.T) { @@ -30,12 +30,12 @@ func TestGetConfig(t *testing.T) { "test unmarshal embedded structs", func() *viper.Viper { v := viper.New() - v.Set("minimum-gas-prices", fmt.Sprintf("100%s", constants.ExampleAttoDenom)) + v.Set("minimum-gas-prices", fmt.Sprintf("100%s", testconfig.ExampleAttoDenom)) return v }, func() serverconfig.Config { cfg := serverconfig.DefaultConfig() - cfg.MinGasPrices = fmt.Sprintf("100%s", constants.ExampleAttoDenom) + cfg.MinGasPrices = fmt.Sprintf("100%s", testconfig.ExampleAttoDenom) return *cfg }, false, diff --git a/tests/integration/ante/ante_test_suite.go b/tests/integration/ante/ante_test_suite.go index 03d5cf70d..6b69355ad 100644 --- a/tests/integration/ante/ante_test_suite.go +++ b/tests/integration/ante/ante_test_suite.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" @@ -100,7 +100,7 @@ func (s *AnteTestSuite) SetupTest() { s.Require().NotNil(s.network.App.AppCodec()) - coinInfo := constants.ExampleChainCoinInfo[constants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := evmtypes.DefaultChainConfig(s.network.GetEIP155ChainID().Uint64(), coinInfo) if !s.enableLondonHF { maxInt := sdkmath.NewInt(math.MaxInt64) diff --git a/tests/integration/ante/evm_ante_test_suite.go b/tests/integration/ante/evm_ante_test_suite.go index 361071447..30f92f2b1 100644 --- a/tests/integration/ante/evm_ante_test_suite.go +++ b/tests/integration/ante/evm_ante_test_suite.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/evm/crypto/ethsecp256k1" "github.com/cosmos/evm/ethereum/eip712" "github.com/cosmos/evm/testutil" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" utiltx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -644,7 +644,7 @@ func PrepareAccountsForDelegationRewards(t *testing.T, ctx sdk.Context, app evm. // set distribution module account balance which pays out the rewards distrAcc := distrKeeper.GetDistributionAccount(ctx) - err := testutil.FundModuleAccount(ctx, bankKeeper, distrAcc.GetName(), sdk.NewCoins(sdk.NewCoin(constants.ExampleAttoDenom, totalRewards))) + err := testutil.FundModuleAccount(ctx, bankKeeper, distrAcc.GetName(), sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, totalRewards))) if err != nil { return sdk.Context{}, fmt.Errorf("failed to fund distribution module account: %s", err.Error()) } @@ -668,14 +668,14 @@ func PrepareAccountsForDelegationRewards(t *testing.T, ctx sdk.Context, app evm. if err != nil { return sdk.Context{}, fmt.Errorf("failed to get staking params: %s", err.Error()) } - stakingParams.BondDenom = constants.ExampleAttoDenom + stakingParams.BondDenom = testconfig.ExampleAttoDenom stakingParams.MinCommissionRate = zeroDec err = stakingKeeper.SetParams(ctx, stakingParams) require.NoError(t, err) stakingHelper := teststaking.NewHelper(t, ctx, stakingKeeper) stakingHelper.Commission = stakingtypes.NewCommissionRates(zeroDec, zeroDec, zeroDec) - stakingHelper.Denom = constants.ExampleAttoDenom + stakingHelper.Denom = testconfig.ExampleAttoDenom valAddr := sdk.ValAddress(addr2.Bytes()) // self-delegate the same amount of tokens as the delegate address also stakes @@ -693,7 +693,7 @@ func PrepareAccountsForDelegationRewards(t *testing.T, ctx sdk.Context, app evm. if err != nil { return sdk.Context{}, fmt.Errorf("failed to get validator: %s", err.Error()) } - allocatedRewards := sdk.NewDecCoins(sdk.NewDecCoin(constants.ExampleAttoDenom, reward.Mul(sdkmath.NewInt(2)))) + allocatedRewards := sdk.NewDecCoins(sdk.NewDecCoin(testconfig.ExampleAttoDenom, reward.Mul(sdkmath.NewInt(2)))) if err = distrKeeper.AllocateTokensToValidator(ctx, validator, allocatedRewards); err != nil { return sdk.Context{}, fmt.Errorf("failed to allocate tokens to validator: %s", err.Error()) } diff --git a/tests/integration/ante/evm_unit_ante_test_suite.go b/tests/integration/ante/evm_unit_ante_test_suite.go index 3fd1597bb..b578506cf 100644 --- a/tests/integration/ante/evm_unit_ante_test_suite.go +++ b/tests/integration/ante/evm_unit_ante_test_suite.go @@ -3,7 +3,7 @@ package ante import ( "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" ) @@ -26,7 +26,7 @@ func NewEvmUnitAnteTestSuite( ) *EvmUnitAnteTestSuite { return &EvmUnitAnteTestSuite{ create: create, - ChainID: constants.ExampleChainID.ChainID, - EvmChainID: constants.ExampleChainID.EVMChainID, + ChainID: testconfig.ExampleChainID.ChainID, + EvmChainID: testconfig.ExampleChainID.EVMChainID, } } diff --git a/tests/integration/ante/test_evm_ante.go b/tests/integration/ante/test_evm_ante.go index be0fec752..7b3e54178 100644 --- a/tests/integration/ante/test_evm_ante.go +++ b/tests/integration/ante/test_evm_ante.go @@ -13,7 +13,7 @@ import ( ethante "github.com/cosmos/evm/ante/evm" "github.com/cosmos/evm/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -289,7 +289,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) gas := uint64(200000) - amount := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 + amount := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 txBuilder, err := s.CreateTestEIP712TxBuilderMsgSend(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) s.Require().NoError(err) return txBuilder.GetTx() @@ -300,7 +300,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) gas := uint64(200000) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas))) //#nosec G115 + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas))) //#nosec G115 amount := sdk.NewCoins(coinAmount) txBuilder, err := s.CreateTestEIP712TxBuilderMsgDelegate(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) s.Require().NoError(err) @@ -311,7 +311,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 create validator", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgCreateValidator(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -323,7 +323,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 create validator (with blank fields)", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgCreateValidator2(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -335,7 +335,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 MsgSubmitProposal", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) gasAmount := sdk.NewCoins(coinAmount) gas := uint64(200000) // reusing the gasAmount for deposit @@ -350,7 +350,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) grantee := sdk.AccAddress("_______grantee______") - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) gasAmount := sdk.NewCoins(coinAmount) gas := uint64(200000) blockTime := time.Date(1, 1, 1, 1, 1, 1, 1, time.UTC) @@ -370,7 +370,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 MsgGrantAllowance", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) gasAmount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712GrantAllowance(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, gasAmount) @@ -383,7 +383,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 edit validator", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgEditValidator(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -395,7 +395,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 submit evidence", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgSubmitEvidence(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -407,7 +407,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 submit proposal v1", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712SubmitProposalV1(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -419,7 +419,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 MsgExec", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgExec(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -431,7 +431,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 MsgVoteV1", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgVoteV1(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -443,7 +443,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 Multiple MsgSend", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MultipleMsgSend(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -455,7 +455,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 Multiple Different Msgs", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MultipleDifferentMsgs(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -467,7 +467,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 Same Msgs, Different Schemas", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712SameMsgDifferentSchemas(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -479,7 +479,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 Zero Value Array (Should Not Omit Field)", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712ZeroValueArray(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -491,7 +491,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 Zero Value Number (Should Not Omit Field)", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712ZeroValueNumber(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -503,7 +503,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 MsgTransfer", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgTransfer(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -515,7 +515,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "success- DeliverTx EIP712 MsgTransfer Without Memo", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MsgTransferWithoutMemo(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -527,7 +527,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { "fails - DeliverTx EIP712 Multiple Signers", func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) - coinAmount := sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20)) + coinAmount := sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20)) amount := sdk.NewCoins(coinAmount) gas := uint64(200000) txBuilder, err := s.CreateTestEIP712MultipleSignerMsgs(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) @@ -540,7 +540,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) gas := uint64(200000) - amount := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 + amount := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 txBuilder, err := s.CreateTestEIP712TxBuilderMsgSend(from, privKey, "cosmos-1", 9002, gas, amount) s.Require().NoError(err) return txBuilder.GetTx() @@ -551,11 +551,11 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) gas := uint64(200000) - amount := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 + amount := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 txBuilder, err := s.CreateTestEIP712TxBuilderMsgSend(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) s.Require().NoError(err) txBuilder.SetGasLimit(uint64(300000)) - txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(30)))) + txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(30)))) return txBuilder.GetTx() }, false, false, false, }, @@ -564,7 +564,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) gas := uint64(200000) - amount := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 + amount := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 txBuilder, err := s.CreateTestEIP712TxBuilderMsgSend(from, privKey, "cosmos-1", 9005, gas, amount) s.Require().NoError(err) return txBuilder.GetTx() @@ -575,7 +575,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) gas := uint64(200000) - amount := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 + amount := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 txBuilder, err := s.CreateTestEIP712TxBuilderMsgSend(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) s.Require().NoError(err) nonce, err := s.GetNetwork().App.GetAccountKeeper().GetSequence(ctx, s.GetKeyring().GetAccAddr(0)) @@ -598,7 +598,7 @@ func (s *EvmAnteTestSuite) TestAnteHandler() { func() sdk.Tx { from := s.GetKeyring().GetAccAddr(0) gas := uint64(200000) - amount := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 + amount := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(100*int64(gas)))) //#nosec G115 txBuilder, err := s.CreateTestEIP712TxBuilderMsgSend(from, privKey, ctx.ChainID(), ethCfg.ChainID.Uint64(), gas, amount) s.Require().NoError(err) nonce, err := s.GetNetwork().App.GetAccountKeeper().GetSequence(ctx, s.GetKeyring().GetAccAddr(0)) diff --git a/tests/integration/ante/test_evm_fee_market.go b/tests/integration/ante/test_evm_fee_market.go index 5008f0c9d..8b916d03b 100644 --- a/tests/integration/ante/test_evm_fee_market.go +++ b/tests/integration/ante/test_evm_fee_market.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/evm/ante/evm" "github.com/cosmos/evm/server/config" "github.com/cosmos/evm/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -97,7 +97,7 @@ func (s *EvmAnteTestSuite) TestGasWantedDecorator() { "EIP712 message", 200000, func() sdk.Tx { - amount := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(20))) + amount := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(20))) gas := uint64(200000) acc := s.GetNetwork().App.GetAccountKeeper().NewAccountWithAddress(ctx, from.Bytes()) s.Require().NoError(acc.SetSequence(1)) @@ -112,13 +112,13 @@ func (s *EvmAnteTestSuite) TestGasWantedDecorator() { "Cosmos Tx - gasWanted > max block gas", TestGasLimit, func() sdk.Tx { - denom := testconstants.ExampleAttoDenom + denom := testconfig.ExampleAttoDenom testMsg := banktypes.MsgSend{ FromAddress: "cosmos1x8fhpj9nmhqk8z9kpgjt95ck2xwyue0ptzkucp", ToAddress: "cosmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn", Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: denom}}, } - txBuilder := s.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), testconstants.ExampleAttoDenom, &testMsg) + txBuilder := s.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), testconfig.ExampleAttoDenom, &testMsg) limit := types.BlockGasLimit(ctx) txBuilder.SetGasLimit(limit + 5) return txBuilder.GetTx() diff --git a/tests/integration/ante/test_evm_unit_04_validate.go b/tests/integration/ante/test_evm_unit_04_validate.go index 81e06a937..a6fae294b 100644 --- a/tests/integration/ante/test_evm_unit_04_validate.go +++ b/tests/integration/ante/test_evm_unit_04_validate.go @@ -8,7 +8,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/cosmos/evm/ante/evm" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" testkeyring "github.com/cosmos/evm/testutil/keyring" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -236,9 +236,9 @@ func (s *EvmUnitAnteTestSuite) TestCheckTxFee() { }, } - for _, chainID := range []testconstants.ChainID{ - testconstants.ExampleChainID, - testconstants.SixDecimalsChainID, + for _, chainID := range []testconfig.ChainID{ + testconfig.ExampleChainID, + testconfig.ExampleSixDecimalsChainID, } { for _, tc := range testCases { s.Run(fmt.Sprintf("%s, %s", chainID.ChainID, tc.name), func() { @@ -246,7 +246,7 @@ func (s *EvmUnitAnteTestSuite) TestCheckTxFee() { // function to be tested. configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - s.Require().NoError(configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[chainID]).Apply()) + s.Require().NoError(configurator.WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[chainID]).Apply()) // If decimals is not 18 decimals, we have to convert txFeeInfo to original // decimals representation. diff --git a/tests/integration/ante/test_evm_unit_06_account_verification.go b/tests/integration/ante/test_evm_unit_06_account_verification.go index b9e248afd..88abfb587 100644 --- a/tests/integration/ante/test_evm_unit_06_account_verification.go +++ b/tests/integration/ante/test_evm_unit_06_account_verification.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/cosmos/evm/ante/evm" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -30,7 +30,7 @@ func (s *EvmUnitAnteTestSuite) TestVerifyAccountBalance() { unitNetwork := network.NewUnitTestNetwork( s.create, network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...), - network.WithChainID(testconstants.ChainID{ + network.WithChainID(testconfig.ChainID{ ChainID: s.ChainID, EVMChainID: s.EvmChainID, }), diff --git a/tests/integration/ante/test_evm_unit_08_gas_consume.go b/tests/integration/ante/test_evm_unit_08_gas_consume.go index 605221891..fae0cf0b3 100644 --- a/tests/integration/ante/test_evm_unit_08_gas_consume.go +++ b/tests/integration/ante/test_evm_unit_08_gas_consume.go @@ -4,7 +4,7 @@ import ( "fmt" evmante "github.com/cosmos/evm/ante/evm" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" commonfactory "github.com/cosmos/evm/testutil/integration/base/factory" testfactory "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" @@ -22,7 +22,7 @@ func (s *EvmUnitAnteTestSuite) TestUpdateCumulativeGasWanted() { keyring := testkeyring.New(1) unitNetwork := network.NewUnitTestNetwork( s.create, - network.WithChainID(testconstants.ChainID{ + network.WithChainID(testconfig.ChainID{ ChainID: s.ChainID, EVMChainID: s.EvmChainID, }), @@ -99,7 +99,7 @@ func (s *EvmUnitAnteTestSuite) TestConsumeGasAndEmitEvent() { keyring := testkeyring.New(1) unitNetwork := network.NewUnitTestNetwork( s.create, - network.WithChainID(testconstants.ChainID{ + network.WithChainID(testconfig.ChainID{ ChainID: s.ChainID, EVMChainID: s.EvmChainID, }), diff --git a/tests/integration/ante/test_evm_unit_09_increment_sequence.go b/tests/integration/ante/test_evm_unit_09_increment_sequence.go index d2b3e0b64..d1fde3185 100644 --- a/tests/integration/ante/test_evm_unit_09_increment_sequence.go +++ b/tests/integration/ante/test_evm_unit_09_increment_sequence.go @@ -3,7 +3,7 @@ package ante import ( "github.com/cosmos/evm/ante/evm" "github.com/cosmos/evm/mempool" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" testkeyring "github.com/cosmos/evm/testutil/keyring" @@ -16,7 +16,7 @@ func (s *EvmUnitAnteTestSuite) TestIncrementSequence() { keyring := testkeyring.New(1) unitNetwork := network.NewUnitTestNetwork( s.create, - network.WithChainID(testconstants.ChainID{ + network.WithChainID(testconfig.ChainID{ ChainID: s.ChainID, EVMChainID: s.EvmChainID, }), diff --git a/tests/integration/ante/test_evm_unit_10_gas_wanted.go b/tests/integration/ante/test_evm_unit_10_gas_wanted.go index 5c30816bc..7915bcbd2 100644 --- a/tests/integration/ante/test_evm_unit_10_gas_wanted.go +++ b/tests/integration/ante/test_evm_unit_10_gas_wanted.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/cosmos/evm/ante/evm" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -22,7 +22,7 @@ func (s *EvmUnitAnteTestSuite) TestCheckGasWanted() { keyring := testkeyring.New(1) unitNetwork := network.NewUnitTestNetwork( s.create, - network.WithChainID(testconstants.ChainID{ + network.WithChainID(testconfig.ChainID{ ChainID: s.ChainID, EVMChainID: s.EvmChainID, }), diff --git a/tests/integration/ante/test_integration.go b/tests/integration/ante/test_integration.go index 3bf348aff..03bdfc10e 100644 --- a/tests/integration/ante/test_integration.go +++ b/tests/integration/ante/test_integration.go @@ -10,7 +10,7 @@ import ( //nolint:revive // dot imports are fine for Ginkgo . "github.com/onsi/gomega" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" commonfactory "github.com/cosmos/evm/testutil/integration/base/factory" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" @@ -57,7 +57,7 @@ func (s *IntegrationTestSuite) SetupTest() { // set non-zero inflation for rewards to accrue (use defaults from SDK for values) mintGen := minttypes.DefaultGenesisState() - mintGen.Params.MintDenom = testconstants.ExampleAttoDenom + mintGen.Params.MintDenom = testconfig.ExampleAttoDenom customGen[minttypes.ModuleName] = mintGen operatorsAddr := make([]sdk.AccAddress, 3) diff --git a/tests/integration/ante/test_min_gas_price.go b/tests/integration/ante/test_min_gas_price.go index 2c06894d1..77a0682bc 100644 --- a/tests/integration/ante/test_min_gas_price.go +++ b/tests/integration/ante/test_min_gas_price.go @@ -5,7 +5,7 @@ import ( cosmosante "github.com/cosmos/evm/ante/cosmos" "github.com/cosmos/evm/testutil" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" testutiltx "github.com/cosmos/evm/testutil/tx" "cosmossdk.io/math" @@ -24,7 +24,7 @@ var execTypes = []struct { } func (s *AnteTestSuite) TestMinGasPriceDecorator() { - denom := constants.ExampleAttoDenom + denom := testconfig.ExampleAttoDenom testMsg := banktypes.MsgSend{ FromAddress: "cosmos1x8fhpj9nmhqk8z9kpgjt95ck2xwyue0ptzkucp", ToAddress: "cosmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn", diff --git a/tests/integration/eip712/test_eip712.go b/tests/integration/eip712/test_eip712.go index 92b498139..fd9d2860c 100644 --- a/tests/integration/eip712/test_eip712.go +++ b/tests/integration/eip712/test_eip712.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/evm/crypto/ethsecp256k1" "github.com/cosmos/evm/ethereum/eip712" "github.com/cosmos/evm/testutil/config" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -333,7 +333,7 @@ func (s *TestSuite) TestEIP712() { err = txBuilder.SetSignatures([]signing.SignatureV2{txSig}...) s.Require().NoError(err) - chainID := constants.ExampleChainID.ChainID + chainID := testconfig.ExampleChainID.ChainID if tc.chainID != "" { chainID = tc.chainID } @@ -347,7 +347,7 @@ func (s *TestSuite) TestEIP712() { AccountNumber: params.accountNumber, Sequence: params.sequence, PubKey: pubKey, - Address: sdk.MustBech32ifyAddressBytes(constants.ExampleBech32Prefix, pubKey.Bytes()), + Address: sdk.MustBech32ifyAddressBytes(testconfig.ExampleBech32Prefix, pubKey.Bytes()), } bz, err := authsigning.GetSignBytesAdapter( diff --git a/tests/integration/indexer/test_kv_indexer.go b/tests/integration/indexer/test_kv_indexer.go index 93a62d8db..0fa0ddf97 100644 --- a/tests/integration/indexer/test_kv_indexer.go +++ b/tests/integration/indexer/test_kv_indexer.go @@ -14,7 +14,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/evm/crypto/ethsecp256k1" "github.com/cosmos/evm/indexer" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/vm/types" @@ -48,7 +48,7 @@ func TestKVIndexer(t *testing.T, create network.CreateEvmApp, options ...network clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig).WithCodec(encodingConfig.Codec) // build cosmos-sdk wrapper tx - tmTx, err := tx.BuildTx(clientCtx.TxConfig.NewTxBuilder(), constants.ExampleAttoDenom) + tmTx, err := tx.BuildTx(clientCtx.TxConfig.NewTxBuilder(), testconfig.ExampleAttoDenom) require.NoError(t, err) txBz, err := clientCtx.TxConfig.TxEncoder()(tmTx) require.NoError(t, err) diff --git a/tests/integration/mempool/test_setup.go b/tests/integration/mempool/test_setup.go index ae80aaee4..de922bec0 100644 --- a/tests/integration/mempool/test_setup.go +++ b/tests/integration/mempool/test_setup.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/suite" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -39,11 +39,11 @@ func NewMempoolIntegrationTestSuite(create network.CreateEvmApp, options ...netw // SetupTest initializes the test environment with default settings. func (s *IntegrationTestSuite) SetupTest() { - s.SetupTestWithChainID(testconstants.ExampleChainID) + s.SetupTestWithChainID(testconfig.ExampleChainID) } // SetupTestWithChainID initializes the test environment with a specific chain ID. -func (s *IntegrationTestSuite) SetupTestWithChainID(chainID testconstants.ChainID) { +func (s *IntegrationTestSuite) SetupTestWithChainID(chainID testconfig.ChainID) { s.keyring = keyring.New(20) options := []network.ConfigOption{ diff --git a/tests/integration/precompiles/distribution/test_distribution.go b/tests/integration/precompiles/distribution/test_distribution.go index c749828b5..6dfd519fa 100644 --- a/tests/integration/precompiles/distribution/test_distribution.go +++ b/tests/integration/precompiles/distribution/test_distribution.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/evm/precompiles/distribution" "github.com/cosmos/evm/precompiles/testutil" chainutil "github.com/cosmos/evm/testutil" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" evmtypes "github.com/cosmos/evm/x/vm/types" "cosmossdk.io/math" @@ -86,7 +86,7 @@ func (s *PrecompileTestSuite) TestRun() { valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].OperatorAddress) s.Require().NoError(err) val, _ := s.network.App.GetStakingKeeper().GetValidator(ctx, valAddr) - coins := sdk.NewCoins(sdk.NewCoin(constants.ExampleAttoDenom, math.NewInt(1e18))) + coins := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1e18))) s.Require().NoError(s.network.App.GetDistrKeeper().AllocateTokensToValidator(ctx, val, sdk.NewDecCoinsFromCoins(coins...))) input, err := s.precompile.Pack( @@ -109,7 +109,7 @@ func (s *PrecompileTestSuite) TestRun() { caller := common.BytesToAddress(valAddr) commAmt := math.LegacyNewDecWithPrec(1000000000000000000, 1) - valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(constants.ExampleAttoDenom, commAmt)} + valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(testconfig.ExampleAttoDenom, commAmt)} // set outstanding rewards s.Require().NoError(s.network.App.GetDistrKeeper().SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: valCommission})) // set commission @@ -189,7 +189,7 @@ func (s *PrecompileTestSuite) TestRun() { s.keyring.GetAddr(0), []cmn.Coin{ { - Denom: constants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, }, @@ -209,7 +209,7 @@ func (s *PrecompileTestSuite) TestRun() { s.keyring.GetAddr(0), []cmn.Coin{ { - Denom: constants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, { @@ -312,7 +312,7 @@ func (s *PrecompileTestSuite) TestCMS() { valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].OperatorAddress) s.Require().NoError(err) val, _ := s.network.App.GetStakingKeeper().GetValidator(ctx, valAddr) - coins := sdk.NewCoins(sdk.NewCoin(constants.ExampleAttoDenom, math.NewInt(1e18))) + coins := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1e18))) s.Require().NoError(s.network.App.GetDistrKeeper().AllocateTokensToValidator(ctx, val, sdk.NewDecCoinsFromCoins(coins...))) input, err := s.precompile.Pack( @@ -334,7 +334,7 @@ func (s *PrecompileTestSuite) TestCMS() { caller := common.BytesToAddress(valAddr) commAmt := math.LegacyNewDecWithPrec(1000000000000000000, 1) - valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(constants.ExampleAttoDenom, commAmt)} + valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(testconfig.ExampleAttoDenom, commAmt)} // set outstanding rewards s.Require().NoError(s.network.App.GetDistrKeeper().SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: valCommission})) // set commission @@ -411,7 +411,7 @@ func (s *PrecompileTestSuite) TestCMS() { s.keyring.GetAddr(0), []cmn.Coin{ { - Denom: constants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, }, @@ -430,7 +430,7 @@ func (s *PrecompileTestSuite) TestCMS() { s.keyring.GetAddr(0), []cmn.Coin{ { - Denom: constants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, { diff --git a/tests/integration/precompiles/distribution/test_event.go b/tests/integration/precompiles/distribution/test_event.go index c83178113..06223040c 100644 --- a/tests/integration/precompiles/distribution/test_event.go +++ b/tests/integration/precompiles/distribution/test_event.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/evm/precompiles/distribution" "github.com/cosmos/evm/precompiles/testutil" "github.com/cosmos/evm/testutil/config" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/vm/statedb" "cosmossdk.io/math" @@ -188,13 +188,13 @@ func (s *PrecompileTestSuite) TestWithdrawValidatorCommissionEvent() { func(operatorAddress string) []interface{} { valAddr, err := sdk.ValAddressFromBech32(operatorAddress) s.Require().NoError(err) - valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(constants.ExampleAttoDenom, math.LegacyNewDecFromInt(amt))} + valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(testconfig.ExampleAttoDenom, math.LegacyNewDecFromInt(amt))} // set outstanding rewards s.Require().NoError(s.network.App.GetDistrKeeper().SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: valCommission})) // set commission s.Require().NoError(s.network.App.GetDistrKeeper().SetValidatorAccumulatedCommission(ctx, valAddr, types.ValidatorAccumulatedCommission{Commission: valCommission})) // set funds to distr mod to pay for commission - coins := sdk.NewCoins(sdk.NewCoin(constants.ExampleAttoDenom, amt)) + coins := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, amt)) err = s.mintCoinsForDistrMod(ctx, coins) s.Require().NoError(err) return []interface{}{ @@ -260,7 +260,7 @@ func (s *PrecompileTestSuite) TestClaimRewardsEvent() { }{ { "success", - sdk.NewCoins(sdk.NewCoin(constants.ExampleAttoDenom, math.NewInt(1e18))), + sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1e18))), func() { log := stDB.Logs()[0] s.Require().Equal(log.Address, s.precompile.Address()) @@ -302,7 +302,7 @@ func (s *PrecompileTestSuite) TestFundCommunityPoolEvent() { }{ { "success - the correct event is emitted", - sdk.NewCoins(sdk.NewCoin(constants.ExampleAttoDenom, math.NewInt(1e18))), + sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1e18))), func(coins sdk.Coins) { log := stDB.Logs()[0] s.Require().Equal(log.Address, s.precompile.Address()) @@ -315,7 +315,7 @@ func (s *PrecompileTestSuite) TestFundCommunityPoolEvent() { err := cmn.UnpackLog(s.precompile.ABI, &fundCommunityPoolEvent, distribution.EventTypeFundCommunityPool, *log) s.Require().NoError(err) s.Require().Equal(s.keyring.GetAddr(0), fundCommunityPoolEvent.Depositor) - s.Require().Equal(constants.ExampleAttoDenom, fundCommunityPoolEvent.Denom) + s.Require().Equal(testconfig.ExampleAttoDenom, fundCommunityPoolEvent.Denom) s.Require().Equal(big.NewInt(1e18), fundCommunityPoolEvent.Amount) }, }, @@ -323,9 +323,9 @@ func (s *PrecompileTestSuite) TestFundCommunityPoolEvent() { // New multi-coin deposit test case name: "success - multiple coins => multiple events emitted", coins: sdk.NewCoins( - sdk.NewCoin(constants.ExampleAttoDenom, math.NewInt(10)), // coin #1 - sdk.NewCoin(constants.OtherCoinDenoms[0], math.NewInt(20)), // coin #2 - sdk.NewCoin(constants.OtherCoinDenoms[1], math.NewInt(30)), // coin #3 + sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(10)), // coin #1 + sdk.NewCoin(testconfig.OtherCoinDenoms[0], math.NewInt(20)), // coin #2 + sdk.NewCoin(testconfig.OtherCoinDenoms[1], math.NewInt(30)), // coin #3 ).Sort(), postCheck: func(coins sdk.Coins) { logs := stDB.Logs() @@ -394,7 +394,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolEvent() { func(operatorAddress string) ([]interface{}, sdk.Coins) { coins := []cmn.Coin{ { - Denom: constants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, } @@ -425,7 +425,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolEvent() { s.Require().NoError(err) s.Require().Equal(depositValidatorRewardsPool.Depositor, s.keyring.GetAddr(0)) s.Require().Equal(depositValidatorRewardsPool.ValidatorAddress, common.BytesToAddress(valAddr.Bytes())) - s.Require().Equal(depositValidatorRewardsPool.Denom, constants.ExampleAttoDenom) + s.Require().Equal(depositValidatorRewardsPool.Denom, testconfig.ExampleAttoDenom) s.Require().Equal(depositValidatorRewardsPool.Amount, amt.BigInt()) }, 20000, @@ -437,7 +437,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolEvent() { func(operatorAddress string) ([]interface{}, sdk.Coins) { coins := []cmn.Coin{ { - Denom: constants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, { diff --git a/tests/integration/precompiles/distribution/test_integration.go b/tests/integration/precompiles/distribution/test_integration.go index 53500a6b6..86ce50fd5 100644 --- a/tests/integration/precompiles/distribution/test_integration.go +++ b/tests/integration/precompiles/distribution/test_integration.go @@ -18,7 +18,7 @@ import ( "github.com/cosmos/evm/precompiles/staking" "github.com/cosmos/evm/precompiles/testutil" "github.com/cosmos/evm/precompiles/testutil/contracts" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" "github.com/cosmos/evm/testutil/integration/evm/utils" testutiltx "github.com/cosmos/evm/testutil/tx" @@ -52,7 +52,7 @@ var ( txArgs evmtypes.EvmTxArgs // minExpRewardOrCommission is the minimun coins expected for validator's rewards or commission // required for the tests - minExpRewardOrCommission = sdk.NewDecCoins(sdk.NewDecCoin(testconstants.ExampleAttoDenom, testRewardsAmt)) + minExpRewardOrCommission = sdk.NewDecCoins(sdk.NewDecCoin(testconfig.ExampleAttoDenom, testRewardsAmt)) ) func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmApp, options ...network.ConfigOption) { @@ -905,8 +905,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp fundAmt := math.NewInt(10) sendAmt := []cmn.Coin{ {Denom: s.bondDenom, Amount: fundAmt.BigInt()}, - {Denom: testconstants.OtherCoinDenoms[0], Amount: fundAmt.BigInt()}, - {Denom: testconstants.OtherCoinDenoms[1], Amount: fundAmt.BigInt()}, + {Denom: testconfig.OtherCoinDenoms[0], Amount: fundAmt.BigInt()}, + {Denom: testconfig.OtherCoinDenoms[1], Amount: fundAmt.BigInt()}, } sendSdkCoins, err := cmn.NewSdkCoinsFromCoins(sendAmt) Expect(err).To(BeNil()) diff --git a/tests/integration/precompiles/distribution/test_setup.go b/tests/integration/precompiles/distribution/test_setup.go index 57b15cb85..08cfcce26 100644 --- a/tests/integration/precompiles/distribution/test_setup.go +++ b/tests/integration/precompiles/distribution/test_setup.go @@ -4,7 +4,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/evm/precompiles/distribution" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -57,7 +57,7 @@ func (s *PrecompileTestSuite) SetupTest() { customGen := network.CustomGenesisState{} // mint some coin to fee collector - coins := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(1000000000000000000))) + coins := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(1000000000000000000))) balances := []banktypes.Balance{ { Address: authtypes.NewModuleAddress(authtypes.FeeCollectorName).String(), @@ -90,7 +90,7 @@ func (s *PrecompileTestSuite) SetupTest() { // set non-zero inflation for rewards to accrue (use defaults from SDK for values) mintGen := minttypes.DefaultGenesisState() - mintGen.Params.MintDenom = testconstants.ExampleAttoDenom + mintGen.Params.MintDenom = testconfig.ExampleAttoDenom customGen[minttypes.ModuleName] = mintGen operatorsAddr := make([]sdk.AccAddress, 3) @@ -99,12 +99,12 @@ func (s *PrecompileTestSuite) SetupTest() { } s.otherDenoms = []string{ - testconstants.OtherCoinDenoms[0], - testconstants.OtherCoinDenoms[1], + testconfig.OtherCoinDenoms[0], + testconfig.OtherCoinDenoms[1], } options := []network.ConfigOption{ - network.WithOtherDenoms(testconstants.OtherCoinDenoms), + network.WithOtherDenoms(testconfig.OtherCoinDenoms), network.WithPreFundedAccounts(keyring.GetAllAccAddrs()...), network.WithOtherDenoms(s.otherDenoms), network.WithCustomGenesis(customGen), diff --git a/tests/integration/precompiles/distribution/test_tx.go b/tests/integration/precompiles/distribution/test_tx.go index 33db8c8b1..2acd9edfb 100644 --- a/tests/integration/precompiles/distribution/test_tx.go +++ b/tests/integration/precompiles/distribution/test_tx.go @@ -10,7 +10,7 @@ import ( cmn "github.com/cosmos/evm/precompiles/common" "github.com/cosmos/evm/precompiles/distribution" "github.com/cosmos/evm/precompiles/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" utiltx "github.com/cosmos/evm/testutil/tx" @@ -199,10 +199,10 @@ func (s *PrecompileTestSuite) TestWithdrawDelegatorReward() { var coins []cmn.Coin err := s.precompile.UnpackIntoInterface(&coins, distribution.WithdrawDelegatorRewardMethod, data) s.Require().NoError(err, "failed to unpack output") - s.Require().Equal(coins[0].Denom, testconstants.ExampleAttoDenom) + s.Require().Equal(coins[0].Denom, testconfig.ExampleAttoDenom) s.Require().Equal(coins[0].Amount.Int64(), expRewardsAmt.Int64()) // Check bank balance after the withdrawal of rewards - balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconstants.ExampleAttoDenom) + balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconfig.ExampleAttoDenom) s.Require().True(balance.Amount.GT(network.PrefundedAccountInitialBalance)) }, 20000, @@ -275,14 +275,14 @@ func (s *PrecompileTestSuite) TestWithdrawValidatorCommission() { valAddr, err := sdk.ValAddressFromBech32(operatorAddress) s.Require().NoError(err) amt := math.LegacyNewDecWithPrec(1000000000000000000, 1) - valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(testconstants.ExampleAttoDenom, amt)} + valCommission := sdk.DecCoins{sdk.NewDecCoinFromDec(testconfig.ExampleAttoDenom, amt)} // set outstanding rewards s.Require().NoError(s.network.App.GetDistrKeeper().SetValidatorOutstandingRewards(ctx, valAddr, types.ValidatorOutstandingRewards{Rewards: valCommission})) // set commission s.Require().NoError(s.network.App.GetDistrKeeper().SetValidatorAccumulatedCommission(ctx, valAddr, types.ValidatorAccumulatedCommission{Commission: valCommission})) // fund distr mod to pay for rewards + commission - coins := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, amt.Mul(math.LegacyNewDec(2)).RoundInt())) + coins := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, amt.Mul(math.LegacyNewDec(2)).RoundInt())) err = s.mintCoinsForDistrMod(ctx, coins) s.Require().NoError(err) return []interface{}{ @@ -294,15 +294,15 @@ func (s *PrecompileTestSuite) TestWithdrawValidatorCommission() { amt := math.NewInt(100000000000000000) err := s.precompile.UnpackIntoInterface(&coins, distribution.WithdrawValidatorCommissionMethod, data) s.Require().NoError(err, "failed to unpack output") - s.Require().Equal(coins[0].Denom, testconstants.ExampleAttoDenom) + s.Require().Equal(coins[0].Denom, testconfig.ExampleAttoDenom) s.Require().Equal(coins[0].Amount, amt.BigInt()) // Check bank balance after the withdrawal of commission valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator()) s.Require().NoError(err) - balance := s.network.App.GetBankKeeper().GetBalance(ctx, valAddr.Bytes(), testconstants.ExampleAttoDenom) + balance := s.network.App.GetBankKeeper().GetBalance(ctx, valAddr.Bytes(), testconfig.ExampleAttoDenom) s.Require().Equal(balance.Amount, prevBalance.Amount.Add(amt)) - s.Require().Equal(balance.Denom, testconstants.ExampleAttoDenom) + s.Require().Equal(balance.Denom, testconfig.ExampleAttoDenom) }, 20000, false, @@ -318,7 +318,7 @@ func (s *PrecompileTestSuite) TestWithdrawValidatorCommission() { valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator()) s.Require().NoError(err) - prevBalance = s.network.App.GetBankKeeper().GetBalance(ctx, valAddr.Bytes(), testconstants.ExampleAttoDenom) + prevBalance = s.network.App.GetBankKeeper().GetBalance(ctx, valAddr.Bytes(), testconfig.ExampleAttoDenom) validatorAddress := common.BytesToAddress(valAddr.Bytes()) var contract *vm.Contract @@ -409,7 +409,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() { } }, func(_ []byte) { - balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAccAddr(0), testconstants.ExampleAttoDenom) + balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAccAddr(0), testconfig.ExampleAttoDenom) // rewards from 3 validators - 5% commission expRewards := expRewardsAmt.Mul(math.NewInt(3)) s.Require().Equal(balance.Amount, prevBalance.Amount.Add(expRewards)) @@ -427,7 +427,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() { } }, func([]byte) { - balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAccAddr(0), testconstants.ExampleAttoDenom) + balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAccAddr(0), testconfig.ExampleAttoDenom) // rewards from 3 validators - 5% commission expRewards := expRewardsAmt.Mul(math.NewInt(3)) s.Require().Equal(balance.Amount, prevBalance.Amount.Add(expRewards)) @@ -445,7 +445,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() { } }, func([]byte) { - balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAccAddr(0), testconstants.ExampleAttoDenom) + balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAccAddr(0), testconfig.ExampleAttoDenom) s.Require().Equal(balance.Amount, prevBalance.Amount.Add(expRewardsAmt)) }, 20000, @@ -480,7 +480,7 @@ func (s *PrecompileTestSuite) TestClaimRewards() { s.Require().NoError(err) // get previous balance to compare final balance in the postCheck func - prevBalance = s.network.App.GetBankKeeper().GetBalance(ctx, addr.Bytes(), testconstants.ExampleAttoDenom) + prevBalance = s.network.App.GetBankKeeper().GetBalance(ctx, addr.Bytes(), testconfig.ExampleAttoDenom) bz, err := s.precompile.ClaimRewards(ctx, contract, s.network.GetStateDB(), &method, tc.malleate()) @@ -536,7 +536,7 @@ func (s *PrecompileTestSuite) TestFundCommunityPool() { s.keyring.GetAddr(0), []cmn.Coin{ { - Denom: testconstants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, }, @@ -547,8 +547,8 @@ func (s *PrecompileTestSuite) TestFundCommunityPool() { s.Require().NoError(err) coins := pool.CommunityPool expectedAmount := new(big.Int).Mul(big.NewInt(1e18), new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(math.LegacyPrecision)), nil)) - s.Require().Equal(expectedAmount, coins.AmountOf(testconstants.ExampleAttoDenom).BigInt()) - userBalance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconstants.ExampleAttoDenom) + s.Require().Equal(expectedAmount, coins.AmountOf(testconfig.ExampleAttoDenom).BigInt()) + userBalance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconfig.ExampleAttoDenom) s.Require().Equal(network.PrefundedAccountInitialBalance.Sub(math.NewInt(1e18)), userBalance.Amount) }, 20000, @@ -566,7 +566,7 @@ func (s *PrecompileTestSuite) TestFundCommunityPool() { contract, ctx = testutil.NewPrecompileContract(s.T(), ctx, s.keyring.GetAddr(0), s.precompile.Address(), tc.gas) // Sanity check to make sure the starting balance is always 100k ATOM - balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconstants.ExampleAttoDenom) + balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconfig.ExampleAttoDenom) s.Require().Equal(balance.Amount, network.PrefundedAccountInitialBalance) bz, err := s.precompile.FundCommunityPool(ctx, contract, s.network.GetStateDB(), &method, tc.malleate()) @@ -611,7 +611,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolMethod() { val.OperatorAddress, []cmn.Coin{ { - Denom: testconstants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, }, @@ -630,7 +630,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolMethod() { "", []cmn.Coin{ { - Denom: testconstants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, }, @@ -663,7 +663,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolMethod() { val.OperatorAddress, []cmn.Coin{ { - Denom: testconstants.ExampleAttoDenom, + Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18), }, }, @@ -682,7 +682,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolMethod() { s.Require().NoError(err) depositCoins := sdk.DecCoins{ - {Denom: testconstants.ExampleAttoDenom, Amount: math.LegacyNewDecFromBigInt(big.NewInt(1e18))}, + {Denom: testconfig.ExampleAttoDenom, Amount: math.LegacyNewDecFromBigInt(big.NewInt(1e18))}, } expectedValCommission := depositCoins.MulDec(val.GetCommission()) expectedCurrentRewards := depositCoins.Sub(expectedValCommission) @@ -704,9 +704,9 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolMethod() { s.Require().Equal(expectedOutstandingRewards, outstandingRewards.Rewards) // check bank balance after the deposit - balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconstants.ExampleAttoDenom) + balance := s.network.App.GetBankKeeper().GetBalance(ctx, s.keyring.GetAddr(0).Bytes(), testconfig.ExampleAttoDenom) s.Require().Equal(balance.Amount, network.PrefundedAccountInitialBalance.Sub(math.NewInt(1e18))) - s.Require().Equal(balance.Denom, testconstants.ExampleAttoDenom) + s.Require().Equal(balance.Denom, testconfig.ExampleAttoDenom) }, 20000, false, diff --git a/tests/integration/precompiles/erc20/test_integration.go b/tests/integration/precompiles/erc20/test_integration.go index 20869e598..e0160174b 100644 --- a/tests/integration/precompiles/erc20/test_integration.go +++ b/tests/integration/precompiles/erc20/test_integration.go @@ -19,7 +19,7 @@ import ( "github.com/cosmos/evm/precompiles/erc20" "github.com/cosmos/evm/precompiles/erc20/testdata" "github.com/cosmos/evm/precompiles/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -251,7 +251,7 @@ func TestIntegrationTestSuite(t *testing.T, create network.CreateEvmApp, options passCheck = failCheck.WithExpPass(true) erc20Keeper := is.network.App.GetErc20Keeper() - available := erc20Keeper.IsNativePrecompileAvailable(is.network.GetContext(), common.HexToAddress(testconstants.WEVMOSContractMainnet)) + available := erc20Keeper.IsNativePrecompileAvailable(is.network.GetContext(), common.HexToAddress(testconfig.WEVMOSContractMainnet)) Expect(available).To(BeTrue()) revertContractAddr, err = is.factory.DeployContract( @@ -261,7 +261,7 @@ func TestIntegrationTestSuite(t *testing.T, create network.CreateEvmApp, options Contract: revertCallerContract, // NOTE: we're passing the precompile address to the constructor because that initiates the contract // to make calls to the correct ERC20 precompile. - ConstructorArgs: []interface{}{common.HexToAddress(testconstants.WEVMOSContractMainnet)}, + ConstructorArgs: []interface{}{common.HexToAddress(testconfig.WEVMOSContractMainnet)}, }, ) Expect(err).ToNot(HaveOccurred(), "failed to deploy reverter contract") diff --git a/tests/integration/precompiles/gov/test_query.go b/tests/integration/precompiles/gov/test_query.go index 3e57f40a9..ae52fe162 100644 --- a/tests/integration/precompiles/gov/test_query.go +++ b/tests/integration/precompiles/gov/test_query.go @@ -10,7 +10,7 @@ import ( cmn "github.com/cosmos/evm/precompiles/common" "github.com/cosmos/evm/precompiles/gov" "github.com/cosmos/evm/precompiles/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "cosmossdk.io/math" @@ -29,7 +29,7 @@ var ( govAcct = authtypes.NewModuleAddress(govtypes.ModuleName) // TestProposalMsgs are msgs used on a proposal. TestProposalMsgs = []sdk.Msg{ - banktypes.NewMsgSend(govAcct, addr, sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(1000)))), + banktypes.NewMsgSend(govAcct, addr, sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1000)))), } ) diff --git a/tests/integration/precompiles/gov/test_setup.go b/tests/integration/precompiles/gov/test_setup.go index 312f91b47..e8c9c6063 100644 --- a/tests/integration/precompiles/gov/test_setup.go +++ b/tests/integration/precompiles/gov/test_setup.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/evm/precompiles/gov" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -100,7 +100,7 @@ func (s *PrecompileTestSuite) SetupTest() { bankGen := banktypes.DefaultGenesisState() bankGen.Balances = []banktypes.Balance{{ Address: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Coins: sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(200))), + Coins: sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(200))), }} govGen := govv1.DefaultGenesisState() govGen.StartingProposalId = 3 @@ -108,15 +108,15 @@ func (s *PrecompileTestSuite) SetupTest() { { ProposalId: 1, Depositor: keyring.GetAccAddr(0).String(), - Amount: sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(100))), + Amount: sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(100))), }, { ProposalId: 2, Depositor: keyring.GetAccAddr(1).String(), - Amount: sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(100))), + Amount: sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(100))), }, } - govGen.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(100))) + govGen.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(100))) govGen.Params.ProposalCancelDest = keyring.GetAccAddr(2).String() govGen.Proposals = append(govGen.Proposals, prop) govGen.Proposals = append(govGen.Proposals, prop2) diff --git a/tests/integration/precompiles/staking/test_integration.go b/tests/integration/precompiles/staking/test_integration.go index 13e48e60c..fbd8064f5 100644 --- a/tests/integration/precompiles/staking/test_integration.go +++ b/tests/integration/precompiles/staking/test_integration.go @@ -21,7 +21,7 @@ import ( "github.com/cosmos/evm/precompiles/staking/testdata" "github.com/cosmos/evm/precompiles/testutil" "github.com/cosmos/evm/precompiles/testutil/contracts" - cosmosevmutil "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" "github.com/cosmos/evm/testutil/integration/evm/utils" testutiltx "github.com/cosmos/evm/testutil/tx" @@ -2673,7 +2673,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp err = s.precompile.UnpackIntoInterface(&delOut, staking.DelegationMethod, ethRes.Ret) Expect(err).To(BeNil(), "error while unpacking the delegation output: %v", err) Expect(delOut.Balance.Amount.Int64()).To(Equal(int64(0)), "expected a different delegation balance") - Expect(delOut.Balance.Denom).To(Equal(cosmosevmutil.ExampleAttoDenom), "expected a different delegation balance") + Expect(delOut.Balance.Denom).To(Equal(testconfig.ExampleAttoDenom), "expected a different delegation balance") }) It("which exists should return the delegation", func() { @@ -2694,7 +2694,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp err = s.precompile.UnpackIntoInterface(&delOut, staking.DelegationMethod, ethRes.Ret) Expect(err).To(BeNil(), "error while unpacking the delegation output: %v", err) Expect(delOut.Balance).To(Equal( - cmn.Coin{Denom: cosmosevmutil.ExampleAttoDenom, Amount: big.NewInt(1e18)}), + cmn.Coin{Denom: testconfig.ExampleAttoDenom, Amount: big.NewInt(1e18)}), "expected a different delegation balance", ) }) diff --git a/tests/integration/precompiles/staking/test_setup.go b/tests/integration/precompiles/staking/test_setup.go index cb4e04d63..2332dc1eb 100644 --- a/tests/integration/precompiles/staking/test_setup.go +++ b/tests/integration/precompiles/staking/test_setup.go @@ -4,7 +4,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/evm/precompiles/staking" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -47,7 +47,7 @@ func (s *PrecompileTestSuite) SetupTest() { keyring := testkeyring.New(2) customGenesis := network.CustomGenesisState{} // mint some coin to fee collector - coins := sdk.NewCoins(sdk.NewCoin(testconstants.ExampleAttoDenom, sdkmath.NewInt(InitialTestBalance))) + coins := sdk.NewCoins(sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(InitialTestBalance))) balances := []banktypes.Balance{ { Address: authtypes.NewModuleAddress(authtypes.FeeCollectorName).String(), diff --git a/tests/integration/precompiles/staking/test_staking.go b/tests/integration/precompiles/staking/test_staking.go index d8b5149dc..ba35a63b1 100644 --- a/tests/integration/precompiles/staking/test_staking.go +++ b/tests/integration/precompiles/staking/test_staking.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/evm/precompiles/staking" "github.com/cosmos/evm/precompiles/testutil" chainutil "github.com/cosmos/evm/testutil" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/keyring" "github.com/cosmos/evm/x/vm/statedb" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -224,7 +224,7 @@ func (s *PrecompileTestSuite) TestRun() { // Needs to be called after setting unbonding delegation // In order to mimic the coins being added to the unboding pool - coin := sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(1000)) + coin := sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1000)) err = s.network.App.GetBankKeeper().SendCoinsFromModuleToModule(ctx, stakingtypes.BondedPoolName, stakingtypes.NotBondedPoolName, sdk.Coins{coin}) s.Require().NoError(err, "failed to send coins from module to module") @@ -352,7 +352,7 @@ func (s *PrecompileTestSuite) TestRun() { // Needs to be called after setting unbonding delegation // In order to mimic the coins being added to the unboding pool - coin := sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(1000)) + coin := sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1000)) err = s.network.App.GetBankKeeper().SendCoinsFromModuleToModule(ctx, stakingtypes.BondedPoolName, stakingtypes.NotBondedPoolName, sdk.Coins{coin}) s.Require().NoError(err, "failed to send coins from module to module") @@ -572,7 +572,7 @@ func (s *PrecompileTestSuite) TestCMS() { // Needs to be called after setting unbonding delegation // In order to mimic the coins being added to the unboding pool - coin := sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(1000)) + coin := sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1000)) err = s.network.App.GetBankKeeper().SendCoinsFromModuleToModule(ctx, stakingtypes.BondedPoolName, stakingtypes.NotBondedPoolName, sdk.Coins{coin}) s.Require().NoError(err, "failed to send coins from module to module") @@ -700,7 +700,7 @@ func (s *PrecompileTestSuite) TestCMS() { // Needs to be called after setting unbonding delegation // In order to mimic the coins being added to the unboding pool - coin := sdk.NewCoin(testconstants.ExampleAttoDenom, math.NewInt(1000)) + coin := sdk.NewCoin(testconfig.ExampleAttoDenom, math.NewInt(1000)) err = s.network.App.GetBankKeeper().SendCoinsFromModuleToModule(ctx, stakingtypes.BondedPoolName, stakingtypes.NotBondedPoolName, sdk.Coins{coin}) s.Require().NoError(err, "failed to send coins from module to module") diff --git a/tests/integration/precompiles/werc20/test_events.go b/tests/integration/precompiles/werc20/test_events.go index e4734754d..7dfff8b14 100644 --- a/tests/integration/precompiles/werc20/test_events.go +++ b/tests/integration/precompiles/werc20/test_events.go @@ -9,7 +9,7 @@ import ( cmn "github.com/cosmos/evm/precompiles/common" "github.com/cosmos/evm/precompiles/werc20" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -44,7 +44,7 @@ func NewPrecompileUnitTestSuite( // SetupTest allows to configure the testing suite embedding a network with a // custom chainID. This is important to check that the correct address is used // for the precompile. -func (s *PrecompileUnitTestSuite) SetupTest(chainID testconstants.ChainID) { +func (s *PrecompileUnitTestSuite) SetupTest(chainID testconfig.ChainID) { keyring := keyring.New(2) options := []network.ConfigOption{ @@ -97,14 +97,14 @@ type WithdrawalEvent struct { func (s *PrecompileUnitTestSuite) TestEmitDepositEvent() { testCases := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "mainnet", - chainID: testconstants.ExampleChainID, + chainID: testconfig.ExampleChainID, }, { name: "six decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, } @@ -156,14 +156,14 @@ func (s *PrecompileUnitTestSuite) TestEmitDepositEvent() { func (s *PrecompileUnitTestSuite) TestEmitWithdrawalEvent() { testCases := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "mainnet", - chainID: testconstants.ExampleChainID, + chainID: testconfig.ExampleChainID, }, { name: "six decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, } diff --git a/tests/integration/precompiles/werc20/test_integration.go b/tests/integration/precompiles/werc20/test_integration.go index ebcd75f5a..36f4d28a6 100644 --- a/tests/integration/precompiles/werc20/test_integration.go +++ b/tests/integration/precompiles/werc20/test_integration.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/evm/precompiles/testutil" "github.com/cosmos/evm/precompiles/werc20" "github.com/cosmos/evm/precompiles/werc20/testdata" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -50,7 +50,7 @@ type PrecompileIntegrationTestSuite struct { } func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmApp, options ...network.ConfigOption) { - _ = DescribeTableSubtree("a user interact with the WEVMOS precompiled contract", func(chainId testconstants.ChainID) { + _ = DescribeTableSubtree("a user interact with the WEVMOS precompiled contract", func(chainId testconfig.ChainID) { var ( is *PrecompileIntegrationTestSuite passCheck, failCheck testutil.LogCheckArgs @@ -71,9 +71,9 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp // precise balance handling across different decimal configurations var conversionFactor *big.Int switch chainId { - case testconstants.SixDecimalsChainID: + case testconfig.ExampleSixDecimalsChainID: conversionFactor = big.NewInt(1e12) // For 6-decimal chains - case testconstants.TwelveDecimalsChainID: + case testconfig.ExampleTwelveDecimalsChainID: conversionFactor = big.NewInt(1e6) // For 12-decimal chains default: conversionFactor = big.NewInt(1) // For 18-decimal chains @@ -111,7 +111,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() Expect(configurator. - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[chainId]). + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[chainId]). Apply()).To(BeNil(), "expected no error setting the evm configurator") opts := []network.ConfigOption{ @@ -130,7 +130,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp is.keyring = keyring is.wrappedCoinDenom = evmtypes.GetEVMCoinDenom() - is.precompileAddrHex = network.GetWEVMOSContractHex(testconstants.ChainID{ + is.precompileAddrHex = network.GetWEVMOSContractHex(testconfig.ChainID{ ChainID: is.network.GetChainID(), EVMChainID: is.network.GetEIP155ChainID().Uint64(), }) @@ -552,7 +552,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp err = is.precompile.UnpackIntoInterface(&decimals, erc20.DecimalsMethod, ethRes.Ret) Expect(err).ToNot(HaveOccurred(), "failed to unpack result") - coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ChainID{ + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ChainID{ ChainID: is.network.GetChainID(), EVMChainID: is.network.GetEIP155ChainID().Uint64(), }] @@ -562,9 +562,9 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp }) }) }, - Entry("6 decimals chain", testconstants.SixDecimalsChainID), - Entry("12 decimals chain", testconstants.TwelveDecimalsChainID), - Entry("18 decimals chain", testconstants.ExampleChainID), + Entry("6 decimals chain", testconfig.ExampleSixDecimalsChainID), + Entry("12 decimals chain", testconfig.ExampleTwelveDecimalsChainID), + Entry("18 decimals chain", testconfig.ExampleChainID), ) // Run Ginkgo integration tests diff --git a/tests/integration/rpc/backend/test_backend_suite.go b/tests/integration/rpc/backend/test_backend_suite.go index c464d673b..10b4fd996 100644 --- a/tests/integration/rpc/backend/test_backend_suite.go +++ b/tests/integration/rpc/backend/test_backend_suite.go @@ -19,7 +19,7 @@ import ( rpcbackend "github.com/cosmos/evm/rpc/backend" "github.com/cosmos/evm/rpc/backend/mocks" rpctypes "github.com/cosmos/evm/rpc/types" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" utiltx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -48,7 +48,7 @@ func NewTestSuite(create network.CreateEvmApp, options ...network.ConfigOption) } } -var ChainID = constants.ExampleChainID +var ChainID = testconfig.ExampleChainID // SetupTest is executed before every TestSuite test func (s *TestSuite) SetupTest() { diff --git a/tests/integration/rpc/backend/test_call_tx.go b/tests/integration/rpc/backend/test_call_tx.go index a35eaba75..2b1aaaf2c 100644 --- a/tests/integration/rpc/backend/test_call_tx.go +++ b/tests/integration/rpc/backend/test_call_tx.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/evm/rpc/backend/mocks" rpctypes "github.com/cosmos/evm/rpc/types" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -337,7 +337,7 @@ func (s *TestSuite) TestSendRawTransaction() { return bytes }, common.Hash{}, - fmt.Errorf("incorrect chain-id; expected %d, got %d", constants.ExampleChainID.EVMChainID, invalidChainID).Error(), + fmt.Errorf("incorrect chain-id; expected %d, got %d", testconfig.ExampleChainID.EVMChainID, invalidChainID).Error(), false, }, { diff --git a/tests/integration/rpc/backend/test_chain_info.go b/tests/integration/rpc/backend/test_chain_info.go index 514132476..3fb2b0369 100644 --- a/tests/integration/rpc/backend/test_chain_info.go +++ b/tests/integration/rpc/backend/test_chain_info.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/evm/rpc/backend/mocks" rpc "github.com/cosmos/evm/rpc/types" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -156,7 +156,7 @@ func (s *TestSuite) TestBaseFee() { } func (s *TestSuite) TestChainID() { - expChainID := (*hexutil.Big)(big.NewInt(int64(constants.ExampleChainID.EVMChainID))) //nolint:gosec // G115 + expChainID := (*hexutil.Big)(big.NewInt(int64(testconfig.ExampleChainID.EVMChainID))) //nolint:gosec // G115 testCases := []struct { name string registerMock func() diff --git a/tests/integration/rpc/backend/test_evm_query_client.go b/tests/integration/rpc/backend/test_evm_query_client.go index cbeed91e9..7724f0ea9 100644 --- a/tests/integration/rpc/backend/test_evm_query_client.go +++ b/tests/integration/rpc/backend/test_evm_query_client.go @@ -18,7 +18,7 @@ import ( "github.com/cosmos/evm/rpc/backend/mocks" rpc "github.com/cosmos/evm/rpc/types" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" proto "github.com/cosmos/gogoproto/proto" @@ -56,18 +56,18 @@ var _ evmtypes.QueryClient = &mocks.EVMQueryClient{} func RegisterTraceTransactionWithPredecessors(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx, predecessors []*evmtypes.MsgEthereumTx) { data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d} queryClient.On("TraceTx", rpc.ContextWithHeight(1), - MatchByProto(&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: int64(constants.ExampleChainID.EVMChainID), BlockMaxGas: -1})). //nolint:gosec // G115 + MatchByProto(&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: int64(testconfig.ExampleChainID.EVMChainID), BlockMaxGas: -1})). //nolint:gosec // G115 Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil) } func RegisterTraceTransaction(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx) { data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d} - queryClient.On("TraceTx", rpc.ContextWithHeight(1), MatchByProto(&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: int64(constants.ExampleChainID.EVMChainID), BlockMaxGas: -1})). //nolint:gosec // G115 + queryClient.On("TraceTx", rpc.ContextWithHeight(1), MatchByProto(&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: int64(testconfig.ExampleChainID.EVMChainID), BlockMaxGas: -1})). //nolint:gosec // G115 Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil) } func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx) { - queryClient.On("TraceTx", rpc.ContextWithHeight(1), MatchByProto(&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: int64(constants.ExampleChainID.EVMChainID)})). //nolint:gosec // G115 + queryClient.On("TraceTx", rpc.ContextWithHeight(1), MatchByProto(&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: int64(testconfig.ExampleChainID.EVMChainID)})). //nolint:gosec // G115 Return(nil, errortypes.ErrInvalidRequest) } @@ -75,7 +75,7 @@ func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx * func RegisterTraceBlock(queryClient *mocks.EVMQueryClient, txs []*evmtypes.MsgEthereumTx) { data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d} queryClient.On("TraceBlock", rpc.ContextWithHeight(1), - MatchByProto(&evmtypes.QueryTraceBlockRequest{Txs: txs, BlockNumber: 1, TraceConfig: &evmtypes.TraceConfig{}, ChainId: int64(constants.ExampleChainID.EVMChainID), BlockMaxGas: -1})). //nolint:gosec // G115 + MatchByProto(&evmtypes.QueryTraceBlockRequest{Txs: txs, BlockNumber: 1, TraceConfig: &evmtypes.TraceConfig{}, ChainId: int64(testconfig.ExampleChainID.EVMChainID), BlockMaxGas: -1})). //nolint:gosec // G115 Return(&evmtypes.QueryTraceBlockResponse{Data: data}, nil) } diff --git a/tests/integration/rpc/backend/test_node_info.go b/tests/integration/rpc/backend/test_node_info.go index 270a3c8a1..a09e8258d 100644 --- a/tests/integration/rpc/backend/test_node_info.go +++ b/tests/integration/rpc/backend/test_node_info.go @@ -14,7 +14,7 @@ import ( "github.com/cosmos/evm/crypto/ethsecp256k1" "github.com/cosmos/evm/rpc/backend/mocks" "github.com/cosmos/evm/server/config" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" evmtypes "github.com/cosmos/evm/x/vm/types" "cosmossdk.io/math" @@ -33,13 +33,13 @@ func (s *TestSuite) TestRPCMinGasPrice() { { "pass - default gas price", func() {}, - big.NewInt(constants.DefaultGasPrice), + big.NewInt(testconfig.DefaultGasPrice), true, }, { "pass - min gas price is 0", func() {}, - big.NewInt(constants.DefaultGasPrice), + big.NewInt(testconfig.DefaultGasPrice), true, }, } @@ -260,7 +260,7 @@ func (s *TestSuite) TestSetEtherbase() { RegisterStatus(client) RegisterValidatorAccount(QueryClient, s.acc) RegisterParams(QueryClient, &header, 1) - c := sdk.NewDecCoin(constants.ExampleAttoDenom, math.NewIntFromBigInt(big.NewInt(1))) + c := sdk.NewDecCoin(testconfig.ExampleAttoDenom, math.NewIntFromBigInt(big.NewInt(1))) s.backend.Cfg.SetMinGasPrices(sdk.DecCoins{c}) delAddr, _ := s.backend.GetCoinbase() // account, _ := s.backend.ClientCtx.AccountRetriever.GetAccount(s.backend.ClientCtx, delAddr) diff --git a/tests/integration/testutil/test_config.go b/tests/integration/testutil/test_config.go index dc57266be..da568adc0 100644 --- a/tests/integration/testutil/test_config.go +++ b/tests/integration/testutil/test_config.go @@ -3,7 +3,7 @@ package testutil import ( - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" grpchandler "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" testkeyring "github.com/cosmos/evm/testutil/keyring" @@ -16,12 +16,12 @@ import ( ) func (s *TestSuite) TestWithChainID() { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] testCases := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID evmChainID uint64 coinInfo evmtypes.EvmCoinInfo expBaseFee math.LegacyDec @@ -29,14 +29,14 @@ func (s *TestSuite) TestWithChainID() { }{ { name: "18 decimals", - chainID: testconstants.ExampleChainID, + chainID: testconfig.ExampleChainID, coinInfo: eighteenDecimalsCoinInfo, expBaseFee: math.LegacyNewDec(875_000_000), expCosmosAmount: network.GetInitialAmount(evmtypes.EighteenDecimals), }, { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, coinInfo: sixDecimalsCoinInfo, expBaseFee: math.LegacyNewDecWithPrec(875, 6), expCosmosAmount: network.GetInitialAmount(evmtypes.SixDecimals), @@ -98,9 +98,9 @@ func (s *TestSuite) TestWithChainID() { } func (s *TestSuite) TestWithBalances() { - key1Balance := sdk.NewCoins(sdk.NewInt64Coin(testconstants.ExampleAttoDenom, 1e18)) + key1Balance := sdk.NewCoins(sdk.NewInt64Coin(testconfig.ExampleAttoDenom, 1e18)) key2Balance := sdk.NewCoins( - sdk.NewInt64Coin(testconstants.ExampleAttoDenom, 2e18), + sdk.NewInt64Coin(testconfig.ExampleAttoDenom, 2e18), sdk.NewInt64Coin("other", 3e18), ) diff --git a/tests/integration/wallets/test_ledger_suite.go b/tests/integration/wallets/test_ledger_suite.go index a9f166c19..c8eadeecd 100644 --- a/tests/integration/wallets/test_ledger_suite.go +++ b/tests/integration/wallets/test_ledger_suite.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" "github.com/cosmos/evm/wallets/ledger" "github.com/cosmos/evm/wallets/ledger/mocks" @@ -93,7 +93,7 @@ func (suite *LedgerTestSuite) getMockTxAmino() []byte { } }], "sequence":"6" - }`, constants.ExampleChainID.ChainID), + }`, testconfig.ExampleChainID.ChainID), "", ) @@ -157,7 +157,7 @@ func (suite *LedgerTestSuite) getMockTxProtobuf() []byte { signBytes, err := tx.DirectSignBytes( bodyBytes, authInfoBytes, - constants.ExampleChainID.ChainID, + testconfig.ExampleChainID.ChainID, 0, ) suite.Require().NoError(err) diff --git a/tests/integration/x/erc20/test_grpc_query.go b/tests/integration/x/erc20/test_grpc_query.go index 138614b4b..b337f9e06 100644 --- a/tests/integration/x/erc20/test_grpc_query.go +++ b/tests/integration/x/erc20/test_grpc_query.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/cosmos/evm/testutil/config" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/erc20/types" @@ -32,7 +32,7 @@ func (s *KeeperTestSuite) TestTokenPairs() { Pagination: &query.PageResponse{ Total: 1, }, - TokenPairs: testconstants.ExampleTokenPairs, + TokenPairs: testconfig.ExampleTokenPairs, } }, true, @@ -43,7 +43,7 @@ func (s *KeeperTestSuite) TestTokenPairs() { req = &types.QueryTokenPairsRequest{ Pagination: &query.PageRequest{Limit: 10, CountTotal: true}, } - pairs := testconstants.ExampleTokenPairs + pairs := testconfig.ExampleTokenPairs pair := types.NewTokenPair(utiltx.GenerateAddress(), "coin", types.OWNER_MODULE) s.network.App.GetErc20Keeper().SetTokenPair(ctx, pair) pairs = append(pairs, pair) @@ -59,7 +59,7 @@ func (s *KeeperTestSuite) TestTokenPairs() { "2 pairs registered wo/pagination", func() { req = &types.QueryTokenPairsRequest{} - pairs := testconstants.ExampleTokenPairs + pairs := testconfig.ExampleTokenPairs pair := types.NewTokenPair(utiltx.GenerateAddress(), "coin", types.OWNER_MODULE) pair2 := types.NewTokenPair(utiltx.GenerateAddress(), "coin2", types.OWNER_MODULE) diff --git a/tests/integration/x/erc20/test_precompiles.go b/tests/integration/x/erc20/test_precompiles.go index 502fce96d..0db7f80de 100644 --- a/tests/integration/x/erc20/test_precompiles.go +++ b/tests/integration/x/erc20/test_precompiles.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/erc20/types" @@ -96,7 +96,7 @@ func (s *KeeperTestSuite) TestGetERC20PrecompileInstance() { func (s *KeeperTestSuite) TestGetNativePrecompiles() { var ctx sdk.Context testAddr := utiltx.GenerateAddress() - defaultWEVMOSAddr := common.HexToAddress(testconstants.WEVMOSContractMainnet) + defaultWEVMOSAddr := common.HexToAddress(testconfig.WEVMOSContractMainnet) testCases := []struct { name string @@ -139,7 +139,7 @@ func (s *KeeperTestSuite) TestGetNativePrecompiles() { func (s *KeeperTestSuite) TestSetNativePrecompile() { var ctx sdk.Context testAddr := utiltx.GenerateAddress() - defaultWEVMOSAddr := common.HexToAddress(testconstants.WEVMOSContractMainnet) + defaultWEVMOSAddr := common.HexToAddress(testconfig.WEVMOSContractMainnet) testCases := []struct { name string @@ -192,7 +192,7 @@ func (s *KeeperTestSuite) TestSetNativePrecompile() { func (s *KeeperTestSuite) TestDeleteNativePrecompile() { var ctx sdk.Context testAddr := utiltx.GenerateAddress() - defaultWEVMOSAddr := common.HexToAddress(testconstants.WEVMOSContractMainnet) + defaultWEVMOSAddr := common.HexToAddress(testconfig.WEVMOSContractMainnet) unavailableAddr := common.HexToAddress("unavailable") testCases := []struct { @@ -285,7 +285,7 @@ func (s *KeeperTestSuite) TestDeleteNativePrecompile() { func (s *KeeperTestSuite) TestIsNativePrecompileAvailable() { var ctx sdk.Context testAddr := utiltx.GenerateAddress() - defaultWEVMOSAddr := common.HexToAddress(testconstants.WEVMOSContractMainnet) + defaultWEVMOSAddr := common.HexToAddress(testconfig.WEVMOSContractMainnet) unavailableAddr := common.HexToAddress("unavailable") testCases := []struct { diff --git a/tests/integration/x/erc20/test_token_pairs.go b/tests/integration/x/erc20/test_token_pairs.go index fc63348e0..1b92e4480 100644 --- a/tests/integration/x/erc20/test_token_pairs.go +++ b/tests/integration/x/erc20/test_token_pairs.go @@ -5,7 +5,7 @@ import ( "github.com/ethereum/go-ethereum/common" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/erc20/types" @@ -23,14 +23,14 @@ func (s *KeeperTestSuite) TestGetTokenPairs() { malleate func() }{ { - "no pair registered", func() { expRes = testconstants.ExampleTokenPairs }, + "no pair registered", func() { expRes = testconfig.ExampleTokenPairs }, }, { "1 pair registered", func() { pair := types.NewTokenPair(utiltx.GenerateAddress(), "coin", types.OWNER_MODULE) s.network.App.GetErc20Keeper().SetTokenPair(ctx, pair) - expRes = testconstants.ExampleTokenPairs + expRes = testconfig.ExampleTokenPairs expRes = append(expRes, pair) }, }, @@ -41,7 +41,7 @@ func (s *KeeperTestSuite) TestGetTokenPairs() { pair2 := types.NewTokenPair(utiltx.GenerateAddress(), "coin2", types.OWNER_MODULE) s.network.App.GetErc20Keeper().SetTokenPair(ctx, pair) s.network.App.GetErc20Keeper().SetTokenPair(ctx, pair2) - expRes = testconstants.ExampleTokenPairs + expRes = testconfig.ExampleTokenPairs expRes = append(expRes, []types.TokenPair{pair, pair2}...) }, }, diff --git a/tests/integration/x/precisebank/test_burn_integration.go b/tests/integration/x/precisebank/test_burn_integration.go index 852b60f59..520eb8fd8 100644 --- a/tests/integration/x/precisebank/test_burn_integration.go +++ b/tests/integration/x/precisebank/test_burn_integration.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/precisebank/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -417,19 +417,19 @@ func (s *KeeperIntegrationTestSuite) TestBurnCoinsSpreadRemainder() { func (s *KeeperIntegrationTestSuite) TestBurnCoinsRandomValueMultiDecimals() { tests := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, { name: "12 decimals", - chainID: testconstants.TwelveDecimalsChainID, + chainID: testconfig.ExampleTwelveDecimalsChainID, }, { name: "2 decimals", - chainID: testconstants.TwoDecimalsChainID, + chainID: testconfig.ExampleTwoDecimalsChainID, }, } @@ -500,7 +500,7 @@ func (s *KeeperIntegrationTestSuite) TestBurnCoinsRandomValueMultiDecimals() { func FuzzBurnCoins(f *testing.F) { configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) + configurator.WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID]) err := configurator.Apply() require.NoError(f, err) diff --git a/tests/integration/x/precisebank/test_genesis.go b/tests/integration/x/precisebank/test_genesis.go index 02f01e130..594b0d487 100644 --- a/tests/integration/x/precisebank/test_genesis.go +++ b/tests/integration/x/precisebank/test_genesis.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/suite" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" "github.com/cosmos/evm/x/precisebank" "github.com/cosmos/evm/x/precisebank/types" @@ -31,10 +31,10 @@ func NewGenesisTestSuite(create network.CreateEvmApp, options ...network.ConfigO } func (s *GenesisTestSuite) SetupTest() { - s.SetupTestWithChainID(testconstants.SixDecimalsChainID) + s.SetupTestWithChainID(testconfig.ExampleSixDecimalsChainID) } -func (s *GenesisTestSuite) SetupTestWithChainID(chainID testconstants.ChainID) { +func (s *GenesisTestSuite) SetupTestWithChainID(chainID testconfig.ChainID) { options := []network.ConfigOption{ network.WithChainID(chainID), } diff --git a/tests/integration/x/precisebank/test_integration.go b/tests/integration/x/precisebank/test_integration.go index 9b568d2af..c6536d9ed 100644 --- a/tests/integration/x/precisebank/test_integration.go +++ b/tests/integration/x/precisebank/test_integration.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/cosmos/evm/contracts" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/utils" testutiltypes "github.com/cosmos/evm/testutil/types" "github.com/cosmos/evm/x/precisebank/types" @@ -21,19 +21,19 @@ import ( func (s *KeeperIntegrationTestSuite) TestMintBurnSendCoinsRandomValueMultiDecimals() { tests := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, { name: "2 decimals", - chainID: testconstants.TwoDecimalsChainID, + chainID: testconfig.ExampleTwoDecimalsChainID, }, { name: "12 decimals", - chainID: testconstants.TwelveDecimalsChainID, + chainID: testconfig.ExampleTwelveDecimalsChainID, }, } @@ -137,19 +137,19 @@ func (s *KeeperIntegrationTestSuite) TestSendEvmTxRandomValueMultiDecimals() { tests := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, { name: "12 decimals", - chainID: testconstants.TwelveDecimalsChainID, + chainID: testconfig.ExampleTwelveDecimalsChainID, }, { name: "2 decimals", - chainID: testconstants.TwoDecimalsChainID, + chainID: testconfig.ExampleTwoDecimalsChainID, }, } @@ -250,19 +250,19 @@ func (s *KeeperIntegrationTestSuite) TestSendEvmTxRandomValueMultiDecimals() { func (s *KeeperIntegrationTestSuite) TestWATOMWrapUnwrapMultiDecimal() { tests := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, { name: "12 decimals", - chainID: testconstants.TwelveDecimalsChainID, + chainID: testconfig.ExampleTwelveDecimalsChainID, }, { name: "2 decimals", - chainID: testconstants.TwoDecimalsChainID, + chainID: testconfig.ExampleTwoDecimalsChainID, }, } diff --git a/tests/integration/x/precisebank/test_mint_integration.go b/tests/integration/x/precisebank/test_mint_integration.go index de411877d..706056d99 100644 --- a/tests/integration/x/precisebank/test_mint_integration.go +++ b/tests/integration/x/precisebank/test_mint_integration.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/precisebank/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -341,19 +341,19 @@ func (s *KeeperIntegrationTestSuite) TestMintCoins() { func (s *KeeperIntegrationTestSuite) TestMintCoinsRandomValueMultiDecimals() { tests := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, { name: "12 decimals", - chainID: testconstants.TwelveDecimalsChainID, + chainID: testconfig.ExampleTwelveDecimalsChainID, }, { name: "2 decimals", - chainID: testconstants.TwoDecimalsChainID, + chainID: testconfig.ExampleTwoDecimalsChainID, }, } @@ -417,7 +417,7 @@ func (s *KeeperIntegrationTestSuite) TestMintCoinsRandomValueMultiDecimals() { func FuzzMintCoins(f *testing.F) { configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) + configurator.WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID]) err := configurator.Apply() require.NoError(f, err) diff --git a/tests/integration/x/precisebank/test_send_integration.go b/tests/integration/x/precisebank/test_send_integration.go index b09919497..2bf6c9c00 100644 --- a/tests/integration/x/precisebank/test_send_integration.go +++ b/tests/integration/x/precisebank/test_send_integration.go @@ -11,7 +11,7 @@ import ( corevm "github.com/ethereum/go-ethereum/core/vm" "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" cosmosevmutils "github.com/cosmos/evm/utils" erc20types "github.com/cosmos/evm/x/erc20/types" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" @@ -719,19 +719,19 @@ func (s *KeeperIntegrationTestSuite) TestSendCoinsFromModuleToAccount() { func (s *KeeperIntegrationTestSuite) TestSendCoinsRandomValueMultiDecimals() { tests := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, { name: "12 decimals", - chainID: testconstants.TwelveDecimalsChainID, + chainID: testconfig.ExampleTwelveDecimalsChainID, }, { name: "2 decimals", - chainID: testconstants.TwoDecimalsChainID, + chainID: testconfig.ExampleTwoDecimalsChainID, }, } @@ -798,7 +798,7 @@ func (s *KeeperIntegrationTestSuite) TestSendCoinsRandomValueMultiDecimals() { func FuzzSendCoins(f *testing.F) { configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) + configurator.WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID]) err := configurator.Apply() require.NoError(f, err) @@ -858,19 +858,19 @@ func FuzzSendCoins(f *testing.F) { func (s *KeeperIntegrationTestSuite) TestSendMsg_RandomValueMultiDecimals() { //nolint:revive // false positive due to file name tests := []struct { name string - chainID testconstants.ChainID + chainID testconfig.ChainID }{ { name: "6 decimals", - chainID: testconstants.SixDecimalsChainID, + chainID: testconfig.ExampleSixDecimalsChainID, }, { name: "12 decimals", - chainID: testconstants.TwelveDecimalsChainID, + chainID: testconfig.ExampleTwelveDecimalsChainID, }, { name: "2 decimals", - chainID: testconstants.TwoDecimalsChainID, + chainID: testconfig.ExampleTwoDecimalsChainID, }, } diff --git a/tests/integration/x/precisebank/test_setup.go b/tests/integration/x/precisebank/test_setup.go index bab55b5f2..7baacd527 100644 --- a/tests/integration/x/precisebank/test_setup.go +++ b/tests/integration/x/precisebank/test_setup.go @@ -3,7 +3,7 @@ package precisebank import ( "github.com/stretchr/testify/suite" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -34,10 +34,10 @@ func NewKeeperIntegrationTestSuite(create network.CreateEvmApp, options ...netwo } func (s *KeeperIntegrationTestSuite) SetupTest() { - s.SetupTestWithChainID(testconstants.SixDecimalsChainID) + s.SetupTestWithChainID(testconfig.ExampleSixDecimalsChainID) } -func (s *KeeperIntegrationTestSuite) SetupTestWithChainID(chainID testconstants.ChainID) { +func (s *KeeperIntegrationTestSuite) SetupTestWithChainID(chainID testconfig.ChainID) { s.keyring = keyring.New(2) options := []network.ConfigOption{ diff --git a/tests/integration/x/vm/keeper_test_suite.go b/tests/integration/x/vm/keeper_test_suite.go index 60893608d..da66a8745 100644 --- a/tests/integration/x/vm/keeper_test_suite.go +++ b/tests/integration/x/vm/keeper_test_suite.go @@ -6,7 +6,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/stretchr/testify/suite" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -89,7 +89,7 @@ func (s *KeeperTestSuite) SetupTest() { s.Handler = gh s.Keyring = keys - coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := evmtypes.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64(), coinInfo) if !s.EnableLondonHF { maxInt := sdkmath.NewInt(math.MaxInt64) diff --git a/tests/integration/x/vm/test_benchmark.go b/tests/integration/x/vm/test_benchmark.go index 77847f070..c7d179c73 100644 --- a/tests/integration/x/vm/test_benchmark.go +++ b/tests/integration/x/vm/test_benchmark.go @@ -8,7 +8,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/vm/keeper/testdata" "github.com/cosmos/evm/x/vm/types" @@ -24,7 +24,7 @@ func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) { suite := KeeperTestSuite{} suite.SetupTest() - amt := sdk.Coins{sdk.NewInt64Coin(testconstants.ExampleAttoDenom, 1000000000000000000)} + amt := sdk.Coins{sdk.NewInt64Coin(testconfig.ExampleAttoDenom, 1000000000000000000)} err := suite.Network.App.GetBankKeeper().MintCoins(suite.Network.GetContext(), types.ModuleName, amt) require.NoError(b, err) err = suite.Network.App.GetBankKeeper().SendCoinsFromModuleToAccount(suite.Network.GetContext(), types.ModuleName, suite.Keyring.GetAddr(0).Bytes(), amt) @@ -42,7 +42,7 @@ func SetupTestMessageCall(b *testing.B) (*KeeperTestSuite, common.Address) { suite := KeeperTestSuite{} suite.SetupTest() - amt := sdk.Coins{sdk.NewInt64Coin(testconstants.ExampleAttoDenom, 1000000000000000000)} + amt := sdk.Coins{sdk.NewInt64Coin(testconfig.ExampleAttoDenom, 1000000000000000000)} err := suite.Network.App.GetBankKeeper().MintCoins(suite.Network.GetContext(), types.ModuleName, amt) require.NoError(b, err) err = suite.Network.App.GetBankKeeper().SendCoinsFromModuleToAccount(suite.Network.GetContext(), types.ModuleName, suite.Keyring.GetAddr(0).Bytes(), amt) diff --git a/tests/integration/x/vm/test_call_evm.go b/tests/integration/x/vm/test_call_evm.go index 013b200f2..385514d8b 100644 --- a/tests/integration/x/vm/test_call_evm.go +++ b/tests/integration/x/vm/test_call_evm.go @@ -6,14 +6,14 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/cosmos/evm/contracts" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/erc20/types" evmtypes "github.com/cosmos/evm/x/vm/types" ) func (s *KeeperTestSuite) TestCallEVM() { - wcosmosEVMContract := common.HexToAddress(testconstants.WEVMOSContractMainnet) + wcosmosEVMContract := common.HexToAddress(testconfig.WEVMOSContractMainnet) testCases := []struct { name string method string @@ -47,7 +47,7 @@ func (s *KeeperTestSuite) TestCallEVM() { func (s *KeeperTestSuite) TestCallEVMWithData() { erc20 := contracts.ERC20MinterBurnerDecimalsContract.ABI - wcosmosEVMContract := common.HexToAddress(testconstants.WEVMOSContractMainnet) + wcosmosEVMContract := common.HexToAddress(testconfig.WEVMOSContractMainnet) testCases := []struct { name string from common.Address diff --git a/tests/integration/x/vm/test_grpc_query.go b/tests/integration/x/vm/test_grpc_query.go index 89aa28ff6..8d7ba7672 100644 --- a/tests/integration/x/vm/test_grpc_query.go +++ b/tests/integration/x/vm/test_grpc_query.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/evm/server/config" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/network" "github.com/cosmos/evm/testutil/keyring" @@ -1592,7 +1592,7 @@ func (s *KeeperTestSuite) TestQueryBaseFee() { feemarketDefault := feemarkettypes.DefaultParams() s.Require().NoError(s.Network.App.GetFeeMarketKeeper().SetParams(s.Network.GetContext(), feemarketDefault)) - coinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] chainConfig := types.DefaultChainConfig(s.Network.GetEIP155ChainID().Uint64(), coinInfo) maxInt := sdkmath.NewInt(math.MaxInt64) chainConfig.LondonBlock = &maxInt @@ -1607,7 +1607,7 @@ func (s *KeeperTestSuite) TestQueryBaseFee() { configurator.ResetTestConfig() err := configurator. WithChainConfig(chainConfig). - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]). Apply() s.Require().NoError(err) }, diff --git a/tests/integration/x/vm/test_iterate_contracts.go b/tests/integration/x/vm/test_iterate_contracts.go index 3c6cd5497..78fc07ef9 100644 --- a/tests/integration/x/vm/test_iterate_contracts.go +++ b/tests/integration/x/vm/test_iterate_contracts.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/evm/contracts" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/factory" "github.com/cosmos/evm/testutil/integration/evm/grpc" "github.com/cosmos/evm/testutil/integration/evm/network" @@ -57,7 +57,7 @@ func TestIterateContracts(t *testing.T, create network.CreateEvmApp, options ... network.App.GetEVMKeeper().IterateContracts(network.GetContext(), func(addr common.Address, codeHash common.Hash) bool { // NOTE: we only care about the 2 contracts deployed above, not the ERC20 native precompile for the aatom denomination - if bytes.Equal(addr.Bytes(), common.HexToAddress(testconstants.WEVMOSContractMainnet).Bytes()) { + if bytes.Equal(addr.Bytes(), common.HexToAddress(testconfig.WEVMOSContractMainnet).Bytes()) { return false } diff --git a/tests/integration/x/vm/test_statedb.go b/tests/integration/x/vm/test_statedb.go index b78480b90..80e1c5a00 100644 --- a/tests/integration/x/vm/test_statedb.go +++ b/tests/integration/x/vm/test_statedb.go @@ -12,7 +12,7 @@ import ( ethparams "github.com/ethereum/go-ethereum/params" "github.com/holiman/uint256" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" testkeyring "github.com/cosmos/evm/testutil/keyring" utiltx "github.com/cosmos/evm/testutil/tx" @@ -685,7 +685,7 @@ func (s *KeeperTestSuite) TestAddLog() { msg2.From = addr.Bytes() ethTx3Params := &types.EvmTxArgs{ - ChainID: big.NewInt(testconstants.ExampleEIP155ChainID), + ChainID: big.NewInt(testconfig.ExampleEIP155ChainID), Nonce: 0, To: &toAddr, Amount: common.Big1, diff --git a/testutil/config/config.go b/testutil/config/config.go index 01d343669..d87864130 100644 --- a/testutil/config/config.go +++ b/testutil/config/config.go @@ -65,8 +65,6 @@ const ( TestChainID1 = 9005 // TestChainID2 is test chain IDs for IBC E2E test TestChainID2 = 9006 - // WEVMOSContractMainnet is the WEVMOS contract address for mainnet - WEVMOSContractMainnet = "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517" ) // SetBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings. diff --git a/testutil/config/constants.go b/testutil/config/constants.go index c600c34f1..982740fc7 100644 --- a/testutil/config/constants.go +++ b/testutil/config/constants.go @@ -17,9 +17,6 @@ const ( // ExampleMicroDenom provides an example denom for use in tests ExampleMicroDenom = "uatom" - // ExampleDisplayDenom provides an example display denom for use in tests - ExampleDisplayDenom = "atom" - // ExampleBech32Prefix provides an example Bech32 prefix for use in tests ExampleBech32Prefix = "cosmos" diff --git a/testutil/config/genesis.go b/testutil/config/genesis.go index 4dc55d415..411e33968 100644 --- a/testutil/config/genesis.go +++ b/testutil/config/genesis.go @@ -3,7 +3,6 @@ package config import ( "encoding/json" - testconstants "github.com/cosmos/evm/testutil/constants" erc20types "github.com/cosmos/evm/x/erc20/types" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -37,8 +36,8 @@ func NewEVMGenesisState() *evmtypes.GenesisState { // which is the base denomination of the chain (i.e. the WEVMOS contract). func NewErc20GenesisState() *erc20types.GenesisState { erc20GenState := erc20types.DefaultGenesisState() - erc20GenState.TokenPairs = testconstants.ExampleTokenPairs - erc20GenState.NativePrecompiles = []string{testconstants.WEVMOSContractMainnet} + erc20GenState.TokenPairs = ExampleTokenPairs + erc20GenState.NativePrecompiles = []string{WEVMOSContractMainnet} return erc20GenState } diff --git a/testutil/integration/evm/network/amounts.go b/testutil/integration/evm/network/amounts.go index a70b6d239..fd4d2de07 100644 --- a/testutil/integration/evm/network/amounts.go +++ b/testutil/integration/evm/network/amounts.go @@ -3,7 +3,7 @@ package network import ( "math/big" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -18,7 +18,7 @@ type InitialAmounts struct { } func DefaultInitialAmounts() InitialAmounts { - baseCoinInfo := testconstants.ExampleChainCoinInfo[defaultChain] + baseCoinInfo := testconfig.ExampleChainCoinInfo[defaultChain] return InitialAmounts{ Base: GetInitialAmount(baseCoinInfo.Decimals), @@ -27,7 +27,7 @@ func DefaultInitialAmounts() InitialAmounts { } func DefaultInitialBondedAmount() math.Int { - baseCoinInfo := testconstants.ExampleChainCoinInfo[defaultChain] + baseCoinInfo := testconfig.ExampleChainCoinInfo[defaultChain] return GetInitialBondedAmount(baseCoinInfo.Decimals) } diff --git a/testutil/integration/evm/network/chain_id_modifiers.go b/testutil/integration/evm/network/chain_id_modifiers.go index 94b4714e4..bbf269470 100644 --- a/testutil/integration/evm/network/chain_id_modifiers.go +++ b/testutil/integration/evm/network/chain_id_modifiers.go @@ -5,7 +5,7 @@ package network import ( - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" erc20types "github.com/cosmos/evm/x/erc20/types" "github.com/cosmos/evm/x/precisebank/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -72,7 +72,7 @@ func generateBankGenesisMetadata() []banktypes.Metadata { // updateErc20GenesisStateForChainID modify the default genesis state for the // erc20 module on the testing suite depending on the chainID. -func updateErc20GenesisStateForChainID(chainID testconstants.ChainID, erc20GenesisState erc20types.GenesisState) erc20types.GenesisState { +func updateErc20GenesisStateForChainID(chainID testconfig.ChainID, erc20GenesisState erc20types.GenesisState) erc20types.GenesisState { erc20GenesisState.TokenPairs = updateErc20TokenPairs(chainID, erc20GenesisState.TokenPairs) return erc20GenesisState @@ -80,11 +80,11 @@ func updateErc20GenesisStateForChainID(chainID testconstants.ChainID, erc20Genes // updateErc20TokenPairs modifies the erc20 token pairs to use the correct // WEVMOS depending on ChainID -func updateErc20TokenPairs(chainID testconstants.ChainID, tokenPairs []erc20types.TokenPair) []erc20types.TokenPair { +func updateErc20TokenPairs(chainID testconfig.ChainID, tokenPairs []erc20types.TokenPair) []erc20types.TokenPair { testnetAddress := GetWEVMOSContractHex(chainID) - coinInfo := testconstants.ExampleChainCoinInfo[chainID] + coinInfo := testconfig.ExampleChainCoinInfo[chainID] - mainnetAddress := GetWEVMOSContractHex(testconstants.ExampleChainID) + mainnetAddress := GetWEVMOSContractHex(testconfig.ExampleChainID) updatedTokenPairs := make([]erc20types.TokenPair, len(tokenPairs)) for i, tokenPair := range tokenPairs { diff --git a/testutil/integration/evm/network/coins.go b/testutil/integration/evm/network/coins.go index 363d21491..dc497ab30 100644 --- a/testutil/integration/evm/network/coins.go +++ b/testutil/integration/evm/network/coins.go @@ -1,7 +1,7 @@ package network import ( - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" evmtypes "github.com/cosmos/evm/x/vm/types" ) @@ -25,7 +25,7 @@ type ChainCoins struct { // DefaultChainCoins returns the default values used for the ChainCoins in which // base and evm denom are the same. func DefaultChainCoins() ChainCoins { - baseCoinInfo := testconstants.ExampleChainCoinInfo[defaultChain] + baseCoinInfo := testconfig.ExampleChainCoinInfo[defaultChain] // baseCoin is used for both base and evm coin as default.. baseCoin := getCoinInfo(baseCoinInfo) diff --git a/testutil/integration/evm/network/config.go b/testutil/integration/evm/network/config.go index 2ad976fb8..7af545ec3 100644 --- a/testutil/integration/evm/network/config.go +++ b/testutil/integration/evm/network/config.go @@ -6,7 +6,7 @@ import ( cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" testtx "github.com/cosmos/evm/testutil/tx" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -20,7 +20,7 @@ import ( ) // defaultChain represents the default chain ID used in the suite setup. -var defaultChain = testconstants.ExampleChainID +var defaultChain = testconfig.ExampleChainID // Config defines the configuration for a chain. // It allows for customization of the network to adjust to @@ -54,8 +54,8 @@ func DefaultConfig() Config { account, _ := testtx.NewAccAddressAndKey() return Config{ - chainID: testconstants.ExampleChainID.ChainID, - eip155ChainID: big.NewInt(testconstants.ExampleEIP155ChainID), + chainID: testconfig.ExampleChainID.ChainID, + eip155ChainID: big.NewInt(testconfig.ExampleEIP155ChainID), chainCoins: DefaultChainCoins(), initialAmounts: DefaultInitialAmounts(), initialBondedAmount: DefaultInitialBondedAmount(), @@ -117,13 +117,13 @@ type ConfigOption func(*Config) // WithChainID sets a custom chainID for the network. Changing the chainID // change automatically also the EVM coin used. It panics if the chainID is invalid. -func WithChainID(chainID testconstants.ChainID) ConfigOption { - evmCoinInfo, found := testconstants.ExampleChainCoinInfo[chainID] +func WithChainID(chainID testconfig.ChainID) ConfigOption { + evmCoinInfo, found := testconfig.ExampleChainCoinInfo[chainID] if !found { panic(fmt.Sprintf( "chain id %q not found in chain coin info; available: %v", chainID, - testconstants.ExampleChainCoinInfo, + testconfig.ExampleChainCoinInfo, )) } diff --git a/testutil/integration/evm/network/example_contracts.go b/testutil/integration/evm/network/example_contracts.go index ab3a3daba..1f99e9022 100644 --- a/testutil/integration/evm/network/example_contracts.go +++ b/testutil/integration/evm/network/example_contracts.go @@ -1,26 +1,26 @@ package network import ( - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" ) // chainsWEVMOSHex is an utility map used to retrieve the WEVMOS contract // address in hex format from the chain ID. // // TODO: refactor to define this in the example chain initialization and pass as function argument -var chainsWEVMOSHex = map[testconstants.ChainID]string{ - testconstants.ExampleChainID: testconstants.WEVMOSContractMainnet, +var chainsWEVMOSHex = map[testconfig.ChainID]string{ + testconfig.ExampleChainID: testconfig.WEVMOSContractMainnet, } // GetWEVMOSContractHex returns the hex format of address for the WEVMOS contract // given the chainID. If the chainID is not found, it defaults to the mainnet // address. -func GetWEVMOSContractHex(chainID testconstants.ChainID) string { +func GetWEVMOSContractHex(chainID testconfig.ChainID) string { address, found := chainsWEVMOSHex[chainID] // default to mainnet address if !found { - address = chainsWEVMOSHex[testconstants.ExampleChainID] + address = chainsWEVMOSHex[testconfig.ExampleChainID] } return address diff --git a/testutil/integration/evm/network/setup.go b/testutil/integration/evm/network/setup.go index f352bd4af..9d4315e18 100644 --- a/testutil/integration/evm/network/setup.go +++ b/testutil/integration/evm/network/setup.go @@ -9,7 +9,7 @@ import ( cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/evm" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" cosmosevmtypes "github.com/cosmos/evm/types" erc20types "github.com/cosmos/evm/x/erc20/types" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" @@ -463,7 +463,7 @@ func setDefaultMintGenesisState(cosmosEVMApp evm.EvmApp, genesisState cosmosevmt func setDefaultErc20GenesisState(cosmosEVMApp evm.EvmApp, evmChainID uint64, genesisState cosmosevmtypes.GenesisState) cosmosevmtypes.GenesisState { // NOTE: here we are using the setup from the example chain erc20Gen := newErc20GenesisState() - updatedErc20Gen := updateErc20GenesisStateForChainID(testconstants.ChainID{ + updatedErc20Gen := updateErc20GenesisStateForChainID(testconfig.ChainID{ ChainID: cosmosEVMApp.ChainID(), EVMChainID: evmChainID, }, *erc20Gen) @@ -479,8 +479,8 @@ func setDefaultErc20GenesisState(cosmosEVMApp evm.EvmApp, evmChainID uint64, gen // which is the base denomination of the chain (i.e. the WEVMOS contract). func newErc20GenesisState() *erc20types.GenesisState { erc20GenState := erc20types.DefaultGenesisState() - erc20GenState.TokenPairs = testconstants.ExampleTokenPairs - erc20GenState.NativePrecompiles = []string{testconstants.WEVMOSContractMainnet} + erc20GenState.TokenPairs = testconfig.ExampleTokenPairs + erc20GenState.NativePrecompiles = []string{testconfig.WEVMOSContractMainnet} return erc20GenState } diff --git a/testutil/integration/evm/utils/genesis.go b/testutil/integration/evm/utils/genesis.go index 76c340fe5..84a445d91 100644 --- a/testutil/integration/evm/utils/genesis.go +++ b/testutil/integration/evm/utils/genesis.go @@ -1,7 +1,7 @@ package utils import ( - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/testutil/integration/evm/network" testkeyring "github.com/cosmos/evm/testutil/keyring" utiltx "github.com/cosmos/evm/testutil/tx" @@ -50,7 +50,7 @@ func CreateGenesisWithTokenPairs(keyring testkeyring.Keyring, denoms ...string) tokenPairs := make([]erc20types.TokenPair, 0, len(denoms)+1) tokenPairs = append(tokenPairs, // NOTE: the example token pairs are being added in the integration test utils - testconstants.ExampleTokenPairs..., + testconfig.ExampleTokenPairs..., ) dynPrecAddr := make([]string, 0, len(denoms)) @@ -70,7 +70,7 @@ func CreateGenesisWithTokenPairs(keyring testkeyring.Keyring, denoms ...string) // with the WEVMOS (default is mainnet) and 'xmpl' tokens in the erc20 params erc20GenesisState := erc20types.DefaultGenesisState() erc20GenesisState.TokenPairs = tokenPairs - erc20GenesisState.NativePrecompiles = []string{testconstants.WEVMOSContractMainnet} + erc20GenesisState.NativePrecompiles = []string{testconfig.WEVMOSContractMainnet} erc20GenesisState.DynamicPrecompiles = dynPrecAddr // Combine module genesis states @@ -86,8 +86,8 @@ func CreateGenesisWithTokenPairs(keyring testkeyring.Keyring, denoms ...string) // which is the base denomination of the chain (i.e. the WEVMOS contract). func NewErc20GenesisState() *erc20types.GenesisState { erc20GenState := erc20types.DefaultGenesisState() - erc20GenState.TokenPairs = testconstants.ExampleTokenPairs - erc20GenState.NativePrecompiles = []string{testconstants.WEVMOSContractMainnet} + erc20GenState.TokenPairs = testconfig.ExampleTokenPairs + erc20GenState.NativePrecompiles = []string{testconfig.WEVMOSContractMainnet} return erc20GenState } diff --git a/testutil/tx/cosmos.go b/testutil/tx/cosmos.go index f130c360c..46e55f8db 100644 --- a/testutil/tx/cosmos.go +++ b/testutil/tx/cosmos.go @@ -4,7 +4,7 @@ import ( protov2 "google.golang.org/protobuf/proto" "github.com/cosmos/evm" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" sdkmath "cosmossdk.io/math" @@ -16,7 +16,7 @@ import ( authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" ) -var DefaultFee = sdk.NewCoin(constants.ExampleAttoDenom, sdkmath.NewInt(1e16)) // 0.01 AATOM +var DefaultFee = sdk.NewCoin(testconfig.ExampleAttoDenom, sdkmath.NewInt(1e16)) // 0.01 AATOM // CosmosTxArgs contains the params to create a cosmos tx type CosmosTxArgs struct { @@ -51,7 +51,7 @@ func PrepareCosmosTx( var fees sdk.Coins if args.GasPrice != nil { - fees = sdk.Coins{{Denom: constants.ExampleAttoDenom, Amount: args.GasPrice.MulRaw(int64(args.Gas))}} //#nosec G115 + fees = sdk.Coins{{Denom: testconfig.ExampleAttoDenom, Amount: args.GasPrice.MulRaw(int64(args.Gas))}} //#nosec G115 } else { fees = sdk.Coins{DefaultFee} } diff --git a/utils/utils_test.go b/utils/utils_test.go index a70b4ce63..7c2911621 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -14,7 +14,7 @@ import ( cryptocodec "github.com/cosmos/evm/crypto/codec" "github.com/cosmos/evm/crypto/ethsecp256k1" "github.com/cosmos/evm/crypto/hd" - "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/types" "github.com/cosmos/evm/utils" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" @@ -487,10 +487,10 @@ func TestAccountEquivalence(t *testing.T) { } func TestCalcBaseFee(t *testing.T) { - for _, chainID := range []constants.ChainID{constants.ExampleChainID, constants.TwelveDecimalsChainID, constants.SixDecimalsChainID} { + for _, chainID := range []testconfig.ChainID{testconfig.ExampleChainID, testconfig.ExampleTwelveDecimalsChainID, testconfig.ExampleSixDecimalsChainID} { t.Run(chainID.ChainID, func(t *testing.T) { evmConfigurator := evmtypes.NewEvmConfig(). - WithEVMCoinInfo(constants.ExampleChainCoinInfo[chainID]) + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[chainID]) evmConfigurator.ResetTestConfig() err := evmConfigurator.Apply() require.NoError(t, err) diff --git a/x/erc20/types/genesis_test.go b/x/erc20/types/genesis_test.go index 10abb1373..69575a2bc 100644 --- a/x/erc20/types/genesis_test.go +++ b/x/erc20/types/genesis_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/suite" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/erc20/types" "cosmossdk.io/math" @@ -23,7 +23,7 @@ func TestGenesisTestSuite(t *testing.T) { } func (suite *GenesisTestSuite) TestValidateGenesis() { - newGen := types.NewGenesisState(types.DefaultParams(), testconstants.ExampleTokenPairs, testconstants.ExampleAllowances) + newGen := types.NewGenesisState(types.DefaultParams(), testconfig.ExampleTokenPairs, testconfig.ExampleAllowances) testCases := []struct { name string @@ -44,8 +44,8 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { name: "valid genesis", genState: &types.GenesisState{ Params: types.DefaultParams(), - TokenPairs: testconstants.ExampleTokenPairs, - Allowances: testconstants.ExampleAllowances, + TokenPairs: testconfig.ExampleTokenPairs, + Allowances: testconfig.ExampleAllowances, }, expPass: true, }, @@ -60,12 +60,12 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Enabled: true, }, { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, - Allowances: testconstants.ExampleAllowances, + Allowances: testconfig.ExampleAllowances, }, expPass: true, }, @@ -85,12 +85,12 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Enabled: true, }, { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, - Allowances: testconstants.ExampleAllowances, + Allowances: testconfig.ExampleAllowances, }, expPass: false, }, @@ -110,12 +110,12 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Enabled: true, }, { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, - Allowances: testconstants.ExampleAllowances, + Allowances: testconfig.ExampleAllowances, }, expPass: false, }, @@ -135,12 +135,12 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Enabled: true, }, { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, - Allowances: testconstants.ExampleAllowances, + Allowances: testconfig.ExampleAllowances, }, expPass: false, }, @@ -155,12 +155,12 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Enabled: true, }, { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, - Allowances: testconstants.ExampleAllowances, + Allowances: testconfig.ExampleAllowances, }, expPass: false, }, @@ -175,7 +175,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Enabled: true, }, }, - Allowances: testconstants.ExampleAllowances, + Allowances: testconfig.ExampleAllowances, }, expPass: false, }, @@ -183,18 +183,18 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { name: "invalid genesis - duplicated allowances", genState: &types.GenesisState{ Params: types.DefaultParams(), - TokenPairs: testconstants.ExampleTokenPairs, + TokenPairs: testconfig.ExampleTokenPairs, Allowances: []types.Allowance{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Owner: testconstants.ExampleEvmAddressAlice, - Spender: testconstants.ExampleEvmAddressBob, + Erc20Address: testconfig.WEVMOSContractMainnet, + Owner: testconfig.ExampleEvmAddressAlice, + Spender: testconfig.ExampleEvmAddressBob, Value: math.NewInt(100), }, { - Erc20Address: testconstants.WEVMOSContractMainnet, - Owner: testconstants.ExampleEvmAddressAlice, - Spender: testconstants.ExampleEvmAddressBob, + Erc20Address: testconfig.WEVMOSContractMainnet, + Owner: testconfig.ExampleEvmAddressAlice, + Spender: testconfig.ExampleEvmAddressBob, Value: math.NewInt(100), }, }, @@ -207,16 +207,16 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Params: types.DefaultParams(), TokenPairs: []types.TokenPair{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, Allowances: []types.Allowance{ { Erc20Address: "bad", - Owner: testconstants.ExampleEvmAddressAlice, - Spender: testconstants.ExampleEvmAddressBob, + Owner: testconfig.ExampleEvmAddressAlice, + Spender: testconfig.ExampleEvmAddressBob, Value: math.NewInt(-1), }, }, @@ -229,16 +229,16 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Params: types.DefaultParams(), TokenPairs: []types.TokenPair{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, Allowances: []types.Allowance{ { - Erc20Address: testconstants.WEVMOSContractMainnet, + Erc20Address: testconfig.WEVMOSContractMainnet, Owner: "bad", - Spender: testconstants.ExampleEvmAddressBob, + Spender: testconfig.ExampleEvmAddressBob, Value: math.NewInt(-1), }, }, @@ -251,15 +251,15 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Params: types.DefaultParams(), TokenPairs: []types.TokenPair{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, Allowances: []types.Allowance{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Owner: testconstants.ExampleEvmAddressAlice, + Erc20Address: testconfig.WEVMOSContractMainnet, + Owner: testconfig.ExampleEvmAddressAlice, Spender: "bad", Value: math.NewInt(-1), }, @@ -273,16 +273,16 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Params: types.DefaultParams(), TokenPairs: []types.TokenPair{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, Allowances: []types.Allowance{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Owner: testconstants.ExampleEvmAddressAlice, - Spender: testconstants.ExampleEvmAddressBob, + Erc20Address: testconfig.WEVMOSContractMainnet, + Owner: testconfig.ExampleEvmAddressAlice, + Spender: testconfig.ExampleEvmAddressBob, Value: math.NewInt(0), }, }, @@ -295,16 +295,16 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { Params: types.DefaultParams(), TokenPairs: []types.TokenPair{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Denom: testconstants.ExampleAttoDenom, + Erc20Address: testconfig.WEVMOSContractMainnet, + Denom: testconfig.ExampleAttoDenom, Enabled: true, }, }, Allowances: []types.Allowance{ { - Erc20Address: testconstants.WEVMOSContractMainnet, - Owner: testconstants.ExampleEvmAddressAlice, - Spender: testconstants.ExampleEvmAddressBob, + Erc20Address: testconfig.WEVMOSContractMainnet, + Owner: testconfig.ExampleEvmAddressAlice, + Spender: testconfig.ExampleEvmAddressBob, Value: math.NewInt(-1), }, }, diff --git a/x/precisebank/keeper/keeper_test.go b/x/precisebank/keeper/keeper_test.go index f1ce34828..1a2280f95 100644 --- a/x/precisebank/keeper/keeper_test.go +++ b/x/precisebank/keeper/keeper_test.go @@ -5,7 +5,7 @@ import ( evmconfig "github.com/cosmos/evm/config" evmosencoding "github.com/cosmos/evm/encoding" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/precisebank/keeper" "github.com/cosmos/evm/x/precisebank/types" "github.com/cosmos/evm/x/precisebank/types/mocks" @@ -40,7 +40,7 @@ func newMockedTestData(t *testing.T) testData { bk := mocks.NewBankKeeper(t) ak := mocks.NewAccountKeeper(t) - chainID := testconstants.SixDecimalsChainID.EVMChainID + chainID := testconfig.ExampleSixDecimalsChainID.EVMChainID cfg := evmosencoding.MakeConfig(chainID) cdc := cfg.Codec k := keeper.NewKeeper(cdc, storeKey, bk, ak) diff --git a/x/precisebank/types/extended_balance_test.go b/x/precisebank/types/extended_balance_test.go index 8c92b5dea..bde284d03 100644 --- a/x/precisebank/types/extended_balance_test.go +++ b/x/precisebank/types/extended_balance_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/precisebank/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -15,7 +15,7 @@ import ( ) func TestSumExtendedCoin(t *testing.T) { - coinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] configurator := evmtypes.NewEvmConfig() err := configurator. WithEVMCoinInfo(coinInfo). diff --git a/x/precisebank/types/genesis_test.go b/x/precisebank/types/genesis_test.go index 41a5ee80e..9908032e8 100644 --- a/x/precisebank/types/genesis_test.go +++ b/x/precisebank/types/genesis_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/precisebank/testutil" "github.com/cosmos/evm/x/precisebank/types" evmtypes "github.com/cosmos/evm/x/vm/types" @@ -258,7 +258,7 @@ func TestGenesisState_TotalAmountWithRemainder(t *testing.T) { func FuzzGenesisStateValidate_NonZeroRemainder(f *testing.F) { configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) + configurator.WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID]) err := configurator.Apply() require.NoError(f, err) @@ -285,7 +285,7 @@ func FuzzGenesisStateValidate_NonZeroRemainder(f *testing.F) { func FuzzGenesisStateValidate_ZeroRemainder(f *testing.F) { configurator := evmtypes.NewEvmConfig() configurator.ResetTestConfig() - configurator.WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID]) + configurator.WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID]) err := configurator.Apply() require.NoError(f, err) diff --git a/x/vm/types/evm_config_test.go b/x/vm/types/evm_config_test.go index 16d621348..5e384791b 100644 --- a/x/vm/types/evm_config_test.go +++ b/x/vm/types/evm_config_test.go @@ -6,13 +6,13 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" "github.com/cosmos/evm/x/vm/types" ) func TestEvmConfigApply(t *testing.T) { evmConfigurator := types.NewEvmConfig(). - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]) + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]) err := evmConfigurator.Apply() require.NoError(t, err) @@ -35,7 +35,7 @@ func TestExtendedEips(t *testing.T) { 3855: func(_ *vm.JumpTable) {}, } ec := types.NewEvmConfig(). - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]). WithExtendedEips(extendedEIPs) return ec }, @@ -49,7 +49,7 @@ func TestExtendedEips(t *testing.T) { 0o000: func(_ *vm.JumpTable) {}, } ec := types.NewEvmConfig(). - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]). WithExtendedEips(extendedEIPs) return ec }, @@ -87,7 +87,7 @@ func TestExtendedDefaultExtraEips(t *testing.T) { extendedDefaultExtraEIPs := []int64{1000} types.DefaultExtraEIPs = append(types.DefaultExtraEIPs, 1000) ec := types.NewEvmConfig(). - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]). WithExtendedDefaultExtraEIPs(extendedDefaultExtraEIPs...) return ec }, @@ -103,7 +103,7 @@ func TestExtendedDefaultExtraEips(t *testing.T) { func() *types.EvmConfig { var extendedDefaultExtraEIPs []int64 ec := types.NewEvmConfig(). - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]). WithExtendedDefaultExtraEIPs(extendedDefaultExtraEIPs...) return ec }, @@ -118,7 +118,7 @@ func TestExtendedDefaultExtraEips(t *testing.T) { func() *types.EvmConfig { extendedDefaultExtraEIPs := []int64{1001} ec := types.NewEvmConfig(). - WithEVMCoinInfo(testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID]). + WithEVMCoinInfo(testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID]). WithExtendedDefaultExtraEIPs(extendedDefaultExtraEIPs...) return ec }, diff --git a/x/vm/types/msg_test.go b/x/vm/types/msg_test.go index 4684ef741..85f2959c4 100644 --- a/x/vm/types/msg_test.go +++ b/x/vm/types/msg_test.go @@ -15,7 +15,7 @@ import ( evmconfig "github.com/cosmos/evm/config" "github.com/cosmos/evm/encoding" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" "github.com/cosmos/evm/x/vm/types" @@ -113,8 +113,8 @@ func (suite *MsgsTestSuite) TestMsgEthereumTx_BuildTx() { }, } for _, coinInfo := range []types.EvmCoinInfo{ - testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], - testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], + testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], + testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID], } { for _, tc := range testCases { configurator := types.NewEvmConfig() diff --git a/x/vm/types/scaling_test.go b/x/vm/types/scaling_test.go index 7eb47cf76..13a379c6e 100644 --- a/x/vm/types/scaling_test.go +++ b/x/vm/types/scaling_test.go @@ -8,7 +8,7 @@ import ( "github.com/holiman/uint256" "github.com/stretchr/testify/require" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" evmtypes "github.com/cosmos/evm/x/vm/types" "cosmossdk.io/math" @@ -17,8 +17,8 @@ import ( ) func TestConvertEvmCoinFrom18Decimals(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] eighteenDecimalsBaseCoinZero := sdk.Coin{Denom: eighteenDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(0)} sixDecimalsBaseCoinZero := sdk.Coin{Denom: sixDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(0)} @@ -92,8 +92,8 @@ func TestConvertEvmCoinFrom18Decimals(t *testing.T) { } func TestConvertCoinsFrom18Decimals(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] nonBaseCoin := sdk.Coin{Denom: "btc", Amount: math.NewInt(10)} eighteenDecimalsBaseCoin := sdk.Coin{Denom: eighteenDecimalsCoinInfo.GetDenom(), Amount: math.NewInt(10)} @@ -183,8 +183,8 @@ func TestConvertAmountTo18DecimalsLegacy(t *testing.T) { } for _, coinInfo := range []evmtypes.EvmCoinInfo{ - testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], - testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], + testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], + testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID], } { for _, tc := range testCases { t.Run(fmt.Sprintf("%d dec - %s", coinInfo.Decimals, tc.name), func(t *testing.T) { @@ -221,8 +221,8 @@ func TestConvertAmountTo18DecimalsBigInt(t *testing.T) { } for _, coinInfo := range []evmtypes.EvmCoinInfo{ - testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], - testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], + testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], + testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID], } { for _, tc := range testCases { t.Run(fmt.Sprintf("%d dec - %s", coinInfo.Decimals, tc.name), func(t *testing.T) { diff --git a/x/vm/wrappers/bank_test.go b/x/vm/wrappers/bank_test.go index 8a6ff4a0b..989e4e755 100644 --- a/x/vm/wrappers/bank_test.go +++ b/x/vm/wrappers/bank_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" evmtypes "github.com/cosmos/evm/x/vm/types" "github.com/cosmos/evm/x/vm/wrappers" "github.com/cosmos/evm/x/vm/wrappers/testutil" @@ -23,8 +23,8 @@ import ( // --------------------------------------TRANSACTIONS----------------------------------------------- func TestMintAmountToAccount(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] testCases := []struct { name string @@ -128,8 +128,8 @@ func TestMintAmountToAccount(t *testing.T) { } func TestBurnAmountFromAccount(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] account := sdk.AccAddress([]byte("test_address")) @@ -249,8 +249,8 @@ func TestBurnAmountFromAccount(t *testing.T) { } func TestSendCoinsFromModuleToAccount(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] account := sdk.AccAddress([]byte("test_address")) @@ -410,8 +410,8 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) { } func TestSendCoinsFromAccountToModule(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] account := sdk.AccAddress([]byte("test_address")) @@ -573,8 +573,8 @@ func TestSendCoinsFromAccountToModule(t *testing.T) { // ----------------------------------------QUERIES------------------------------------------------- func TestGetBalance(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] maxInt64 := int64(9223372036854775807) account := sdk.AccAddress([]byte("test_address")) @@ -720,8 +720,8 @@ func TestGetBalance(t *testing.T) { // ----------------------------------------QUERIES------------------------------------------------- func TestSppendableCoin(t *testing.T) { - eighteenDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID] - sixDecimalsCoinInfo := testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID] + eighteenDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] + sixDecimalsCoinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID] maxInt64 := int64(9223372036854775807) account := sdk.AccAddress([]byte("test_address")) diff --git a/x/vm/wrappers/feemarket_test.go b/x/vm/wrappers/feemarket_test.go index 6486e51f2..bf9697883 100644 --- a/x/vm/wrappers/feemarket_test.go +++ b/x/vm/wrappers/feemarket_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - testconstants "github.com/cosmos/evm/testutil/constants" + testconfig "github.com/cosmos/evm/testutil/config" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" evmtypes "github.com/cosmos/evm/x/vm/types" "github.com/cosmos/evm/x/vm/wrappers" @@ -27,7 +27,7 @@ func TestGetBaseFee(t *testing.T) { }{ { name: "success - does not convert 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID], expResult: big.NewInt(1e18), // 1 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -37,7 +37,7 @@ func TestGetBaseFee(t *testing.T) { }, { name: "success - convert 6 decimals to 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(1e18), // 1 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -47,7 +47,7 @@ func TestGetBaseFee(t *testing.T) { }, { name: "success - nil base fee", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: nil, mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -57,7 +57,7 @@ func TestGetBaseFee(t *testing.T) { }, { name: "success - small amount 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(1e12), // 0.000001 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -67,7 +67,7 @@ func TestGetBaseFee(t *testing.T) { }, { name: "success - base fee is zero", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(0), mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -77,7 +77,7 @@ func TestGetBaseFee(t *testing.T) { }, { name: "success - truncate decimals with number less than 1", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(0), // 0.000001 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -117,7 +117,7 @@ func TestCalculateBaseFee(t *testing.T) { }{ { name: "success - does not convert 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID], expResult: big.NewInt(1e18), // 1 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -127,7 +127,7 @@ func TestCalculateBaseFee(t *testing.T) { }, { name: "success - convert 6 decimals to 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(1e18), // 1 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -137,7 +137,7 @@ func TestCalculateBaseFee(t *testing.T) { }, { name: "success - nil base fee", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: nil, mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -147,7 +147,7 @@ func TestCalculateBaseFee(t *testing.T) { }, { name: "success - small amount 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(1e12), // 0.000001 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -157,7 +157,7 @@ func TestCalculateBaseFee(t *testing.T) { }, { name: "success - base fee is zero", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(0), mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -167,7 +167,7 @@ func TestCalculateBaseFee(t *testing.T) { }, { name: "success - truncate decimals with number less than 1", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expResult: big.NewInt(0), // 0.000001 token in 18 decimals mockSetup: func(mfk *testutil.MockFeeMarketKeeper) { mfk.EXPECT(). @@ -206,7 +206,7 @@ func TestGetParams(t *testing.T) { }{ { name: "success - convert 6 decimals to 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.SixDecimalsChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleSixDecimalsChainID], expParams: feemarkettypes.Params{ BaseFee: sdkmath.LegacyNewDec(1e18), MinGasPrice: sdkmath.LegacyNewDec(1e18), @@ -222,7 +222,7 @@ func TestGetParams(t *testing.T) { }, { name: "success - does not convert 18 decimals", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID], expParams: feemarkettypes.Params{ BaseFee: sdkmath.LegacyNewDec(1e18), MinGasPrice: sdkmath.LegacyNewDec(1e18), @@ -238,7 +238,7 @@ func TestGetParams(t *testing.T) { }, { name: "success - nil base fee", - coinInfo: testconstants.ExampleChainCoinInfo[testconstants.ExampleChainID], + coinInfo: testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID], expParams: feemarkettypes.Params{ MinGasPrice: sdkmath.LegacyNewDec(1e18), }, From 96530d5248c30ed8ae899f002511ca6895a6f486 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Tue, 16 Sep 2025 17:43:51 -0400 Subject: [PATCH 15/23] fix testcofig in root --- evmd/cmd/evmd/cmd/root.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/evmd/cmd/root.go index da63597c3..764f1e74b 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/evmd/cmd/root.go @@ -151,8 +151,7 @@ func NewRootCmd() *cobra.Command { panic(err) } - chainConfig := evmconfig.NewTestChainConfig(evmconfig.DefaultEvmChainID) - + chainConfig := evmconfig.DefaultChainConfig if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } From b9196e4590a7ad008b46ca5db7fc5e0463c57d67 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Wed, 17 Sep 2025 12:37:50 -0400 Subject: [PATCH 16/23] pass in coin info flags --- config/chain_config.go | 8 +++----- evmd/cmd/evmd/cmd/root.go | 11 +++++------ go.mod | 3 +-- local_node.sh | 14 +++++++++++++- x/vm/types/config.go | 12 +++++------- x/vm/types/config_testing.go | 5 +++-- x/vm/types/evm_config.go | 12 +++++++++++- 7 files changed, 41 insertions(+), 24 deletions(-) diff --git a/config/chain_config.go b/config/chain_config.go index 996e6ebb0..e17757121 100644 --- a/config/chain_config.go +++ b/config/chain_config.go @@ -51,11 +51,8 @@ func NewChainConfig( // ApplyEvmConfig applies the evm config to the global singleton chain config and coin info func (cc *ChainConfig) ApplyChainConfig() error { - if cc.EvmConfig == nil { - return nil // no op if evm config is nil - } - if cc.EvmConfig == nil { - return fmt.Errorf("evm config is nil, cannot apply chain config") + if cc.EvmConfig == nil || types.IsSealed() { + return nil // no op if evm config is nil or sealed } if cc.EvmConfig.GetChainConfig() == nil { return fmt.Errorf("chain config is nil, cannot apply chain config") @@ -70,6 +67,7 @@ func (cc *ChainConfig) ApplyChainConfig() error { // setBaseDenom registers the display denom and base denom and sets the // base denom for the chain. The function registered different values based on // the EvmCoinInfo to allow different configurations in mainnet and testnet. +// TODO: look into deprecating this if it is not needed func setBaseDenom(ci types.EvmCoinInfo) (err error) { // defer setting the base denom, and capture any potential error from it. // when failing because the denom was already registered, we ignore it and set diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/evmd/cmd/root.go index 764f1e74b..43e6e6126 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/evmd/cmd/root.go @@ -4,7 +4,6 @@ import ( "errors" "io" "os" - "strconv" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/spf13/cast" @@ -141,7 +140,7 @@ func NewRootCmd() *cobra.Command { if initClientCtx.ChainID == "" { // if the chain id is not set in client.toml, populate it with the default evm chain id - initClientCtx = initClientCtx.WithChainID(strconv.FormatUint(evmconfig.DefaultEvmChainID, 10)) + initClientCtx = initClientCtx.WithChainID(evmconfig.DefaultChainID) } initClientCtx, _ = clientcfg.ReadFromClientConfig(initClientCtx) @@ -151,10 +150,10 @@ func NewRootCmd() *cobra.Command { panic(err) } - chainConfig := evmconfig.DefaultChainConfig - if err := chainConfig.ApplyChainConfig(); err != nil { - panic(err) - } + // chainConfig := evmconfig.DefaultChainConfig + // if err := chainConfig.ApplyChainConfig(); err != nil { + // panic(err) + // } return rootCmd } diff --git a/go.mod b/go.mod index 4166dd6d3..2e66b7626 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,6 @@ require ( github.com/onsi/ginkgo/v2 v2.23.4 github.com/onsi/gomega v1.38.0 github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.22.0 github.com/rs/cors v1.11.1 github.com/spf13/cast v1.9.2 github.com/spf13/cobra v1.9.1 @@ -181,7 +180,6 @@ require ( github.com/klauspost/cpuid/v2 v2.2.10 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect - github.com/kylelemons/godebug v1.1.0 // indirect github.com/lib/pq v1.10.9 // indirect github.com/manifoldco/promptui v0.9.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect @@ -207,6 +205,7 @@ require ( github.com/pion/transport/v3 v3.0.1 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/prometheus/client_golang v1.22.0 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.63.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect diff --git a/local_node.sh b/local_node.sh index c04c16382..0bca43205 100755 --- a/local_node.sh +++ b/local_node.sh @@ -14,6 +14,15 @@ CHAINDIR="$HOME/.evmd" BASEFEE=10000000 +# Coin info +DISPLAY_DENOM="test" +DECIMALS=18 +EXTENDED_DECIMALS=18 + +# Extended denom +EXTENDED_DECIMALS_SI_PREFIX="a" # a = atto (18 decimals) +EXTENDED_DENOM="${EXTENDED_DECIMALS_SI_PREFIX}${DISPLAY_DENOM}" + # Path variables CONFIG_TOML=$CHAINDIR/config/config.toml APP_TOML=$CHAINDIR/config/app.toml @@ -358,7 +367,10 @@ fi evmd start "$TRACE" \ --pruning nothing \ --log_level $LOGLEVEL \ - --minimum-gas-prices=0atest \ + --minimum-gas-prices=0$EXTENDED_DENOM \ + --evm.coin-info.display-denom=$DISPLAY_DENOM \ + --evm.coin-info.decimals=$DECIMALS \ + --evm.coin-info.extended-decimals=$EXTENDED_DECIMALS \ --evm.min-tip=0 \ --home "$CHAINDIR" \ --json-rpc.api eth,txpool,personal,net,debug,web3 \ diff --git a/x/vm/types/config.go b/x/vm/types/config.go index 928c27881..8518cfc90 100644 --- a/x/vm/types/config.go +++ b/x/vm/types/config.go @@ -4,18 +4,16 @@ package types import ( - "fmt" - "github.com/ethereum/go-ethereum/core/vm" geth "github.com/ethereum/go-ethereum/params" ) // Apply applies the changes to the virtual machine configuration. func (ec *EvmConfig) Apply() error { - // If Apply method has been already used in the object, return - // an error to avoid overriding configuration. - if ec.sealed { - return fmt.Errorf("error applying EvmConfig: already sealed and cannot be modified") + // If Apply method has been already used in the object, return nil and no not overwrite + // This mirrors the silent behavior of the previous EvmAppOptions implementation + if IsSealed() { + return nil } if err := setChainConfig(ec.chainConfig); err != nil { @@ -36,7 +34,7 @@ func (ec *EvmConfig) Apply() error { // After applying modifiers the configurator is sealed. This way, it is not possible // to call the configure method twice. - ec.sealed = true + Seal() return nil } diff --git a/x/vm/types/config_testing.go b/x/vm/types/config_testing.go index 8ed238984..221e5d825 100644 --- a/x/vm/types/config_testing.go +++ b/x/vm/types/config_testing.go @@ -19,7 +19,7 @@ var testChainConfig *ChainConfig func (ec *EvmConfig) Apply() error { // If Apply method has been already used in the object, return // an error to avoid overriding configuration. - if ec.sealed { + if IsSealed() { return fmt.Errorf("error applying EvmConfig: already sealed and cannot be modified") } @@ -41,7 +41,7 @@ func (ec *EvmConfig) Apply() error { // After applying modifications, the configurator is sealed. This way, it is not possible // to call the configure method twice. - ec.sealed = true + Seal() return nil } @@ -50,6 +50,7 @@ func (ec *EvmConfig) ResetTestConfig() { vm.ResetActivators() resetEVMCoinInfo() testChainConfig = nil + sealed = false } func setTestChainConfig(cc *ChainConfig) error { diff --git a/x/vm/types/evm_config.go b/x/vm/types/evm_config.go index d2d26c2bb..9ccb5ff80 100644 --- a/x/vm/types/evm_config.go +++ b/x/vm/types/evm_config.go @@ -7,11 +7,21 @@ import ( "github.com/ethereum/go-ethereum/core/vm" ) +// TOODO: remove singleton pattern and use a context instead +var sealed = false + +func Seal() { + sealed = true +} + +func IsSealed() bool { + return sealed +} + // EvmConfig allows to extend x/evm module configurations. The configurator modifies // the EVM before starting the node. This means that all init genesis validations will be // applied to each change. type EvmConfig struct { - sealed bool extendedEIPs map[int]func(*vm.JumpTable) extendedDefaultExtraEIPs []int64 chainConfig *ChainConfig From 3c1f82925bb482c206c69af1381d686eae16bf58 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Wed, 17 Sep 2025 16:28:21 -0400 Subject: [PATCH 17/23] move around evmd files --- Makefile | 5 +- {evmd/config => client}/client.toml | 15 ++- client/flags/flags.go | 42 +++++++ .../cmd/evmd/config => config}/evmd_config.go | 0 config/server_app_options.go | 106 +++++++++--------- evmd/{ => app}/app.go | 20 ++-- evmd/{cmd/evmd/cmd => app}/creator.go | 15 ++- evmd/{ => app}/export.go | 2 +- evmd/{ => app}/genesis.go | 2 +- evmd/{ => app}/interfaces.go | 2 +- evmd/{ => app}/precompiles.go | 2 +- evmd/{ => app}/upgrades.go | 2 +- evmd/cmd/{evmd/cmd => }/root.go | 48 ++++---- evmd/cmd/{evmd/cmd => testnet}/testnet.go | 35 +++--- evmd/{cmd/evmd => }/main.go | 6 +- evmd/tests/ibc/ibc_middleware_test.go | 20 ++-- .../ibc/ics20_precompile_transfer_test.go | 16 +-- evmd/tests/ibc/transfer_test.go | 4 +- evmd/tests/ibc/v2_ibc_middleware_test.go | 16 +-- .../ibc/v2_ics20_precompile_transfer_test.go | 16 +-- evmd/tests/ibc/v2_transfer_test.go | 10 +- evmd/tests/integration/create_app.go | 6 +- evmd/tests/ledger/evmosd_suite_test.go | 7 +- evmd/tests/network/network.go | 23 ++-- evmd/{test_helpers.go => testutil/helpers.go} | 19 ++-- server/config/toml.go | 11 -- server/flags/flags.go | 3 - server/start.go | 3 - 28 files changed, 247 insertions(+), 209 deletions(-) rename {evmd/config => client}/client.toml (63%) create mode 100644 client/flags/flags.go rename {evmd/cmd/evmd/config => config}/evmd_config.go (100%) rename evmd/{ => app}/app.go (98%) rename evmd/{cmd/evmd/cmd => app}/creator.go (95%) rename evmd/{ => app}/export.go (99%) rename evmd/{ => app}/genesis.go (99%) rename evmd/{ => app}/interfaces.go (93%) rename evmd/{ => app}/precompiles.go (99%) rename evmd/{ => app}/upgrades.go (99%) rename evmd/cmd/{evmd/cmd => }/root.go (88%) rename evmd/cmd/{evmd/cmd => testnet}/testnet.go (96%) rename evmd/{cmd/evmd => }/main.go (50%) rename evmd/{test_helpers.go => testutil/helpers.go} (88%) diff --git a/Makefile b/Makefile index 5bd994ea3..f7b5f2867 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,6 @@ export GO111MODULE = on # evmd is a separate module under ./evmd EVMD_DIR := evmd -EVMD_MAIN_PKG := ./cmd/evmd ############################################################################### ### Build & Install evmd ### @@ -91,7 +90,7 @@ endif build: go.sum $(BUILDDIR)/ @echo "🏗️ Building evmd to $(BUILDDIR)/$(EXAMPLE_BINARY) ..." @cd $(EVMD_DIR) && CGO_ENABLED="1" \ - go build $(BUILD_FLAGS) -o $(BUILDDIR)/$(EXAMPLE_BINARY) $(EVMD_MAIN_PKG) + go build $(BUILD_FLAGS) -o $(BUILDDIR)/$(EXAMPLE_BINARY) # Cross-compile for Linux AMD64 build-linux: @@ -101,7 +100,7 @@ build-linux: install: go.sum @echo "🚚 Installing evmd to $(BINDIR) ..." @cd $(EVMD_DIR) && CGO_ENABLED="1" \ - go install $(BUILD_FLAGS) $(EVMD_MAIN_PKG) + go install $(BUILD_FLAGS) $(BUILDDIR)/: mkdir -p $(BUILDDIR)/ diff --git a/evmd/config/client.toml b/client/client.toml similarity index 63% rename from evmd/config/client.toml rename to client/client.toml index 02df72407..d27222bda 100644 --- a/evmd/config/client.toml +++ b/client/client.toml @@ -6,7 +6,7 @@ ############################################################################### # The network chain ID -chain-id = "" +chain-id = "cosmos" # The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory) keyring-backend = "os" @@ -18,4 +18,15 @@ output = "text" node = "tcp://localhost:26657" # Transaction broadcasting mode (sync|async) -broadcast-mode = "sync" \ No newline at end of file +broadcast-mode = "sync" + +[coin-info] + +# DisplayDenom defines the display denomination shown to users +display-denom = "atom" + +# Decimals defines the precision/decimals for the base denomination (1-18) +decimals = 18 + +# ExtendedDecimals defines the precision/decimals for the extended denomination (typically 18 decimals for atto-denom) +extended-decimals = 18 \ No newline at end of file diff --git a/client/flags/flags.go b/client/flags/flags.go new file mode 100644 index 000000000..81cb60841 --- /dev/null +++ b/client/flags/flags.go @@ -0,0 +1,42 @@ +package flags + +import ( + "github.com/cosmos/evm/config" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// Client configuration flags +const ( + // Custom client flags that will be added to client.toml + DisplayDenom = "coin-info.display-denom" + Decimals = "coin-info.decimals" + ExtendedDecimals = "coin-info.extended-decimals" +) + +// Default values for client flags +const ( + DefaultDisplayDenom = config.DisplayDenom + DefaultDecimals = config.Decimals + DefaultExtendedDecimals = config.ExtendedDecimals +) + +// AddClientFlags adds custom client flags to the command +func AddClientFlags(cmd *cobra.Command) error { + cmd.PersistentFlags().String(DisplayDenom, DefaultDisplayDenom, "the display denom used to derive the denom and extended denom") + cmd.PersistentFlags().Uint8(Decimals, uint8(DefaultDecimals), "the decimals for the base denomination") + cmd.PersistentFlags().Uint8(ExtendedDecimals, uint8(DefaultExtendedDecimals), "the decimals for the extended denomination") + + // Bind flags to viper for client.toml precedence + if err := viper.BindPFlag(DisplayDenom, cmd.PersistentFlags().Lookup(DisplayDenom)); err != nil { + return err + } + if err := viper.BindPFlag(Decimals, cmd.PersistentFlags().Lookup(Decimals)); err != nil { + return err + } + if err := viper.BindPFlag(ExtendedDecimals, cmd.PersistentFlags().Lookup(ExtendedDecimals)); err != nil { + return err + } + + return nil +} diff --git a/evmd/cmd/evmd/config/evmd_config.go b/config/evmd_config.go similarity index 100% rename from evmd/cmd/evmd/config/evmd_config.go rename to config/evmd_config.go diff --git a/config/server_app_options.go b/config/server_app_options.go index 89d4db633..99be07abf 100644 --- a/config/server_app_options.go +++ b/config/server_app_options.go @@ -8,9 +8,7 @@ import ( "github.com/holiman/uint256" "github.com/spf13/cast" - "github.com/cosmos/evm/config/eips" srvflags "github.com/cosmos/evm/server/flags" - evmtypes "github.com/cosmos/evm/x/vm/types" "cosmossdk.io/log" @@ -128,55 +126,55 @@ func GetEvmChainID(appOpts servertypes.AppOptions) (uint64, error) { return evmChainID, nil } -func GetEvmCoinInfo(appOpts servertypes.AppOptions) (*evmtypes.EvmCoinInfo, error) { - displayDenom := cast.ToString(appOpts.Get(srvflags.EVMDisplayDenom)) - if displayDenom == "" { - return nil, errors.New("display denom flag not found in app options") - } - decimals := cast.ToUint8(appOpts.Get(srvflags.EVMDecimals)) - if decimals == 0 { - return nil, errors.New("decimals flag not found in app options") - } - extendedDecimals := cast.ToUint8(appOpts.Get(srvflags.EVMExtendedDecimals)) - if extendedDecimals == 0 { - return nil, errors.New("extended decimals flag not found in app options") - } - - evmCoinInfo := evmtypes.EvmCoinInfo{ - DisplayDenom: displayDenom, - Decimals: evmtypes.Decimals(decimals), - ExtendedDecimals: evmtypes.Decimals(extendedDecimals), - } - if err := evmCoinInfo.Validate(); err != nil { - return nil, err - } - - return &evmCoinInfo, nil -} - -func CreateChainConfig(appOpts servertypes.AppOptions) (*ChainConfig, error) { - chainID, err := GetChainID(appOpts) - if err != nil { - return nil, err - } - evmChainID, err := GetEvmChainID(appOpts) - if err != nil { - return nil, err - } - evmCoinInfo, err := GetEvmCoinInfo(appOpts) - if err != nil { - return nil, err - } - - chainConfig := NewChainConfig( - chainID, - evmChainID, - eips.CosmosEVMActivators, - nil, - nil, - *evmCoinInfo, - false, - ) - - return &chainConfig, nil -} +// func GetEvmCoinInfo(appOpts servertypes.AppOptions) (*evmtypes.EvmCoinInfo, error) { +// displayDenom := cast.ToString(appOpts.Get(srvflags.EVMDisplayDenom)) +// if displayDenom == "" { +// return nil, errors.New("display denom flag not found in app options") +// } +// decimals := cast.ToUint8(appOpts.Get(srvflags.EVMDecimals)) +// if decimals == 0 { +// return nil, errors.New("decimals flag not found in app options") +// } +// extendedDecimals := cast.ToUint8(appOpts.Get(srvflags.EVMExtendedDecimals)) +// if extendedDecimals == 0 { +// return nil, errors.New("extended decimals flag not found in app options") +// } + +// evmCoinInfo := evmtypes.EvmCoinInfo{ +// DisplayDenom: displayDenom, +// Decimals: evmtypes.Decimals(decimals), +// ExtendedDecimals: evmtypes.Decimals(extendedDecimals), +// } +// if err := evmCoinInfo.Validate(); err != nil { +// return nil, err +// } + +// return &evmCoinInfo, nil +// } + +// func CreateChainConfig(appOpts servertypes.AppOptions) (*ChainConfig, error) { +// chainID, err := GetChainID(appOpts) +// if err != nil { +// return nil, err +// } +// evmChainID, err := GetEvmChainID(appOpts) +// if err != nil { +// return nil, err +// } +// evmCoinInfo, err := GetEvmCoinInfo(appOpts) +// if err != nil { +// return nil, err +// } + +// chainConfig := NewChainConfig( +// chainID, +// evmChainID, +// eips.CosmosEVMActivators, +// nil, +// nil, +// *evmCoinInfo, +// false, +// ) + +// return &chainConfig, nil +// } diff --git a/evmd/app.go b/evmd/app/app.go similarity index 98% rename from evmd/app.go rename to evmd/app/app.go index 54859ff43..281abc770 100644 --- a/evmd/app.go +++ b/evmd/app/app.go @@ -1,4 +1,4 @@ -package evmd +package app import ( "encoding/json" @@ -18,10 +18,10 @@ import ( abci "github.com/cometbft/cometbft/abci/types" dbm "github.com/cosmos/cosmos-db" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" evmante "github.com/cosmos/evm/ante" cosmosevmante "github.com/cosmos/evm/ante/evm" "github.com/cosmos/evm/config" - evmconfig "github.com/cosmos/evm/config" evmosencoding "github.com/cosmos/evm/encoding" "github.com/cosmos/evm/evmd/ante" evmmempool "github.com/cosmos/evm/mempool" @@ -37,7 +37,6 @@ import ( ibccallbackskeeper "github.com/cosmos/evm/x/ibc/callbacks/keeper" // NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens - evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" "github.com/cosmos/evm/x/ibc/transfer" transferkeeper "github.com/cosmos/evm/x/ibc/transfer/keeper" transferv2 "github.com/cosmos/evm/x/ibc/transfer/v2" @@ -100,7 +99,6 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" - authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" @@ -138,13 +136,13 @@ func init() { // manually update the power reduction by replacing micro (u) -> atto (a) evmos sdk.DefaultPowerReduction = cosmosevmtypes.AttoPowerReduction - defaultNodeHome = evmdconfig.MustGetDefaultNodeHome() + DefaultNodeHome = config.MustGetDefaultNodeHome() } const appName = "evmd" -// defaultNodeHome default home directories for the application daemon -var defaultNodeHome string +// DefaultNodeHome default home directories for the application daemon +var DefaultNodeHome string var ( _ runtime.AppI = (*EVMD)(nil) @@ -318,7 +316,7 @@ func NewExampleApp( // add keepers app.AccountKeeper = authkeeper.NewAccountKeeper( appCodec, runtime.NewKVStoreService(keys[authtypes.StoreKey]), - authtypes.ProtoBaseAccount, evmdconfig.GetMaccPerms(), + authtypes.ProtoBaseAccount, config.GetMaccPerms(), authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.GetConfig().GetBech32AccountAddrPrefix(), authAddr, @@ -328,7 +326,7 @@ func NewExampleApp( appCodec, runtime.NewKVStoreService(keys[banktypes.StoreKey]), app.AccountKeeper, - evmdconfig.BlockedAddresses(), + config.BlockedAddresses(), authAddr, logger, ) @@ -755,9 +753,9 @@ func NewExampleApp( // If you wish to use the noop mempool, remove this codeblock if evmtypes.GetChainConfig() != nil { // Get the block gas limit from genesis file - blockGasLimit := evmconfig.GetBlockGasLimit(appOpts, logger) + blockGasLimit := config.GetBlockGasLimit(appOpts, logger) // Get GetMinTip from app.toml or cli flag configuration - mipTip := evmconfig.GetMinTip(appOpts, logger) + mipTip := config.GetMinTip(appOpts, logger) mempoolConfig := &evmmempool.EVMMempoolConfig{ AnteHandler: app.GetAnteHandler(), diff --git a/evmd/cmd/evmd/cmd/creator.go b/evmd/app/creator.go similarity index 95% rename from evmd/cmd/evmd/cmd/creator.go rename to evmd/app/creator.go index 73aac47ad..35d2a941f 100644 --- a/evmd/cmd/evmd/cmd/creator.go +++ b/evmd/app/creator.go @@ -1,4 +1,4 @@ -package cmd +package app import ( "errors" @@ -13,7 +13,6 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" evmconfig "github.com/cosmos/evm/config" - "github.com/cosmos/evm/evmd" "github.com/spf13/cast" "github.com/spf13/viper" @@ -24,9 +23,9 @@ import ( storetypes "cosmossdk.io/store/types" ) -type appCreator struct{} +type AppCreator struct{} -func (a appCreator) newApp( +func (a AppCreator) newApp( logger log.Logger, db dbm.DB, traceStore io.Writer, @@ -93,7 +92,7 @@ func (a appCreator) newApp( panic(err) } - return evmd.NewExampleApp( + return NewExampleApp( logger, db, traceStore, @@ -104,7 +103,7 @@ func (a appCreator) newApp( ) } -func (a appCreator) appExport( +func (a AppCreator) appExport( logger log.Logger, db dbm.DB, traceStore io.Writer, @@ -114,7 +113,7 @@ func (a appCreator) appExport( appOpts servertypes.AppOptions, modulesToExport []string, ) (servertypes.ExportedApp, error) { - var evmApp *evmd.EVMD + var evmApp *EVMD homePath, ok := appOpts.Get(flags.FlagHome).(string) if !ok || homePath == "" { @@ -140,7 +139,7 @@ func (a appCreator) appExport( return servertypes.ExportedApp{}, err } - evmApp = evmd.NewExampleApp( + evmApp = NewExampleApp( logger, db, traceStore, diff --git a/evmd/export.go b/evmd/app/export.go similarity index 99% rename from evmd/export.go rename to evmd/app/export.go index 096f5eb2c..e308428da 100644 --- a/evmd/export.go +++ b/evmd/app/export.go @@ -1,4 +1,4 @@ -package evmd +package app import ( "encoding/json" diff --git a/evmd/genesis.go b/evmd/app/genesis.go similarity index 99% rename from evmd/genesis.go rename to evmd/app/genesis.go index 01ef01b32..51cbdf778 100644 --- a/evmd/genesis.go +++ b/evmd/app/genesis.go @@ -1,4 +1,4 @@ -package evmd +package app import ( "encoding/json" diff --git a/evmd/interfaces.go b/evmd/app/interfaces.go similarity index 93% rename from evmd/interfaces.go rename to evmd/app/interfaces.go index 98a22647c..ed391bc14 100644 --- a/evmd/interfaces.go +++ b/evmd/app/interfaces.go @@ -1,4 +1,4 @@ -package evmd +package app import ( cmn "github.com/cosmos/evm/precompiles/common" diff --git a/evmd/precompiles.go b/evmd/app/precompiles.go similarity index 99% rename from evmd/precompiles.go rename to evmd/app/precompiles.go index cd7fe94b4..f557c2c40 100644 --- a/evmd/precompiles.go +++ b/evmd/app/precompiles.go @@ -1,4 +1,4 @@ -package evmd +package app import ( "fmt" diff --git a/evmd/upgrades.go b/evmd/app/upgrades.go similarity index 99% rename from evmd/upgrades.go rename to evmd/app/upgrades.go index 2413912c1..4bc34c7c2 100644 --- a/evmd/upgrades.go +++ b/evmd/app/upgrades.go @@ -1,4 +1,4 @@ -package evmd +package app import ( "context" diff --git a/evmd/cmd/evmd/cmd/root.go b/evmd/cmd/root.go similarity index 88% rename from evmd/cmd/evmd/cmd/root.go rename to evmd/cmd/root.go index 43e6e6126..71605717d 100644 --- a/evmd/cmd/evmd/cmd/root.go +++ b/evmd/cmd/root.go @@ -15,10 +15,11 @@ import ( dbm "github.com/cosmos/cosmos-db" cosmosevmcmd "github.com/cosmos/evm/client" + "github.com/cosmos/evm/config" evmconfig "github.com/cosmos/evm/config" cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring" - "github.com/cosmos/evm/evmd" - evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" + evmdapp "github.com/cosmos/evm/evmd/app" + testnetcmd "github.com/cosmos/evm/evmd/cmd/testnet" cosmosevmserver "github.com/cosmos/evm/server" srvflags "github.com/cosmos/evm/server/flags" @@ -30,7 +31,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" - clientcfg "github.com/cosmos/cosmos-sdk/client/config" + sdkclientcfg "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/pruning" @@ -47,6 +48,7 @@ import ( txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + clientflags "github.com/cosmos/evm/client/flags" ) // NewRootCmd creates a new root command for evmd. It is called once in the @@ -57,13 +59,13 @@ func NewRootCmd() *cobra.Command { // and the CLI options for the modules // add keyring to autocli opts - tempApp := evmd.NewExampleApp( + tempApp := evmdapp.NewExampleApp( log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{}, - evmconfig.ChainConfig{}, + config.ChainConfig{}, ) encodingConfig := sdktestutil.TestEncodingConfig{ @@ -80,7 +82,7 @@ func NewRootCmd() *cobra.Command { WithInput(os.Stdin). WithAccountRetriever(authtypes.AccountRetriever{}). WithBroadcastMode(flags.FlagBroadcastMode). - WithHomeDir(evmdconfig.MustGetDefaultNodeHome()). + WithHomeDir(config.MustGetDefaultNodeHome()). WithViper(""). // In simapp, we don't use any prefix for env variables. // Cosmos EVM specific setup WithKeyringOptions(cosmosevmkeyring.Option()). @@ -100,7 +102,7 @@ func NewRootCmd() *cobra.Command { return err } - initClientCtx, err = clientcfg.ReadFromClientConfig(initClientCtx) + initClientCtx, err = sdkclientcfg.ReadFromClientConfig(initClientCtx) if err != nil { return err } @@ -129,7 +131,7 @@ func NewRootCmd() *cobra.Command { return err } - customAppTemplate, customAppConfig := evmdconfig.InitAppConfig(evmconfig.BaseDenom, evmconfig.DefaultEvmChainID) + customAppTemplate, customAppConfig := config.InitAppConfig(evmconfig.BaseDenom, evmconfig.DefaultEvmChainID) customTMConfig := initCometConfig() return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) @@ -142,7 +144,7 @@ func NewRootCmd() *cobra.Command { // if the chain id is not set in client.toml, populate it with the default evm chain id initClientCtx = initClientCtx.WithChainID(evmconfig.DefaultChainID) } - initClientCtx, _ = clientcfg.ReadFromClientConfig(initClientCtx) + initClientCtx, _ = sdkclientcfg.ReadFromClientConfig(initClientCtx) autoCliOpts := tempApp.AutoCliOpts() autoCliOpts.ClientCtx = initClientCtx @@ -150,10 +152,10 @@ func NewRootCmd() *cobra.Command { panic(err) } - // chainConfig := evmconfig.DefaultChainConfig - // if err := chainConfig.ApplyChainConfig(); err != nil { - // panic(err) - // } + chainConfig := evmconfig.DefaultChainConfig + if err := chainConfig.ApplyChainConfig(); err != nil { + panic(err) + } return rootCmd } @@ -176,11 +178,11 @@ func initCometConfig() *cmtcfg.Config { return cfg } -func initRootCmd(rootCmd *cobra.Command, evmApp *evmd.EVMD) { +func initRootCmd(rootCmd *cobra.Command, evmApp *evmdapp.EVMD) { cfg := sdk.GetConfig() cfg.Seal() - defaultNodeHome := evmdconfig.MustGetDefaultNodeHome() + defaultNodeHome := config.MustGetDefaultNodeHome() sdkAppCreator := func(l log.Logger, d dbm.DB, w io.Writer, ao servertypes.AppOptions) servertypes.Application { return newApp(l, d, w, ao) } @@ -192,7 +194,7 @@ func initRootCmd(rootCmd *cobra.Command, evmApp *evmd.EVMD) { confixcmd.ConfigCommand(), pruning.Cmd(sdkAppCreator, defaultNodeHome), snapshot.Cmd(sdkAppCreator), - NewTestnetCmd(evmApp.BasicModuleManager, banktypes.GenesisBalancesIterator{}, appCreator{}), + testnetcmd.NewTestnetCmd(evmApp.BasicModuleManager, banktypes.GenesisBalancesIterator{}, evmdapp.AppCreator{}), ) // add Cosmos EVM' flavored TM commands to start server, etc. @@ -221,6 +223,12 @@ func initRootCmd(rootCmd *cobra.Command, evmApp *evmd.EVMD) { if err != nil { panic(err) } + + // add custom client flags to the root command + err = clientflags.AddClientFlags(rootCmd) + if err != nil { + panic(err) + } } func addModuleInitFlags(_ *cobra.Command) {} @@ -329,7 +337,7 @@ func newApp( panic(err) } - return evmd.NewExampleApp( + return evmdapp.NewExampleApp( logger, db, traceStore, true, appOpts, *chainConfig, @@ -348,7 +356,7 @@ func appExport( appOpts servertypes.AppOptions, modulesToExport []string, ) (servertypes.ExportedApp, error) { - var exampleApp *evmd.EVMD + var exampleApp *evmdapp.EVMD // this check is necessary as we use the flag in x/upgrade. // we can exit more gracefully by checking the flag here. @@ -379,13 +387,13 @@ func appExport( } if height != -1 { - exampleApp = evmd.NewExampleApp(logger, db, traceStore, false, appOpts, *chainConfig, baseapp.SetChainID(chainID)) + exampleApp = evmdapp.NewExampleApp(logger, db, traceStore, false, appOpts, *chainConfig, baseapp.SetChainID(chainID)) if err := exampleApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - exampleApp = evmd.NewExampleApp(logger, db, traceStore, true, appOpts, *chainConfig, baseapp.SetChainID(chainID)) + exampleApp = evmdapp.NewExampleApp(logger, db, traceStore, true, appOpts, *chainConfig, baseapp.SetChainID(chainID)) } return exampleApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) diff --git a/evmd/cmd/evmd/cmd/testnet.go b/evmd/cmd/testnet/testnet.go similarity index 96% rename from evmd/cmd/evmd/cmd/testnet.go rename to evmd/cmd/testnet/testnet.go index 8ee891b07..e338cfd9d 100644 --- a/evmd/cmd/evmd/cmd/testnet.go +++ b/evmd/cmd/testnet/testnet.go @@ -1,4 +1,4 @@ -package cmd +package testnet import ( "bufio" @@ -11,7 +11,6 @@ import ( cosmosevmhd "github.com/cosmos/evm/crypto/hd" cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring" - "github.com/cosmos/evm/evmd" cosmosevmserverconfig "github.com/cosmos/evm/server/config" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -19,8 +18,8 @@ import ( cmtconfig "github.com/cometbft/cometbft/config" "github.com/cometbft/cometbft/types" tmtime "github.com/cometbft/cometbft/types/time" - evmconfig "github.com/cosmos/evm/config" - evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" + "github.com/cosmos/evm/config" + evmdapp "github.com/cosmos/evm/evmd/app" dbm "github.com/cosmos/cosmos-db" @@ -75,7 +74,7 @@ var mnemonics = []string{ "doll midnight silk carpet brush boring pluck office gown inquiry duck chief aim exit gain never tennis crime fragile ship cloud surface exotic patch", } -type UnsafeStartValidatorCmdCreator func(ac appCreator) *cobra.Command +type UnsafeStartValidatorCmdCreator func(ac evmdapp.AppCreator) *cobra.Command type initArgs struct { algo string @@ -126,7 +125,7 @@ func addTestnetFlagsToCmd(cmd *cobra.Command) { // 1. run an in-process testnet or // 2. initialize validator configuration files for running a multi-validator testnet in a separate process or // 3. update application and consensus state with the local validator info -func NewTestnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator, appCreator appCreator) *cobra.Command { +func NewTestnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator, appCreator evmdapp.AppCreator) *cobra.Command { testnetCmd := &cobra.Command{ Use: "testnet", Short: "subcommands for starting or configuring local testnets", @@ -269,8 +268,8 @@ func initTestnetFiles( appConfig.Telemetry.EnableHostnameLabel = false appConfig.Telemetry.GlobalLabels = [][]string{{"chain_id", args.chainID}} evm := cosmosevmserverconfig.DefaultEVMConfig() - evm.EVMChainID = evmconfig.DefaultEvmChainID - evmCfg := evmdconfig.EVMAppConfig{ + evm.EVMChainID = config.DefaultEvmChainID + evmCfg := config.EVMAppConfig{ Config: *appConfig, EVM: *evm, JSONRPC: *cosmosevmserverconfig.DefaultJSONRPCConfig(), @@ -442,7 +441,7 @@ func initTestnetFiles( return err } - srvconfig.SetConfigTemplate(evmdconfig.EVMAppTemplate) + srvconfig.SetConfigTemplate(config.EVMAppTemplate) srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config", "app.toml"), evmCfg) } @@ -678,34 +677,34 @@ func NewTestNetworkFixture() network.TestFixture { } defer os.RemoveAll(dir) - app := evmd.NewExampleApp( + newApp := evmdapp.NewExampleApp( log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{}, - evmconfig.DefaultChainConfig, + config.DefaultChainConfig, ) appCtr := func(val network.ValidatorI) servertypes.Application { - return evmd.NewExampleApp( + return evmdapp.NewExampleApp( log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.EmptyAppOptions{}, - evmconfig.DefaultChainConfig, + config.DefaultChainConfig, ) } return network.TestFixture{ AppConstructor: appCtr, - GenesisState: app.DefaultGenesis(), + GenesisState: newApp.DefaultGenesis(), EncodingConfig: moduletestutil.TestEncodingConfig{ - InterfaceRegistry: app.InterfaceRegistry(), - Codec: app.AppCodec(), - TxConfig: app.GetTxConfig(), - Amino: app.LegacyAmino(), + InterfaceRegistry: newApp.InterfaceRegistry(), + Codec: newApp.AppCodec(), + TxConfig: newApp.GetTxConfig(), + Amino: newApp.LegacyAmino(), }, } } diff --git a/evmd/cmd/evmd/main.go b/evmd/main.go similarity index 50% rename from evmd/cmd/evmd/main.go rename to evmd/main.go index 3dad66a57..8c38275e4 100644 --- a/evmd/cmd/evmd/main.go +++ b/evmd/main.go @@ -4,15 +4,15 @@ import ( "fmt" "os" - "github.com/cosmos/evm/evmd/cmd/evmd/cmd" - evmconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" + "github.com/cosmos/evm/config" + "github.com/cosmos/evm/evmd/cmd" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" ) func main() { rootCmd := cmd.NewRootCmd() - if err := svrcmd.Execute(rootCmd, "evmd", evmconfig.MustGetDefaultNodeHome()); err != nil { + if err := svrcmd.Execute(rootCmd, "evmd", config.MustGetDefaultNodeHome()); err != nil { fmt.Fprintln(rootCmd.OutOrStderr(), err) os.Exit(1) } diff --git a/evmd/tests/ibc/ibc_middleware_test.go b/evmd/tests/ibc/ibc_middleware_test.go index f704a3704..026b42c58 100644 --- a/evmd/tests/ibc/ibc_middleware_test.go +++ b/evmd/tests/ibc/ibc_middleware_test.go @@ -11,7 +11,7 @@ import ( testifysuite "github.com/stretchr/testify/suite" "github.com/cosmos/evm/contracts" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" "github.com/cosmos/evm/evmd/tests/integration" "github.com/cosmos/evm/ibc" "github.com/cosmos/evm/testutil" @@ -381,7 +381,7 @@ func (suite *MiddlewareTestSuite) TestOnRecvPacketWithCallback() { ) // Validate successful callback - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) singleTokenRepresentation, err := types.NewTokenPairSTRv2(voucherDenom) suite.Require().NoError(err) erc20Contract := singleTokenRepresentation.GetERC20Contract() @@ -542,7 +542,7 @@ func (suite *MiddlewareTestSuite) TestOnRecvPacket() { voucherDenom := testutil.GetVoucherDenomFromPacketData(data, packet.GetDestPort(), packet.GetDestChannel()) - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) voucherCoin := evmApp.BankKeeper.GetBalance(ctxA, receiver, voucherDenom) suite.Require().Equal(sendAmt.String(), voucherCoin.Amount.String()) @@ -574,7 +574,7 @@ func (suite *MiddlewareTestSuite) TestOnRecvPacketNativeErc20() { nativeErc20 := SetupNativeErc20(suite.T(), suite.evmChainA, suite.evmChainA.SenderAccounts[0]) evmCtx := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) // Scenario: Native ERC20 token transfer from evmChainA to chainB timeoutHeight := clienttypes.NewHeight(1, 110) @@ -998,7 +998,7 @@ func (suite *MiddlewareTestSuite) TestOnAcknowledgementPacketWithCallback() { suite.SetupTest() ctxA := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) bondDenom, err := evmApp.StakingKeeper.BondDenom(ctxA) suite.Require().NoError(err) @@ -1226,7 +1226,7 @@ func (suite *MiddlewareTestSuite) TestOnAcknowledgementPacket() { suite.SetupTest() ctxA := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) bondDenom, err := evmApp.StakingKeeper.BondDenom(ctxA) suite.Require().NoError(err) @@ -1378,7 +1378,7 @@ func (suite *MiddlewareTestSuite) TestOnAcknowledgementPacketNativeErc20() { nativeErc20 := SetupNativeErc20(suite.T(), suite.evmChainA, suite.evmChainA.SenderAccounts[0]) evmCtx := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) timeoutHeight := clienttypes.NewHeight(1, 110) path := suite.path @@ -1507,7 +1507,7 @@ func (suite *MiddlewareTestSuite) TestOnTimeoutPacket() { suite.SetupTest() ctxA := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) bondDenom, err := evmApp.StakingKeeper.BondDenom(ctxA) suite.Require().NoError(err) @@ -1825,7 +1825,7 @@ func (suite *MiddlewareTestSuite) TestOnTimeoutPacketWithCallback() { suite.SetupTest() ctxA := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) bondDenom, err := evmApp.StakingKeeper.BondDenom(ctxA) suite.Require().NoError(err) @@ -2025,7 +2025,7 @@ func (suite *MiddlewareTestSuite) TestOnTimeoutPacketNativeErc20() { nativeErc20 := SetupNativeErc20(suite.T(), suite.evmChainA, suite.evmChainA.SenderAccounts[0]) evmCtx := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) timeoutHeight := clienttypes.NewHeight(1, 110) path := suite.path diff --git a/evmd/tests/ibc/ics20_precompile_transfer_test.go b/evmd/tests/ibc/ics20_precompile_transfer_test.go index cae1ee3cb..85726f5b5 100644 --- a/evmd/tests/ibc/ics20_precompile_transfer_test.go +++ b/evmd/tests/ibc/ics20_precompile_transfer_test.go @@ -13,7 +13,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" "github.com/cosmos/evm/evmd/tests/integration" "github.com/cosmos/evm/precompiles/ics20" chainutil "github.com/cosmos/evm/testutil" @@ -45,14 +45,14 @@ func (suite *ICS20TransferTestSuite) SetupTest() { suite.chainA = suite.coordinator.GetChain(evmibctesting.GetEvmChainID(1)) suite.chainB = suite.coordinator.GetChain(evmibctesting.GetEvmChainID(2)) - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) suite.chainAPrecompile, _ = ics20.NewPrecompile( evmAppA.BankKeeper, *evmAppA.StakingKeeper, evmAppA.TransferKeeper, evmAppA.IBCKeeper.ChannelKeeper, ) - evmAppB := suite.chainB.App.(*evmd.EVMD) + evmAppB := suite.chainB.App.(*evmdapp.EVMD) suite.chainBPrecompile, _ = ics20.NewPrecompile( evmAppB.BankKeeper, *evmAppB.StakingKeeper, @@ -81,7 +81,7 @@ func (suite *ICS20TransferTestSuite) TestHandleMsgTransfer() { { "transfer single denom", func(_ evmibctesting.SenderAccount) { - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) sourceDenomToTransfer, err = evmAppA.StakingKeeper.BondDenom(suite.chainA.GetContext()) msgAmount = evmibctesting.DefaultCoinAmount }, @@ -90,7 +90,7 @@ func (suite *ICS20TransferTestSuite) TestHandleMsgTransfer() { "transfer amount larger than int64", func(_ evmibctesting.SenderAccount) { var ok bool - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) sourceDenomToTransfer, err = evmAppA.StakingKeeper.BondDenom(suite.chainA.GetContext()) msgAmount, ok = sdkmath.NewIntFromString("9223372036854775808") // 2^63 (one above int64) suite.Require().True(ok) @@ -99,7 +99,7 @@ func (suite *ICS20TransferTestSuite) TestHandleMsgTransfer() { { "transfer entire balance", func(_ evmibctesting.SenderAccount) { - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) sourceDenomToTransfer, err = evmAppA.StakingKeeper.BondDenom(suite.chainA.GetContext()) msgAmount = transfertypes.UnboundedSpendLimit() }, @@ -133,7 +133,7 @@ func (suite *ICS20TransferTestSuite) TestHandleMsgTransfer() { tc.malleate(senderAccount) - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) GetBalance := func(addr sdk.AccAddress) sdk.Coin { ctx := suite.chainA.GetContext() @@ -214,7 +214,7 @@ func (suite *ICS20TransferTestSuite) TestHandleMsgTransfer() { suite.Require().Equal(transferAmount.String(), chainAEscrowBalance.Amount.String()) // check that voucher exists on chain B - evmAppB := suite.chainB.App.(*evmd.EVMD) + evmAppB := suite.chainB.App.(*evmdapp.EVMD) chainBDenom := transfertypes.NewDenom(originalCoin.Denom, traceAToB) chainBBalance := evmAppB.BankKeeper.GetBalance( suite.chainB.GetContext(), diff --git a/evmd/tests/ibc/transfer_test.go b/evmd/tests/ibc/transfer_test.go index a386e1e68..e868a0d05 100644 --- a/evmd/tests/ibc/transfer_test.go +++ b/evmd/tests/ibc/transfer_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" "github.com/cosmos/evm/evmd/tests/integration" evmibctesting "github.com/cosmos/evm/testutil/ibc" "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types" @@ -95,7 +95,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() { senderAddr := senderAccount.SenderAccount.GetAddress() tc.malleate() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) sourceDenomToTransfer, err = evmApp.StakingKeeper.BondDenom(suite.evmChainA.GetContext()) suite.Require().NoError(err) senderBalance := evmApp.BankKeeper.GetBalance(suite.evmChainA.GetContext(), senderAddr, sourceDenomToTransfer) diff --git a/evmd/tests/ibc/v2_ibc_middleware_test.go b/evmd/tests/ibc/v2_ibc_middleware_test.go index 23f25c557..286741119 100644 --- a/evmd/tests/ibc/v2_ibc_middleware_test.go +++ b/evmd/tests/ibc/v2_ibc_middleware_test.go @@ -10,7 +10,7 @@ import ( "github.com/ethereum/go-ethereum/common" testifysuite "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" "github.com/cosmos/evm/evmd/tests/integration" "github.com/cosmos/evm/testutil" evmibctesting "github.com/cosmos/evm/testutil/ibc" @@ -144,7 +144,7 @@ func (suite *MiddlewareV2TestSuite) TestOnSendPacket() { suite.Run(tc.name, func() { suite.SetupTest() ctx = suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) bondDenom, err := evmApp.StakingKeeper.BondDenom(ctx) suite.Require().NoError(err) packetData = transfertypes.NewFungibleTokenPacketData( @@ -248,7 +248,7 @@ func (suite *MiddlewareV2TestSuite) TestOnRecvPacket() { tc.malleate() } - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) // erc20 module is routed as top level middleware transferStack := evmApp.GetIBCKeeper().ChannelKeeperV2.Router.Route(ibctesting.TransferPort) sourceClient := suite.pathBToA.EndpointB.ClientID @@ -323,7 +323,7 @@ func (suite *MiddlewareV2TestSuite) TestOnRecvPacketNativeERC20() { sendAmt := math.NewIntFromBigInt(nativeErc20.InitialBal) evmCtx := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) // MOCK erc20 native coin transfer from chainA to chainB // 1: Convert erc20 tokens to native erc20 coins for sending through IBC. _, err := evmApp.Erc20Keeper.ConvertERC20( @@ -482,7 +482,7 @@ func (suite *MiddlewareV2TestSuite) TestOnAcknowledgementPacket() { suite.Run(tc.name, func() { suite.SetupTest() ctx = suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) bondDenom, err := evmApp.StakingKeeper.BondDenom(ctx) suite.Require().NoError(err) sendAmt := ibctesting.DefaultCoinAmount @@ -607,7 +607,7 @@ func (suite *MiddlewareV2TestSuite) TestOnAcknowledgementPacketNativeErc20() { sendAmt := math.NewIntFromBigInt(nativeErc20.InitialBal) evmCtx := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) // MOCK erc20 native coin transfer from chainA to chainB // 1: Convert erc20 tokens to native erc20 coins for sending through IBC. @@ -744,7 +744,7 @@ func (suite *MiddlewareV2TestSuite) TestOnTimeoutPacket() { suite.Run(tc.name, func() { suite.SetupTest() ctx = suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) bondDenom, err := evmApp.StakingKeeper.BondDenom(ctx) suite.Require().NoError(err) packetData = transfertypes.NewFungibleTokenPacketData( @@ -841,7 +841,7 @@ func (suite *MiddlewareV2TestSuite) TestOnTimeoutPacketNativeErc20() { sendAmt := math.NewIntFromBigInt(nativeErc20.InitialBal) evmCtx := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) // MOCK erc20 native coin transfer from chainA to chainB // 1: Convert erc20 tokens to native erc20 coins for sending through IBC. diff --git a/evmd/tests/ibc/v2_ics20_precompile_transfer_test.go b/evmd/tests/ibc/v2_ics20_precompile_transfer_test.go index 740f8c3d8..06220775c 100644 --- a/evmd/tests/ibc/v2_ics20_precompile_transfer_test.go +++ b/evmd/tests/ibc/v2_ics20_precompile_transfer_test.go @@ -14,7 +14,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" "github.com/cosmos/evm/evmd/tests/integration" "github.com/cosmos/evm/precompiles/ics20" chainutil "github.com/cosmos/evm/testutil" @@ -46,14 +46,14 @@ func (suite *ICS20TransferV2TestSuite) SetupTest() { suite.chainA = suite.coordinator.GetChain(evmibctesting.GetEvmChainID(1)) suite.chainB = suite.coordinator.GetChain(evmibctesting.GetEvmChainID(2)) - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) suite.chainAPrecompile, _ = ics20.NewPrecompile( evmAppA.BankKeeper, *evmAppA.StakingKeeper, evmAppA.TransferKeeper, evmAppA.IBCKeeper.ChannelKeeper, ) - evmAppB := suite.chainB.App.(*evmd.EVMD) + evmAppB := suite.chainB.App.(*evmdapp.EVMD) suite.chainBPrecompile, _ = ics20.NewPrecompile( evmAppB.BankKeeper, *evmAppB.StakingKeeper, @@ -81,7 +81,7 @@ func (suite *ICS20TransferV2TestSuite) TestHandleMsgTransfer() { { "transfer single denom", func(_ evmibctesting.SenderAccount) { - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) sourceDenomToTransfer, err = evmAppA.StakingKeeper.BondDenom(suite.chainA.GetContext()) msgAmount = evmibctesting.DefaultCoinAmount }, @@ -90,7 +90,7 @@ func (suite *ICS20TransferV2TestSuite) TestHandleMsgTransfer() { "transfer amount larger than int64", func(_ evmibctesting.SenderAccount) { var ok bool - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) sourceDenomToTransfer, err = evmAppA.StakingKeeper.BondDenom(suite.chainA.GetContext()) msgAmount, ok = sdkmath.NewIntFromString("9223372036854775808") // 2^63 (one above int64) suite.Require().True(ok) @@ -99,7 +99,7 @@ func (suite *ICS20TransferV2TestSuite) TestHandleMsgTransfer() { { "transfer entire balance", func(_ evmibctesting.SenderAccount) { - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) sourceDenomToTransfer, err = evmAppA.StakingKeeper.BondDenom(suite.chainA.GetContext()) msgAmount = transfertypes.UnboundedSpendLimit() }, @@ -134,7 +134,7 @@ func (suite *ICS20TransferV2TestSuite) TestHandleMsgTransfer() { tc.malleate(senderAccount) - evmAppA := suite.chainA.App.(*evmd.EVMD) + evmAppA := suite.chainA.App.(*evmdapp.EVMD) GetBalance := func(addr sdk.AccAddress) sdk.Coin { ctx := suite.chainA.GetContext() @@ -220,7 +220,7 @@ func (suite *ICS20TransferV2TestSuite) TestHandleMsgTransfer() { suite.Require().True(transferAmount.Equal(chainAEscrowBalance.Amount)) // check that voucher exists on chain B - evmAppB := suite.chainB.App.(*evmd.EVMD) + evmAppB := suite.chainB.App.(*evmdapp.EVMD) chainBDenom := transfertypes.NewDenom(originalCoin.Denom, traceAToB) chainBBalance := evmAppB.BankKeeper.GetBalance( suite.chainB.GetContext(), diff --git a/evmd/tests/ibc/v2_transfer_test.go b/evmd/tests/ibc/v2_transfer_test.go index efcf5fc94..0da239db7 100644 --- a/evmd/tests/ibc/v2_transfer_test.go +++ b/evmd/tests/ibc/v2_transfer_test.go @@ -19,7 +19,7 @@ import ( testifysuite "github.com/stretchr/testify/suite" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" "github.com/cosmos/evm/evmd/tests/integration" evmibctesting "github.com/cosmos/evm/testutil/ibc" "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types" @@ -150,7 +150,7 @@ func (suite *TransferTestSuiteV2) TestOnSendPacket() { suite.Run(tc.name, func() { suite.SetupTest() // reset - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) originalBalance := evmApp.BankKeeper.GetBalance( suite.evmChainA.GetContext(), suite.evmChainA.SenderAccount.GetAddress(), @@ -312,7 +312,7 @@ func (suite *TransferTestSuiteV2) TestOnRecvPacket() { ) ctx := suite.evmChainA.GetContext() - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) cbs := evmApp.GetIBCKeeper().ChannelKeeperV2.Router.Route(evmibctesting.TransferPort) // malleate payload after it has been sent but before OnRecvPacket callback is called @@ -379,7 +379,7 @@ func (suite *TransferTestSuiteV2) TestOnAckPacket() { suite.Run(tc.name, func() { suite.SetupTest() // reset - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) originalBalance := evmApp.BankKeeper.GetBalance(suite.evmChainA.GetContext(), suite.evmChainA.SenderAccount.GetAddress(), tc.sourceDenomToTransfer) timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix()) //nolint:gosec // G115 @@ -486,7 +486,7 @@ func (suite *TransferTestSuiteV2) TestOnTimeoutPacket() { suite.Run(tc.name, func() { suite.SetupTest() // reset - evmApp := suite.evmChainA.App.(*evmd.EVMD) + evmApp := suite.evmChainA.App.(*evmdapp.EVMD) originalBalance := evmApp.BankKeeper.GetBalance(suite.evmChainA.GetContext(), suite.evmChainA.SenderAccount.GetAddress(), tc.sourceDenomToTransfer) timeoutTimestamp := uint64(suite.chainB.GetContext().BlockTime().Add(time.Hour).Unix()) //nolint:gosec // G115 diff --git a/evmd/tests/integration/create_app.go b/evmd/tests/integration/create_app.go index 0f8e501ce..2a28d602f 100644 --- a/evmd/tests/integration/create_app.go +++ b/evmd/tests/integration/create_app.go @@ -6,7 +6,7 @@ import ( dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/evm" "github.com/cosmos/evm/config" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" testconfig "github.com/cosmos/evm/testutil/config" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" ibctesting "github.com/cosmos/ibc-go/v10/testing" @@ -48,7 +48,7 @@ func CreateEvmd(chainID string, evmChainID uint64, customBaseAppOptions ...func( if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } - return evmd.NewExampleApp( + return evmdapp.NewExampleApp( logger, db, nil, @@ -75,7 +75,7 @@ func SetupEvmd() (ibctesting.TestingApp, map[string]json.RawMessage) { if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } - app := evmd.NewExampleApp( + app := evmdapp.NewExampleApp( log.NewNopLogger(), dbm.NewMemDB(), nil, diff --git a/evmd/tests/ledger/evmosd_suite_test.go b/evmd/tests/ledger/evmosd_suite_test.go index 47c803257..fa8de7b07 100644 --- a/evmd/tests/ledger/evmosd_suite_test.go +++ b/evmd/tests/ledger/evmosd_suite_test.go @@ -27,8 +27,9 @@ import ( "github.com/cosmos/evm/crypto/hd" cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring" "github.com/cosmos/evm/encoding" - "github.com/cosmos/evm/evmd" + evmdapp "github.com/cosmos/evm/evmd/app" "github.com/cosmos/evm/evmd/tests/ledger/mocks" + testutil "github.com/cosmos/evm/evmd/testutil" testconfig "github.com/cosmos/evm/testutil/config" utiltx "github.com/cosmos/evm/testutil/tx" @@ -47,7 +48,7 @@ var s *LedgerTestSuite type LedgerTestSuite struct { suite.Suite - app *evmd.EVMD + app *evmdapp.EVMD ctx sdk.Context ledger *mocks.SECP256K1 @@ -88,7 +89,7 @@ func (suite *LedgerTestSuite) SetupEvmosApp() { // init app chainID := testconfig.ExampleChainID - suite.app = evmd.Setup(suite.T(), chainID.ChainID, chainID.EVMChainID) + suite.app = testutil.Setup(suite.T(), chainID.ChainID, chainID.EVMChainID) suite.ctx = suite.app.NewContextLegacy(false, tmproto.Header{ Height: 1, ChainID: chainID.ChainID, diff --git a/evmd/tests/network/network.go b/evmd/tests/network/network.go index 50981c3fc..10d6c06e9 100644 --- a/evmd/tests/network/network.go +++ b/evmd/tests/network/network.go @@ -27,11 +27,10 @@ import ( cmtclient "github.com/cometbft/cometbft/rpc/client" dbm "github.com/cosmos/cosmos-db" - evmconfig "github.com/cosmos/evm/config" + "github.com/cosmos/evm/config" "github.com/cosmos/evm/crypto/hd" - "github.com/cosmos/evm/evmd" - evmdconfig "github.com/cosmos/evm/evmd/cmd/evmd/config" - "github.com/cosmos/evm/server/config" + evmdapp "github.com/cosmos/evm/evmd/app" + serverconfig "github.com/cosmos/evm/server/config" testconfig "github.com/cosmos/evm/testutil/config" cosmosevmtypes "github.com/cosmos/evm/types" @@ -111,7 +110,7 @@ func DefaultConfig() Config { } defer os.RemoveAll(dir) coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] - chainConfig := evmconfig.NewChainConfig( + chainConfig := config.NewChainConfig( chainID, evmChainID, nil, @@ -123,7 +122,7 @@ func DefaultConfig() Config { if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } - tempApp := evmd.NewExampleApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simutils.NewAppOptionsWithFlagHome(dir), chainConfig, baseapp.SetChainID(chainID)) + tempApp := evmdapp.NewExampleApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simutils.NewAppOptionsWithFlagHome(dir), chainConfig, baseapp.SetChainID(chainID)) cfg := Config{ Codec: tempApp.AppCodec(), @@ -154,7 +153,7 @@ func DefaultConfig() Config { func NewAppConstructor(chainID string, evmChainID uint64) AppConstructor { return func(val Validator) servertypes.Application { coinInfo := testconfig.ExampleChainCoinInfo[testconfig.ExampleChainID] - chainConfig := evmconfig.NewChainConfig( + chainConfig := config.NewChainConfig( chainID, evmChainID, nil, @@ -166,7 +165,7 @@ func NewAppConstructor(chainID string, evmChainID uint64) AppConstructor { if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } - return evmd.NewExampleApp( + return evmdapp.NewExampleApp( val.Ctx.Logger, dbm.NewMemDB(), nil, true, simutils.NewAppOptionsWithFlagHome(val.Ctx.Config.RootDir), chainConfig, @@ -200,7 +199,7 @@ type ( // a client can make RPC and API calls and interact with any client command // or handler. Validator struct { - AppConfig *config.Config + AppConfig *serverconfig.Config ClientCtx client.Context Ctx *server.Context Dir string @@ -283,7 +282,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { // generate private keys, node IDs, and initial transactions for i := 0; i < cfg.NumValidators; i++ { - appCfg := config.DefaultConfig() + appCfg := serverconfig.DefaultConfig() appCfg.Pruning = cfg.PruningStrategy appCfg.MinGasPrices = cfg.MinGasPrices appCfg.API.Enable = true @@ -353,7 +352,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { appCfg.JSONRPC.Address = fmt.Sprintf("0.0.0.0:%s", port) } appCfg.JSONRPC.Enable = true - appCfg.JSONRPC.API = config.GetAPINamespaces() + appCfg.JSONRPC.API = serverconfig.GetAPINamespaces() } logger := log.NewNopLogger() @@ -501,7 +500,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { return nil, err } - customAppTemplate, _ := evmdconfig.InitAppConfig(testconfig.ExampleAttoDenom, testconfig.ExampleEIP155ChainID) + customAppTemplate, _ := config.InitAppConfig(testconfig.ExampleAttoDenom, testconfig.ExampleEIP155ChainID) srvconfig.SetConfigTemplate(customAppTemplate) srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appCfg) diff --git a/evmd/test_helpers.go b/evmd/testutil/helpers.go similarity index 88% rename from evmd/test_helpers.go rename to evmd/testutil/helpers.go index 54c08d721..50ec2f6b9 100644 --- a/evmd/test_helpers.go +++ b/evmd/testutil/helpers.go @@ -1,4 +1,4 @@ -package evmd +package testutil import ( "encoding/json" @@ -12,6 +12,7 @@ import ( dbm "github.com/cosmos/cosmos-db" evmconfig "github.com/cosmos/evm/config" + evmdapp "github.com/cosmos/evm/evmd/app" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" ibctesting "github.com/cosmos/ibc-go/v10/testing" @@ -47,24 +48,24 @@ func init() { evmconfig.SetBip44CoinType(cfg) } -func setup(withGenesis bool, invCheckPeriod uint, chainID string, evmChainID uint64) (*EVMD, GenesisState) { +func setup(withGenesis bool, invCheckPeriod uint, chainID string, evmChainID uint64) (*evmdapp.EVMD, evmdapp.GenesisState) { db := dbm.NewMemDB() appOptions := make(simtestutil.AppOptionsMap, 0) - appOptions[flags.FlagHome] = defaultNodeHome + appOptions[flags.FlagHome] = evmdapp.DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = invCheckPeriod chainConfig := evmconfig.DefaultChainConfig - app := NewExampleApp(log.NewNopLogger(), db, nil, true, appOptions, chainConfig, baseapp.SetChainID(chainID)) + app := evmdapp.NewExampleApp(log.NewNopLogger(), db, nil, true, appOptions, chainConfig, baseapp.SetChainID(chainID)) if withGenesis { return app, app.DefaultGenesis() } - return app, GenesisState{} + return app, evmdapp.GenesisState{} } // Setup initializes a new EVMD. A Nop logger is set in EVMD. -func Setup(t *testing.T, chainID string, evmChainID uint64) *EVMD { +func Setup(t *testing.T, chainID string, evmChainID uint64) *evmdapp.EVMD { t.Helper() privVal := mock.NewPV() @@ -92,7 +93,7 @@ func Setup(t *testing.T, chainID string, evmChainID uint64) *EVMD { // that also act as delegators. For simplicity, each validator is bonded with a delegation // of one consensus engine unit in the default token of the simapp from first genesis // account. A Nop logger is set in EVMD. -func SetupWithGenesisValSet(t *testing.T, chainID string, evmChainID uint64, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *EVMD { +func SetupWithGenesisValSet(t *testing.T, chainID string, evmChainID uint64, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *evmdapp.EVMD { t.Helper() app, genesisState := setup(true, 5, chainID, evmChainID) @@ -127,10 +128,10 @@ func SetupWithGenesisValSet(t *testing.T, chainID string, evmChainID uint64, val func SetupTestingApp(chainConfig evmconfig.ChainConfig) func() (ibctesting.TestingApp, map[string]json.RawMessage) { return func() (ibctesting.TestingApp, map[string]json.RawMessage) { db := dbm.NewMemDB() - app := NewExampleApp( + app := evmdapp.NewExampleApp( log.NewNopLogger(), db, nil, true, - simtestutil.NewAppOptionsWithFlagHome(defaultNodeHome), + simtestutil.NewAppOptionsWithFlagHome(evmdapp.DefaultNodeHome), chainConfig, baseapp.SetChainID(chainConfig.ChainID), ) diff --git a/server/config/toml.go b/server/config/toml.go index 52ce9c29c..1e9d4689a 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -25,17 +25,6 @@ evm-chain-id = {{ .EVM.EVMChainID }} # MinTip defines the minimum priority fee for the mempool. min-tip = {{ .EVM.MinTip }} -[evm.coin-info] - -# DisplayDenom defines the display denomination shown to users -display-denom = "{{ .EVM.CoinInfo.DisplayDenom }}" - -# Decimals defines the precision/decimals for the base denomination (1-18) -decimals = {{ .EVM.CoinInfo.Decimals }} - -# ExtendedDecimals defines the precision/decimals for the extended denomination (typically 18 decimals for atto-denom) -extended-decimals = {{ .EVM.CoinInfo.ExtendedDecimals }} - ############################################################################### ### JSON RPC Configuration ### ############################################################################### diff --git a/server/flags/flags.go b/server/flags/flags.go index 704d6d2e0..3844fc7df 100644 --- a/server/flags/flags.go +++ b/server/flags/flags.go @@ -71,9 +71,6 @@ const ( EVMEnablePreimageRecording = "evm.cache-preimage" EVMChainID = "evm.evm-chain-id" EVMMinTip = "evm.min-tip" - EVMDisplayDenom = "evm.coin-info.display-denom" - EVMDecimals = "evm.coin-info.decimals" - EVMExtendedDecimals = "evm.coin-info.extended-decimals" ) // TLS flags diff --git a/server/start.go b/server/start.go index 904e50edc..aa317693c 100644 --- a/server/start.go +++ b/server/start.go @@ -222,9 +222,6 @@ which accepts a path for the resulting pprof file. cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll cmd.Flags().Uint64(srvflags.EVMChainID, cosmosevmserverconfig.DefaultEVMChainID, "the EIP-155 compatible replay protection chain ID") cmd.Flags().Uint64(srvflags.EVMMinTip, cosmosevmserverconfig.DefaultEVMMinTip, "the minimum priority fee for the mempool") - cmd.Flags().String(srvflags.EVMDisplayDenom, cosmosevmserverconfig.DefaultEvmCoinInfoDisplayDenom, "the display denomination for the chain") - cmd.Flags().Uint8(srvflags.EVMDecimals, uint8(cosmosevmserverconfig.DefaultEvmCoinInfoDecimals), "the decimals for the base denomination") - cmd.Flags().Uint8(srvflags.EVMExtendedDecimals, uint8(cosmosevmserverconfig.DefaultEvmCoinInfoExtendedDecimals), "the decimals for the extended denomination") cmd.Flags().String(srvflags.TLSCertPath, "", "the cert.pem file path for the server TLS configuration") cmd.Flags().String(srvflags.TLSKeyPath, "", "the key.pem file path for the server TLS configuration") From ea492dd8aa65d67c46e5177b8cce6c911270cec0 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Wed, 17 Sep 2025 18:08:10 -0400 Subject: [PATCH 18/23] refactor keys package and clean up client dir --- client/config.go | 46 ---------------- client/config_test.go | 28 ---------- client/context.go | 18 ------- client/keys.go | 101 ------------------------------------ client/keys/add.go | 88 ++++++++++++++++++++++++++++++- client/{ => keys}/export.go | 2 +- client/{ => keys}/import.go | 2 +- evmd/app/creator.go | 18 ++++--- evmd/cmd/root.go | 31 +++++------ go.mod | 1 + go.sum | 2 + 11 files changed, 118 insertions(+), 219 deletions(-) delete mode 100644 client/config.go delete mode 100644 client/config_test.go delete mode 100644 client/context.go delete mode 100644 client/keys.go rename client/{ => keys}/export.go (99%) rename client/{ => keys}/import.go (98%) diff --git a/client/config.go b/client/config.go deleted file mode 100644 index 1b6303599..000000000 --- a/client/config.go +++ /dev/null @@ -1,46 +0,0 @@ -package client - -import ( - "os" - "path/filepath" - - "github.com/spf13/cobra" - "github.com/spf13/viper" - - "github.com/cometbft/cometbft/libs/cli" - - "github.com/cosmos/cosmos-sdk/client/flags" -) - -// InitConfig adds the chain-id, encoding and output flags to the persistent flag set. -func InitConfig(cmd *cobra.Command) error { - home, err := cmd.PersistentFlags().GetString(cli.HomeFlag) - if err != nil { - return err - } - - configFile := filepath.Join(home, "config", "config.toml") - _, err = os.Stat(configFile) - if err != nil && !os.IsNotExist(err) { - // Immediately return if the error isn't related to the file not existing. - // See issue https://github.com/evmos/ethermint/issues/539 - return err - } - if err == nil { - viper.SetConfigFile(configFile) - - if err := viper.ReadInConfig(); err != nil { - return err - } - } - - if err := viper.BindPFlag(flags.FlagChainID, cmd.PersistentFlags().Lookup(flags.FlagChainID)); err != nil { - return err - } - - if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil { - return err - } - - return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag)) -} diff --git a/client/config_test.go b/client/config_test.go deleted file mode 100644 index 0b94d35f5..000000000 --- a/client/config_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package client - -import ( - "os" - "path/filepath" - "testing" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client/flags" -) - -func TestInitConfigNonNotExistError(t *testing.T) { - tempDir := t.TempDir() - subDir := filepath.Join(tempDir, "nonPerms") - if err := os.Mkdir(subDir, 0o600); err != nil { - t.Fatalf("Failed to create sub directory: %v", err) - } - cmd := &cobra.Command{} - cmd.PersistentFlags().String(flags.FlagHome, "", "") - if err := cmd.PersistentFlags().Set(flags.FlagHome, subDir); err != nil { - t.Fatalf("Could not set home flag [%T] %v", err, err) - } - - if err := InitConfig(cmd); !os.IsPermission(err) { - t.Fatalf("Failed to catch permissions error, got: [%T] %v", err, err) - } -} diff --git a/client/context.go b/client/context.go deleted file mode 100644 index e29319b59..000000000 --- a/client/context.go +++ /dev/null @@ -1,18 +0,0 @@ -package client - -import ( - "github.com/cosmos/cosmos-sdk/client" // import the original package -) - -// EVMContext embeds the original Context and adds your own field -type EVMContext struct { - client.Context // Embedding the original Context - EVMChainID uint64 `json:"evm_chain_id"` -} - -func (ctx EVMContext) WithEVMChainID(evmChainID uint64) EVMContext { - return EVMContext{ - Context: ctx.Context, - EVMChainID: evmChainID, - } -} diff --git a/client/keys.go b/client/keys.go deleted file mode 100644 index 288507a6c..000000000 --- a/client/keys.go +++ /dev/null @@ -1,101 +0,0 @@ -package client - -import ( - "bufio" - - "github.com/spf13/cobra" - - "github.com/cometbft/cometbft/libs/cli" - - clientkeys "github.com/cosmos/evm/client/keys" - "github.com/cosmos/evm/crypto/hd" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/crypto/keyring" -) - -// KeyCommands registers a subtree of commands to interact with -// local private key storage. -// -// The defaultToEthKeys boolean indicates whether to use -// Ethereum compatible keys by default or stick with the Cosmos SDK default. -func KeyCommands(defaultNodeHome string, defaultToEthKeys bool) *cobra.Command { - cmd := &cobra.Command{ - Use: "keys", - Short: "Manage your application's keys", - Long: `Keyring management commands. These keys may be in any format supported by the -CometBFT crypto library and can be used by light-clients, full nodes, or any other application -that needs to sign with a private key. - -The keyring supports the following backends: - - os Uses the operating system's default credentials store. - file Uses encrypted file-based keystore within the app's configuration directory. - This keyring will request a password each time it is accessed, which may occur - multiple times in a single command resulting in repeated password prompts. - kwallet Uses KDE Wallet Manager as a credentials management application. - pass Uses the pass command line utility to store and retrieve keys. - test Stores keys insecurely to disk. It does not prompt for a password to be unlocked - and it should be use only for testing purposes. - -kwallet and pass backends depend on external tools. Refer to their respective documentation for more -information: - KWallet https://github.com/KDE/kwallet - pass https://www.passwordstore.org/ - -The pass backend requires GnuPG: https://gnupg.org/ -`, - } - - // support adding Ethereum supported keys - addCmd := keys.AddKeyCommand() - - if defaultToEthKeys { - ethSecp256k1Str := string(hd.EthSecp256k1Type) - - // update the default signing algorithm value to "eth_secp256k1" - algoFlag := addCmd.Flag(flags.FlagKeyType) - algoFlag.DefValue = ethSecp256k1Str - err := algoFlag.Value.Set(ethSecp256k1Str) - if err != nil { - panic(err) - } - } - - addCmd.RunE = runAddCmd - - cmd.AddCommand( - keys.MnemonicKeyCommand(), - addCmd, - keys.ExportKeyCommand(), - keys.ImportKeyCommand(), - keys.ListKeysCmd(), - keys.ListKeyTypesCmd(), - keys.ShowKeysCmd(), - keys.DeleteKeyCommand(), - keys.RenameKeyCommand(), - keys.ParseKeyStringCommand(), - keys.MigrateCommand(), - flags.LineBreak, - UnsafeExportEthKeyCommand(), - UnsafeImportKeyCommand(), - ) - - cmd.PersistentFlags().String(flags.FlagHome, defaultNodeHome, "The application home directory") - cmd.PersistentFlags().String(flags.FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used") - cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendOS, "Select keyring's backend (os|file|test)") - cmd.PersistentFlags().String(cli.OutputFlag, "text", "Output format (text|json)") - return cmd -} - -func runAddCmd(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd).WithKeyringOptions(hd.EthSecp256k1Option()) - clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) - if err != nil { - return err - } - buf := bufio.NewReader(clientCtx.Input) - return clientkeys.RunAddCmd(clientCtx, cmd, args, buf) -} diff --git a/client/keys/add.go b/client/keys/add.go index 23ebf13f7..39e516222 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -10,6 +10,9 @@ import ( "github.com/spf13/cobra" + "github.com/cometbft/cometbft/libs/cli" + + "github.com/cosmos/cosmos-sdk/crypto/hd" cryptohd "github.com/cosmos/evm/crypto/hd" bip39 "github.com/cosmos/go-bip39" @@ -17,7 +20,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -39,6 +41,90 @@ const ( mnemonicEntropySize = 256 ) +// KeyCommands registers a subtree of commands to interact with +// local private key storage. +// +// The defaultToEthKeys boolean indicates whether to use +// Ethereum compatible keys by default or stick with the Cosmos SDK default. +func KeyCommands(defaultNodeHome string, defaultToEthKeys bool) *cobra.Command { + cmd := &cobra.Command{ + Use: "keys", + Short: "Manage your application's keys", + Long: `Keyring management commands. These keys may be in any format supported by the +CometBFT crypto library and can be used by light-clients, full nodes, or any other application +that needs to sign with a private key. + +The keyring supports the following backends: + + os Uses the operating system's default credentials store. + file Uses encrypted file-based keystore within the app's configuration directory. + This keyring will request a password each time it is accessed, which may occur + multiple times in a single command resulting in repeated password prompts. + kwallet Uses KDE Wallet Manager as a credentials management application. + pass Uses the pass command line utility to store and retrieve keys. + test Stores keys insecurely to disk. It does not prompt for a password to be unlocked + and it should be use only for testing purposes. + +kwallet and pass backends depend on external tools. Refer to their respective documentation for more +information: + KWallet https://github.com/KDE/kwallet + pass https://www.passwordstore.org/ + +The pass backend requires GnuPG: https://gnupg.org/ +`, + } + + // support adding Ethereum supported keys + addCmd := keys.AddKeyCommand() + + if defaultToEthKeys { + ethSecp256k1Str := string(cryptohd.EthSecp256k1Type) + + // update the default signing algorithm value to "eth_secp256k1" + algoFlag := addCmd.Flag(flags.FlagKeyType) + algoFlag.DefValue = ethSecp256k1Str + err := algoFlag.Value.Set(ethSecp256k1Str) + if err != nil { + panic(err) + } + } + + addCmd.RunE = runAddCmd + + cmd.AddCommand( + keys.MnemonicKeyCommand(), + addCmd, + keys.ExportKeyCommand(), + keys.ImportKeyCommand(), + keys.ListKeysCmd(), + keys.ListKeyTypesCmd(), + keys.ShowKeysCmd(), + keys.DeleteKeyCommand(), + keys.RenameKeyCommand(), + keys.ParseKeyStringCommand(), + keys.MigrateCommand(), + flags.LineBreak, + UnsafeExportEthKeyCommand(), + UnsafeImportKeyCommand(), + ) + + cmd.PersistentFlags().String(flags.FlagHome, defaultNodeHome, "The application home directory") + cmd.PersistentFlags().String(flags.FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used") + cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendOS, "Select keyring's backend (os|file|test)") + cmd.PersistentFlags().String(cli.OutputFlag, "text", "Output format (text|json)") + return cmd +} + +func runAddCmd(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd).WithKeyringOptions(cryptohd.EthSecp256k1Option()) + clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags()) + if err != nil { + return err + } + buf := bufio.NewReader(clientCtx.Input) + return RunAddCmd(clientCtx, cmd, args, buf) +} + /* RunAddCmd input diff --git a/client/export.go b/client/keys/export.go similarity index 99% rename from client/export.go rename to client/keys/export.go index 49c59b5e2..37f8c0942 100644 --- a/client/export.go +++ b/client/keys/export.go @@ -1,4 +1,4 @@ -package client +package keys import ( "bufio" diff --git a/client/import.go b/client/keys/import.go similarity index 98% rename from client/import.go rename to client/keys/import.go index b9a97e357..844ec12ae 100644 --- a/client/import.go +++ b/client/keys/import.go @@ -1,4 +1,4 @@ -package client +package keys import ( "bufio" diff --git a/evmd/app/creator.go b/evmd/app/creator.go index 35d2a941f..e901340a8 100644 --- a/evmd/app/creator.go +++ b/evmd/app/creator.go @@ -87,10 +87,11 @@ func (a AppCreator) newApp( baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), } - chainConfig, err := evmconfig.CreateChainConfig(appOpts) - if err != nil { - panic(err) - } + chainConfig := &evmconfig.DefaultChainConfig + // chainConfig, err := evmconfig.CreateChainConfig(appOpts) + // if err != nil { + // panic(err) + // } return NewExampleApp( logger, @@ -134,10 +135,11 @@ func (a AppCreator) appExport( loadLatest = true } - chainConfig, err := evmconfig.CreateChainConfig(appOpts) - if err != nil { - return servertypes.ExportedApp{}, err - } + chainConfig := &evmconfig.DefaultChainConfig + // chainConfig, err := evmconfig.CreateChainConfig(appOpts) + // if err != nil { + // return servertypes.ExportedApp{}, err + // } evmApp = NewExampleApp( logger, diff --git a/evmd/cmd/root.go b/evmd/cmd/root.go index 71605717d..8f3e25520 100644 --- a/evmd/cmd/root.go +++ b/evmd/cmd/root.go @@ -14,8 +14,7 @@ import ( cmtcli "github.com/cometbft/cometbft/libs/cli" dbm "github.com/cosmos/cosmos-db" - cosmosevmcmd "github.com/cosmos/evm/client" - "github.com/cosmos/evm/config" + clientkeys "github.com/cosmos/evm/client/keys" evmconfig "github.com/cosmos/evm/config" cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring" evmdapp "github.com/cosmos/evm/evmd/app" @@ -65,7 +64,7 @@ func NewRootCmd() *cobra.Command { nil, true, simtestutil.EmptyAppOptions{}, - config.ChainConfig{}, + evmconfig.DefaultChainConfig, ) encodingConfig := sdktestutil.TestEncodingConfig{ @@ -82,7 +81,7 @@ func NewRootCmd() *cobra.Command { WithInput(os.Stdin). WithAccountRetriever(authtypes.AccountRetriever{}). WithBroadcastMode(flags.FlagBroadcastMode). - WithHomeDir(config.MustGetDefaultNodeHome()). + WithHomeDir(evmconfig.MustGetDefaultNodeHome()). WithViper(""). // In simapp, we don't use any prefix for env variables. // Cosmos EVM specific setup WithKeyringOptions(cosmosevmkeyring.Option()). @@ -131,7 +130,7 @@ func NewRootCmd() *cobra.Command { return err } - customAppTemplate, customAppConfig := config.InitAppConfig(evmconfig.BaseDenom, evmconfig.DefaultEvmChainID) + customAppTemplate, customAppConfig := evmconfig.InitAppConfig(evmconfig.BaseDenom, evmconfig.DefaultEvmChainID) customTMConfig := initCometConfig() return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) @@ -182,7 +181,7 @@ func initRootCmd(rootCmd *cobra.Command, evmApp *evmdapp.EVMD) { cfg := sdk.GetConfig() cfg.Seal() - defaultNodeHome := config.MustGetDefaultNodeHome() + defaultNodeHome := evmconfig.MustGetDefaultNodeHome() sdkAppCreator := func(l log.Logger, d dbm.DB, w io.Writer, ao servertypes.AppOptions) servertypes.Application { return newApp(l, d, w, ao) } @@ -207,7 +206,7 @@ func initRootCmd(rootCmd *cobra.Command, evmApp *evmdapp.EVMD) { // add Cosmos EVM key commands rootCmd.AddCommand( - cosmosevmcmd.KeyCommands(defaultNodeHome, true), + clientkeys.KeyCommands(defaultNodeHome, true), ) // add keybase, auxiliary RPC, query, genesis, and tx child commands @@ -332,10 +331,11 @@ func newApp( baseapp.SetChainID(chainID), } - chainConfig, err := evmconfig.CreateChainConfig(appOpts) - if err != nil { - panic(err) - } + chainConfig := &evmconfig.DefaultChainConfig + // chainConfig, err := evmconfig.CreateChainConfig(appOpts) + // if err != nil { + // panic(err) + // } return evmdapp.NewExampleApp( logger, db, traceStore, true, @@ -381,10 +381,11 @@ func appExport( } // create the chain config - chainConfig, err := evmconfig.CreateChainConfig(appOpts) - if err != nil { - return servertypes.ExportedApp{}, err - } + chainConfig := &evmconfig.DefaultChainConfig + // chainConfig, err := evmconfig.CreateChainConfig(appOpts) + // if err != nil { + // return servertypes.ExportedApp{}, err + // } if height != -1 { exampleApp = evmdapp.NewExampleApp(logger, db, traceStore, false, appOpts, *chainConfig, baseapp.SetChainID(chainID)) diff --git a/go.mod b/go.mod index 2e66b7626..e3ea8d9b5 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.23.8 require ( cosmossdk.io/api v0.9.2 + cosmossdk.io/client/v2 v2.0.0-beta.7 cosmossdk.io/core v0.11.3 cosmossdk.io/errors v1.0.2 cosmossdk.io/log v1.6.1 diff --git a/go.sum b/go.sum index b3f7089a2..fb1913581 100644 --- a/go.sum +++ b/go.sum @@ -616,6 +616,8 @@ cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT cloud.google.com/go/workflows v1.10.0/go.mod h1:fZ8LmRmZQWacon9UCX1r/g/DfAXx5VcPALq2CxzdePw= cosmossdk.io/api v0.9.2 h1:9i9ptOBdmoIEVEVWLtYYHjxZonlF/aOVODLFaxpmNtg= cosmossdk.io/api v0.9.2/go.mod h1:CWt31nVohvoPMTlPv+mMNCtC0a7BqRdESjCsstHcTkU= +cosmossdk.io/client/v2 v2.0.0-beta.7 h1:O0PfZL5kC3Sp54wZASLNihQ612Gd6duMp11aM9wawNg= +cosmossdk.io/client/v2 v2.0.0-beta.7/go.mod h1:TzwwrzeK+AfSVSESVEIOYO/9xuCh1fPv0HgeocmfVnM= cosmossdk.io/collections v1.2.1 h1:mAlNMs5vJwkda4TA+k5q/43p24RVAQ/qyDrjANu3BXE= cosmossdk.io/collections v1.2.1/go.mod h1:PSsEJ/fqny0VPsHLFT6gXDj/2C1tBOTS9eByK0+PBFU= cosmossdk.io/core v0.11.3 h1:mei+MVDJOwIjIniaKelE3jPDqShCc/F4LkNNHh+4yfo= From 2673aaa42e6e7956c225f1d240fdc7234c6a6dea Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Wed, 17 Sep 2025 18:09:56 -0400 Subject: [PATCH 19/23] remove err logging without nil check --- server/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/start.go b/server/start.go index aa317693c..727afdbf6 100644 --- a/server/start.go +++ b/server/start.go @@ -271,7 +271,7 @@ func startStandAlone(svrCtx *server.Context, clientCtx client.Context, opts Star }() evmApp, ok := app.(Application) if !ok { - svrCtx.Logger.Error("failed to get server config", "error", err.Error()) + svrCtx.Logger.Error("failed to get server config") } evmApp.SetClientCtx(clientCtx) From 28b6677b201b920853c41fc445b439ca1b07a545 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Thu, 18 Sep 2025 11:06:51 -0400 Subject: [PATCH 20/23] add cmd extraction helper --- config/evmd_config.go | 4 +- config/server_app_options.go | 144 ++++++++++++++++++++++------------- evmd/app/app.go | 2 +- evmd/app/creator.go | 18 ++--- evmd/cmd/root.go | 40 +++++----- server/config/config.go | 2 +- server/config/toml.go | 11 +++ server/flags/flags.go | 3 + server/start.go | 4 + 9 files changed, 145 insertions(+), 83 deletions(-) diff --git a/config/evmd_config.go b/config/evmd_config.go index 2f9303699..641715e42 100644 --- a/config/evmd_config.go +++ b/config/evmd_config.go @@ -96,7 +96,7 @@ type EVMAppConfig struct { // InitAppConfig helps to override default appConfig template and configs. // return "", nil if no custom configuration is required for the application. -func InitAppConfig(denom string, evmChainID uint64) (string, interface{}) { +func InitAppConfig(denom string, evmChainID uint64) (string, *EVMAppConfig) { // Optionally allow the chain developer to overwrite the SDK's default // server config. srvCfg := serverconfig.DefaultConfig() @@ -124,7 +124,7 @@ func InitAppConfig(denom string, evmChainID uint64) (string, interface{}) { TLS: *cosmosevmserverconfig.DefaultTLSConfig(), } - return EVMAppTemplate, customAppConfig + return EVMAppTemplate, &customAppConfig } const EVMAppTemplate = serverconfig.DefaultConfigTemplate + cosmosevmserverconfig.DefaultEVMConfigTemplate diff --git a/config/server_app_options.go b/config/server_app_options.go index 99be07abf..cf583eb6c 100644 --- a/config/server_app_options.go +++ b/config/server_app_options.go @@ -2,12 +2,15 @@ package config import ( "errors" + "fmt" "math" "path/filepath" "github.com/holiman/uint256" "github.com/spf13/cast" + "github.com/spf13/cobra" + "github.com/cosmos/evm/config/eips" srvflags "github.com/cosmos/evm/server/flags" "cosmossdk.io/log" @@ -19,6 +22,7 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + evmtypes "github.com/cosmos/evm/x/vm/types" ) // GetBlockGasLimit reads the genesis json file using AppGenesisFromFile @@ -126,55 +130,91 @@ func GetEvmChainID(appOpts servertypes.AppOptions) (uint64, error) { return evmChainID, nil } -// func GetEvmCoinInfo(appOpts servertypes.AppOptions) (*evmtypes.EvmCoinInfo, error) { -// displayDenom := cast.ToString(appOpts.Get(srvflags.EVMDisplayDenom)) -// if displayDenom == "" { -// return nil, errors.New("display denom flag not found in app options") -// } -// decimals := cast.ToUint8(appOpts.Get(srvflags.EVMDecimals)) -// if decimals == 0 { -// return nil, errors.New("decimals flag not found in app options") -// } -// extendedDecimals := cast.ToUint8(appOpts.Get(srvflags.EVMExtendedDecimals)) -// if extendedDecimals == 0 { -// return nil, errors.New("extended decimals flag not found in app options") -// } - -// evmCoinInfo := evmtypes.EvmCoinInfo{ -// DisplayDenom: displayDenom, -// Decimals: evmtypes.Decimals(decimals), -// ExtendedDecimals: evmtypes.Decimals(extendedDecimals), -// } -// if err := evmCoinInfo.Validate(); err != nil { -// return nil, err -// } - -// return &evmCoinInfo, nil -// } - -// func CreateChainConfig(appOpts servertypes.AppOptions) (*ChainConfig, error) { -// chainID, err := GetChainID(appOpts) -// if err != nil { -// return nil, err -// } -// evmChainID, err := GetEvmChainID(appOpts) -// if err != nil { -// return nil, err -// } -// evmCoinInfo, err := GetEvmCoinInfo(appOpts) -// if err != nil { -// return nil, err -// } - -// chainConfig := NewChainConfig( -// chainID, -// evmChainID, -// eips.CosmosEVMActivators, -// nil, -// nil, -// *evmCoinInfo, -// false, -// ) - -// return &chainConfig, nil -// } +func GetEvmCoinInfo(appOpts servertypes.AppOptions) (*evmtypes.EvmCoinInfo, error) { + displayDenom := cast.ToString(appOpts.Get(srvflags.EVMDisplayDenom)) + if displayDenom == "" { + return nil, errors.New("display denom flag not found in app options") + } + decimals := cast.ToUint8(appOpts.Get(srvflags.EVMDecimals)) + if decimals == 0 { + return nil, errors.New("decimals flag not found in app options") + } + extendedDecimals := cast.ToUint8(appOpts.Get(srvflags.EVMExtendedDecimals)) + if extendedDecimals == 0 { + return nil, errors.New("extended decimals flag not found in app options") + } + + evmCoinInfo := evmtypes.EvmCoinInfo{ + DisplayDenom: displayDenom, + Decimals: evmtypes.Decimals(decimals), + ExtendedDecimals: evmtypes.Decimals(extendedDecimals), + } + if err := evmCoinInfo.Validate(); err != nil { + return nil, err + } + + return &evmCoinInfo, nil +} + +func CreateChainConfig(appOpts servertypes.AppOptions) (*ChainConfig, error) { + chainID, err := GetChainID(appOpts) + if err != nil { + return nil, err + } + evmChainID, err := GetEvmChainID(appOpts) + if err != nil { + return nil, err + } + evmCoinInfo, err := GetEvmCoinInfo(appOpts) + if err != nil { + return nil, err + } + + chainConfig := NewChainConfig( + chainID, + evmChainID, + eips.CosmosEVMActivators, + nil, + nil, + *evmCoinInfo, + false, + ) + + return &chainConfig, nil +} + +func CreateChainConfigFromCmd(chainID string, cmd *cobra.Command, reset bool) (*ChainConfig, error) { + evmChainID := cast.ToUint64(cmd.Flag(srvflags.EVMChainID).Value.String()) + displayDenom := cast.ToString(cmd.Flag(srvflags.EVMDisplayDenom).Value.String()) + decimals := cast.ToUint8(cmd.Flag(srvflags.EVMDecimals).Value.String()) + extendedDecimals := cast.ToUint8(cmd.Flag(srvflags.EVMExtendedDecimals).Value.String()) + + if chainID == "" || evmChainID == 0 || displayDenom == "" || decimals == 0 || extendedDecimals == 0 { + return nil, fmt.Errorf( + "cannot create chain config, missing one or more required config values: chain id: %s, evm chain id: %d, display denom: %s, decimals: %d, extended decimals: %d", + chainID, evmChainID, displayDenom, decimals, extendedDecimals, + ) + } + + evmCoinInfo := evmtypes.EvmCoinInfo{ + DisplayDenom: displayDenom, + Decimals: evmtypes.Decimals(decimals), + ExtendedDecimals: evmtypes.Decimals(extendedDecimals), + } + err := evmCoinInfo.Validate() + if err != nil { + return nil, fmt.Errorf("cannot create chain config, invalid evm coin info: %w", err) + } + + chainConfig := NewChainConfig( + chainID, + evmChainID, + eips.CosmosEVMActivators, + nil, + nil, + evmCoinInfo, + reset, + ) + + return &chainConfig, nil +} diff --git a/evmd/app/app.go b/evmd/app/app.go index 281abc770..78a926879 100644 --- a/evmd/app/app.go +++ b/evmd/app/app.go @@ -260,7 +260,7 @@ func NewExampleApp( bApp.SetInterfaceRegistry(interfaceRegistry) bApp.SetTxEncoder(txConfig.TxEncoder()) - // initialize the Cosmos EVM application configuration + // initialize the Cosmos EVM application configuration, if not already initialized if err := chainConfig.ApplyChainConfig(); err != nil { panic(err) } diff --git a/evmd/app/creator.go b/evmd/app/creator.go index e901340a8..35d2a941f 100644 --- a/evmd/app/creator.go +++ b/evmd/app/creator.go @@ -87,11 +87,10 @@ func (a AppCreator) newApp( baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))), } - chainConfig := &evmconfig.DefaultChainConfig - // chainConfig, err := evmconfig.CreateChainConfig(appOpts) - // if err != nil { - // panic(err) - // } + chainConfig, err := evmconfig.CreateChainConfig(appOpts) + if err != nil { + panic(err) + } return NewExampleApp( logger, @@ -135,11 +134,10 @@ func (a AppCreator) appExport( loadLatest = true } - chainConfig := &evmconfig.DefaultChainConfig - // chainConfig, err := evmconfig.CreateChainConfig(appOpts) - // if err != nil { - // return servertypes.ExportedApp{}, err - // } + chainConfig, err := evmconfig.CreateChainConfig(appOpts) + if err != nil { + return servertypes.ExportedApp{}, err + } evmApp = NewExampleApp( logger, diff --git a/evmd/cmd/root.go b/evmd/cmd/root.go index 8f3e25520..2dca40310 100644 --- a/evmd/cmd/root.go +++ b/evmd/cmd/root.go @@ -15,6 +15,7 @@ import ( dbm "github.com/cosmos/cosmos-db" clientkeys "github.com/cosmos/evm/client/keys" + "github.com/cosmos/evm/config" evmconfig "github.com/cosmos/evm/config" cosmosevmkeyring "github.com/cosmos/evm/crypto/keyring" evmdapp "github.com/cosmos/evm/evmd/app" @@ -64,7 +65,7 @@ func NewRootCmd() *cobra.Command { nil, true, simtestutil.EmptyAppOptions{}, - evmconfig.DefaultChainConfig, + config.ChainConfig{}, ) encodingConfig := sdktestutil.TestEncodingConfig{ @@ -133,7 +134,19 @@ func NewRootCmd() *cobra.Command { customAppTemplate, customAppConfig := evmconfig.InitAppConfig(evmconfig.BaseDenom, evmconfig.DefaultEvmChainID) customTMConfig := initCometConfig() - return sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) + if err := sdkserver.InterceptConfigsPreRunHandler(cmd, customAppTemplate, *customAppConfig, customTMConfig); err != nil { + return err + } + + chainConfig, err := config.CreateChainConfigFromCmd(initClientCtx.ChainID, cmd, false) + if err != nil { + return err + } + if err := chainConfig.ApplyChainConfig(); err != nil { + return err + } + + return nil }, } @@ -151,11 +164,6 @@ func NewRootCmd() *cobra.Command { panic(err) } - chainConfig := evmconfig.DefaultChainConfig - if err := chainConfig.ApplyChainConfig(); err != nil { - panic(err) - } - return rootCmd } @@ -331,11 +339,10 @@ func newApp( baseapp.SetChainID(chainID), } - chainConfig := &evmconfig.DefaultChainConfig - // chainConfig, err := evmconfig.CreateChainConfig(appOpts) - // if err != nil { - // panic(err) - // } + chainConfig, err := evmconfig.CreateChainConfig(appOpts) + if err != nil { + panic(err) + } return evmdapp.NewExampleApp( logger, db, traceStore, true, @@ -381,11 +388,10 @@ func appExport( } // create the chain config - chainConfig := &evmconfig.DefaultChainConfig - // chainConfig, err := evmconfig.CreateChainConfig(appOpts) - // if err != nil { - // return servertypes.ExportedApp{}, err - // } + chainConfig, err := evmconfig.CreateChainConfig(appOpts) + if err != nil { + return servertypes.ExportedApp{}, err + } if height != -1 { exampleApp = evmdapp.NewExampleApp(logger, db, traceStore, false, appOpts, *chainConfig, baseapp.SetChainID(chainID)) diff --git a/server/config/config.go b/server/config/config.go index 9450a39c1..2d9c70b8f 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -74,7 +74,7 @@ const ( // DefaultEvmCoinInfoDecimals is the default decimals for the base denomination DefaultEvmCoinInfoDecimals = evmtypes.EighteenDecimals - // DefaultEvmCoinInfoExtendedDecimals is the default decimals for the extended denomination + // DefaultEvmCoinInfoExtendedDecimals is the default decimals for the extended denomination, typically 18 decimals (atto-denom) DefaultEvmCoinInfoExtendedDecimals = evmtypes.EighteenDecimals // DefaultEVMMinTip is the default minimum priority fee for the mempool diff --git a/server/config/toml.go b/server/config/toml.go index 1e9d4689a..52ce9c29c 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -25,6 +25,17 @@ evm-chain-id = {{ .EVM.EVMChainID }} # MinTip defines the minimum priority fee for the mempool. min-tip = {{ .EVM.MinTip }} +[evm.coin-info] + +# DisplayDenom defines the display denomination shown to users +display-denom = "{{ .EVM.CoinInfo.DisplayDenom }}" + +# Decimals defines the precision/decimals for the base denomination (1-18) +decimals = {{ .EVM.CoinInfo.Decimals }} + +# ExtendedDecimals defines the precision/decimals for the extended denomination (typically 18 decimals for atto-denom) +extended-decimals = {{ .EVM.CoinInfo.ExtendedDecimals }} + ############################################################################### ### JSON RPC Configuration ### ############################################################################### diff --git a/server/flags/flags.go b/server/flags/flags.go index 3844fc7df..704d6d2e0 100644 --- a/server/flags/flags.go +++ b/server/flags/flags.go @@ -71,6 +71,9 @@ const ( EVMEnablePreimageRecording = "evm.cache-preimage" EVMChainID = "evm.evm-chain-id" EVMMinTip = "evm.min-tip" + EVMDisplayDenom = "evm.coin-info.display-denom" + EVMDecimals = "evm.coin-info.decimals" + EVMExtendedDecimals = "evm.coin-info.extended-decimals" ) // TLS flags diff --git a/server/start.go b/server/start.go index 727afdbf6..5aeba9fd8 100644 --- a/server/start.go +++ b/server/start.go @@ -223,6 +223,10 @@ which accepts a path for the resulting pprof file. cmd.Flags().Uint64(srvflags.EVMChainID, cosmosevmserverconfig.DefaultEVMChainID, "the EIP-155 compatible replay protection chain ID") cmd.Flags().Uint64(srvflags.EVMMinTip, cosmosevmserverconfig.DefaultEVMMinTip, "the minimum priority fee for the mempool") + cmd.PersistentFlags().String(srvflags.EVMDisplayDenom, cosmosevmserverconfig.DefaultEvmCoinInfoDisplayDenom, "the display denomination for the chain") + cmd.PersistentFlags().Uint8(srvflags.EVMDecimals, uint8(cosmosevmserverconfig.DefaultEvmCoinInfoDecimals), "the decimals for the base denomination") + cmd.PersistentFlags().Uint8(srvflags.EVMExtendedDecimals, uint8(cosmosevmserverconfig.DefaultEvmCoinInfoExtendedDecimals), "the decimals for the extended denomination") + cmd.Flags().String(srvflags.TLSCertPath, "", "the cert.pem file path for the server TLS configuration") cmd.Flags().String(srvflags.TLSKeyPath, "", "the key.pem file path for the server TLS configuration") From 54e765f04afedfa61a487c32b645db1ff04503ed Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Thu, 18 Sep 2025 12:28:17 -0400 Subject: [PATCH 21/23] fix local node vars --- local_node.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/local_node.sh b/local_node.sh index 0bca43205..b7089e585 100755 --- a/local_node.sh +++ b/local_node.sh @@ -15,7 +15,7 @@ CHAINDIR="$HOME/.evmd" BASEFEE=10000000 # Coin info -DISPLAY_DENOM="test" +DISPLAY_DENOM="atom" DECIMALS=18 EXTENDED_DECIMALS=18 @@ -173,7 +173,7 @@ write_mnemonics_yaml() { # ---------- Add funded account ---------- add_genesis_funds() { local keyname="$1" - evmd genesis add-genesis-account "$keyname" 1000000000000000000000atest --keyring-backend "$KEYRING" --home "$CHAINDIR" + evmd genesis add-genesis-account "$keyname" "1000000000000000000000$EXTENDED_DENOM" --keyring-backend "$KEYRING" --home "$CHAINDIR" } # Setup local node if overwrite is set to Yes, otherwise skip setup @@ -240,21 +240,21 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then echo "$VAL_MNEMONIC" | evmd init $MONIKER -o --chain-id "$CHAINID" --home "$CHAINDIR" --recover # ---------- Genesis customizations ---------- - jq '.app_state["staking"]["params"]["bond_denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state["gov"]["params"]["expedited_min_deposit"][0]["denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state["evm"]["params"]["evm_denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state["mint"]["params"]["mint_denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["staking"]["params"]["bond_denom"]="'$EXTENDED_DENOM'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="'$EXTENDED_DENOM'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="'$EXTENDED_DENOM'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["gov"]["params"]["expedited_min_deposit"][0]["denom"]="'$EXTENDED_DENOM'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["evm"]["params"]["evm_denom"]="'$EXTENDED_DENOM'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["mint"]["params"]["mint_denom"]="'$EXTENDED_DENOM'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state["bank"]["denom_metadata"]=[{"description":"The native staking token for evmd.","denom_units":[{"denom":"atest","exponent":0,"aliases":["attotest"]},{"denom":"test","exponent":18,"aliases":[]}],"base":"atest","display":"test","name":"Test Token","symbol":"TEST","uri":"","uri_hash":""}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["bank"]["denom_metadata"]=[{"description":"The native staking token for evmd.","denom_units":[{"denom":"'$EXTENDED_DENOM'","exponent":0,"aliases":["atto'$DISPLAY_DENOM'"]},{"denom":"'$DISPLAY_DENOM'","exponent":'$DECIMALS',"aliases":[]}],"base":"'$EXTENDED_DENOM'","display":"'$DISPLAY_DENOM'","name":"'$DISPLAY_DENOM'","symbol":"'$DISPLAY_DENOM'","uri":"","uri_hash":""}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" jq '.app_state["evm"]["params"]["active_static_precompiles"]=["0x0000000000000000000000000000000000000100","0x0000000000000000000000000000000000000400","0x0000000000000000000000000000000000000800","0x0000000000000000000000000000000000000801","0x0000000000000000000000000000000000000802","0x0000000000000000000000000000000000000803","0x0000000000000000000000000000000000000804","0x0000000000000000000000000000000000000805", "0x0000000000000000000000000000000000000806", "0x0000000000000000000000000000000000000807"]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state["evm"]["params"]["evm_denom"]="atest"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state["evm"]["params"]["evm_denom"]="'$EXTENDED_DENOM'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" jq '.app_state.erc20.native_precompiles=["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" - jq '.app_state.erc20.token_pairs=[{contract_owner:1,erc20_address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",denom:"atest",enabled:true}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" + jq '.app_state.erc20.token_pairs=[{contract_owner:1,erc20_address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",denom:"'$EXTENDED_DENOM'",enabled:true}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" jq '.consensus.params.block.max_gas="10000000"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS" @@ -297,7 +297,7 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then sed -i.bak 's/"expedited_voting_period": "86400s"/"expedited_voting_period": "15s"/g' "$GENESIS" # fund validator (devs already funded in the loop) - evmd genesis add-genesis-account "$VAL_KEY" 100000000000000000000000000atest --keyring-backend "$KEYRING" --home "$CHAINDIR" + evmd genesis add-genesis-account "$VAL_KEY" "100000000000000000000000000$EXTENDED_DENOM" --keyring-backend "$KEYRING" --home "$CHAINDIR" # --------- maybe generate additional users --------- # start with provided/default list @@ -349,7 +349,7 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then fi # --------- Finalize genesis --------- - evmd genesis gentx "$VAL_KEY" 1000000000000000000000atest --gas-prices ${BASEFEE}atest --keyring-backend "$KEYRING" --chain-id "$CHAINID" --home "$CHAINDIR" + evmd genesis gentx "$VAL_KEY" "1000000000000000000000$EXTENDED_DENOM" --gas-prices ${BASEFEE}$EXTENDED_DENOM --keyring-backend "$KEYRING" --chain-id "$CHAINID" --home "$CHAINDIR" evmd genesis collect-gentxs --home "$CHAINDIR" evmd genesis validate-genesis --home "$CHAINDIR" From acf25cdacb9ef10ee75689bd122af59c04ff22c9 Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Thu, 18 Sep 2025 12:28:53 -0400 Subject: [PATCH 22/23] remove duplicate toml --- client/client.toml | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 client/client.toml diff --git a/client/client.toml b/client/client.toml deleted file mode 100644 index d27222bda..000000000 --- a/client/client.toml +++ /dev/null @@ -1,32 +0,0 @@ -# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -############################################################################### -### Client Configuration ### -############################################################################### - -# The network chain ID -chain-id = "cosmos" - -# The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory) -keyring-backend = "os" - -# CLI output format (text|json) -output = "text" - -# : to CometBFT RPC interface for this chain -node = "tcp://localhost:26657" - -# Transaction broadcasting mode (sync|async) -broadcast-mode = "sync" - -[coin-info] - -# DisplayDenom defines the display denomination shown to users -display-denom = "atom" - -# Decimals defines the precision/decimals for the base denomination (1-18) -decimals = 18 - -# ExtendedDecimals defines the precision/decimals for the extended denomination (typically 18 decimals for atto-denom) -extended-decimals = 18 \ No newline at end of file From 5efe6f07acef90dcd5070dd58bf55cb6e87bcdaf Mon Sep 17 00:00:00 2001 From: Abdul Malek Date: Thu, 18 Sep 2025 12:29:56 -0400 Subject: [PATCH 23/23] remove cmd call --- evmd/cmd/root.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/evmd/cmd/root.go b/evmd/cmd/root.go index 2dca40310..daf3db362 100644 --- a/evmd/cmd/root.go +++ b/evmd/cmd/root.go @@ -138,14 +138,6 @@ func NewRootCmd() *cobra.Command { return err } - chainConfig, err := config.CreateChainConfigFromCmd(initClientCtx.ChainID, cmd, false) - if err != nil { - return err - } - if err := chainConfig.ApplyChainConfig(); err != nil { - return err - } - return nil }, } @@ -164,6 +156,11 @@ func NewRootCmd() *cobra.Command { panic(err) } + chainConfig := evmconfig.DefaultChainConfig + if err := chainConfig.ApplyChainConfig(); err != nil { + panic(err) + } + return rootCmd }