2021-11-17 13:32:05 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
2021-11-19 16:22:25 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-01-26 10:36:07 +00:00
|
|
|
ethparams "github.com/ethereum/go-ethereum/params"
|
2021-11-17 13:32:05 +00:00
|
|
|
"github.com/tharsis/ethermint/x/feemarket/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestQueryParams() {
|
2021-11-19 16:22:25 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"pass",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
|
|
|
exp := &types.QueryParamsResponse{Params: params}
|
|
|
|
|
|
|
|
res, err := suite.queryClient.Params(suite.ctx.Context(), &types.QueryParamsRequest{})
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().Equal(exp, res, tc.name)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestQueryBaseFee() {
|
|
|
|
var (
|
|
|
|
aux sdk.Int
|
|
|
|
expRes *types.QueryBaseFeeResponse
|
|
|
|
)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
malleate func()
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{
|
2022-01-26 10:36:07 +00:00
|
|
|
"pass - default Base Fee",
|
2021-11-19 16:22:25 +00:00
|
|
|
func() {
|
2022-01-26 10:36:07 +00:00
|
|
|
initialBaseFee := sdk.NewInt(ethparams.InitialBaseFee)
|
|
|
|
expRes = &types.QueryBaseFeeResponse{BaseFee: &initialBaseFee}
|
2021-11-19 16:22:25 +00:00
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
tc.malleate()
|
2021-11-17 13:32:05 +00:00
|
|
|
|
2021-11-19 16:22:25 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 13:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) TestQueryBlockGas() {
|
2021-11-19 16:22:25 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
expPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"pass",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
gas := suite.app.FeeMarketKeeper.GetBlockGasUsed(suite.ctx)
|
|
|
|
exp := &types.QueryBlockGasResponse{Gas: int64(gas)}
|
2021-11-17 13:32:05 +00:00
|
|
|
|
2021-11-19 16:22:25 +00:00
|
|
|
res, err := suite.queryClient.BlockGas(suite.ctx.Context(), &types.QueryBlockGasRequest{})
|
|
|
|
if tc.expPass {
|
|
|
|
suite.Require().Equal(exp, res, tc.name)
|
|
|
|
suite.Require().NoError(err)
|
|
|
|
} else {
|
|
|
|
suite.Require().Error(err)
|
|
|
|
}
|
|
|
|
}
|
2021-11-17 13:32:05 +00:00
|
|
|
}
|