Skip to content

Commit

Permalink
Merge tag 'v4.1.9-evm-devnet' into firehose/evm-devnet
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/upgrades.go
#	contracts/test/EVMPrecompileTester.js
#	x/evm/keeper/msg_server.go
  • Loading branch information
maoueh committed Apr 17, 2024
2 parents 3bed587 + 1d2961b commit 852c8dc
Show file tree
Hide file tree
Showing 81 changed files with 1,963 additions and 660 deletions.
4 changes: 2 additions & 2 deletions aclmapping/evm/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func (suite *KeeperTestSuite) buildSendMsgTo(to common.Address, amt *big.Int) *t
To: &to,
Value: amt,
Data: []byte(""),
ChainID: suite.App.EvmKeeper.ChainID(suite.Ctx),
ChainID: suite.App.EvmKeeper.ChainID(),
}
ethCfg := types.DefaultChainConfig().EthereumConfig(suite.App.EvmKeeper.ChainID(suite.Ctx))
ethCfg := types.DefaultChainConfig().EthereumConfig(suite.App.EvmKeeper.ChainID())
signer := ethtypes.MakeSigner(ethCfg, big.NewInt(suite.Ctx.BlockHeight()), uint64(suite.Ctx.BlockTime().Unix()))
tx := ethtypes.NewTx(&txData)
tx, err := ethtypes.SignTx(tx, signer, suite.sender)
Expand Down
1 change: 1 addition & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk
sdk.DefaultWrappedAnteDecorator(evmante.NewGasLimitDecorator(options.EVMKeeper)),
}
evmAnteHandler, evmAnteDepGenerator := sdk.ChainAnteDecorators(evmAnteDecorators...)
evmAnteHandler = evmante.NewAnteErrorHandler(evmAnteHandler, options.EVMKeeper).Handle

router := evmante.NewEVMRouterDecorator(anteHandler, evmAnteHandler, anteDepGenerator, evmAnteDepGenerator)

Expand Down
52 changes: 52 additions & 0 deletions app/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package app_test

import (
"context"
"crypto/sha256"
"encoding/hex"
"math/big"
"testing"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand All @@ -18,11 +21,18 @@ import (
"github.com/cosmos/cosmos-sdk/utils/tracing"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
app "github.com/sei-protocol/sei-chain/app"
"github.com/sei-protocol/sei-chain/app/apptesting"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
"go.opentelemetry.io/otel"
)

Expand Down Expand Up @@ -212,3 +222,45 @@ func (suite *AnteTestSuite) TestValidateDepedencies() {

suite.Require().Nil(err, "ValidateBasicDecorator ran on ReCheck")
}

func TestEvmAnteErrorHandler(t *testing.T) {
ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{})
privKey := testkeeper.MockPrivateKey()
testPrivHex := hex.EncodeToString(privKey.Bytes())
key, _ := crypto.HexToECDSA(testPrivHex)
txData := ethtypes.LegacyTx{
GasPrice: big.NewInt(1000000000000),
Gas: 200000,
To: nil,
Value: big.NewInt(0),
Data: []byte{},
Nonce: 1, // will cause ante error
}
chainID := testkeeper.EVMTestApp.EvmKeeper.ChainID()
chainCfg := evmtypes.DefaultChainConfig()
ethCfg := chainCfg.EthereumConfig(chainID)
blockNum := big.NewInt(ctx.BlockHeight())
signer := ethtypes.MakeSigner(ethCfg, blockNum, uint64(ctx.BlockTime().Unix()))
tx, err := ethtypes.SignTx(ethtypes.NewTx(&txData), signer, key)
require.Nil(t, err)
txwrapper, err := ethtx.NewLegacyTx(tx)
require.Nil(t, err)
req, err := types.NewMsgEVMTransaction(txwrapper)
require.Nil(t, err)
builder := testkeeper.EVMTestApp.GetTxConfig().NewTxBuilder()
builder.SetMsgs(req)
txToSend := builder.GetTx()
encodedTx, err := testkeeper.EVMTestApp.GetTxConfig().TxEncoder()(txToSend)
require.Nil(t, err)

addr, _ := testkeeper.PrivateKeyToAddresses(privKey)
testkeeper.EVMTestApp.BankKeeper.AddCoins(ctx, addr, sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(100000000000))), true)
res := testkeeper.EVMTestApp.DeliverTx(ctx, abci.RequestDeliverTx{Tx: encodedTx}, txToSend, sha256.Sum256(encodedTx))
require.NotEqual(t, 0, res.Code)
testkeeper.EVMTestApp.EvmKeeper.SetTxResults([]*abci.ExecTxResult{{
Code: res.Code,
}})
deferredInfo := testkeeper.EVMTestApp.EvmKeeper.GetEVMTxDeferredInfo(ctx)
require.Equal(t, 1, len(deferredInfo))
require.Contains(t, deferredInfo[0].Error, "nonce too high")
}
7 changes: 6 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import (
"github.com/sei-protocol/sei-chain/x/evm"
evmante "github.com/sei-protocol/sei-chain/x/evm/ante"
"github.com/sei-protocol/sei-chain/x/evm/blocktest"
evmconfig "github.com/sei-protocol/sei-chain/x/evm/config"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/querier"
"github.com/sei-protocol/sei-chain/x/evm/replay"
Expand Down Expand Up @@ -594,9 +595,13 @@ func New(
wasmOpts...,
)

evmConfig, err := evmconfig.ReadConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error reading EVM config due to %s", err))
}
app.EvmKeeper = *evmkeeper.NewKeeper(keys[evmtypes.StoreKey], memKeys[evmtypes.MemStoreKey],
app.GetSubspace(evmtypes.ModuleName), app.BankKeeper, &app.AccountKeeper, &app.StakingKeeper,
app.TransferKeeper, wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper))
app.TransferKeeper, wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper), &evmConfig)
app.evmRPCConfig, err = evmrpc.ReadConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error reading EVM config due to %s", err))
Expand Down
1 change: 1 addition & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var upgradesList = []string{
"v4.1.6-evm-devnet",
"v4.1.7-evm-devnet",
"v4.1.8-evm-devnet",
"v4.1.9-evm-devnet",
}

