-
Notifications
You must be signed in to change notification settings - Fork 33
[Chore] Submodule pattern updates to TreeStore #896
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cb1f17a
[chore] submodule pattern updates to TreeStore
dylanlott 34d4e82
updates TreeStore to use Submodule type
dylanlott 8fdebb8
[fixup] fixes mocks for treestore module
dylanlott aba1bb6
[fixup] embeds TreeStoreFactory on to TreeStoreModule
dylanlott 342c611
[fixup] TreeStoreOption and TreeStoreModule updates
dylanlott a3b6d34
[docs] updates the Modules readme to reflect some best practices
dylanlott 3beb528
[fixup] removes bus and txindexer from TreeStore struct and only fetc…
dylanlott b98ddec
[fixup] get height provider from bus in tree tests
dylanlott c004456
[fixup] only use bus to fetch TreeStore
dylanlott 614597b
[fixup] renames TreeStoreModuleName
dylanlott a6f8b27
[fixup] renames tree store factory function
dylanlott 4b3ce44
[docs] adds techdebt comment about privatization to TreeStore struct
dylanlott 7ce02c0
[fixup] privatize treeStoreDir field on TreeStore struct
dylanlott ad0cdcb
[docs] Apply documentation suggestions from code review
dylanlott 4a9d866
[Temp] s/TreeStore/treeStore (#920)
Olshansk 61e2f61
[fixup] adds error logs to treeStore#Commit error paths
dylanlott 6aaff89
[fixup] formatting long mock definitions
dylanlott c9dfe00
[fixup] change assertion on empty byte slice
dylanlott 33a42da
[docs] adds documentation on order of module registration
dylanlott 9b0ab2c
[fixup] register treestore submodule after processing options
dylanlott c8acc11
Merge branch 'main' into persistence/tree-store-submodule
dylanlott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| package trees_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/golang/mock/gomock" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/pokt-network/pocket/internal/testutil" | ||
| "github.com/pokt-network/pocket/p2p/providers/peerstore_provider" | ||
| "github.com/pokt-network/pocket/persistence/trees" | ||
| "github.com/pokt-network/pocket/runtime" | ||
| "github.com/pokt-network/pocket/runtime/genesis" | ||
| "github.com/pokt-network/pocket/runtime/test_artifacts" | ||
| coreTypes "github.com/pokt-network/pocket/shared/core/types" | ||
| cryptoPocket "github.com/pokt-network/pocket/shared/crypto" | ||
| "github.com/pokt-network/pocket/shared/modules" | ||
| mockModules "github.com/pokt-network/pocket/shared/modules/mocks" | ||
| ) | ||
|
|
||
| const ( | ||
| serviceURLFormat = "node%d.consensus:42069" | ||
| ) | ||
|
|
||
| func TestTreeStore_Create(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| mockRuntimeMgr := mockModules.NewMockRuntimeMgr(ctrl) | ||
| mockBus := createMockBus(t, mockRuntimeMgr) | ||
| genesisStateMock := createMockGenesisState(nil) | ||
| persistenceMock := preparePersistenceMock(t, mockBus, genesisStateMock) | ||
|
|
||
| mockBus.EXPECT(). | ||
| GetPersistenceModule(). | ||
| Return(persistenceMock). | ||
| AnyTimes() | ||
| persistenceMock.EXPECT(). | ||
| GetBus(). | ||
| AnyTimes(). | ||
| Return(mockBus) | ||
| persistenceMock.EXPECT(). | ||
| NewRWContext(int64(0)). | ||
| AnyTimes() | ||
| persistenceMock.EXPECT(). | ||
| GetTxIndexer(). | ||
| AnyTimes() | ||
|
|
||
| treemod, err := trees.Create(mockBus, trees.WithTreeStoreDirectory(":memory:")) | ||
| assert.NoError(t, err) | ||
|
|
||
| got := treemod.GetBus() | ||
| assert.Equal(t, got, mockBus) | ||
|
|
||
| // root hash should be empty for empty tree | ||
| root, ns := treemod.GetTree(trees.TransactionsTreeName) | ||
| require.Equal(t, root, make([]byte, 32)) | ||
|
|
||
| // nodestore should have no values in it | ||
| keys, vals, err := ns.GetAll(nil, false) | ||
| require.NoError(t, err) | ||
| require.Empty(t, keys, vals) | ||
| } | ||
|
|
||
| func TestTreeStore_DebugClearAll(t *testing.T) { | ||
| // TODO: Write test case for the DebugClearAll method | ||
| t.Skip("TODO: Write test case for DebugClearAll method") | ||
| } | ||
|
|
||
| // createMockGenesisState configures and returns a mocked GenesisState | ||
| func createMockGenesisState(valKeys []cryptoPocket.PrivateKey) *genesis.GenesisState { | ||
| genesisState := new(genesis.GenesisState) | ||
| validators := make([]*coreTypes.Actor, len(valKeys)) | ||
| for i, valKey := range valKeys { | ||
| addr := valKey.Address().String() | ||
| mockActor := &coreTypes.Actor{ | ||
| ActorType: coreTypes.ActorType_ACTOR_TYPE_VAL, | ||
| Address: addr, | ||
| PublicKey: valKey.PublicKey().String(), | ||
| ServiceUrl: validatorId(i + 1), | ||
| StakedAmount: test_artifacts.DefaultStakeAmountString, | ||
| PausedHeight: int64(0), | ||
| UnstakingHeight: int64(0), | ||
| Output: addr, | ||
| } | ||
| validators[i] = mockActor | ||
| } | ||
| genesisState.Validators = validators | ||
|
|
||
| return genesisState | ||
| } | ||
|
|
||
| // Persistence mock - only needed for validatorMap access | ||
| func preparePersistenceMock(t *testing.T, busMock *mockModules.MockBus, genesisState *genesis.GenesisState) *mockModules.MockPersistenceModule { | ||
| ctrl := gomock.NewController(t) | ||
|
|
||
| persistenceModuleMock := mockModules.NewMockPersistenceModule(ctrl) | ||
| readCtxMock := mockModules.NewMockPersistenceReadContext(ctrl) | ||
|
|
||
| readCtxMock.EXPECT(). | ||
| GetAllValidators(gomock.Any()). | ||
| Return(genesisState.GetValidators(), nil).AnyTimes() | ||
| readCtxMock.EXPECT(). | ||
| GetAllStakedActors(gomock.Any()). | ||
| DoAndReturn(func(height int64) ([]*coreTypes.Actor, error) { | ||
| return testutil.Concatenate[*coreTypes.Actor]( | ||
| genesisState.GetValidators(), | ||
| genesisState.GetServicers(), | ||
| genesisState.GetFishermen(), | ||
| genesisState.GetApplications(), | ||
| ), nil | ||
| }). | ||
| AnyTimes() | ||
| persistenceModuleMock.EXPECT(). | ||
| NewReadContext(gomock.Any()). | ||
| Return(readCtxMock, nil). | ||
| AnyTimes() | ||
| readCtxMock.EXPECT(). | ||
| Release(). | ||
| AnyTimes() | ||
| persistenceModuleMock.EXPECT(). | ||
| GetBus(). | ||
| Return(busMock). | ||
| AnyTimes() | ||
| persistenceModuleMock.EXPECT(). | ||
| SetBus(busMock). | ||
| AnyTimes() | ||
| persistenceModuleMock.EXPECT(). | ||
| GetModuleName(). | ||
| Return(modules.PersistenceModuleName). | ||
| AnyTimes() | ||
| busMock. | ||
| RegisterModule(persistenceModuleMock) | ||
|
|
||
| return persistenceModuleMock | ||
| } | ||
|
|
||
| func validatorId(i int) string { | ||
| return fmt.Sprintf(serviceURLFormat, i) | ||
| } | ||
|
|
||
| // 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) | ||
| mockModulesRegistry := mockModules.NewMockModulesRegistry(ctrl) | ||
|
|
||
| mockBus.EXPECT(). | ||
| GetRuntimeMgr(). | ||
| Return(runtimeMgr). | ||
| AnyTimes() | ||
| mockBus.EXPECT(). | ||
| RegisterModule(gomock.Any()). | ||
| DoAndReturn(func(m modules.Submodule) { | ||
| m.SetBus(mockBus) | ||
| }). | ||
| AnyTimes() | ||
| mockModulesRegistry.EXPECT(). | ||
| GetModule(peerstore_provider.PeerstoreProviderSubmoduleName). | ||
| Return(nil, runtime.ErrModuleNotRegistered(peerstore_provider.PeerstoreProviderSubmoduleName)). | ||
| AnyTimes() | ||
| mockModulesRegistry.EXPECT(). | ||
| GetModule(modules.CurrentHeightProviderSubmoduleName). | ||
| Return(nil, runtime.ErrModuleNotRegistered(modules.CurrentHeightProviderSubmoduleName)). | ||
| AnyTimes() | ||
| mockBus.EXPECT(). | ||
| GetModulesRegistry(). | ||
| Return(mockModulesRegistry). | ||
| AnyTimes() | ||
| mockBus.EXPECT(). | ||
| PublishEventToBus(gomock.Any()). | ||
| AnyTimes() | ||
|
|
||
| return mockBus | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.