Skip to content

Commit

Permalink
sdk-v50 - wip fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteHerrmann committed Sep 19, 2024
1 parent f11afe0 commit 35656cb
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 30 deletions.
26 changes: 13 additions & 13 deletions ante/evm/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
}

ethContractCreationTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
Nonce: 0,
Amount: big.NewInt(10),
GasLimit: 100000,
Expand All @@ -52,7 +52,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
}

ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
To: &to,
Nonce: 0,
Amount: big.NewInt(10),
Expand Down Expand Up @@ -163,7 +163,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
nonce, err := suite.GetNetwork().App.AccountKeeper.GetSequence(ctx, suite.GetKeyring().GetAccAddr(0))
suite.Require().NoError(err)
ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
To: &to,
Nonce: nonce,
Amount: big.NewInt(10),
Expand All @@ -182,7 +182,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
nonce, err := suite.GetNetwork().App.AccountKeeper.GetSequence(ctx, suite.GetKeyring().GetAccAddr(0))
suite.Require().NoError(err)
ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
To: &to,
Nonce: nonce,
Amount: big.NewInt(10),
Expand All @@ -200,7 +200,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
nonce, err := suite.GetNetwork().App.AccountKeeper.GetSequence(ctx, suite.GetKeyring().GetAccAddr(0))
suite.Require().NoError(err)
ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
To: &to,
Nonce: nonce,
Amount: big.NewInt(10),
Expand All @@ -218,7 +218,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
nonce, err := suite.GetNetwork().App.AccountKeeper.GetSequence(ctx, suite.GetKeyring().GetAccAddr(0))
suite.Require().NoError(err)
ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
To: &to,
Nonce: nonce,
Amount: big.NewInt(10),
Expand All @@ -240,7 +240,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
nonce, err := suite.GetNetwork().App.AccountKeeper.GetSequence(ctx, suite.GetKeyring().GetAccAddr(0))
suite.Require().NoError(err)
ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
To: &to,
Nonce: nonce,
Amount: big.NewInt(10),
Expand Down Expand Up @@ -918,7 +918,7 @@ func (suite *AnteTestSuite) TestAnteHandlerWithDynamicTxFee() {
to := utiltx.GenerateAddress()

ethContractCreationTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
Nonce: 0,
Amount: big.NewInt(10),
GasLimit: 100000,
Expand All @@ -928,7 +928,7 @@ func (suite *AnteTestSuite) TestAnteHandlerWithDynamicTxFee() {
}

ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
Nonce: 0,
Amount: big.NewInt(10),
GasLimit: 100000,
Expand Down Expand Up @@ -1060,7 +1060,7 @@ func (suite *AnteTestSuite) TestAnteHandlerWithDynamicTxFee() {
suite.GetNetwork().App.AccountKeeper.SetAccount(ctx, acc)

ctx = ctx.WithIsCheckTx(tc.checkTx).WithIsReCheckTx(tc.reCheckTx)
err := suite.GetNetwork().App.EvmKeeper.SetBalance(ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000))
err := suite.GetNetwork().App.EVMKeeper.SetBalance(ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000))
suite.Require().NoError(err)

anteHandler := suite.GetAnteHandler()
Expand All @@ -1081,7 +1081,7 @@ func (suite *AnteTestSuite) TestAnteHandlerWithParams() {
to := utiltx.GenerateAddress()

ethContractCreationTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
Nonce: 0,
Amount: big.NewInt(10),
GasLimit: 100000,
Expand All @@ -1092,7 +1092,7 @@ func (suite *AnteTestSuite) TestAnteHandlerWithParams() {
}

ethTxParams := evmtypes.EvmTxArgs{
ChainID: suite.GetNetwork().App.EvmKeeper.ChainID(),
ChainID: suite.GetNetwork().App.EVMKeeper.ChainID(),
Nonce: 0,
Amount: big.NewInt(10),
GasLimit: 100000,
Expand Down Expand Up @@ -1185,7 +1185,7 @@ func (suite *AnteTestSuite) TestAnteHandlerWithParams() {
suite.GetNetwork().App.AccountKeeper.SetAccount(ctx, acc)

ctx = ctx.WithIsCheckTx(true)
err := suite.GetNetwork().App.EvmKeeper.SetBalance(ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000))
err := suite.GetNetwork().App.EVMKeeper.SetBalance(ctx, addr, big.NewInt((ethparams.InitialBaseFee+10)*100000))
suite.Require().NoError(err)

anteHandler := suite.GetAnteHandler()
Expand Down
7 changes: 3 additions & 4 deletions ante/evm/fee_market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (
"github.com/evmos/os/testutil"
utiltx "github.com/evmos/os/testutil/tx"
"github.com/evmos/os/types"
"github.com/evmos/os/utils"
evmtypes "github.com/evmos/os/x/evm/types"
)

func (suite *AnteTestSuite) TestGasWantedDecorator() {
suite.WithFeemarketEnabled(true)
suite.SetupTest()
ctx := suite.GetNetwork().GetContext()
dec := evm.NewGasWantedDecorator(suite.GetNetwork().App.EvmKeeper, suite.GetNetwork().App.FeeMarketKeeper)
dec := evm.NewGasWantedDecorator(suite.GetNetwork().App.EVMKeeper, suite.GetNetwork().App.FeeMarketKeeper)
from, fromPrivKey := utiltx.NewAddrKey()
to := utiltx.GenerateAddress()

Expand All @@ -40,7 +39,7 @@ func (suite *AnteTestSuite) TestGasWantedDecorator() {
ToAddress: "evmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn",
Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: denom}},
}
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), utils.BaseDenom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), testutil.ExampleAttoDenom, &testMsg)
return txBuilder.GetTx()
},
true,
Expand Down Expand Up @@ -115,7 +114,7 @@ func (suite *AnteTestSuite) TestGasWantedDecorator() {
ToAddress: "evmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn",
Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: denom}},
}
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), utils.BaseDenom, &testMsg)
txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), testutil.ExampleAttoDenom, &testMsg)
limit := types.BlockGasLimit(ctx)
txBuilder.SetGasLimit(limit + 5)
return txBuilder.GetTx()
Expand Down
4 changes: 4 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
)