// if there is an override list, use that instead, for integration tests
Expand Down
3 changes: 3 additions & 0 deletions cmd/seid/cmd/blocktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper"
ethtests "github.com/ethereum/go-ethereum/tests"
"github.com/sei-protocol/sei-chain/app"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/tendermint/tendermint/libs/log"

//nolint:gosec,G108
Expand Down Expand Up @@ -57,6 +58,8 @@ func BlocktestCmd(defaultNodeHome string) *cobra.Command {
cache := store.NewCommitKVStoreCacheManager()
wasmGasRegisterConfig := wasmkeeper.DefaultGasRegisterConfig()
wasmGasRegisterConfig.GasMultiplier = 21_000_000
// turn on Cancun for block test
evmtypes.CancunTime = 0
a := app.New(
logger,
db,
Expand Down
7 changes: 7 additions & 0 deletions cmd/seid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/sei-protocol/sei-chain/evmrpc"
"github.com/sei-protocol/sei-chain/tools"
"github.com/sei-protocol/sei-chain/x/evm/blocktest"
evmconfig "github.com/sei-protocol/sei-chain/x/evm/config"
"github.com/sei-protocol/sei-chain/x/evm/querier"
"github.com/sei-protocol/sei-chain/x/evm/replay"
"github.com/spf13/cast"
Expand Down Expand Up @@ -381,6 +382,8 @@ func initAppConfig() (string, interface{}) {
ETHBlockTest blocktest.Config `mapstructure:"eth_block_test"`

EvmQuery querier.Config `mapstructure:"evm_query"`

EvmModule evmconfig.Config `mapstructure:"evm_module"`
}

// Optionally allow the chain developer to overwrite the SDK's default
Expand Down Expand Up @@ -424,6 +427,7 @@ func initAppConfig() (string, interface{}) {
ETHReplay: replay.DefaultConfig,
ETHBlockTest: blocktest.DefaultConfig,
EvmQuery: querier.DefaultConfig,
EvmModule: evmconfig.DefaultConfig,
}

customAppTemplate := serverconfig.DefaultConfigTemplate + `
Expand Down Expand Up @@ -503,6 +507,9 @@ eth_blocktest_test_data_path = "{{ .ETHBlockTest.TestDataPath }}"
[evm_query]
evm_query_gas_limit = {{ .EvmQuery.GasLimit }}
[evm_module]
evm_chain_id = {{ .EvmModule.ChainID }}
`

return customAppTemplate, customAppConfig
Expand Down
Loading

0 comments on commit 852c8dc

Please sign in to comment.