Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import: set correct version on empty import #230

Merged
merged 5 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Special thanks to external contributors on this release:

### Bug Fixes

- [import] [\#230](https://github.com/tendermint/iavl/pull/230/files) Set correct version when committing an empty import.

## 0.13.2 (March 18, 2020)

### Improvements
Expand Down
8 changes: 5 additions & 3 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ func (i *Importer) Commit() error {
return ErrNoImport
}

switch {
case len(i.stack) == 1:
switch len(i.stack) {
case 0:
i.batch.Set(i.tree.ndb.rootKey(i.version), []byte{})
case 1:
i.batch.Set(i.tree.ndb.rootKey(i.version), i.stack[0].hash)
case len(i.stack) > 2:
default:
return errors.Errorf("invalid node structure, found stack size %v when committing",
len(i.stack))
}
Expand Down
13 changes: 13 additions & 0 deletions import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package iavl
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

db "github.com/tendermint/tm-db"
Expand Down Expand Up @@ -199,6 +200,18 @@ func TestImporter_Commit_Closed(t *testing.T) {
require.Equal(t, ErrNoImport, err)
}

func TestImporter_Commit_Empty(t *testing.T) {
tree, err := NewMutableTree(db.NewMemDB(), 0)
require.NoError(t, err)
importer, err := tree.Import(3)
require.NoError(t, err)
defer importer.Close()

err = importer.Commit()
require.NoError(t, err)
assert.EqualValues(t, 3, tree.Version())
}

func BenchmarkImport(b *testing.B) {
b.StopTimer()
tree := setupExportTreeSized(b, 4096)
Expand Down