-
Notifications
You must be signed in to change notification settings - Fork 900
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
[WIP]fraud/testing: Use header/mocks.Store instead of custom mockStore #1674
Closed
richardgreg
wants to merge
1
commit into
celestiaorg:main
from
richardgreg:header.mocks.mockStore-usage
Closed
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -16,6 +16,8 @@ import ( | |
|
||
"github.com/celestiaorg/celestia-node/header" | ||
"github.com/celestiaorg/celestia-node/headertest" | ||
libheader "github.com/celestiaorg/celestia-node/libs/header" | ||
mockstore "github.com/celestiaorg/celestia-node/libs/header/mocks" | ||
) | ||
|
||
type DummyService struct { | ||
|
@@ -33,34 +35,33 @@ func (d *DummyService) Get(context.Context, ProofType) ([]Proof, error) { | |
return nil, nil | ||
} | ||
|
||
type mockStore struct { | ||
headers map[int64]*header.ExtendedHeader | ||
headHeight int64 | ||
} | ||
type H libheader.Header | ||
|
||
type mockStore mockstore.MockStore[H] | ||
|
||
// createStore creates a mock store and adds several random | ||
// headers. | ||
func createStore(t *testing.T, numHeaders int) *mockStore { | ||
store := &mockStore{ | ||
headers: make(map[int64]*header.ExtendedHeader), | ||
headHeight: 0, | ||
Headers: make(map[int64]H), | ||
HeadHeight: 0, | ||
} | ||
|
||
suite := headertest.NewTestSuite(t, numHeaders) | ||
|
||
for i := 0; i < numHeaders; i++ { | ||
header := suite.GenExtendedHeader() | ||
store.headers[header.Height()] = header | ||
store.Headers[header.Height()] = header | ||
|
||
if header.Height() > store.headHeight { | ||
store.headHeight = header.Height() | ||
if header.Height() > store.HeadHeight { | ||
store.HeadHeight = header.Height() | ||
} | ||
} | ||
Comment on lines
45
to
59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use |
||
return store | ||
} | ||
|
||
func (m *mockStore) GetByHeight(_ context.Context, height uint64) (*header.ExtendedHeader, error) { | ||
return m.headers[int64(height)], nil | ||
func (m *mockStore) GetByHeight(_ context.Context, height uint64) (H, error) { | ||
return m.Headers[int64(height)], nil | ||
} | ||
|
||
func (m *mockStore) Close() error { return nil } | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to define another type can use MockStore directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we wouldn't be able to define methods on them; at least, that's the error I get when I call
headerMock.MockStore
instead of the custom mockStorep.s. My knowledge of GO isn't deep, so if I sound too naive, I can skip this problem and take on another one 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @richardgreg no worries! If you want to define additional methods on
MockStore
, you are welcome to add them inlibs/header/mocks/store.go
if they are necessary/useful :) So no need to alias the type here. We'd like to keepMockStore
and all its methods within the scope of thelibs/header/mocks
package anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @richardgreg are you still working on this? If not, we can take it over no problem!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @renaynay, I kept running into dead ends when attempting to fix this. It's evident I need to improve my GO skills. Yeah, you can take it over. 🙂