Skip to content

Commit

Permalink
Merge branch 'master' into pirtleshell/delete-versions-from
Browse files Browse the repository at this point in the history
  • Loading branch information
pirtleshell authored Jul 16, 2024
2 parents 148f43f + a514883 commit 7b226b3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5.5.2
- uses: amannn/action-semantic-pull-request@v5.5.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements

- [#952](https://github.com/cosmos/iavl/pull/952) Add `DeleteVersionsFrom(int64)` API.
- [#961](https://github.com/cosmos/iavl/pull/961) Add new `GetLatestVersion` API to get the latest version.

## v1.2.0 May 13, 2024

Expand Down
5 changes: 5 additions & 0 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func (tree *MutableTree) IsEmpty() bool {
return tree.ImmutableTree.Size() == 0
}

// GetLatestVersion returns the latest version of the tree.
func (tree *MutableTree) GetLatestVersion() (int64, error) {
return tree.ndb.getLatestVersion()
}

// VersionExists returns whether or not a version exists.
func (tree *MutableTree) VersionExists(version int64) bool {
legacyLatestVersion, err := tree.ndb.getLegacyLatestVersion()
Expand Down
6 changes: 5 additions & 1 deletion mutable_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,15 @@ func prepareTree(t *testing.T) *MutableTree {
return newTree
}

func TestMutableTree_VersionExists(t *testing.T) {
func TestMutableTree_Version(t *testing.T) {
tree := prepareTree(t)
require.True(t, tree.VersionExists(1))
require.True(t, tree.VersionExists(2))
require.False(t, tree.VersionExists(3))

v, err := tree.GetLatestVersion()
require.NoError(t, err)
require.Equal(t, int64(2), v)
}

func checkGetVersioned(t *testing.T, tree *MutableTree, version int64, key, value []byte) {
Expand Down

0 comments on commit 7b226b3

Please sign in to comment.