Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jan 9, 2025
1 parent ac1b2bb commit 8436859
Show file tree
Hide file tree
Showing 38 changed files with 454 additions and 570 deletions.
4 changes: 2 additions & 2 deletions app/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ func (suite AnteTestSuite) TestAnteHandlerWithDynamicTxFee() {
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

suite.ctx = suite.ctx.WithIsCheckTx(tc.checkTx).WithIsReCheckTx(tc.reCheckTx).WithConsensusParams(*app.DefaultConsensusParams)
suite.app.EvmKeeper.SetBalance(suite.ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000), evmtypes.DefaultEVMDenom)
suite.app.EvmKeeper.SetBalance(suite.ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000))
_, err := suite.anteHandler(suite.ctx, tc.txFn(), false)
if tc.expPass {
suite.Require().NoError(err)
Expand Down Expand Up @@ -1335,7 +1335,7 @@ func (suite AnteTestSuite) TestAnteHandlerWithParams() {
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)

suite.ctx = suite.ctx.WithIsCheckTx(true).WithConsensusParams(*app.DefaultConsensusParams)
suite.app.EvmKeeper.SetBalance(suite.ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000), evmtypes.DefaultEVMDenom)
suite.app.EvmKeeper.SetBalance(suite.ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000))
_, err := suite.anteHandler(suite.ctx, tc.txFn(), false)
if tc.expErr == nil {
suite.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
BaseFee: baseFee,
}

stateDB := statedb.New(ctx, ctd.evmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))
stateDB := statedb.New(ctx, ctd.evmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash())))
evm := ctd.evmKeeper.NewEVM(ctx, coreMsg, cfg, evmtypes.NewNoOpTracer(), stateDB)

valueU256, isOverflow := uint256.FromBig(coreMsg.Value)
Expand Down
23 changes: 9 additions & 14 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/holiman/uint256"

storetypes "cosmossdk.io/store/types"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/zeta-chain/ethermint/app/ante"
"github.com/zeta-chain/ethermint/server/config"
"github.com/zeta-chain/ethermint/tests"
ethermint "github.com/zeta-chain/ethermint/types"
"github.com/zeta-chain/ethermint/x/evm/statedb"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"

storetypes "cosmossdk.io/store/types"
ethtypes "github.com/ethereum/go-ethereum/core/types"
)

func (suite AnteTestSuite) TestNewEthAccountVerificationDecorator() {
Expand Down Expand Up @@ -173,7 +174,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
ethCfg := suite.app.EvmKeeper.GetParams(suite.ctx).
ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID())
baseFee := suite.app.EvmKeeper.GetBaseFee(suite.ctx, ethCfg)
suite.Require().Equal(int64(765625000), baseFee.Int64())
suite.Require().Equal(int64(1000000000), baseFee.Int64())

gasPrice := new(big.Int).Add(baseFee, evmtypes.DefaultPriorityReduction.BigInt())

