forked from cerc-io/laconicd-deprecated
feemarket: unit tests EIP1559 (#758)
* Fee-Market(Types): Setup Params tests * Fee-Market(Types): Add all Params tests * Fee-Market(Types): Add genesis tests * Fee-Market(Keeper): Copy Keeper setup from EVM module and add Params tests * Fee-Market(Keeper): Add Keeper tests * Fee-Market(Keeper): Add review comments * Fee-Market(Keeper): WIP grpc tests * Fee-Market(Keeper): WIP ERIP1559 tests * Fee-Market(Keeper): WIP ERIP1559 tests * Fee-Market(Keeper): WIP ERIP1559 tests maxGas influences on baseFee * Fee-Market(Keeper): Add last ERIP1559 tests * Fee-Market(Keeper): Add abci tests
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestEndBlock() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
NoBaseFee bool
|
||||
malleate func()
|
||||
expGasUsed uint64
|
||||
}{
|
||||
{
|
||||
"basFee nil",
|
||||
true,
|
||||
func() {},
|
||||
uint64(0),
|
||||
},
|
||||
{
|
||||
"Block gas meter is nil",
|
||||
false,
|
||||
func() {},
|
||||
uint64(0),
|
||||
},
|
||||
{
|
||||
"pass",
|
||||
false,
|
||||
func() {
|
||||
meter := sdk.NewGasMeter(uint64(1000000000))
|
||||
suite.ctx = suite.ctx.WithBlockGasMeter(meter)
|
||||
suite.ctx.BlockGasMeter().ConsumeGas(uint64(5000000), "consume gas")
|
||||
},
|
||||
uint64(5000000),
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
||||
suite.SetupTest() // reset
|
||||
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||
params.NoBaseFee = tc.NoBaseFee
|
||||
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||
|
||||
tc.malleate()
|
||||
|
||||
req := abci.RequestEndBlock{Height: 1}
|
||||
suite.app.FeeMarketKeeper.EndBlock(suite.ctx, req)
|
||||
gasUsed := suite.app.FeeMarketKeeper.GetBlockGasUsed(suite.ctx)
|
||||
suite.Require().Equal(tc.expGasUsed, gasUsed, tc.name)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestCalculateBaseFee() {
|
||||
testCases := []struct {
|
||||
name string
|
||||
NoBaseFee bool
|
||||
malleate func()
|
||||
expFee *big.Int
|
||||
}{
|
||||
{
|
||||
"without BaseFee",
|
||||
true,
|
||||
func() {},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"with BaseFee - initial EIP-1559 block",
|
||||
false,
|
||||
func() {
|
||||
suite.ctx = suite.ctx.WithBlockHeight(0)
|
||||
},
|
||||
big.NewInt(suite.app.FeeMarketKeeper.GetParams(suite.ctx).InitialBaseFee),
|
||||
},
|
||||
{
|
||||
"with BaseFee - parent block used the same gas as its target",
|
||||
false,
|
||||
func() {
|
||||
// non initial block
|
||||
suite.ctx = suite.ctx.WithBlockHeight(1)
|
||||
|
||||
// Set gas used
|
||||
suite.app.FeeMarketKeeper.SetBlockGasUsed(suite.ctx, 100)
|
||||
|
||||
// Set target/gasLimit through Consensus Param MaxGas
|
||||
blockParams := abci.BlockParams{
|
||||
MaxGas: 100,
|
||||
MaxBytes: 10,
|
||||
}
|
||||
consParams := abci.ConsensusParams{Block: &blockParams}
|
||||
suite.ctx = suite.ctx.WithConsensusParams(&consParams)
|
||||
|
||||
// set ElasticityMultiplier
|
||||
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||
params.ElasticityMultiplier = 1
|
||||
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||
},
|
||||
big.NewInt(suite.app.FeeMarketKeeper.GetParams(suite.ctx).InitialBaseFee),
|
||||
},
|
||||
{
|
||||
"with BaseFee - parent block used more gas than its target",
|
||||
false,
|
||||
func() {
|
||||
suite.ctx = suite.ctx.WithBlockHeight(1)
|
||||
|
||||
suite.app.FeeMarketKeeper.SetBlockGasUsed(suite.ctx, 200)
|
||||
|
||||
blockParams := abci.BlockParams{
|
||||
MaxGas: 100,
|
||||
MaxBytes: 10,
|
||||
}
|
||||
consParams := abci.ConsensusParams{Block: &blockParams}
|
||||
suite.ctx = suite.ctx.WithConsensusParams(&consParams)
|
||||
|
||||
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||
params.ElasticityMultiplier = 1
|
||||
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||
},
|
||||
big.NewInt(1125000000),
|
||||
},
|
||||
{
|
||||
"with BaseFee - Parent gas used smaller than parent gas target",
|
||||
false,
|
||||
func() {
|
||||
suite.ctx = suite.ctx.WithBlockHeight(1)
|
||||
|
||||
suite.app.FeeMarketKeeper.SetBlockGasUsed(suite.ctx, 50)
|
||||
|
||||
blockParams := abci.BlockParams{
|
||||
MaxGas: 100,
|
||||
MaxBytes: 10,
|
||||
}
|
||||
consParams := abci.ConsensusParams{Block: &blockParams}
|
||||
suite.ctx = suite.ctx.WithConsensusParams(&consParams)
|
||||
|
||||
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||
params.ElasticityMultiplier = 1
|
||||
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||
},
|
||||
big.NewInt(937500000),
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
suite.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
||||
suite.SetupTest() // reset
|
||||
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||
params.NoBaseFee = tc.NoBaseFee
|
||||
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
|
||||
|
||||
tc.malleate()
|
||||
|
||||
fee := suite.app.FeeMarketKeeper.CalculateBaseFee(suite.ctx)
|
||||
if tc.NoBaseFee {
|
||||
suite.Require().Nil(fee, tc.name)
|
||||
} else {
|
||||
suite.Require().Equal(tc.expFee, fee, tc.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,103 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/tharsis/ethermint/x/feemarket/types"
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryParams() {
|
||||
ctx := sdk.WrapSDKContext(suite.ctx)
|
||||
expParams := types.DefaultParams()
|
||||
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(ctx, &types.QueryParamsRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(expParams, res.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
|
||||
}{
|
||||
{
|
||||
"pass - nil Base Fee",
|
||||
func() {
|
||||
expRes = &types.QueryBaseFeeResponse{}
|
||||
},
|
||||
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 {
|
||||
fee := suite.app.FeeMarketKeeper.GetBaseFee(suite.ctx)
|
||||
fmt.Printf("baseFee: %v", fee)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestQueryBlockGas() {
|
||||
ctx := sdk.WrapSDKContext(suite.ctx)
|
||||
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)}
|
||||
|
||||
res, err := suite.queryClient.BlockGas(ctx, &types.QueryBlockGasRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(int64(0), res.Gas)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,12 +131,6 @@ func (suite *KeeperTestSuite) TestSetGetBlockGasUsed() {
|
||||
malleate func()
|
||||
expGas uint64
|
||||
}{
|
||||
// TODO How to test len(bz) = 0
|
||||
// {
|
||||
// "no KeyPrefixBlockGasUsed",
|
||||
// func() {},
|
||||
// uint64(0),
|
||||
// },
|
||||
{
|
||||
"with last block given",
|
||||
func() {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/tharsis/ethermint/x/feemarket/types"
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestParams() {
|
||||
func (suite *KeeperTestSuite) TestSetGetParams() {
|
||||
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
|
||||
suite.Require().Equal(types.DefaultParams(), params)
|
||||
params.ElasticityMultiplier = 3
|
||||
|
||||
@@ -2,9 +2,9 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -42,13 +42,12 @@ func NewParams(noBaseFee bool, baseFeeChangeDenom, elasticityMultiplier uint32,
|
||||
|
||||
// DefaultParams returns default evm parameters
|
||||
func DefaultParams() Params {
|
||||
// TODO: use geth parameters
|
||||
return Params{
|
||||
NoBaseFee: true,
|
||||
BaseFeeChangeDenominator: DefaultBaseFeeChangeDenominator,
|
||||
ElasticityMultiplier: DefaultElasticityMultiplier,
|
||||
InitialBaseFee: DefaultInitialBaseFee,
|
||||
EnableHeight: math.MaxInt64,
|
||||
BaseFeeChangeDenominator: params.BaseFeeChangeDenominator,
|
||||
ElasticityMultiplier: params.ElasticityMultiplier,
|
||||
InitialBaseFee: params.InitialBaseFee,
|
||||
EnableHeight: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user