Skip to content

Commit

Permalink
fix feemarket evm test
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Nov 12, 2024
1 parent 11ece47 commit a91b46a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 46 deletions.
49 changes: 6 additions & 43 deletions x/feemarket/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper_test

import (
"context"
"encoding/json"
"math/big"
"strings"

Expand All @@ -14,7 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/tx"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
Expand All @@ -28,9 +26,7 @@ import (
utiltx "github.com/evmos/ethermint/testutil/tx"
"github.com/evmos/ethermint/x/feemarket/types"

"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
dbm "github.com/cosmos/cosmos-db"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)
Expand Down Expand Up @@ -458,7 +454,10 @@ func setupTestWithContext(valMinGasPrice string, minGasPrice sdkmath.LegacyDec,
}

func setupTest(localMinGasPrices string) (*ethsecp256k1.PrivKey, banktypes.MsgSend) {
setupChain(localMinGasPrices)
s.SetupApp(false,
baseapp.SetMinGasPrices(localMinGasPrices),
baseapp.SetChainID("ethermint_9000-1"),
)

privKey, address := generateKey()
amount, ok := sdkmath.NewIntFromString("10000000000000000000")
Expand All @@ -467,7 +466,8 @@ func setupTest(localMinGasPrices string) (*ethsecp256k1.PrivKey, banktypes.MsgSe
Denom: s.denom,
Amount: amount,
}}
testutil.FundAccount(s.app.BankKeeper, s.ctx, address, initBalance)
s.Require().NoError(testutil.FundAccount(s.app.BankKeeper, s.ctx, address, initBalance), "failed to fund account")


msg := banktypes.MsgSend{
FromAddress: address.String(),
Expand All @@ -481,43 +481,6 @@ func setupTest(localMinGasPrices string) (*ethsecp256k1.PrivKey, banktypes.MsgSe
return privKey, msg
}

func setupChain(localMinGasPricesStr string) {
// Initialize the app, so we can use SetMinGasPrices to set the
// validator-specific min-gas-prices setting
db := dbm.NewMemDB()
newapp := app.NewEthermintApp(
log.NewNopLogger(),
db,
nil,
true,
map[int64]bool{},
app.DefaultNodeHome,
simtestutil.EmptyAppOptions{},
baseapp.SetMinGasPrices(localMinGasPricesStr),
// NOTE: added as init examines the chain id
baseapp.SetChainID("ethermint_9000-1"),
)

genesisState := newapp.DefaultGenesis()
genesisState[types.ModuleName] = newapp.AppCodec().MustMarshalJSON(types.DefaultGenesisState())

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
s.Require().NoError(err)

// Initialize the chain
newapp.InitChain(
&abci.RequestInitChain{
ChainId: "ethermint_9000-1",
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
ConsensusParams: app.DefaultConsensusParams,
},
)

s.app = newapp
s.SetupApp(false)
}

func generateKey() (*ethsecp256k1.PrivKey, sdk.AccAddress) {
address, priv := utiltx.NewAddrKey()
return priv, sdk.AccAddress(address.Bytes())
Expand Down
8 changes: 5 additions & 3 deletions x/feemarket/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ func TestKeeperTestSuite(t *testing.T) {
// SetupTest setup test environment, it uses`require.TestingT` to support both `testing.T` and `testing.B`.
func (suite *KeeperTestSuite) SetupTest() {
checkTx := false
suite.app = app.Setup(checkTx, nil)
suite.SetupApp(checkTx)
}

func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
func (suite *KeeperTestSuite) SetupApp(checkTx bool,baseAppOptions ...func(*baseapp.BaseApp)) {
t := suite.T()
// account key
priv, err := ethsecp256k1.GenerateKey()
Expand All @@ -89,6 +88,7 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
priv, err = ethsecp256k1.GenerateKey()
require.NoError(t, err)
suite.consAddress = sdk.ConsAddress(priv.PubKey().Address())
suite.app = app.Setup(checkTx, nil, baseAppOptions...)

suite.ctx = suite.app.BaseApp.NewContextLegacy(checkTx, tmproto.Header{
Height: 1,
Expand Down Expand Up @@ -118,8 +118,10 @@ func (suite *KeeperTestSuite) SetupApp(checkTx bool) {
types.RegisterQueryServer(queryHelper, suite.app.FeeMarketKeeper)
suite.queryClient = types.NewQueryClient(queryHelper)

accountNumber, err := suite.app.AccountKeeper.AccountNumber.Next(suite.ctx)
require.NoError(t, err)
acc := &ethermint.EthAccount{
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, 0, 0),
BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(suite.address.Bytes()), nil, accountNumber, 0),
CodeHash: common.BytesToHash(crypto.Keccak256(nil)).String(),
}

Expand Down

0 comments on commit a91b46a

Please sign in to comment.