Sync from fork #74
@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|
||||||
|
* (ante) [\#1388](https://github.com/evmos/ethermint/pull/1388) Optimize AnteHandler gas consumption
|
||||||
* (lint) [#1298](https://github.com/evmos/ethermint/pull/1298) 150 character line length limit, `gofumpt`, and linting
|
* (lint) [#1298](https://github.com/evmos/ethermint/pull/1298) 150 character line length limit, `gofumpt`, and linting
|
||||||
* (feemarket) [\#1165](https://github.com/evmos/ethermint/pull/1165) Add hint in specs about different gas terminology in Cosmos and Ethereum.
|
* (feemarket) [\#1165](https://github.com/evmos/ethermint/pull/1165) Add hint in specs about different gas terminology in Cosmos and Ethereum.
|
||||||
* (cli) [#1226](https://github.com/evmos/ethermint/pull/1226) Add custom app db backend flag.
|
* (cli) [#1226](https://github.com/evmos/ethermint/pull/1226) Add custom app db backend flag.
|
||||||
|
@ -344,7 +344,7 @@ func (suite AnteTestSuite) TestAnteHandler() {
|
|||||||
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
|
coinAmount := sdk.NewCoin(evmtypes.DefaultEVMDenom, sdk.NewInt(20))
|
||||||
gasAmount := sdk.NewCoins(coinAmount)
|
gasAmount := sdk.NewCoins(coinAmount)
|
||||||
gas := uint64(200000)
|
gas := uint64(200000)
|
||||||
//reusing the gasAmount for deposit
|
// reusing the gasAmount for deposit
|
||||||
deposit := sdk.NewCoins(coinAmount)
|
deposit := sdk.NewCoins(coinAmount)
|
||||||
txBuilder := suite.CreateTestEIP712SubmitProposal(from, privKey, "ethermint_9000-1", gas, gasAmount, deposit)
|
txBuilder := suite.CreateTestEIP712SubmitProposal(from, privKey, "ethermint_9000-1", gas, gasAmount, deposit)
|
||||||
return txBuilder.GetTx()
|
return txBuilder.GetTx()
|
||||||
|
@ -40,10 +40,8 @@ func NewEthSigVerificationDecorator(ek EVMKeeper) EthSigVerificationDecorator {
|
|||||||
// won't see the error message.
|
// won't see the error message.
|
||||||
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
||||||
chainID := esvd.evmKeeper.ChainID()
|
chainID := esvd.evmKeeper.ChainID()
|
||||||
|
chainCfg := esvd.evmKeeper.GetChainConfig(ctx)
|
||||||
params := esvd.evmKeeper.GetParams(ctx)
|
ethCfg := chainCfg.EthereumConfig(chainID)
|
||||||
|
|
||||||
ethCfg := params.ChainConfig.EthereumConfig(chainID)
|
|
||||||
blockNum := big.NewInt(ctx.BlockHeight())
|
blockNum := big.NewInt(ctx.BlockHeight())
|
||||||
signer := ethtypes.MakeSigner(ethCfg, blockNum)
|
signer := ethtypes.MakeSigner(ethCfg, blockNum)
|
||||||
|
|
||||||
@ -53,8 +51,9 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
|
|||||||
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allowUnprotectedTxs := esvd.evmKeeper.GetAllowUnprotectedTxs(ctx)
|
||||||
ethTx := msgEthTx.AsTransaction()
|
ethTx := msgEthTx.AsTransaction()
|
||||||
if !params.AllowUnprotectedTxs && !ethTx.Protected() {
|
if !allowUnprotectedTxs && !ethTx.Protected() {
|
||||||
return ctx, sdkerrors.Wrapf(
|
return ctx, sdkerrors.Wrapf(
|
||||||
sdkerrors.ErrNotSupported,
|
sdkerrors.ErrNotSupported,
|
||||||
"rejected unprotected Ethereum txs. Please EIP155 sign your transaction to protect it against replay-attacks")
|
"rejected unprotected Ethereum txs. Please EIP155 sign your transaction to protect it against replay-attacks")
|
||||||
@ -176,15 +175,13 @@ func NewEthGasConsumeDecorator(
|
|||||||
// - transaction or block gas meter runs out of gas
|
// - transaction or block gas meter runs out of gas
|
||||||
// - sets the gas meter limit
|
// - sets the gas meter limit
|
||||||
func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
|
func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
|
||||||
params := egcd.evmKeeper.GetParams(ctx)
|
chainCfg := egcd.evmKeeper.GetChainConfig(ctx)
|
||||||
|
ethCfg := chainCfg.EthereumConfig(egcd.evmKeeper.ChainID())
|
||||||
ethCfg := params.ChainConfig.EthereumConfig(egcd.evmKeeper.ChainID())
|
|
||||||
|
|
||||||
blockHeight := big.NewInt(ctx.BlockHeight())
|
blockHeight := big.NewInt(ctx.BlockHeight())
|
||||||
homestead := ethCfg.IsHomestead(blockHeight)
|
homestead := ethCfg.IsHomestead(blockHeight)
|
||||||
istanbul := ethCfg.IsIstanbul(blockHeight)
|
istanbul := ethCfg.IsIstanbul(blockHeight)
|
||||||
london := ethCfg.IsLondon(blockHeight)
|
london := ethCfg.IsLondon(blockHeight)
|
||||||
evmDenom := params.EvmDenom
|
|
||||||
gasWanted := uint64(0)
|
gasWanted := uint64(0)
|
||||||
var events sdk.Events
|
var events sdk.Events
|
||||||
|
|
||||||
@ -213,6 +210,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
|
|||||||
gasWanted += txData.GetGas()
|
gasWanted += txData.GetGas()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
evmDenom := egcd.evmKeeper.GetEVMDenom(ctx)
|
||||||
fees, priority, err := egcd.evmKeeper.DeductTxCostsFromUserBalance(
|
fees, priority, err := egcd.evmKeeper.DeductTxCostsFromUserBalance(
|
||||||
ctx,
|
ctx,
|
||||||
*msgEthTx,
|
*msgEthTx,
|
||||||
@ -436,9 +434,9 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
|
|||||||
txFee := sdk.Coins{}
|
txFee := sdk.Coins{}
|
||||||
txGasLimit := uint64(0)
|
txGasLimit := uint64(0)
|
||||||
|
|
||||||
params := vbd.evmKeeper.GetParams(ctx)
|
chainCfg := vbd.evmKeeper.GetChainConfig(ctx)
|
||||||
chainID := vbd.evmKeeper.ChainID()
|
chainID := vbd.evmKeeper.ChainID()
|
||||||
ethCfg := params.ChainConfig.EthereumConfig(chainID)
|
ethCfg := chainCfg.EthereumConfig(chainID)
|
||||||
baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg)
|
baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg)
|
||||||
|
|
||||||
for _, msg := range protoTx.GetMsgs() {
|
for _, msg := range protoTx.GetMsgs() {
|
||||||
@ -460,9 +458,12 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return error if contract creation or call are disabled through governance
|
// return error if contract creation or call are disabled through governance
|
||||||
if !params.EnableCreate && txData.GetTo() == nil {
|
enableCreate := vbd.evmKeeper.GetEnableCreate(ctx)
|
||||||
|
enableCall := vbd.evmKeeper.GetEnableCall(ctx)
|
||||||
|
|
||||||
|
if !enableCreate && txData.GetTo() == nil {
|
||||||
return ctx, sdkerrors.Wrap(evmtypes.ErrCreateDisabled, "failed to create new contract")
|
return ctx, sdkerrors.Wrap(evmtypes.ErrCreateDisabled, "failed to create new contract")
|
||||||
} else if !params.EnableCall && txData.GetTo() != nil {
|
} else if !enableCall && txData.GetTo() != nil {
|
||||||
return ctx, sdkerrors.Wrap(evmtypes.ErrCallDisabled, "failed to call contract")
|
return ctx, sdkerrors.Wrap(evmtypes.ErrCallDisabled, "failed to call contract")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,7 +471,8 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
|
|||||||
return ctx, sdkerrors.Wrap(ethtypes.ErrTxTypeNotSupported, "dynamic fee tx not supported")
|
return ctx, sdkerrors.Wrap(ethtypes.ErrTxTypeNotSupported, "dynamic fee tx not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
txFee = txFee.Add(sdk.NewCoin(params.EvmDenom, sdkmath.NewIntFromBigInt(txData.Fee())))
|
evmDenom := vbd.evmKeeper.GetEVMDenom(ctx)
|
||||||
|
txFee = txFee.Add(sdk.NewCoin(evmDenom, sdkmath.NewIntFromBigInt(txData.Fee())))
|
||||||
}
|
}
|
||||||
|
|
||||||
authInfo := protoTx.AuthInfo
|
authInfo := protoTx.AuthInfo
|
||||||
@ -546,8 +548,8 @@ func NewEthMempoolFeeDecorator(ek EVMKeeper) EthMempoolFeeDecorator {
|
|||||||
// It only do the check if london hardfork not enabled or feemarket not enabled, because in that case feemarket will take over the task.
|
// It only do the check if london hardfork not enabled or feemarket not enabled, because in that case feemarket will take over the task.
|
||||||
func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
||||||
if ctx.IsCheckTx() && !simulate {
|
if ctx.IsCheckTx() && !simulate {
|
||||||
params := mfd.evmKeeper.GetParams(ctx)
|
chainCfg := mfd.evmKeeper.GetChainConfig(ctx)
|
||||||
ethCfg := params.ChainConfig.EthereumConfig(mfd.evmKeeper.ChainID())
|
ethCfg := chainCfg.EthereumConfig(mfd.evmKeeper.ChainID())
|
||||||
baseFee := mfd.evmKeeper.GetBaseFee(ctx, ethCfg)
|
baseFee := mfd.evmKeeper.GetBaseFee(ctx, ethCfg)
|
||||||
if baseFee == nil {
|
if baseFee == nil {
|
||||||
for _, msg := range tx.GetMsgs() {
|
for _, msg := range tx.GetMsgs() {
|
||||||
@ -556,7 +558,7 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
|
|||||||
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
evmDenom := params.EvmDenom
|
evmDenom := mfd.evmKeeper.GetEVMDenom(ctx)
|
||||||
feeAmt := ethMsg.GetFee()
|
feeAmt := ethMsg.GetFee()
|
||||||
glDec := sdk.NewDec(int64(ethMsg.GetGas()))
|
glDec := sdk.NewDec(int64(ethMsg.GetGas()))
|
||||||
requiredFee := ctx.MinGasPrices().AmountOf(evmDenom).Mul(glDec)
|
requiredFee := ctx.MinGasPrices().AmountOf(evmDenom).Mul(glDec)
|
||||||
|
@ -27,8 +27,8 @@ func NewGasWantedDecorator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
||||||
params := gwd.evmKeeper.GetParams(ctx)
|
chainCfg := gwd.evmKeeper.GetChainConfig(ctx)
|
||||||
ethCfg := params.ChainConfig.EthereumConfig(gwd.evmKeeper.ChainID())
|
ethCfg := chainCfg.EthereumConfig(gwd.evmKeeper.ChainID())
|
||||||
|
|
||||||
blockHeight := big.NewInt(ctx.BlockHeight())
|
blockHeight := big.NewInt(ctx.BlockHeight())
|
||||||
isLondon := ethCfg.IsLondon(blockHeight)
|
isLondon := ethCfg.IsLondon(blockHeight)
|
||||||
@ -39,10 +39,10 @@ func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
gasWanted := feeTx.GetGas()
|
gasWanted := feeTx.GetGas()
|
||||||
feeMktParams := gwd.feeMarketKeeper.GetParams(ctx)
|
isBaseFeeEnabled := gwd.feeMarketKeeper.GetBaseFeeEnabled(ctx)
|
||||||
|
|
||||||
// Add total gasWanted to cumulative in block transientStore in FeeMarket module
|
// Add total gasWanted to cumulative in block transientStore in FeeMarket module
|
||||||
if feeMktParams.IsBaseFeeEnabled(ctx.BlockHeight()) {
|
if isBaseFeeEnabled {
|
||||||
if _, err := gwd.feeMarketKeeper.AddTransientGasWanted(ctx, gasWanted); err != nil {
|
if _, err := gwd.feeMarketKeeper.AddTransientGasWanted(ctx, gasWanted); err != nil {
|
||||||
return ctx, sdkerrors.Wrapf(err, "failed to add gas wanted to transient store")
|
return ctx, sdkerrors.Wrapf(err, "failed to add gas wanted to transient store")
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,10 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
|
|||||||
return next(ctx, tx, simulate)
|
return next(ctx, tx, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
evmParams := mpd.evmKeeper.GetParams(ctx)
|
evmDenom := mpd.evmKeeper.GetEVMDenom(ctx)
|
||||||
minGasPrices := sdk.DecCoins{
|
minGasPrices := sdk.DecCoins{
|
||||||
{
|
{
|
||||||
Denom: evmParams.EvmDenom,
|
Denom: evmDenom,
|
||||||
Amount: minGasPrice,
|
Amount: minGasPrice,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -93,8 +93,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
|
|||||||
return next(ctx, tx, simulate)
|
return next(ctx, tx, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
paramsEvm := empd.evmKeeper.GetParams(ctx)
|
chainCfg := empd.evmKeeper.GetChainConfig(ctx)
|
||||||
ethCfg := paramsEvm.ChainConfig.EthereumConfig(empd.evmKeeper.ChainID())
|
ethCfg := chainCfg.EthereumConfig(empd.evmKeeper.ChainID())
|
||||||
baseFee := empd.evmKeeper.GetBaseFee(ctx, ethCfg)
|
baseFee := empd.evmKeeper.GetBaseFee(ctx, ethCfg)
|
||||||
|
|
||||||
for _, msg := range tx.GetMsgs() {
|
for _, msg := range tx.GetMsgs() {
|
||||||
|
@ -20,7 +20,7 @@ type HandlerOptions struct {
|
|||||||
AccountKeeper evmtypes.AccountKeeper
|
AccountKeeper evmtypes.AccountKeeper
|
||||||
BankKeeper evmtypes.BankKeeper
|
BankKeeper evmtypes.BankKeeper
|
||||||
IBCKeeper *ibckeeper.Keeper
|
IBCKeeper *ibckeeper.Keeper
|
||||||
FeeMarketKeeper evmtypes.FeeMarketKeeper
|
FeeMarketKeeper FeeMarketKeeper
|
||||||
EvmKeeper EVMKeeper
|
EvmKeeper EVMKeeper
|
||||||
FeegrantKeeper ante.FeegrantKeeper
|
FeegrantKeeper ante.FeegrantKeeper
|
||||||
SignModeHandler authsigning.SignModeHandler
|
SignModeHandler authsigning.SignModeHandler
|
||||||
@ -70,9 +70,9 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
|
|||||||
RejectMessagesDecorator{}, // reject MsgEthereumTxs
|
RejectMessagesDecorator{}, // reject MsgEthereumTxs
|
||||||
ante.NewSetUpContextDecorator(),
|
ante.NewSetUpContextDecorator(),
|
||||||
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
|
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
|
||||||
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
|
|
||||||
ante.NewValidateBasicDecorator(),
|
ante.NewValidateBasicDecorator(),
|
||||||
ante.NewTxTimeoutHeightDecorator(),
|
ante.NewTxTimeoutHeightDecorator(),
|
||||||
|
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
|
||||||
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
||||||
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
||||||
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
|
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
|
||||||
@ -93,9 +93,9 @@ func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
|
|||||||
ante.NewSetUpContextDecorator(),
|
ante.NewSetUpContextDecorator(),
|
||||||
// NOTE: extensions option decorator removed
|
// NOTE: extensions option decorator removed
|
||||||
// ante.NewRejectExtensionOptionsDecorator(),
|
// ante.NewRejectExtensionOptionsDecorator(),
|
||||||
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
|
|
||||||
ante.NewValidateBasicDecorator(),
|
ante.NewValidateBasicDecorator(),
|
||||||
ante.NewTxTimeoutHeightDecorator(),
|
ante.NewTxTimeoutHeightDecorator(),
|
||||||
|
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
|
||||||
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
||||||
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
||||||
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
|
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
|
||||||
|
@ -34,6 +34,11 @@ type EVMKeeper interface {
|
|||||||
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
|
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
|
||||||
ResetTransientGasUsed(ctx sdk.Context)
|
ResetTransientGasUsed(ctx sdk.Context)
|
||||||
GetTxIndexTransient(ctx sdk.Context) uint64
|
GetTxIndexTransient(ctx sdk.Context) uint64
|
||||||
|
GetChainConfig(ctx sdk.Context) evmtypes.ChainConfig
|
||||||
|
GetEVMDenom(ctx sdk.Context) string
|
||||||
|
GetEnableCreate(ctx sdk.Context) bool
|
||||||
|
GetEnableCall(ctx sdk.Context) bool
|
||||||
|
GetAllowUnprotectedTxs(ctx sdk.Context) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type protoTxProvider interface {
|
type protoTxProvider interface {
|
||||||
@ -44,4 +49,5 @@ type protoTxProvider interface {
|
|||||||
type FeeMarketKeeper interface {
|
type FeeMarketKeeper interface {
|
||||||
GetParams(ctx sdk.Context) (params feemarkettypes.Params)
|
GetParams(ctx sdk.Context) (params feemarkettypes.Params)
|
||||||
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
|
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
|
||||||
|
GetBaseFeeEnabled(ctx sdk.Context) bool
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Testing Constants
|
// Testing Constants
|
||||||
var chainId = "ethermint_9000-1"
|
var (
|
||||||
var ctx = client.Context{}.WithTxConfig(
|
chainId = "ethermint_9000-1"
|
||||||
encoding.MakeConfig(app.ModuleBasics).TxConfig,
|
ctx = client.Context{}.WithTxConfig(
|
||||||
|
encoding.MakeConfig(app.ModuleBasics).TxConfig,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
var feePayerAddress = "ethm17xpfvakm2amg962yls6f84z3kell8c5lthdzgl"
|
var feePayerAddress = "ethm17xpfvakm2amg962yls6f84z3kell8c5lthdzgl"
|
||||||
|
|
||||||
|
@ -3,13 +3,14 @@ package rpc
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -21,3 +21,38 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
|
|||||||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
||||||
k.paramSpace.SetParamSet(ctx, ¶ms)
|
k.paramSpace.SetParamSet(ctx, ¶ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetChainConfig returns the chain configuration parameter.
|
||||||
|
func (k Keeper) GetChainConfig(ctx sdk.Context) types.ChainConfig {
|
||||||
|
chainCfg := types.ChainConfig{}
|
||||||
|
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyChainConfig, &chainCfg)
|
||||||
|
return chainCfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetEVMDenom returns the EVM denom.
|
||||||
|
func (k Keeper) GetEVMDenom(ctx sdk.Context) string {
|
||||||
|
evmDenom := ""
|
||||||
|
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEVMDenom, &evmDenom)
|
||||||
|
return evmDenom
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetEnableCall returns true if the EVM Call operation is enabled.
|
||||||
|
func (k Keeper) GetEnableCall(ctx sdk.Context) bool {
|
||||||
|
enableCall := false
|
||||||
|
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableCall, &enableCall)
|
||||||
|
return enableCall
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetEnableCreate returns true if the EVM Create contract operation is enabled.
|
||||||
|
func (k Keeper) GetEnableCreate(ctx sdk.Context) bool {
|
||||||
|
enableCreate := false
|
||||||
|
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableCreate, &enableCreate)
|
||||||
|
return enableCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAllowUnprotectedTxs returns true if unprotected txs (i.e non-replay protected as per EIP-155) are supported by the chain.
|
||||||
|
func (k Keeper) GetAllowUnprotectedTxs(ctx sdk.Context) bool {
|
||||||
|
allowUnprotectedTx := false
|
||||||
|
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyAllowUnprotectedTxs, &allowUnprotectedTx)
|
||||||
|
return allowUnprotectedTx
|
||||||
|
}
|
||||||
|
@ -2,13 +2,94 @@ package keeper_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/evmos/ethermint/x/evm/types"
|
"github.com/evmos/ethermint/x/evm/types"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestParams() {
|
func (suite *KeeperTestSuite) TestParams() {
|
||||||
params := suite.app.EvmKeeper.GetParams(suite.ctx)
|
params := suite.app.EvmKeeper.GetParams(suite.ctx)
|
||||||
suite.Require().Equal(types.DefaultParams(), params)
|
|
||||||
params.EvmDenom = "inj"
|
|
||||||
suite.app.EvmKeeper.SetParams(suite.ctx, params)
|
suite.app.EvmKeeper.SetParams(suite.ctx, params)
|
||||||
newParams := suite.app.EvmKeeper.GetParams(suite.ctx)
|
testCases := []struct {
|
||||||
suite.Require().Equal(newParams, params)
|
name string
|
||||||
|
paramsFun func() interface{}
|
||||||
|
getFun func() interface{}
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"success - Checks if the default params are set correctly",
|
||||||
|
func() interface{} {
|
||||||
|
return types.DefaultParams()
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.EvmKeeper.GetParams(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - EvmDenom param is set to \"inj\" and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
params.EvmDenom = "inj"
|
||||||
|
suite.app.EvmKeeper.SetParams(suite.ctx, params)
|
||||||
|
return params.EvmDenom
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.EvmKeeper.GetEVMDenom(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - Check EnableCreate param is set to false and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
params.EnableCreate = false
|
||||||
|
suite.app.EvmKeeper.SetParams(suite.ctx, params)
|
||||||
|
return params.EnableCreate
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.EvmKeeper.GetEnableCreate(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - Check EnableCall param is set to false and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
params.EnableCall = false
|
||||||
|
suite.app.EvmKeeper.SetParams(suite.ctx, params)
|
||||||
|
return params.EnableCall
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.EvmKeeper.GetEnableCall(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - Check AllowUnprotectedTxs param is set to false and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
params.AllowUnprotectedTxs = false
|
||||||
|
suite.app.EvmKeeper.SetParams(suite.ctx, params)
|
||||||
|
return params.AllowUnprotectedTxs
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.EvmKeeper.GetAllowUnprotectedTxs(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - Check ChainConfig param is set to the default value and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
params.ChainConfig = types.DefaultChainConfig()
|
||||||
|
suite.app.EvmKeeper.SetParams(suite.ctx, params)
|
||||||
|
return params.ChainConfig
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.EvmKeeper.GetChainConfig(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range testCases {
|
||||||
|
suite.Run(tc.name, func() {
|
||||||
|
outcome := reflect.DeepEqual(tc.paramsFun(), tc.getFun())
|
||||||
|
suite.Require().Equal(tc.expected, outcome)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func (suite *TxDataTestSuite) TestAccessListTxGetGasFeeCap() {
|
|||||||
func (suite *TxDataTestSuite) TestEmptyAccessList() {
|
func (suite *TxDataTestSuite) TestEmptyAccessList() {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
tx AccessListTx
|
tx AccessListTx
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty access list tx",
|
"empty access list tx",
|
||||||
|
@ -627,7 +627,7 @@ func (suite *TxDataTestSuite) TestDynamicFeeTxEffectiveFee() {
|
|||||||
DynamicFeeTx{
|
DynamicFeeTx{
|
||||||
GasTipCap: &suite.sdkInt,
|
GasTipCap: &suite.sdkInt,
|
||||||
GasFeeCap: &suite.sdkInt,
|
GasFeeCap: &suite.sdkInt,
|
||||||
GasLimit: uint64(1),
|
GasLimit: uint64(1),
|
||||||
},
|
},
|
||||||
(&suite.sdkInt).BigInt(),
|
(&suite.sdkInt).BigInt(),
|
||||||
(&suite.sdkInt).BigInt(),
|
(&suite.sdkInt).BigInt(),
|
||||||
@ -653,8 +653,8 @@ func (suite *TxDataTestSuite) TestDynamicFeeTxEffectiveCost() {
|
|||||||
DynamicFeeTx{
|
DynamicFeeTx{
|
||||||
GasTipCap: &suite.sdkInt,
|
GasTipCap: &suite.sdkInt,
|
||||||
GasFeeCap: &suite.sdkInt,
|
GasFeeCap: &suite.sdkInt,
|
||||||
GasLimit: uint64(1),
|
GasLimit: uint64(1),
|
||||||
Amount: &suite.sdkZeroInt,
|
Amount: &suite.sdkZeroInt,
|
||||||
},
|
},
|
||||||
(&suite.sdkInt).BigInt(),
|
(&suite.sdkInt).BigInt(),
|
||||||
(&suite.sdkInt).BigInt(),
|
(&suite.sdkInt).BigInt(),
|
||||||
|
@ -116,9 +116,9 @@ func (suite *GenesisTestSuite) TestValidateGenesis() {
|
|||||||
expPass: false,
|
expPass: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "copied genesis",
|
name: "copied genesis",
|
||||||
genState: NewGenesisState(DefaultGenesisState().Params, DefaultGenesisState().Accounts),
|
genState: NewGenesisState(DefaultGenesisState().Params, DefaultGenesisState().Accounts),
|
||||||
expPass: true,
|
expPass: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid genesis",
|
name: "invalid genesis",
|
||||||
|
@ -198,4 +198,3 @@ func TestConversionFunctions(t *testing.T) {
|
|||||||
require.Nil(t, conversionErr)
|
require.Nil(t, conversionErr)
|
||||||
require.Nil(t, copyErr)
|
require.Nil(t, copyErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ import (
|
|||||||
|
|
||||||
func (suite *TxDataTestSuite) TestTxArgsString() {
|
func (suite *TxDataTestSuite) TestTxArgsString() {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
txArgs TransactionArgs
|
txArgs TransactionArgs
|
||||||
expectedString string
|
expectedString string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty tx args",
|
"empty tx args",
|
||||||
@ -32,13 +32,13 @@ func (suite *TxDataTestSuite) TestTxArgsString() {
|
|||||||
AccessList: ðtypes.AccessList{},
|
AccessList: ðtypes.AccessList{},
|
||||||
},
|
},
|
||||||
fmt.Sprintf("TransactionArgs{From:%v, To:%v, Gas:%v, Nonce:%v, Data:%v, Input:%v, AccessList:%v}",
|
fmt.Sprintf("TransactionArgs{From:%v, To:%v, Gas:%v, Nonce:%v, Data:%v, Input:%v, AccessList:%v}",
|
||||||
&suite.addr,
|
&suite.addr,
|
||||||
&suite.addr,
|
&suite.addr,
|
||||||
&suite.hexUint64,
|
&suite.hexUint64,
|
||||||
&suite.hexUint64,
|
&suite.hexUint64,
|
||||||
&suite.hexDataBytes,
|
&suite.hexDataBytes,
|
||||||
&suite.hexInputBytes,
|
&suite.hexInputBytes,
|
||||||
ðtypes.AccessList{}),
|
ðtypes.AccessList{}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
@ -49,8 +49,8 @@ func (suite *TxDataTestSuite) TestTxArgsString() {
|
|||||||
|
|
||||||
func (suite *TxDataTestSuite) TestConvertTxArgsEthTx() {
|
func (suite *TxDataTestSuite) TestConvertTxArgsEthTx() {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
txArgs TransactionArgs
|
txArgs TransactionArgs
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty tx args",
|
"empty tx args",
|
||||||
@ -227,9 +227,9 @@ func (suite *TxDataTestSuite) TestToMessageEVM() {
|
|||||||
|
|
||||||
func (suite *TxDataTestSuite) TestGetFrom() {
|
func (suite *TxDataTestSuite) TestGetFrom() {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
txArgs TransactionArgs
|
txArgs TransactionArgs
|
||||||
expAddress common.Address
|
expAddress common.Address
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty from field",
|
"empty from field",
|
||||||
|
@ -28,6 +28,15 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|||||||
// Required by EIP1559 base fee calculation.
|
// Required by EIP1559 base fee calculation.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// GetBaseFeeEnabled returns true if base fee is enabled
|
||||||
|
func (k Keeper) GetBaseFeeEnabled(ctx sdk.Context) bool {
|
||||||
|
noBaseFee := false
|
||||||
|
enableHeight := int64(0)
|
||||||
|
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyNoBaseFee, &noBaseFee)
|
||||||
|
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableHeight, &enableHeight)
|
||||||
|
return !noBaseFee && ctx.BlockHeight() >= enableHeight
|
||||||
|
}
|
||||||
|
|
||||||
// GetBaseFee get's the base fee from the paramSpace
|
// GetBaseFee get's the base fee from the paramSpace
|
||||||
// return nil if base fee is not enabled
|
// return nil if base fee is not enabled
|
||||||
func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
|
func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
|
||||||
|
@ -2,13 +2,69 @@ package keeper_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/evmos/ethermint/x/feemarket/types"
|
"github.com/evmos/ethermint/x/feemarket/types"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestSetGetParams() {
|
func (suite *KeeperTestSuite) TestSetGetParams() {
|
||||||
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||||
suite.Require().Equal(types.DefaultParams(), params)
|
|
||||||
params.ElasticityMultiplier = 3
|
|
||||||
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||||
newParams := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
testCases := []struct {
|
||||||
suite.Require().Equal(newParams, params)
|
name string
|
||||||
|
paramsFun func() interface{}
|
||||||
|
getFun func() interface{}
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"success - Checks if the default params are set correctly",
|
||||||
|
func() interface{} {
|
||||||
|
return types.DefaultParams()
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - Check ElasticityMultiplier is set to 3 and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
params.ElasticityMultiplier = 3
|
||||||
|
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||||
|
return params.ElasticityMultiplier
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.FeeMarketKeeper.GetParams(suite.ctx).ElasticityMultiplier
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - Check BaseFeeEnabled is computed with its default params and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
suite.app.FeeMarketKeeper.SetParams(suite.ctx, types.DefaultParams())
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.FeeMarketKeeper.GetBaseFeeEnabled(suite.ctx)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"success - Check BaseFeeEnabled is computed with alternate params and can be retrieved correctly",
|
||||||
|
func() interface{} {
|
||||||
|
params.NoBaseFee = true
|
||||||
|
params.EnableHeight = 5
|
||||||
|
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
func() interface{} {
|
||||||
|
return suite.app.FeeMarketKeeper.GetBaseFeeEnabled(suite.ctx)
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range testCases {
|
||||||
|
suite.Run(tc.name, func() {
|
||||||
|
outcome := reflect.DeepEqual(tc.paramsFun(), tc.getFun())
|
||||||
|
suite.Require().Equal(tc.expected, outcome)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user