mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 08:15:19 +00:00
initialize claim period ids if they don't exist (#620)
This commit is contained in:
parent
e9e038a2c4
commit
928ce5f064
@ -90,6 +90,10 @@ func (k Keeper) GetAllRewardPeriods(ctx sdk.Context) types.RewardPeriods {
|
|||||||
func (k Keeper) GetNextClaimPeriodID(ctx sdk.Context, denom string) uint64 {
|
func (k Keeper) GetNextClaimPeriodID(ctx sdk.Context, denom string) uint64 {
|
||||||
store := prefix.NewStore(ctx.KVStore(k.key), types.NextClaimPeriodIDPrefix)
|
store := prefix.NewStore(ctx.KVStore(k.key), types.NextClaimPeriodIDPrefix)
|
||||||
bz := store.Get([]byte(denom))
|
bz := store.Get([]byte(denom))
|
||||||
|
if bz == nil {
|
||||||
|
k.SetNextClaimPeriodID(ctx, denom, 1)
|
||||||
|
return uint64(1)
|
||||||
|
}
|
||||||
return types.BytesToUint64(bz)
|
return types.BytesToUint64(bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,14 +86,16 @@ func (suite *KeeperTestSuite) TestGetSetDeleteClaimPeriod() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestGetSetClaimPeriodID() {
|
func (suite *KeeperTestSuite) TestGetSetClaimPeriodID() {
|
||||||
suite.Panics(func() {
|
suite.NotPanics(func() {
|
||||||
suite.keeper.GetNextClaimPeriodID(suite.ctx, "bnb")
|
suite.keeper.GetNextClaimPeriodID(suite.ctx, "yolo")
|
||||||
})
|
})
|
||||||
suite.NotPanics(func() {
|
suite.NotPanics(func() {
|
||||||
suite.keeper.SetNextClaimPeriodID(suite.ctx, "bnb", 1)
|
suite.keeper.SetNextClaimPeriodID(suite.ctx, "bnb", 1)
|
||||||
})
|
})
|
||||||
testID := suite.keeper.GetNextClaimPeriodID(suite.ctx, "bnb")
|
testID := suite.keeper.GetNextClaimPeriodID(suite.ctx, "bnb")
|
||||||
suite.Equal(uint64(1), testID)
|
suite.Equal(uint64(1), testID)
|
||||||
|
testID = suite.keeper.GetNextClaimPeriodID(suite.ctx, "yolo")
|
||||||
|
suite.Equal(uint64(1), testID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KeeperTestSuite) TestGetSetDeleteClaim() {
|
func (suite *KeeperTestSuite) TestGetSetDeleteClaim() {
|
||||||
|
Loading…
Reference in New Issue
Block a user