1
1
package sstest
2
2
3
3
import (
4
+ "fmt"
4
5
"sync"
5
6
6
7
"github.com/cosmos/iavl"
8
+ "github.com/sei-protocol/sei-db/ss/types"
7
9
"github.com/stretchr/testify/suite"
8
10
"golang.org/x/exp/slices"
9
-
10
- "fmt"
11
-
12
- "github.com/sei-protocol/sei-db/ss/types"
13
11
)
14
12
15
13
const (
@@ -305,7 +303,7 @@ func (s *StorageTestSuite) TestDatabaseIterator() {
305
303
s .Require ().False (itr .Valid ())
306
304
}
307
305
308
- // iterator with with a start and end domain over multiple versions
306
+ // iterator with a start and end domain over multiple versions
309
307
for v := int64 (1 ); v < 5 ; v ++ {
310
308
itr2 , err := db .Iterator (storeKey1 , v , []byte ("key010" ), []byte ("key019" ))
311
309
s .Require ().NoError (err )
@@ -333,7 +331,6 @@ func (s *StorageTestSuite) TestDatabaseIterator() {
333
331
s .Require ().Error (err )
334
332
s .Require ().Nil (iter3 )
335
333
}
336
-
337
334
func (s * StorageTestSuite ) TestDatabaseIteratorRangedDeletes () {
338
335
db , err := s .NewDB (s .T ().TempDir ())
339
336
s .Require ().NoError (err )
@@ -359,6 +356,40 @@ func (s *StorageTestSuite) TestDatabaseIteratorRangedDeletes() {
359
356
s .Require ().NoError (itr .Error ())
360
357
}
361
358
359
+ func (s * StorageTestSuite ) TestDatabaseIteratorDeletes () {
360
+ db , err := s .NewDB (s .T ().TempDir ())
361
+ s .Require ().NoError (err )
362
+ defer db .Close ()
363
+
364
+ s .Require ().NoError (DBApplyChangeset (db , 1 , storeKey1 , [][]byte {[]byte ("key001" )}, [][]byte {[]byte ("value001" )}))
365
+ s .Require ().NoError (DBApplyDeleteChangeset (db , 5 , storeKey1 , [][]byte {[]byte ("key001" )}))
366
+
367
+ itr , err := db .Iterator (storeKey1 , 11 , []byte ("key001" ), nil )
368
+
369
+ // there should be no valid key in the iterator
370
+ var count = 0
371
+ for ; itr .Valid (); itr .Next () {
372
+ count ++
373
+ }
374
+ s .Require ().Equal (0 , count )
375
+ s .Require ().NoError (itr .Error ())
376
+ itr .Close ()
377
+
378
+ s .Require ().NoError (DBApplyChangeset (db , 10 , storeKey1 , [][]byte {[]byte ("key001" )}, [][]byte {[]byte ("value002" )}))
379
+ itr , err = db .Iterator (storeKey1 , 11 , []byte ("key001" ), nil )
380
+ s .Require ().NoError (err )
381
+
382
+ // there should only be one valid key in the iterator
383
+ count = 0
384
+ for ; itr .Valid (); itr .Next () {
385
+ s .Require ().Equal ([]byte ("key001" ), itr .Key ())
386
+ count ++
387
+ }
388
+ s .Require ().Equal (1 , count )
389
+ s .Require ().NoError (itr .Error ())
390
+ itr .Close ()
391
+ }
392
+
362
393
func (s * StorageTestSuite ) TestDatabaseIteratorMultiVersion () {
363
394
db , err := s .NewDB (s .T ().TempDir ())
364
395
s .Require ().NoError (err )
0 commit comments