Skip to content

Commit

Permalink
[fixup] updates rollback test to use Errors#Is
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlott committed Jul 26, 2023
1 parent 7511743 commit 9a3c346
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 10 additions & 9 deletions persistence/trees/trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ type stateTree struct {

var _ modules.TreeStoreModule = &treeStore{}

// errFailedRollback is thrown whenever a rollback is attempted with no savepoint set
var errFailedRollback = fmt.Errorf("failed to rollback")
// ErrFailedRollback is thrown when a rollback fails to reset the TreeStore to a known good state
var ErrFailedRollback = fmt.Errorf("failed to rollback")

// treeStore stores a set of merkle trees that it manages.
// It fulfills the modules.treeStore interface
Expand All @@ -102,11 +102,12 @@ type treeStore struct {

// PrevState holds a previous view of the Worldstate.
// The tree store rolls back to this view if errors are encountered during block application.
PrevState *Worldstate
PrevState *worldstate
}

// Worldstate holds a (de)serializable view of the entire tree state.
type Worldstate struct {
// worldstate holds a (de)serializable view of the entire tree state.
// TECHDEBT(#566) - Hook this up to node CLI subcommands
type worldstate struct {
TreeStoreDir string
RootTree *stateTree
MerkleTrees map[string]*stateTree
Expand Down Expand Up @@ -303,20 +304,20 @@ func (t *treeStore) Rollback() error {
t.rootTree = t.PrevState.RootTree
return nil
}
t.logger.Err(errFailedRollback)
return errFailedRollback
t.logger.Err(ErrFailedRollback)
return ErrFailedRollback
}

// save commits any pending changes to the trees and creates a copy of the current state of the
// tree store then saves that copy as a rollback point for later use if errors are encountered.
// OPTIMIZE: Consider saving only the root hash of each tree and the tree directory here and then
// load the trees up in Rollback instead of setting them up here.
func (t *treeStore) save() (*Worldstate, error) {
func (t *treeStore) save() (*worldstate, error) {
if err := t.Commit(); err != nil {
return nil, err
}

w := &Worldstate{
w := &worldstate{
TreeStoreDir: t.treeStoreDir,
MerkleTrees: map[string]*stateTree{},
}
Expand Down
5 changes: 3 additions & 2 deletions persistence/trees/trees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/pokt-network/pocket/persistence"
"github.com/pokt-network/pocket/persistence/trees"
"github.com/pokt-network/pocket/runtime"
"github.com/pokt-network/pocket/runtime/configs"
"github.com/pokt-network/pocket/runtime/test_artifacts"
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestTreeStore_Update(t *testing.T) {

err := context.RollbackToSavePoint()
require.Error(t, err)
require.ErrorContainsf(t, err, "failed to rollback", "incorrect error returned")
require.ErrorIs(t, err, trees.ErrFailedRollback)
})
}

Expand Down Expand Up @@ -200,4 +201,4 @@ func resetStateToGenesis(m modules.PersistenceModule) {
// TODO_AFTER(#861): Implement this test with the test suite available in #861
func TestTreeStore_GetTreeHashes(t *testing.T) {
t.Skip("TODO: Write test case for GetTreeHashes method") // context: https://github.com/pokt-network/pocket/pull/915#discussion_r1267313664
} //
}

0 comments on commit 9a3c346

Please sign in to comment.