Skip to content

Commit fb7e407

Browse files
authored
refactor: fully decouple evm from evmd (#229)
* tests: add ics20 precompile tests and refactor test utils - Make gas limit configurable for testing lower gas limit scenario - Get ibctesting.AppCreator when create coordinator, so other applications can leverage this test suits. - Make GenerateContractCallArgs as separate function. This doens't have to be a member method of TxFactory implementation. un-necessary dependency. - SendEvmTx now supports contract creation. * fix ibc test suite and ics20 tx vulnerability Previous ibc test suite uses different bond denom ("stake) with EVM denom ("aatom"). Even though it could be different technically, but we need to make sure everything works correctly with default config (bond denom == evm denom). Wit this commit, we can make sure IBC and ICS20 transfers with default config should work well. Updated test util for writing test cases more easily. * add revert test case * fix lint * implement safeCopyInputs and add query test case Currently, Arguments.Copy in geth panics if there are type mismatch. Returning error instead makes more sense * refactor: decouple evm from evmd and relocate evmd-specific tests - Moved shared test/data files from evmd to evm to eliminate evm → evmd dependency - Relocated evmd-bound tests that directly depend on App implementation into evmd/ - Refactored remaining evmd-dependent tests to use EvmApp interface instead - Updated Makefile to reflect cmd relocation under evmd/ * fix ci and update test-helper's config path * resolve conflicts after merge upstream * nit: changed filename Variables in evmd_config.go are defined for serving evmd * chore: update importing package name * Refactor: relocate evmd-specific configurations and add test counterparts Moved evmd-specific app configurations under the evmd/ directory to improve modularity and maintain clearer separation between evmd and other components. Introduced corresponding configuration files under testutil/ to support test applications, since relocating the original files required new equivalents for testing purposes. * Refactor: relocate app specific ante handler * fix solidity test config path * chore: update import package name
1 parent 09e1895 commit fb7e407

Some content is hidden

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

69 files changed

+886
-494
lines changed

Makefile

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
#!/usr/bin/make -f
22

3-
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
3+
###############################################################################
4+
### Module & Versioning ###
5+
###############################################################################
6+
47
VERSION ?= $(shell echo $(shell git describe --tags --always) | sed 's/^v//')
58
TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
69
COMMIT := $(shell git log -1 --format='%H')
10+
11+
###############################################################################
12+
### Directories & Binaries ###
13+
###############################################################################
14+
715
BINDIR ?= $(GOPATH)/bin
8-
EXAMPLE_BINARY = evmd
916
BUILDDIR ?= $(CURDIR)/build
17+
EXAMPLE_BINARY := evmd
18+
19+
###############################################################################
20+
### Repo Info ###
21+
###############################################################################
22+
1023
HTTPS_GIT := https://github.com/cosmos/evm.git
1124
DOCKER := $(shell which docker)
1225

1326
export GO111MODULE = on
1427

15-
# Default target executed when no arguments are given to make.
16-
default_target: all
28+
###############################################################################
29+
### Submodule Settings ###
30+
###############################################################################
1731

18-
.PHONY: build default_target
32+
# evmd is a separate module under ./evmd
33+
EVMD_DIR := evmd
34+
EVMD_MAIN_PKG := ./cmd/evmd
1935

2036
###############################################################################
21-
### evmd Build & Install ###
37+
### Build & Install evmd ###
2238
###############################################################################
2339

2440
# process build tags
@@ -71,19 +87,29 @@ ifneq (,$(findstring nooptimization,$(COSMOS_BUILD_OPTIONS)))
7187
BUILD_FLAGS += -gcflags "all=-N -l"
7288
endif
7389

90+
# Build into $(BUILDDIR)
91+
build: go.sum $(BUILDDIR)/
92+
@echo "🏗️ Building evmd to $(BUILDDIR)/$(EXAMPLE_BINARY) ..."
93+
@cd $(EVMD_DIR) && CGO_ENABLED="1" \
94+
go build $(BUILD_FLAGS) -o $(BUILDDIR)/$(EXAMPLE_BINARY) $(EVMD_MAIN_PKG)
7495

75-
BUILD_TARGETS := build install
76-
77-
build: BUILD_ARGS=-o $(BUILDDIR)/
96+
# Cross-compile for Linux AMD64
7897
build-linux:
7998
GOOS=linux GOARCH=amd64 $(MAKE) build
8099

81-
$(BUILD_TARGETS): go.sum $(BUILDDIR)/
82-
CGO_ENABLED="1" go $@ $(BUILD_FLAGS) $(BUILD_ARGS) ./...
100+
# Install into $(BINDIR)
101+
install: go.sum
102+
@echo "🚚 Installing evmd to $(BINDIR) ..."
103+
@cd $(EVMD_DIR) && CGO_ENABLED="1" \
104+
go install $(BUILD_FLAGS) $(EVMD_MAIN_PKG)
83105

84106
$(BUILDDIR)/:
85107
mkdir -p $(BUILDDIR)/
86108

109+
# Default & all target
110+
.PHONY: all build build-linux install
111+
all: build
112+
87113
###############################################################################
88114
### Tools & Dependencies ###
89115
###############################################################################
@@ -101,6 +127,7 @@ vulncheck:
101127
### Tests & Simulation ###
102128
###############################################################################
103129

130+
PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
104131
PACKAGES_UNIT := $(shell go list ./... | grep -v '/tests/e2e$$' | grep -v '/simulation')
105132
PACKAGES_EVMD := $(shell cd evmd && go list ./... | grep -v '/simulation')
106133
COVERPKG_EVM := $(shell go list ./... | grep -v '/tests/e2e$$' | grep -v '/simulation' | paste -sd, -)

ante/evm/fee_checker_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import (
1010

1111
"github.com/cosmos/evm/ante/evm"
1212
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
13-
evmdconfig "github.com/cosmos/evm/cmd/evmd/config"
1413
"github.com/cosmos/evm/encoding"
15-
"github.com/cosmos/evm/evmd"
14+
"github.com/cosmos/evm/testutil/config"
1615
testconstants "github.com/cosmos/evm/testutil/constants"
1716
"github.com/cosmos/evm/types"
1817
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
@@ -58,9 +57,9 @@ func TestSDKTxFeeChecker(t *testing.T) {
5857
// with extension option
5958
// without extension option
6059
// london hardfork enableness
61-
chainID := uint64(evmdconfig.EighteenDecimalsChainID)
60+
chainID := uint64(config.EighteenDecimalsChainID)
6261
encodingConfig := encoding.MakeConfig(chainID)
63-
err := evmd.EvmAppOptions(chainID)
62+
err := config.EvmAppOptions(chainID)
6463
require.NoError(t, err)
6564

6665
evmDenom := evmtypes.GetEVMCoinDenom()

cmd/evmd/config/opendb.go

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

tests/integration/ante/benchmark_evm_antehandler.go renamed to evmd/ante/evm_antehandler_benchmark_test.go

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

33
import (
44
"fmt"
@@ -7,7 +7,8 @@ import (
77

88
"github.com/cosmos/evm/ante"
99
ethante "github.com/cosmos/evm/ante/evm"
10-
chainante "github.com/cosmos/evm/evmd/ante"
10+
evmdante "github.com/cosmos/evm/evmd/ante"
11+
"github.com/cosmos/evm/evmd/tests/integration"
1112
basefactory "github.com/cosmos/evm/testutil/integration/base/factory"
1213
"github.com/cosmos/evm/testutil/integration/evm/factory"
1314
"github.com/cosmos/evm/testutil/integration/evm/grpc"
@@ -81,7 +82,7 @@ func RunBenchmarkAnteHandler(b *testing.B, create network.CreateEvmApp, options
8182
}
8283

8384
handlerOptions := suite.generateHandlerOptions()
84-
ante := chainante.NewAnteHandler(handlerOptions)
85+
ante := evmdante.NewAnteHandler(handlerOptions)
8586
b.StartTimer()
8687

8788
b.Run(fmt.Sprintf("tx_type_%v", v.name), func(b *testing.B) {
@@ -141,9 +142,9 @@ func (s *benchmarkSuite) generateTxType(txType string) (sdktypes.Tx, error) {
141142
}
142143
}
143144

144-
func (s *benchmarkSuite) generateHandlerOptions() chainante.HandlerOptions {
145+
func (s *benchmarkSuite) generateHandlerOptions() evmdante.HandlerOptions {
145146
encCfg := s.network.GetEncodingConfig()
146-
return chainante.HandlerOptions{
147+
return evmdante.HandlerOptions{
147148
Cdc: s.network.App.AppCodec(),
148149
AccountKeeper: s.network.App.GetAccountKeeper(),
149150
BankKeeper: s.network.App.GetBankKeeper(),
@@ -158,3 +159,8 @@ func (s *benchmarkSuite) generateHandlerOptions() chainante.HandlerOptions {
158159
TxFeeChecker: ethante.NewDynamicFeeChecker(s.network.App.GetFeeMarketKeeper()),
159160
}
160161
}
162+
163+
func BenchmarkAnteHandler(b *testing.B) {
164+
// Run the benchmark with a mock EVM app
165+
RunBenchmarkAnteHandler(b, integration.CreateEvmd)
166+
}

tests/integration/ante/test_validate_handler_options.go renamed to evmd/ante/validate_handler_options_test.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ante
1+
package ante_test
22

33
import (
44
"testing"
@@ -7,7 +7,8 @@ import (
77

88
"github.com/cosmos/evm/ante"
99
ethante "github.com/cosmos/evm/ante/evm"
10-
chainante "github.com/cosmos/evm/evmd/ante"
10+
evmdante "github.com/cosmos/evm/evmd/ante"
11+
"github.com/cosmos/evm/evmd/tests/integration"
1112
"github.com/cosmos/evm/testutil/integration/evm/network"
1213
"github.com/cosmos/evm/types"
1314
)
@@ -17,25 +18,25 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
1718
nw := network.NewUnitTestNetwork(create, options...)
1819
cases := []struct {
1920
name string
20-
options chainante.HandlerOptions
21+
options evmdante.HandlerOptions
2122
expPass bool
2223
}{
2324
{
2425
"fail - empty options",
25-
chainante.HandlerOptions{},
26+
evmdante.HandlerOptions{},
2627
false,
2728
},
2829
{
2930
"fail - empty account keeper",
30-
chainante.HandlerOptions{
31+
evmdante.HandlerOptions{
3132
Cdc: nw.App.AppCodec(),
3233
AccountKeeper: nil,
3334
},
3435
false,
3536
},
3637
{
3738
"fail - empty bank keeper",
38-
chainante.HandlerOptions{
39+
evmdante.HandlerOptions{
3940
Cdc: nw.App.AppCodec(),
4041
AccountKeeper: nw.App.GetAccountKeeper(),
4142
BankKeeper: nil,
@@ -44,7 +45,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
4445
},
4546
{
4647
"fail - empty IBC keeper",
47-
chainante.HandlerOptions{
48+
evmdante.HandlerOptions{
4849
Cdc: nw.App.AppCodec(),
4950
AccountKeeper: nw.App.GetAccountKeeper(),
5051
BankKeeper: nw.App.GetBankKeeper(),
@@ -54,7 +55,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
5455
},
5556
{
5657
"fail - empty fee market keeper",
57-
chainante.HandlerOptions{
58+
evmdante.HandlerOptions{
5859
Cdc: nw.App.AppCodec(),
5960
AccountKeeper: nw.App.GetAccountKeeper(),
6061
BankKeeper: nw.App.GetBankKeeper(),
@@ -65,7 +66,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
6566
},
6667
{
6768
"fail - empty EVM keeper",
68-
chainante.HandlerOptions{
69+
evmdante.HandlerOptions{
6970
Cdc: nw.App.AppCodec(),
7071
AccountKeeper: nw.App.GetAccountKeeper(),
7172
BankKeeper: nw.App.GetBankKeeper(),
@@ -77,7 +78,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
7778
},
7879
{
7980
"fail - empty signature gas consumer",
80-
chainante.HandlerOptions{
81+
evmdante.HandlerOptions{
8182
Cdc: nw.App.AppCodec(),
8283
AccountKeeper: nw.App.GetAccountKeeper(),
8384
BankKeeper: nw.App.GetBankKeeper(),
@@ -90,7 +91,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
9091
},
9192
{
9293
"fail - empty signature mode handler",
93-
chainante.HandlerOptions{
94+
evmdante.HandlerOptions{
9495
Cdc: nw.App.AppCodec(),
9596
AccountKeeper: nw.App.GetAccountKeeper(),
9697
BankKeeper: nw.App.GetBankKeeper(),
@@ -104,7 +105,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
104105
},
105106
{
106107
"fail - empty tx fee checker",
107-
chainante.HandlerOptions{
108+
evmdante.HandlerOptions{
108109
Cdc: nw.App.AppCodec(),
109110
AccountKeeper: nw.App.GetAccountKeeper(),
110111
BankKeeper: nw.App.GetBankKeeper(),
@@ -119,7 +120,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
119120
},
120121
{
121122
"success - default app options",
122-
chainante.HandlerOptions{
123+
evmdante.HandlerOptions{
123124
Cdc: nw.App.AppCodec(),
124125
AccountKeeper: nw.App.GetAccountKeeper(),
125126
BankKeeper: nw.App.GetBankKeeper(),
@@ -146,3 +147,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
146147
}
147148
}
148149
}
150+
151+
func TestValidateHandlerOptions(t *testing.T) {
152+
RunValidateHandlerOptionsTest(t, integration.CreateEvmd)
153+
}

0 commit comments

Comments
 (0)