2022-09-05 14:07:56 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/tendermint/tendermint/abci/types"
|
|
|
|
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
|
|
|
|
|
|
|
|
"github.com/evmos/ethermint/rpc/backend/mocks"
|
|
|
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
|
|
|
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *BackendTestSuite) TestBaseFee() {
|
|
|
|
baseFee := sdk.NewInt(1)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
blockRes *tmrpctypes.ResultBlockResults
|
|
|
|
registerMock func()
|
|
|
|
expBaseFee *big.Int
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"fail - grpc BaseFee error",
|
|
|
|
&tmrpctypes.ResultBlockResults{Height: 1},
|
|
|
|
func() {
|
2022-10-11 18:43:32 +00:00
|
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
|
2022-09-05 14:07:56 +00:00
|
|
|
RegisterBaseFeeError(queryClient)
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fail - grpc BaseFee error - with non feemarket block event",
|
|
|
|
&tmrpctypes.ResultBlockResults{
|
|
|
|
Height: 1,
|
|
|
|
BeginBlockEvents: []types.Event{
|
|
|
|
{
|
|
|
|
Type: evmtypes.EventTypeBlockBloom,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func() {
|
2022-10-11 18:43:32 +00:00
|
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
|
2022-09-05 14:07:56 +00:00
|
|
|
RegisterBaseFeeError(queryClient)
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fail - grpc BaseFee error - with feemarket block event",
|
|
|
|
&tmrpctypes.ResultBlockResults{
|
|
|
|
Height: 1,
|
|
|
|
BeginBlockEvents: []types.Event{
|
|
|
|
{
|
|
|
|
Type: feemarkettypes.EventTypeFeeMarket,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func() {
|
2022-10-11 18:43:32 +00:00
|
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
|
2022-09-05 14:07:56 +00:00
|
|
|
RegisterBaseFeeError(queryClient)
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fail - grpc BaseFee error - with feemarket block event with wrong attribute value",
|
|
|
|
&tmrpctypes.ResultBlockResults{
|
|
|
|
Height: 1,
|
|
|
|
BeginBlockEvents: []types.Event{
|
|
|
|
{
|
|
|
|
Type: feemarkettypes.EventTypeFeeMarket,
|
|
|
|
Attributes: []types.EventAttribute{
|
|
|
|
{Value: []byte{0x1}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func() {
|
2022-10-11 18:43:32 +00:00
|
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
|
2022-09-05 14:07:56 +00:00
|
|
|
RegisterBaseFeeError(queryClient)
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fail - grpc baseFee error - with feemarket block event with baseFee attribute value",
|
|
|
|
&tmrpctypes.ResultBlockResults{
|
|
|
|
Height: 1,
|
|
|
|
BeginBlockEvents: []types.Event{
|
|
|
|
{
|
|
|
|
Type: feemarkettypes.EventTypeFeeMarket,
|
|
|
|
Attributes: []types.EventAttribute{
|
|
|
|
{Value: []byte(baseFee.String())},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func() {
|
2022-10-11 18:43:32 +00:00
|
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
|
2022-09-05 14:07:56 +00:00
|
|
|
RegisterBaseFeeError(queryClient)
|
|
|
|
},
|
|
|
|
baseFee.BigInt(),
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"fail - base fee or london fork not enabled",
|
|
|
|
&tmrpctypes.ResultBlockResults{Height: 1},
|
|
|
|
func() {
|
2022-10-11 18:43:32 +00:00
|
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
|
2022-09-05 14:07:56 +00:00
|
|
|
RegisterBaseFeeDisabled(queryClient)
|
|
|
|
},
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"pass",
|
|
|
|
&tmrpctypes.ResultBlockResults{Height: 1},
|
|
|
|
func() {
|
2022-10-11 18:43:32 +00:00
|
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
|
2022-09-05 14:07:56 +00:00
|
|
|
RegisterBaseFee(queryClient, baseFee)
|
|
|
|
},
|
|
|
|
baseFee.BigInt(),
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
|
|
|
suite.SetupTest() // reset test and queries
|
|
|
|
tc.registerMock()
|
|
|
|
|
|
|
|
baseFee, err := suite.backend.BaseFee(tc.blockRes)
|
|
|
|
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
suite.Require().Equal(tc.expBaseFee, baseFee)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|