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() {