From 49fc5683b50661e68b8239a9e8b9560bfd337f06 Mon Sep 17 00:00:00 2001 From: Lucas Bertrand Date: Mon, 7 Aug 2023 18:55:38 +0200 Subject: [PATCH] refactor(`fungible`): define interface for EVM keeper reference (#900) * createinterface * use interface * use pointer reference * fix testkeeper * goimports --- app/app.go | 2 +- testutil/keeper/fungible.go | 2 +- x/fungible/keeper/keeper.go | 12 +++++------- x/fungible/types/expected_keepers.go | 24 +++++++++++++++++++++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/app.go b/app/app.go index 8b3b328371..6940a09798 100644 --- a/app/app.go +++ b/app/app.go @@ -389,7 +389,7 @@ func New( keys[fungibleModuleTypes.MemStoreKey], app.GetSubspace(fungibleModuleTypes.ModuleName), app.AccountKeeper, - *app.EvmKeeper, + app.EvmKeeper, app.BankKeeper, app.ZetaObserverKeeper, ) diff --git a/testutil/keeper/fungible.go b/testutil/keeper/fungible.go index fffac000a7..047c9c5eb3 100644 --- a/testutil/keeper/fungible.go +++ b/testutil/keeper/fungible.go @@ -43,7 +43,7 @@ func FungibleKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { bankkeeper := bankkeeper2.BaseKeeper{} authkeeper := authkeeper2.AccountKeeper{} - evmKeeper := evmkeeper.Keeper{} + evmKeeper := &evmkeeper.Keeper{} zetaObserverKeeper := zetaObserverModuleKeeper.Keeper{} keeper := keeper.NewKeeper( codec.NewProtoCodec(registry), diff --git a/x/fungible/keeper/keeper.go b/x/fungible/keeper/keeper.go index 4c1d53a90c..bb1b75664a 100644 --- a/x/fungible/keeper/keeper.go +++ b/x/fungible/keeper/keeper.go @@ -3,13 +3,12 @@ package keeper import ( "fmt" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/tendermint/tendermint/libs/log" - "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - evmkeeper "github.com/evmos/ethermint/x/evm/keeper" + "github.com/tendermint/tendermint/libs/log" + "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -20,7 +19,7 @@ type ( memKey storetypes.StoreKey paramstore paramtypes.Subspace authKeeper types.AccountKeeper - evmKeeper evmkeeper.Keeper + evmKeeper types.EVMKeeper bankKeeper types.BankKeeper zetaobserverKeeper types.ZetaObserverKeeper } @@ -32,7 +31,7 @@ func NewKeeper( memKey storetypes.StoreKey, ps paramtypes.Subspace, authKeeper types.AccountKeeper, - evmKeeper evmkeeper.Keeper, + evmKeeper types.EVMKeeper, bankKeeper types.BankKeeper, zetacobservKeeper types.ZetaObserverKeeper, ) *Keeper { @@ -42,7 +41,6 @@ func NewKeeper( } return &Keeper{ - cdc: cdc, storeKey: storeKey, memKey: memKey, diff --git a/x/fungible/types/expected_keepers.go b/x/fungible/types/expected_keepers.go index a8dbe958ac..a5bac6ea0a 100644 --- a/x/fungible/types/expected_keepers.go +++ b/x/fungible/types/expected_keepers.go @@ -1,9 +1,16 @@ package types import ( + "context" + "math/big" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/vm" + evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/zeta-chain/zetacore/common" zetaObserverTypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -11,7 +18,6 @@ import ( // AccountKeeper defines the expected account keeper used for simulations (noalias) type AccountKeeper interface { GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI - // Methods imported from account should be defined here GetSequence(ctx sdk.Context, addr sdk.AccAddress) (uint64, error) GetModuleAccount(ctx sdk.Context, name string) types.ModuleAccountI } @@ -39,3 +45,19 @@ type ZetaObserverKeeper interface { GetParams(ctx sdk.Context) (params zetaObserverTypes.Params) GetCoreParamsByChainID(ctx sdk.Context, chainID int64) (params *zetaObserverTypes.CoreParams, found bool) } + +type EVMKeeper interface { + ChainID() *big.Int + GetBlockBloomTransient(ctx sdk.Context) *big.Int + GetLogSizeTransient(ctx sdk.Context) uint64 + WithChainID(ctx sdk.Context) + SetBlockBloomTransient(ctx sdk.Context, bloom *big.Int) + SetLogSizeTransient(ctx sdk.Context, logSize uint64) + EstimateGas(c context.Context, req *evmtypes.EthCallRequest) (*evmtypes.EstimateGasResponse, error) + ApplyMessage( + ctx sdk.Context, + msg core.Message, + tracer vm.EVMLogger, + commit bool, + ) (*evmtypes.MsgEthereumTxResponse, error) +}