laconicd-deprecated/x/feemarket/keeper/params_test.go
Vladislav Varadinov 83e509bc57
refactor: optimize AnteHandler gas consumption (#1388)
* refactor: antehandler order and params optimization

* removed additional individual params for the feemarket module

* typo fix

* Apply suggestions from code review - Fede

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

* typo fix

* formatted using gofumpt

* typo fix - missed negate operator

* missed to negate conditions

* added unit tests for the new param getter methods

* updated changelog

* Apply suggestions from code review

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

* moved to improvements

* Converted unit tests into table-driven tests

* added Require().Equal() to test case

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
2022-10-19 18:21:59 +02:00

71 lines
1.8 KiB
Go

package keeper_test
import (
"github.com/evmos/ethermint/x/feemarket/types"
"reflect"
)
func (suite *KeeperTestSuite) TestSetGetParams() {
params := suite.app.FeeMarketKeeper.GetParams(suite.ctx)
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
testCases := []struct {
name string
paramsFun func() interface{}
getFun func() interface{}
expected bool
}{
{
"success - Checks if the default params are set correctly",
func() interface{} {
return types.DefaultParams()
},
func() interface{} {
return suite.app.FeeMarketKeeper.GetParams(suite.ctx)
},
true,
},
{
"success - Check ElasticityMultiplier is set to 3 and can be retrieved correctly",
func() interface{} {
params.ElasticityMultiplier = 3
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
return params.ElasticityMultiplier
},
func() interface{} {
return suite.app.FeeMarketKeeper.GetParams(suite.ctx).ElasticityMultiplier
},
true,
},
{
"success - Check BaseFeeEnabled is computed with its default params and can be retrieved correctly",
func() interface{} {
suite.app.FeeMarketKeeper.SetParams(suite.ctx, types.DefaultParams())
return true
},
func() interface{} {
return suite.app.FeeMarketKeeper.GetBaseFeeEnabled(suite.ctx)
},
true,
},
{
"success - Check BaseFeeEnabled is computed with alternate params and can be retrieved correctly",
func() interface{} {
params.NoBaseFee = true
params.EnableHeight = 5
suite.app.FeeMarketKeeper.SetParams(suite.ctx, params)
return true
},
func() interface{} {
return suite.app.FeeMarketKeeper.GetBaseFeeEnabled(suite.ctx)
},
false,
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
outcome := reflect.DeepEqual(tc.paramsFun(), tc.getFun())
suite.Require().Equal(tc.expected, outcome)
})
}
}