Skip to content

Commit

Permalink
linter updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlott committed Jul 11, 2023
1 parent f0c6203 commit 0a6c72f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 66 deletions.
5 changes: 3 additions & 2 deletions persistence/trees/atomic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions persistence/trees/trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,6 @@ func (t *TreeStore) updateMerkleTrees(pgtx pgx.Tx, txi indexer.TxIndexer, height
return t.getStateHash(), nil
}

func (t *TreeStore) Commit() error {
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)
Expand Down
60 changes: 5 additions & 55 deletions persistence/trees/trees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -56,60 +52,14 @@ 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)
hash, err := context.ComputeStateHash()
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 {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 0a6c72f

Please sign in to comment.