Skip to content

Commit

Permalink
Incremental unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zmanian committed Dec 13, 2023
1 parent 81a73d3 commit d737632
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions x/cellarfees/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func (suite *KeeperTestSuite) TestBeginBlockerZeroRewardsBalance() {
ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper

require := suite.Require()

params := cellarfeesTypes.DefaultParams()
Expand All @@ -26,6 +27,8 @@ func (suite *KeeperTestSuite) TestBeginBlockerZeroRewardsBalance() {

func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndPreviousPeakZero() {
ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper
cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters())

require := suite.Require()

params := cellarfeesTypes.DefaultParams()
Expand All @@ -48,6 +51,7 @@ func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndPreviousPeakZe

func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndHigherPreviousPeak() {
ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper
cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters())
require := suite.Require()

params := cellarfeesTypes.DefaultParams()
Expand All @@ -72,6 +76,8 @@ func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndHigherPrevious

func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndLowerPreviousPeak() {
ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper
cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters())

require := suite.Require()

params := cellarfeesTypes.DefaultParams()
Expand All @@ -97,6 +103,7 @@ func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndLowerPreviousP
// If the emission calculation underflows to zero, it should be set to 1
func (suite *KeeperTestSuite) TestBeginBlockerEmissionCalculationUnderflowsToZero() {
ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper
cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters())
require := suite.Require()

params := cellarfeesTypes.DefaultParams()
Expand All @@ -118,6 +125,8 @@ func (suite *KeeperTestSuite) TestBeginBlockerEmissionCalculationUnderflowsToZer
// If the calculated emission is greater than the remaining supply, it should be set to the remaining supply
func (suite *KeeperTestSuite) TestBeginBlockerEmissionGreaterThanRewardSupply() {
ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper
cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters())

require := suite.Require()
params := cellarfeesTypes.DefaultParams()
cellarfeesKeeper.SetParams(ctx, params)
Expand Down
2 changes: 2 additions & 0 deletions x/cellarfees/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (suite *KeeperTestSuite) TestImportingPopulatedGenesis() {
testGenesis.Params.InitialPriceDecreaseRate = sdk.MustNewDecFromStr("0.01")
testGenesis.Params.PriceDecreaseBlockInterval = 10
testGenesis.Params.RewardEmissionPeriod = 600
testGenesis.Params.AuctionInterval = 1000

require.NotPanics(func() {
suite.accountKeeper.EXPECT().GetModuleAccount(ctx, feesAccount.GetName()).Return(feesAccount)
Expand Down Expand Up @@ -82,6 +83,7 @@ func (suite *KeeperTestSuite) TestExportingPopulatedGenesis() {
params.InitialPriceDecreaseRate = sdk.MustNewDecFromStr("0.01")
params.PriceDecreaseBlockInterval = 10
params.RewardEmissionPeriod = 600
params.AuctionInterval = 1000
cellarfeesKeeper.SetParams(ctx, params)
counters := cellarfeesTypes.FeeAccrualCounters{
Counters: []cellarfeesTypes.FeeAccrualCounter{
Expand Down
18 changes: 18 additions & 0 deletions x/cellarfees/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
DefaultInitialPriceDecreaseRate string = "0.0000648"
// Blocks between each auction price decrease
DefaultPriceDecreaseBlockInterval uint64 = 10
// Blocks between each auction
DefaultAuctionInterval uint64 = 1000
)

// Parameter keys
Expand All @@ -25,6 +27,7 @@ var (
KeyRewardEmissionPeriod = []byte("RewardEmissionPeriod")
KeyInitialPriceDecreaseRate = []byte("InitialPriceDecreaseRate")
KeyPriceDecreaseBlockInterval = []byte("PriceDecreaseBlockInterval")
KeyAuctionInterval = []byte("AuctionInterval")
)

var _ paramtypes.ParamSet = &Params{}
Expand All @@ -41,6 +44,7 @@ func DefaultParams() Params {
RewardEmissionPeriod: DefaultRewardEmissionPeriod,
InitialPriceDecreaseRate: sdk.MustNewDecFromStr(DefaultInitialPriceDecreaseRate),
PriceDecreaseBlockInterval: DefaultPriceDecreaseBlockInterval,
AuctionInterval: DefaultAuctionInterval,
}
}

Expand All @@ -51,6 +55,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyRewardEmissionPeriod, &p.RewardEmissionPeriod, validateRewardEmissionPeriod),
paramtypes.NewParamSetPair(KeyInitialPriceDecreaseRate, &p.InitialPriceDecreaseRate, validateInitialPriceDecreaseRate),
paramtypes.NewParamSetPair(KeyPriceDecreaseBlockInterval, &p.PriceDecreaseBlockInterval, validatePriceDecreaseBlockInterval),
paramtypes.NewParamSetPair(KeyAuctionInterval, &p.AuctionInterval, validateAuctionInterval),
}
}

Expand Down Expand Up @@ -127,6 +132,19 @@ func validatePriceDecreaseBlockInterval(i interface{}) error {
return nil
}

func validateAuctionInterval(i interface{}) error {
interval, ok := i.(uint64)
if !ok {
return errorsmod.Wrapf(ErrInvalidAuctionInterval, "auction interval: %T", i)
}

if interval == 0 {
return errorsmod.Wrapf(ErrInvalidAuctionInterval, "auction interval cannot be zero")
}

return nil
}

// String implements the String interface
func (p Params) String() string {
out, _ := yaml.Marshal(p)
Expand Down

0 comments on commit d737632

Please sign in to comment.