Expand Down Expand Up @@ -252,7 +253,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
tx2,
0,
func() {
vmdb.AddBalance(addr, big.NewInt(1000000))
vmdb.AddBalance(addr, uint256.NewInt(1000000))
suite.ctx = suite.ctx.WithBlockGasMeter(storetypes.NewGasMeter(1))
},
false, true,
Expand All @@ -263,7 +264,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
tx2,
tx2GasLimit, // it's capped
func() {
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
suite.ctx = suite.ctx.WithBlockGasMeter(storetypes.NewGasMeter(10000000000000000000))
},
true, false,
Expand All @@ -274,7 +275,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
dynamicFeeTx,
tx2GasLimit, // it's capped
func() {
vmdb.AddBalance(addr, big.NewInt(1001000000000000))
vmdb.AddBalance(addr, uint256.NewInt(1001000000000000))
suite.ctx = suite.ctx.WithBlockGasMeter(storetypes.NewGasMeter(10000000000000000000))
},
true, false,
Expand All @@ -301,18 +302,12 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {

if tc.expPanic {
suite.Require().Panics(func() {
_, _ = ante.CheckEthGasConsume(
suite.ctx.WithIsCheckTx(true).WithGasMeter(storetypes.NewGasMeter(1)), tc.tx,
ethCfg, suite.app.EvmKeeper, baseFee, config.DefaultMaxTxGasWanted, evmtypes.DefaultEVMDenom,
)
_, _ = dec.AnteHandle(suite.ctx.WithIsCheckTx(true).WithGasMeter(storetypes.NewGasMeter(1)), tc.tx, false, NextFn)
})
return
}

ctx, err := ante.CheckEthGasConsume(
suite.ctx.WithIsCheckTx(true).WithGasMeter(storetypes.NewInfiniteGasMeter()), tc.tx,
ethCfg, suite.app.EvmKeeper, baseFee, config.DefaultMaxTxGasWanted, evmtypes.DefaultEVMDenom,
)
ctx, err := dec.AnteHandle(suite.ctx.WithIsCheckTx(true).WithGasMeter(storetypes.NewInfiniteGasMeter()), tc.tx, false, NextFn)
if tc.expPass {
suite.Require().NoError(err)
suite.Require().Equal(tc.expPriority, ctx.Priority())
Expand Down
11 changes: 1 addition & 10 deletions app/ante/fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
ethermint "github.com/zeta-chain/ethermint/types"
"github.com/zeta-chain/ethermint/x/evm/types"
evmtypes "github.com/zeta-chain/ethermint/x/evm/types"
feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types"
)

var _ DynamicFeeEVMKeeper = MockEVMKeeper{}
Expand Down Expand Up @@ -208,15 +207,7 @@ func TestSDKTxFeeChecker(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
evmParams := tc.keeper.GetParams(tc.ctx)
feemarketParams := feemarkettypes.Params{
NoBaseFee: false,
BaseFee: sdkmath.NewIntFromBigInt(tc.keeper.BaseFee),
}
chainID := tc.keeper.ChainID()
chainCfg := evmParams.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(chainID)
fees, priority, err := NewDynamicFeeChecker(ethCfg, &evmParams, &feemarketParams)(tc.ctx, tc.buildTx())
fees, priority, err := NewDynamicFeeChecker(tc.keeper)(tc.ctx, tc.buildTx())
if tc.expSuccess {
require.Equal(t, tc.expFees, fees.String())
require.Equal(t, tc.expPriority, priority)
Expand Down
1 change: 1 addition & 0 deletions app/ante/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"math/big"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down
6 changes: 3 additions & 3 deletions app/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu

msgs := tx.GetMsgs()
if msgs == nil {
return errorsmod.Wrap(errortypes.ErrUnknownRequest, "invalid transaction. Transaction without messages")
return ctx, errorsmod.Wrap(errortypes.ErrUnknownRequest, "invalid transaction. Transaction without messages")
}

if t, ok := tx.(sdk.HasValidateBasic); ok {
err := t.ValidateBasic()
// ErrNoSignatures is fine with eth tx
if err != nil && !errors.Is(err, errortypes.ErrNoSignatures) {
return errorsmod.Wrap(err, "tx basic validation failed")
return ctx, errorsmod.Wrap(err, "tx basic validation failed")
}
}

Expand Down Expand Up @@ -202,7 +202,7 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
}

if !authInfo.Fee.Amount.Equal(txFee) {
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid AuthInfo Fee Amount (%s != %s)", authInfo.Fee.Amount, txFee)
return ctx, errorsmod.Wrapf(errortypes.ErrInvalidRequest, "invalid AuthInfo Fee Amount (%s != %s)", authInfo.Fee.Amount, txFee)
}

if authInfo.Fee.GasLimit != txGasLimit {
Expand Down
14 changes: 4 additions & 10 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package ante_test

import (
"context"
"encoding/json"
"fmt"
"math"
"math/big"
"time"
Expand All @@ -13,6 +15,7 @@ import (
"google.golang.org/protobuf/types/known/anypb"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
"github.com/cosmos/cosmos-sdk/codec"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/zeta-chain/ethermint/app"
Expand All @@ -35,6 +38,7 @@ import (
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
sdkante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -465,15 +469,6 @@ func StdSignBytes(cdc *codec.LegacyAmino, chainID string, accnum uint64, sequenc
msgsBytes = append(msgsBytes, json.RawMessage(legacyMsg.GetSignBytes()))
}

var stdTip *legacytx.StdTip
if tip != nil {
if tip.Tipper == "" {
panic(fmt.Errorf("tipper cannot be empty"))
}

stdTip = &legacytx.StdTip{Amount: tip.Amount, Tipper: tip.Tipper}
}

bz, err := cdc.MarshalJSON(legacytx.StdSignDoc{
AccountNumber: accnum,
ChainID: chainID,
Expand All @@ -482,7 +477,6 @@ func StdSignBytes(cdc *codec.LegacyAmino, chainID string, accnum uint64, sequenc
Msgs: msgsBytes,
Sequence: sequence,
TimeoutHeight: timeout,
Tip: stdTip,
})
if err != nil {
panic(err)
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server"

"github.com/cosmos/gogoproto/proto"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -525,6 +525,7 @@ func NewEthermintApp(
app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper,
tracer,
nil,
app.ConsensusParamsKeeper,
allKeys,
)

Expand Down
24 changes: 4 additions & 20 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ import (
"errors"
"io"
"os"
"path/filepath"

"github.com/spf13/cast"
"github.com/spf13/cobra"
"github.com/spf13/viper"

cmtlog "cosmossdk.io/log"
confixcmd "cosmossdk.io/tools/confix/cmd"
Expand All @@ -33,14 +30,13 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"

"cosmossdk.io/store"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
clientcfg "github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/pruning"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdkserver "github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -141,6 +137,7 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {

cfg := sdk.GetConfig()
cfg.Seal()
a := appCreator{encodingConfig}

rootCmd.AddCommand(
ethermintclient.ValidateChainID(
Expand All @@ -161,7 +158,6 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {
snapshot.Cmd(a.newApp),
)

a := appCreator{encodingConfig}
server.AddCommands(rootCmd, server.NewDefaultStartOptions(a.newApp, app.DefaultNodeHome), a.appExport, addModuleInitFlags)

// add keybase, auxiliary RPC, query, and tx child commands
Expand All @@ -182,7 +178,7 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {

autoCliOpts := tempApp.AutoCliOpts()
initClientCtx, _ = clientcfg.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring)

autoCliOpts.ClientCtx = initClientCtx
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
Expand Down Expand Up @@ -252,20 +248,8 @@ func (a appCreator) newApp(logger cmtlog.Logger, db dbm.DB, traceStore io.Writer
ethermintApp := app.NewEthermintApp(
logger, db, traceStore, true,
appOpts,
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(sdkserver.FlagMinGasPrices))),
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(sdkserver.FlagHaltHeight))),
baseapp.SetHaltTime(cast.ToUint64(appOpts.Get(sdkserver.FlagHaltTime))),
baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(sdkserver.FlagMinRetainBlocks))),
baseapp.SetInterBlockCache(cache),
baseapp.SetTrace(cast.ToBool(appOpts.Get(sdkserver.FlagTrace))),
baseapp.SetIndexEvents(cast.ToStringSlice(appOpts.Get(sdkserver.FlagIndexEvents))),
baseapp.SetSnapshot(snapshotStore, snapshotOptions),
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(sdkserver.FlagIAVLCacheSize))),
baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(sdkserver.FlagDisableIAVLFastNode))),
baseapp.SetChainID(chainID),
baseappOptions...,
)

return ethermintApp
}

Expand Down
7 changes: 0 additions & 7 deletions indexer/kv_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/zeta-chain/ethermint/app"
"github.com/zeta-chain/ethermint/crypto/ethsecp256k1"
evmenc "github.com/zeta-chain/ethermint/encoding"
"github.com/zeta-chain/ethermint/indexer"
"github.com/zeta-chain/ethermint/tests"
ethermint "github.com/zeta-chain/ethermint/types"
"github.com/zeta-chain/ethermint/x/evm/types"
)

