Skip to content

refactor: fully decouple evm from evmd #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
#!/usr/bin/make -f

PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
###############################################################################
### Module & Versioning ###
###############################################################################

VERSION ?= $(shell echo $(shell git describe --tags --always) | sed 's/^v//')
TMVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')

###############################################################################
### Directories & Binaries ###
###############################################################################

BINDIR ?= $(GOPATH)/bin
EXAMPLE_BINARY = evmd
BUILDDIR ?= $(CURDIR)/build
EXAMPLE_BINARY := evmd

###############################################################################
### Repo Info ###
###############################################################################

HTTPS_GIT := https://github.com/cosmos/evm.git
DOCKER := $(shell which docker)

export GO111MODULE = on

# Default target executed when no arguments are given to make.
default_target: all
###############################################################################
### Submodule Settings ###
###############################################################################

.PHONY: build default_target
# evmd is a separate module under ./evmd
EVMD_DIR := evmd
EVMD_MAIN_PKG := ./cmd/evmd

###############################################################################
### evmd Build & Install ###
### Build & Install evmd ###
###############################################################################

# process build tags
Expand Down Expand Up @@ -71,19 +87,29 @@ ifneq (,$(findstring nooptimization,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif

# Build into $(BUILDDIR)
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)

BUILD_TARGETS := build install

build: BUILD_ARGS=-o $(BUILDDIR)/
# Cross-compile for Linux AMD64
build-linux:
GOOS=linux GOARCH=amd64 $(MAKE) build

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
CGO_ENABLED="1" go $@ $(BUILD_FLAGS) $(BUILD_ARGS) ./...
# Install into $(BINDIR)
install: go.sum
@echo "🚚 Installing evmd to $(BINDIR) ..."
@cd $(EVMD_DIR) && CGO_ENABLED="1" \
go install $(BUILD_FLAGS) $(EVMD_MAIN_PKG)

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

# Default & all target
.PHONY: all build build-linux install
all: build

###############################################################################
### Tools & Dependencies ###
###############################################################################
Expand All @@ -101,6 +127,7 @@ vulncheck:
### Tests & Simulation ###
###############################################################################

PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation')
PACKAGES_UNIT := $(shell go list ./... | grep -v '/tests/e2e$$' | grep -v '/simulation')
PACKAGES_EVMD := $(shell cd evmd && go list ./... | grep -v '/simulation')
COVERPKG_EVM := $(shell go list ./... | grep -v '/tests/e2e$$' | grep -v '/simulation' | paste -sd, -)
Expand Down
7 changes: 3 additions & 4 deletions ante/evm/fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (

"github.com/cosmos/evm/ante/evm"
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
evmdconfig "github.com/cosmos/evm/cmd/evmd/config"
"github.com/cosmos/evm/encoding"
"github.com/cosmos/evm/evmd"
"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"
Expand Down Expand Up @@ -58,9 +57,9 @@ func TestSDKTxFeeChecker(t *testing.T) {
// with extension option
// without extension option
// london hardfork enableness
chainID := uint64(evmdconfig.EighteenDecimalsChainID)
chainID := uint64(config.EighteenDecimalsChainID)
encodingConfig := encoding.MakeConfig(chainID)
err := evmd.EvmAppOptions(chainID)
err := config.EvmAppOptions(chainID)
require.NoError(t, err)

evmDenom := evmtypes.GetEVMCoinDenom()
Expand Down
30 changes: 0 additions & 30 deletions cmd/evmd/config/opendb.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ante
package ante_test

import (
"fmt"
Expand All @@ -7,7 +7,8 @@ import (

"github.com/cosmos/evm/ante"
ethante "github.com/cosmos/evm/ante/evm"
chainante "github.com/cosmos/evm/evmd/ante"
evmdante "github.com/cosmos/evm/evmd/ante"
"github.com/cosmos/evm/evmd/tests/integration"
basefactory "github.com/cosmos/evm/testutil/integration/base/factory"
"github.com/cosmos/evm/testutil/integration/evm/factory"
"github.com/cosmos/evm/testutil/integration/evm/grpc"
Expand Down Expand Up @@ -81,7 +82,7 @@ func RunBenchmarkAnteHandler(b *testing.B, create network.CreateEvmApp, options
}

handlerOptions := suite.generateHandlerOptions()
ante := chainante.NewAnteHandler(handlerOptions)
ante := evmdante.NewAnteHandler(handlerOptions)
b.StartTimer()

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

func (s *benchmarkSuite) generateHandlerOptions() chainante.HandlerOptions {
func (s *benchmarkSuite) generateHandlerOptions() evmdante.HandlerOptions {
encCfg := s.network.GetEncodingConfig()
return chainante.HandlerOptions{
return evmdante.HandlerOptions{
Cdc: s.network.App.AppCodec(),
AccountKeeper: s.network.App.GetAccountKeeper(),
BankKeeper: s.network.App.GetBankKeeper(),
Expand All @@ -158,3 +159,8 @@ func (s *benchmarkSuite) generateHandlerOptions() chainante.HandlerOptions {
TxFeeChecker: ethante.NewDynamicFeeChecker(s.network.App.GetFeeMarketKeeper()),
}
}

func BenchmarkAnteHandler(b *testing.B) {
// Run the benchmark with a mock EVM app
RunBenchmarkAnteHandler(b, integration.CreateEvmd)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ante
package ante_test

import (
"testing"
Expand All @@ -7,7 +7,8 @@ import (

"github.com/cosmos/evm/ante"
ethante "github.com/cosmos/evm/ante/evm"
chainante "github.com/cosmos/evm/evmd/ante"
evmdante "github.com/cosmos/evm/evmd/ante"
"github.com/cosmos/evm/evmd/tests/integration"
"github.com/cosmos/evm/testutil/integration/evm/network"
"github.com/cosmos/evm/types"
)
Expand All @@ -17,25 +18,25 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
nw := network.NewUnitTestNetwork(create, options...)
cases := []struct {
name string
options chainante.HandlerOptions
options evmdante.HandlerOptions
expPass bool
}{
{
"fail - empty options",
chainante.HandlerOptions{},
evmdante.HandlerOptions{},
false,
},
{
"fail - empty account keeper",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nil,
},
false,
},
{
"fail - empty bank keeper",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nil,
Expand All @@ -44,7 +45,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
},
{
"fail - empty IBC keeper",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nw.App.GetBankKeeper(),
Expand All @@ -54,7 +55,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
},
{
"fail - empty fee market keeper",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nw.App.GetBankKeeper(),
Expand All @@ -65,7 +66,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
},
{
"fail - empty EVM keeper",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nw.App.GetBankKeeper(),
Expand All @@ -77,7 +78,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
},
{
"fail - empty signature gas consumer",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nw.App.GetBankKeeper(),
Expand All @@ -90,7 +91,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
},
{
"fail - empty signature mode handler",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nw.App.GetBankKeeper(),
Expand All @@ -104,7 +105,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
},
{
"fail - empty tx fee checker",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nw.App.GetBankKeeper(),
Expand All @@ -119,7 +120,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
},
{
"success - default app options",
chainante.HandlerOptions{
evmdante.HandlerOptions{
Cdc: nw.App.AppCodec(),
AccountKeeper: nw.App.GetAccountKeeper(),
BankKeeper: nw.App.GetBankKeeper(),
Expand All @@ -146,3 +147,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
}
}
}

func TestValidateHandlerOptions(t *testing.T) {
RunValidateHandlerOptionsTest(t, integration.CreateEvmd)
}
Loading
Loading