Skip to content

Commit

Permalink
Merge branch 'main' into sai/multi_msg_sign_13066
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 authored Sep 26, 2022
2 parents 162e22e + 35e5a3d commit d0780aa
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions store/cachekv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,59 @@ func TestCacheKVIteratorBounds(t *testing.T) {
require.Equal(t, 4, i)
}

func TestCacheKVReverseIteratorBounds(t *testing.T) {
st := newCacheKVStore()

// set some items
nItems := 5
for i := 0; i < nItems; i++ {
st.Set(keyFmt(i), valFmt(i))
}

// iterate over all of them
itr := st.ReverseIterator(nil, nil)
i := 0
for ; itr.Valid(); itr.Next() {
k, v := itr.Key(), itr.Value()
require.Equal(t, keyFmt(nItems-1-i), k)
require.Equal(t, valFmt(nItems-1-i), v)
i++
}
require.Equal(t, nItems, i)

// iterate over none
itr = st.ReverseIterator(bz("money"), nil)
i = 0
for ; itr.Valid(); itr.Next() {
i++
}
require.Equal(t, 0, i)

// iterate over lower
end := 3
itr = st.ReverseIterator(keyFmt(0), keyFmt(end))
i = 0
for ; itr.Valid(); itr.Next() {
i++
k, v := itr.Key(), itr.Value()
require.Equal(t, keyFmt(end-i), k)
require.Equal(t, valFmt(end-i), v)
}
require.Equal(t, 3, i)

// iterate over upper
end = 4
itr = st.ReverseIterator(keyFmt(2), keyFmt(end))
i = 0
for ; itr.Valid(); itr.Next() {
i++
k, v := itr.Key(), itr.Value()
require.Equal(t, keyFmt(end-i), k)
require.Equal(t, valFmt(end-i), v)
}
require.Equal(t, 2, i)
}

func TestCacheKVMergeIteratorBasics(t *testing.T) {
st := newCacheKVStore()

Expand Down Expand Up @@ -291,6 +344,21 @@ func TestCacheKVMergeIteratorChunks(t *testing.T) {
assertIterateDomainCheck(t, st, truth, []keyRange{{0, 15}, {25, 35}, {38, 40}, {45, 80}})
}

func TestCacheKVMergeIteratorDomain(t *testing.T) {
st := newCacheKVStore()

start, end := st.Iterator(nil, nil).Domain()
require.Equal(t, start, end)

start, end = st.Iterator(keyFmt(40), keyFmt(60)).Domain()
require.Equal(t, keyFmt(40), start)
require.Equal(t, keyFmt(60), end)

start, end = st.ReverseIterator(keyFmt(0), keyFmt(80)).Domain()
require.Equal(t, keyFmt(0), start)
require.Equal(t, keyFmt(80), end)
}

func TestCacheKVMergeIteratorRandom(t *testing.T) {
st := newCacheKVStore()
truth := dbm.NewMemDB()
Expand Down

0 comments on commit d0780aa

Please sign in to comment.