const (
// ServerStartTime defines the time duration that the server need to stay running after startup
// for the startup be considered successful
ServerStartTime = 5 * time.Second

// DefaultAPIEnable is the default value for the parameter that defines if the cosmos REST API server is enabled
DefaultAPIEnable = false

Expand Down
4 changes: 2 additions & 2 deletions server/indexer_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func NewIndexTxCmd() *cobra.Command {
if blk == nil {
return fmt.Errorf("block not found %d", height)
}
resBlk, err := stateStore.LoadABCIResponses(height)
resBlk, err := stateStore.LoadFinalizeBlockResponse(height)
if err != nil {
return err
}
if err := idxer.IndexBlock(blk, resBlk.DeliverTxs); err != nil {
if err := idxer.IndexBlock(blk, resBlk.TxResults); err != nil {
return err
}
fmt.Println(height)
Expand Down
2 changes: 2 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ which accepts a path for the resulting pprof file.
}

serverCtx.Logger.Debug("received quit signal")
// TODO: why is this check here? Should not make sense since err is checked above
if err != nil {
serverCtx.Logger.Error(fmt.Sprintf("error on quit: %s", err.Error()))
}

return nil
},
}
Expand Down
40 changes: 40 additions & 0 deletions testutil/fund.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Tharsis Labs Ltd.(Evmos)
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE)

package testutil

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

// FundAccount is a utility function that funds an account by minting and
// sending the coins to the address.
func FundAccount(ctx sdk.Context, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, amounts sdk.Coins) error {
if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
return err
}

return bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, amounts)
}

// FundAccountWithBaseDenom is a utility function that uses the FundAccount function
// to fund an account with the default Evmos denomination.
func FundAccountWithBaseDenom(ctx sdk.Context, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, amount int64) error {
coins := sdk.NewCoins(
sdk.NewCoin(ExampleAttoDenom, math.NewInt(amount)),
)
return FundAccount(ctx, bankKeeper, addr, coins)
}

// FundModuleAccount is a utility function that funds a module account by
// minting and sending the coins to the address.
func FundModuleAccount(ctx sdk.Context, bankKeeper bankkeeper.Keeper, recipientMod string, amounts sdk.Coins) error {
if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
return err
}

return bankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, recipientMod, amounts)
}
21 changes: 13 additions & 8 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/evmos/os/crypto/hd"
"github.com/evmos/os/encoding"
exampleapp "github.com/evmos/os/example_chain"
chaincmd "github.com/evmos/os/example_chain/osd/cmd"
"github.com/evmos/os/server/config"
Expand Down Expand Up @@ -101,16 +100,22 @@ type Config struct {
// DefaultConfig returns a sane default configuration suitable for nearly all
// testing requirements.
func DefaultConfig() Config {
encCfg := encoding.MakeConfig(exampleapp.ModuleBasics)
chainID := fmt.Sprintf("evmos_%d-1", cmtrand.Int63n(9999999999999)+1)
dir, err := os.MkdirTemp("", "simapp")
if err != nil {
panic(fmt.Sprintf("failed creating temporary directory: %v", err))
}
defer os.RemoveAll(dir)
tempApp := exampleapp.NewExampleApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simutils.NewAppOptionsWithFlagHome(dir), baseapp.SetChainID(chainID))

return Config{
Codec: encCfg.Codec,
TxConfig: encCfg.TxConfig,
LegacyAmino: encCfg.Amino,
InterfaceRegistry: encCfg.InterfaceRegistry,
Codec: tempApp.AppCodec(),
TxConfig: tempApp.TxConfig(),
LegacyAmino: tempApp.LegacyAmino(),
InterfaceRegistry: tempApp.InterfaceRegistry(),
AccountRetriever: authtypes.AccountRetriever{},
AppConstructor: NewAppConstructor(chainID),
GenesisState: exampleapp.ModuleBasics.DefaultGenesis(encCfg.Codec),
GenesisState: tempApp.DefaultGenesis(),
TimeoutCommit: 3 * time.Second,
ChainID: chainID,
NumValidators: 4,
Expand All @@ -131,7 +136,7 @@ func DefaultConfig() Config {
func NewAppConstructor(chainID string) AppConstructor {
return func(val Validator) servertypes.Application {
return exampleapp.NewExampleApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
val.Ctx.Logger, dbm.NewMemDB(), nil, true,
simutils.NewAppOptionsWithFlagHome(val.Ctx.Config.RootDir),
baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
Expand Down
Loading

0 comments on commit 35656cb

Please sign in to comment.