Expand Down Expand Up @@ -182,8 +180,3 @@ func TestKVIndexer(t *testing.T) {
})
}
}

// MakeEncodingConfig creates the EncodingConfig
func MakeEncodingConfig() ethermint.EncodingConfig {
return evmenc.MakeConfig(app.ModuleBasics)
}
4 changes: 0 additions & 4 deletions rpc/backend/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ func (suite *BackendTestSuite) TestFeeHistory() {
},
sdk.AccAddress(tests.GenerateAddress().Bytes()),
true,
nil,
},
{
"pass - Concurrent FeeHistoryResults object",
Expand Down Expand Up @@ -460,9 +459,6 @@ func (suite *BackendTestSuite) TestFeeHistory() {
},
sdk.AccAddress(tests.GenerateAddress().Bytes()),
true,
[]*big.Int{
big.NewInt(0), // for overwrite overlap
},
},
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func RegisterBlockResultsWithEventLog(client *mocks.Client, height int64) (*tmrp
res := &tmrpctypes.ResultBlockResults{
Height: height,
TxsResults: []*abci.ExecTxResult{
{Code: 0, GasUsed: 0, Data: data},
{Code: 0, GasUsed: 0, Data: []byte("data")},
},
}
client.On("BlockResults", rpc.ContextWithHeight(height), mock.AnythingOfType("*int64")).
Expand Down
6 changes: 4 additions & 2 deletions rpc/backend/node_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import (
)

func (suite *BackendTestSuite) TestRPCMinGasPrice() {
defaultPrice := new(big.Int).SetInt64(ethermint.DefaultGasPrice)
bigPrice, _ := new(big.Int).SetString("18446744073709551616", 10)
testCases := []struct {
name string
registerMock func()
expMinGasPrice int64
expMinGasPrice *big.Int
expPass bool
}{
{
Expand All @@ -30,7 +32,7 @@ func (suite *BackendTestSuite) TestRPCMinGasPrice() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParamsWithoutHeaderError(queryClient, 1)
},
ethermint.DefaultGasPrice,
defaultPrice,
true,
},
{
Expand Down
9 changes: 1 addition & 8 deletions rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,8 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
} else {
status = hexutil.Uint(ethtypes.ReceiptStatusSuccessful)
}
chainID, err := b.ChainID()
if err != nil {
return nil, err
}

from, err := ethMsg.GetSender(chainID.ToInt())
if err != nil {
return nil, err
}
from := ethMsg.GetSender()

// parse tx logs from events
logs, err := TxLogsFromEvents(blockRes.TxsResults[res.TxIndex].Events, int(res.MsgIndex))
Expand Down
Loading

0 comments on commit 8436859

Please sign in to comment.