@@ -61,6 +61,58 @@ func TestIterateKeysInPrefixRange(t *testing.T) {
6161 })
6262}
6363
64+ func TestIterationBoundary (t * testing.T ) {
65+ dbtest .RunWithStorages (t , func (t * testing.T , r storage.Reader , withWriter dbtest.WithWriter ) {
66+ // Define the prefix range
67+ prefixStart := []byte {0x01 }
68+ prefixEnd := []byte {0xff }
69+
70+ // Create a range of keys around the prefix start/end values
71+ keys := [][]byte {
72+ {0x00 },
73+ {0x00 , 0x00 },
74+ {0x00 , 0xff },
75+ {0x01 },
76+ {0x01 , 0x00 },
77+ {0x01 , 0xff },
78+ {0x02 },
79+ {0xff },
80+ {0xff , 0x00 },
81+ {0xff , 0xff },
82+ }
83+
84+ expectedKeys := [][]byte {
85+ {0x01 },
86+ {0x01 , 0x00 },
87+ {0x01 , 0xff },
88+ {0x02 },
89+ {0xff },
90+ {0xff , 0x00 },
91+ {0xff , 0xff },
92+ }
93+
94+ // Insert the keys into the storage
95+ require .NoError (t , withWriter (func (writer storage.Writer ) error {
96+ for _ , key := range keys {
97+ value := []byte {0x00 } // value are skipped, doesn't matter
98+ err := operation .Upsert (key , value )(writer )
99+ if err != nil {
100+ return err
101+ }
102+ }
103+ return nil
104+ }))
105+
106+ // Forward iteration and check boundaries
107+ var found [][]byte
108+ require .NoError (t , operation .IterateKeysInPrefixRange (prefixStart , prefixEnd , func (key []byte ) error {
109+ found = append (found , key )
110+ return nil
111+ })(r ), "should iterate forward without error" )
112+ require .ElementsMatch (t , expectedKeys , found , "forward iteration should return the correct keys in range" )
113+ })
114+ }
115+
64116func TestTraverse (t * testing.T ) {
65117 dbtest .RunWithStorages (t , func (t * testing.T , r storage.Reader , withWriter dbtest.WithWriter ) {
66118 keyVals := map [[2 ]byte ]uint64 {
0 commit comments