diff --git a/persistence/trees/atomic_test.go b/persistence/trees/atomic_test.go index c502d2b60..d1dbbe45a 100644 --- a/persistence/trees/atomic_test.go +++ b/persistence/trees/atomic_test.go @@ -28,13 +28,14 @@ func TestTreeStore_AtomicUpdates(t *testing.T) { TXI: mockBus.GetPersistenceModule().GetTxIndexer(), TreeStoreDir: ":memory:", } - ts.setupTrees() + err := ts.setupTrees() + require.NoError(t, err) require.NotEmpty(t, ts) hash0 := ts.getStateHash() require.NotEmpty(t, hash0) - err := ts.Savepoint() + err = ts.Savepoint() require.NoError(t, err) for _, treeName := range stateTreeNames { diff --git a/persistence/trees/trees.go b/persistence/trees/trees.go index 44a3ced39..4bf85928f 100644 --- a/persistence/trees/trees.go +++ b/persistence/trees/trees.go @@ -231,19 +231,6 @@ func (t *TreeStore) updateMerkleTrees(pgtx pgx.Tx, txi indexer.TxIndexer, height return t.getStateHash(), nil } -func (t *TreeStore) Commit() error { - if err := t.rootTree.tree.Commit(); err != nil { - return fmt.Errorf("failed to commit root tree: %w", err) - } - - for name, treeStore := range t.merkleTrees { - if err := treeStore.tree.Commit(); err != nil { - return fmt.Errorf("failed to commit %s: %w", name, err) - } - } - return nil -} - func (t *TreeStore) getStateHash() string { for _, stateTree := range t.merkleTrees { key := []byte(stateTree.name) diff --git a/persistence/trees/trees_test.go b/persistence/trees/trees_test.go index 13edd4d5f..a28bbae37 100644 --- a/persistence/trees/trees_test.go +++ b/persistence/trees/trees_test.go @@ -6,9 +6,6 @@ import ( "math/big" "testing" - "github.com/golang/mock/gomock" - "github.com/pokt-network/pocket/p2p/providers/current_height_provider" - "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" "github.com/pokt-network/pocket/persistence" "github.com/pokt-network/pocket/runtime" "github.com/pokt-network/pocket/runtime/configs" @@ -18,7 +15,6 @@ import ( "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/messaging" "github.com/pokt-network/pocket/shared/modules" - mockModules "github.com/pokt-network/pocket/shared/modules/mocks" "github.com/pokt-network/pocket/shared/utils" "github.com/stretchr/testify/assert" ) @@ -56,7 +52,7 @@ func TestTreeStore_Update(t *testing.T) { pmod := newTestPersistenceModule(t, dbUrl) context := NewTestPostgresContext(t, 0, pmod) - actor, err := createAndInsertDefaultTestApp(context) + actor, err := createAndInsertDefaultTestApp(t, context) assert.NoError(t, err) t.Logf("actor inserted %+v", actor) @@ -64,52 +60,6 @@ func TestTreeStore_Update(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, hash) }) - - t.Run("compute state hash should fail if called after rollback", func(t *testing.T) { - pmod := newTestPersistenceModule(t, dbUrl) - context := NewTestPostgresContext(t, 0, pmod) - - actor, err := createAndInsertDefaultTestApp(context) - assert.NoError(t, err) - assert.NotEmpty(t, actor) - - hash1, err := context.ComputeStateHash() - assert.NoError(t, err) - assert.NotEmpty(t, hash1) - - err = context.NewSavePoint() - assert.NoError(t, err) - - actor2, err := createAndInsertDefaultTestApp(context) - assert.NoError(t, err) - assert.NotEmpty(t, actor2) - - hash2, err := context.ComputeStateHash() - assert.NoError(t, err) - assert.NotEmpty(t, hash2) - - context.RollbackToSavePoint() - - _, err = context.ComputeStateHash() - assert.Error(t, err) - }) -} - -// createMockBus returns a mock bus with stubbed out functions for bus registration -func createMockBus(t *testing.T, runtimeMgr modules.RuntimeMgr) *mockModules.MockBus { - t.Helper() - ctrl := gomock.NewController(t) - mockBus := mockModules.NewMockBus(ctrl) - mockBus.EXPECT().GetRuntimeMgr().Return(runtimeMgr).AnyTimes() - mockBus.EXPECT().RegisterModule(gomock.Any()).DoAndReturn(func(m modules.Module) { - m.SetBus(mockBus) - }).AnyTimes() - mockModulesRegistry := mockModules.NewMockModulesRegistry(ctrl) - mockModulesRegistry.EXPECT().GetModule(peerstore_provider.PeerstoreProviderSubmoduleName).Return(nil, runtime.ErrModuleNotRegistered(peerstore_provider.PeerstoreProviderSubmoduleName)).AnyTimes() - mockModulesRegistry.EXPECT().GetModule(current_height_provider.ModuleName).Return(nil, runtime.ErrModuleNotRegistered(current_height_provider.ModuleName)).AnyTimes() - mockBus.EXPECT().GetModulesRegistry().Return(mockModulesRegistry).AnyTimes() - mockBus.EXPECT().PublishEventToBus(gomock.Any()).AnyTimes() - return mockBus } func newTestPersistenceModule(t *testing.T, databaseUrl string) modules.PersistenceModule { @@ -149,7 +99,7 @@ func newTestPersistenceModule(t *testing.T, databaseUrl string) modules.Persiste return persistenceMod.(modules.PersistenceModule) } -func createAndInsertDefaultTestApp(db *persistence.PostgresContext) (*coreTypes.Actor, error) { +func createAndInsertDefaultTestApp(t *testing.T, db *persistence.PostgresContext) (*coreTypes.Actor, error) { app, err := newTestApp() if err != nil { return nil, err @@ -158,15 +108,15 @@ func createAndInsertDefaultTestApp(db *persistence.PostgresContext) (*coreTypes. // TODO(andrew): Use `require.NoError` instead of `log.Fatal` in tests` addrBz, err := hex.DecodeString(app.Address) if err != nil { - log.Fatalf("an error occurred converting address to bytes %s", app.Address) + t.Errorf("an error occurred converting address to bytes %s", app.Address) } pubKeyBz, err := hex.DecodeString(app.PublicKey) if err != nil { - log.Fatalf("an error occurred converting pubKey to bytes %s", app.PublicKey) + t.Errorf("an error occurred converting pubKey to bytes %s", app.PublicKey) } outputBz, err := hex.DecodeString(app.Output) if err != nil { - log.Fatalf("an error occurred converting output to bytes %s", app.Output) + t.Errorf("an error occurred converting output to bytes %s", app.Output) } return app, db.InsertApp( addrBz,