9f03ca713d
* wip * rename GetTendermintBlockByNumber to TendermintBlockByNumber * rename GetTendermintBlockResultByNumber to TendermintBlockResultByNumber * rename GetTendermintBlockByHash to TendermintBlockByHash * rename BlockByNumber to EthBlockByNumber * rename BlockByHash to EthBlockByHash * rename GetBlockNumberByHash to BlockNumberFromTendermintByHash * rename GetBlockNumber to BlockNumberFromTendermint * rename GetEthereumMsgsFromTendermintBlock to EthMsgsFromTendermintBlock * rename GetEthBlockFromTendermint to BlockFromTendermintBlock * rename EthBlockFromTendermint to EthBlockFromTendermintBlock * add TestEthBlockFromTendermintBlock with no transactions. Note that this endpoint is breaking when querying a block with transactions * add block transaction count tests * add TendermintBlockByHash test' * add TestBlockNumberFromTendermint tests * add HeaderByHash and HeaderByNumber tests * add EthBlockFromTendermintBlock test * add TestEthBlockByNumber tests * Specificy that the endpoints are getting Etherum transactions in comments * Refactor shared logic into GetBlockTransactionCount * rename BlockFromTendermintBlock to RPCBlockFromTendermintBlock * add CHangelog
147 lines
3.4 KiB
Go
147 lines
3.4 KiB
Go
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() {
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.QueryClient)
|
|
RegisterBaseFeeError(queryClient)
|
|
},
|
|
nil,
|
|
false,
|
|
},
|
|
{
|
|
"fail - grpc BaseFee error - with non feemarket block event",
|
|
&tmrpctypes.ResultBlockResults{
|
|
Height: 1,
|
|
BeginBlockEvents: []types.Event{
|
|
{
|
|
Type: evmtypes.EventTypeBlockBloom,
|
|
},
|
|
},
|
|
},
|
|
func() {
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.QueryClient)
|
|
RegisterBaseFeeError(queryClient)
|
|
},
|
|
nil,
|
|
false,
|
|
},
|
|
{
|
|
"fail - grpc BaseFee error - with feemarket block event",
|
|
&tmrpctypes.ResultBlockResults{
|
|
Height: 1,
|
|
BeginBlockEvents: []types.Event{
|
|
{
|
|
Type: feemarkettypes.EventTypeFeeMarket,
|
|
},
|
|
},
|
|
},
|
|
func() {
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.QueryClient)
|
|
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() {
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.QueryClient)
|
|
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() {
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.QueryClient)
|
|
RegisterBaseFeeError(queryClient)
|
|
},
|
|
baseFee.BigInt(),
|
|
true,
|
|
},
|
|
{
|
|
"fail - base fee or london fork not enabled",
|
|
&tmrpctypes.ResultBlockResults{Height: 1},
|
|
func() {
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.QueryClient)
|
|
RegisterBaseFeeDisabled(queryClient)
|
|
},
|
|
nil,
|
|
true,
|
|
},
|
|
{
|
|
"pass",
|
|
&tmrpctypes.ResultBlockResults{Height: 1},
|
|
func() {
|
|
queryClient := suite.backend.queryClient.QueryClient.(*mocks.QueryClient)
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|