From 928ce5f0649d6df711715f6a1a994b2f1268432b Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Wed, 29 Jul 2020 13:06:14 -0400 Subject: [PATCH] initialize claim period ids if they don't exist (#620) --- x/incentive/keeper/keeper.go | 4 ++++ x/incentive/keeper/keeper_test.go | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index cf7705b7..1c97b3c9 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -90,6 +90,10 @@ func (k Keeper) GetAllRewardPeriods(ctx sdk.Context) types.RewardPeriods { func (k Keeper) GetNextClaimPeriodID(ctx sdk.Context, denom string) uint64 { store := prefix.NewStore(ctx.KVStore(k.key), types.NextClaimPeriodIDPrefix) bz := store.Get([]byte(denom)) + if bz == nil { + k.SetNextClaimPeriodID(ctx, denom, 1) + return uint64(1) + } return types.BytesToUint64(bz) } diff --git a/x/incentive/keeper/keeper_test.go b/x/incentive/keeper/keeper_test.go index 8da12fd6..96438195 100644 --- a/x/incentive/keeper/keeper_test.go +++ b/x/incentive/keeper/keeper_test.go @@ -86,14 +86,16 @@ func (suite *KeeperTestSuite) TestGetSetDeleteClaimPeriod() { } func (suite *KeeperTestSuite) TestGetSetClaimPeriodID() { - suite.Panics(func() { - suite.keeper.GetNextClaimPeriodID(suite.ctx, "bnb") + suite.NotPanics(func() { + suite.keeper.GetNextClaimPeriodID(suite.ctx, "yolo") }) suite.NotPanics(func() { suite.keeper.SetNextClaimPeriodID(suite.ctx, "bnb", 1) }) testID := suite.keeper.GetNextClaimPeriodID(suite.ctx, "bnb") suite.Equal(uint64(1), testID) + testID = suite.keeper.GetNextClaimPeriodID(suite.ctx, "yolo") + suite.Equal(uint64(1), testID) } func (suite *KeeperTestSuite) TestGetSetDeleteClaim() {