Skip to content

Commit

Permalink
fix: rootKey empty check by len equals 0 (backport: #801) (#808)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <marbar3778@yahoo.com>
  • Loading branch information
mmsqe and tac0turtle committed Aug 10, 2023
1 parent 633397c commit b35e4ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
- [#726](https://github.com/cosmos/iavl/pull/726) Make `KVPair` and `ChangeSet` serializable with protobuf.
- [#795](https://github.com/cosmos/iavl/pull/795) Use gogofaster buf plugin.

### Bug Fixes

- [#801](https://github.com/cosmos/iavl/pull/801) Fix rootKey empty check by len equals 0.

## 0.20.0 (March 14, 2023)

- [#622](https://github.com/cosmos/iavl/pull/622) `export/newExporter()` and `ImmutableTree.Export()` returns error for nil arguements
Expand Down
2 changes: 1 addition & 1 deletion iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ type NodeIterator struct {

// NewNodeIterator returns a new NodeIterator to traverse the tree of the root node.
func NewNodeIterator(rootKey []byte, ndb *nodeDB) (*NodeIterator, error) {
if rootKey == nil {
if len(rootKey) == 0 {
return &NodeIterator{
nodesToVisit: []*Node{},
ndb: ndb,
Expand Down
10 changes: 10 additions & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,13 @@ func setupUnsavedFastIterator(t *testing.T, config *iteratorTestConfig) (dbm.Ite
itr := NewUnsavedFastIterator(config.startIterate, config.endIterate, config.ascending, tree.ndb, tree.unsavedFastNodeAdditions, tree.unsavedFastNodeRemovals)
return itr, mirror
}

func TestNodeIterator_WithEmptyRoot(t *testing.T) {
itr, err := NewNodeIterator(nil, newNodeDB(dbm.NewMemDB(), 0, nil))
require.NoError(t, err)
require.False(t, itr.Valid())

itr, err = NewNodeIterator([]byte{}, newNodeDB(dbm.NewMemDB(), 0, nil))
require.NoError(t, err)
require.False(t, itr.Valid())
}

0 comments on commit b35e4ff

Please sign in to comment.