forked from cerc-io/laconicd-deprecated
fix!: london hardfork check logic in json-rpc apis (#1068)
This commit is contained in:
@@ -583,3 +583,20 @@ func (k *Keeper) traceTx(
|
||||
|
||||
return &result, txConfig.LogIndex + uint(len(res.Logs)), nil
|
||||
}
|
||||
|
||||
// BaseFee implements the Query/BaseFee gRPC method
|
||||
func (k Keeper) BaseFee(c context.Context, _ *types.QueryBaseFeeRequest) (*types.QueryBaseFeeResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
params := k.GetParams(ctx)
|
||||
ethCfg := params.ChainConfig.EthereumConfig(k.eip155ChainID)
|
||||
baseFee := k.GetBaseFee(ctx, ethCfg)
|
||||
|
||||
res := &types.QueryBaseFeeResponse{}
|
||||
if baseFee != nil {
|
||||
aux := sdk.NewIntFromBigInt(baseFee)
|
||||
res.BaseFee = &aux
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
ethparams "github.com/ethereum/go-ethereum/params"
|
||||
"github.com/tharsis/ethermint/x/evm/statedb"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -899,3 +900,76 @@ func (suite *KeeperTestSuite) TestNonceInQuery() {
|
||||
})
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryBaseFee() {
|
||||
var (
|
||||
aux sdk.Int
|
||||
expRes *types.QueryBaseFeeResponse
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
malleate func()
|
||||
expPass bool
|
||||
enableFeemarket bool
|
||||
enableLondonHF bool
|
||||
}{
|
||||
{
|
||||
"pass - default Base Fee",
|
||||
func() {
|
||||
initialBaseFee := sdk.NewInt(ethparams.InitialBaseFee)
|
||||
expRes = &types.QueryBaseFeeResponse{BaseFee: &initialBaseFee}
|
||||
},
|
||||
true, true, true,
|
||||
},
|
||||
{
|
||||
"pass - non-nil Base Fee",
|
||||
func() {
|
||||
baseFee := sdk.OneInt().BigInt()
|
||||
suite.app.FeeMarketKeeper.SetBaseFee(suite.ctx, baseFee)
|
||||
|
||||
aux = sdk.NewIntFromBigInt(baseFee)
|
||||
expRes = &types.QueryBaseFeeResponse{BaseFee: &aux}
|
||||
},
|
||||
true, true, true,
|
||||
},
|
||||
{
|
||||
"pass - nil Base Fee when london hardfork not activated",
|
||||
func() {
|
||||
baseFee := sdk.OneInt().BigInt()
|
||||
suite.app.FeeMarketKeeper.SetBaseFee(suite.ctx, baseFee)
|
||||
|
||||
expRes = &types.QueryBaseFeeResponse{}
|
||||
},
|
||||
true, true, false,
|
||||
},
|
||||
{
|
||||
"pass - zero Base Fee when feemarket not activated",
|
||||
func() {
|
||||
baseFee := sdk.ZeroInt()
|
||||
expRes = &types.QueryBaseFeeResponse{BaseFee: &baseFee}
|
||||
},
|
||||
true, false, true,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
suite.Run(tc.name, func() {
|
||||
suite.enableFeemarket = tc.enableFeemarket
|
||||
suite.enableLondonHF = tc.enableLondonHF
|
||||
suite.SetupTest()
|
||||
|
||||
tc.malleate()
|
||||
|
||||
res, err := suite.queryClient.BaseFee(suite.ctx.Context(), &types.QueryBaseFeeRequest{})
|
||||
if tc.expPass {
|
||||
suite.Require().NotNil(res)
|
||||
suite.Require().Equal(expRes, res, tc.name)
|
||||
suite.Require().NoError(err)
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
suite.enableFeemarket = false
|
||||
suite.enableLondonHF = true
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ func (k *Keeper) GetBalance(ctx sdk.Context, addr common.Address) *big.Int {
|
||||
// - `nil`: london hardfork not enabled.
|
||||
// - `0`: london hardfork enabled but feemarket is not enabled.
|
||||
// - `n`: both london hardfork and feemarket are enabled.
|
||||
func (k Keeper) BaseFee(ctx sdk.Context, ethCfg *params.ChainConfig) *big.Int {
|
||||
func (k Keeper) GetBaseFee(ctx sdk.Context, ethCfg *params.ChainConfig) *big.Int {
|
||||
if !types.IsLondon(ethCfg, ctx.BlockHeight()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ func (suite *KeeperTestSuite) TestBaseFee() {
|
||||
suite.app.EvmKeeper.BeginBlock(suite.ctx, abci.RequestBeginBlock{})
|
||||
params := suite.app.EvmKeeper.GetParams(suite.ctx)
|
||||
ethCfg := params.ChainConfig.EthereumConfig(suite.app.EvmKeeper.ChainID())
|
||||
baseFee := suite.app.EvmKeeper.BaseFee(suite.ctx, ethCfg)
|
||||
baseFee := suite.app.EvmKeeper.GetBaseFee(suite.ctx, ethCfg)
|
||||
suite.Require().Equal(tc.expectBaseFee, baseFee)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (k *Keeper) EVMConfig(ctx sdk.Context) (*types.EVMConfig, error) {
|
||||
return nil, sdkerrors.Wrap(err, "failed to obtain coinbase address")
|
||||
}
|
||||
|
||||
baseFee := k.BaseFee(ctx, ethCfg)
|
||||
baseFee := k.GetBaseFee(ctx, ethCfg)
|
||||
return &types.EVMConfig{
|
||||
Params: params,
|
||||
ChainConfig: ethCfg,
|
||||
|
||||
Reference in New Issue
Block a user