Skip to content

Commit

Permalink
DeleteHeadOfPendingPackets unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Aug 7, 2023
1 parent 130de0d commit 8a35533
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions x/ccv/consumer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,11 @@ func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint
}

// DeleteHeadOfPendingPackets deletes the head of the pending packets queue.
// TODO: UTs
func (k Keeper) DeleteHeadOfPendingPackets(ctx sdk.Context) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix})
defer iterator.Close()
if !iterator.Valid() { // TODO: needed?
if !iterator.Valid() {
return
}
store.Delete(iterator.Key())
Expand Down
28 changes: 28 additions & 0 deletions x/ccv/consumer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,31 @@ func TestPrevStandaloneChainFlag(t *testing.T) {
ck.MarkAsPrevStandaloneChain(ctx)
require.True(t, ck.IsPrevStandaloneChain(ctx))
}

func TestDeleteHeadOfPendingPackets(t *testing.T) {
consumerKeeper, ctx, ctrl, _ := testkeeper.GetConsumerKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

// append some pending packets
consumerKeeper.AppendPendingPacket(ctx, ccv.VscMaturedPacket, &ccv.ConsumerPacketData_VscMaturedPacketData{})
consumerKeeper.AppendPendingPacket(ctx, ccv.SlashPacket, &ccv.ConsumerPacketData_SlashPacketData{})
consumerKeeper.AppendPendingPacket(ctx, ccv.VscMaturedPacket, &ccv.ConsumerPacketData_VscMaturedPacketData{})

// Check there's 3 pending packets, vsc matured at head
pp := consumerKeeper.GetPendingPackets(ctx)
require.Len(t, pp, 3)
require.Equal(t, pp[0].Type, ccv.VscMaturedPacket)

// Delete the head, confirm slash packet is now at head
consumerKeeper.DeleteHeadOfPendingPackets(ctx)
pp = consumerKeeper.GetPendingPackets(ctx)
require.Len(t, pp, 2)
require.Equal(t, pp[0].Type, ccv.SlashPacket)

// Delete the head, confirm vsc matured packet is now at head
consumerKeeper.DeleteHeadOfPendingPackets(ctx)
pp = consumerKeeper.GetPendingPackets(ctx)
require.Len(t, pp, 1)
require.Equal(t, pp[0].Type, ccv.VscMaturedPacket)

Check failure on line 608 in x/ccv/consumer/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
}

0 comments on commit 8a35533

Please sign in to comment.