initialize claim period ids if they don't exist (#620)

This commit is contained in:
Kevin Davis 2020-07-29 13:06:14 -04:00 committed by GitHub
parent e9e038a2c4
commit 928ce5f064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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)
}

View File

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