Skip to content

Commit

Permalink
test: UintTree start key comparing
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon committed Jan 7, 2025
1 parent 0d789a5 commit 7a038f8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions staker/reward_calculation_types_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ func TestRewardCacheTree(t *testing.T) {
tree.CurrentRewardAt(400)
}

func TestReverseIterateEmptyStringStart(t *testing.T) {
tree := NewRewardCacheTree()

tree.Set(100, "reward1")
tree.Set(200, "reward2")
tree.Set(300, "reward3")
tree.Set(400, "reward4")
tree.Set(500, "reward5")

var resEmptyString interface{}
var resZeroPadded interface{}

tree.tree.ReverseIterate("", EncodeUint(250), func(k string, v interface{}) bool {
resEmptyString = v
return true
})

tree.tree.ReverseIterate(EncodeUint(0), EncodeUint(250), func(k string, v interface{}) bool {
resZeroPadded = v
return true
})

if resEmptyString != resZeroPadded {
t.Errorf("ReverseIterate with '' got %v, while zero-padded got %v; want same result",
resEmptyString, resZeroPadded)
}
}

// Helper function to compare slices of uint64
func compareUintSlices(t *testing.T, a, b []uint64) bool {
t.Helper()
Expand Down

0 comments on commit 7a038f8

Please sign in to comment.