Skip to content
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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions fraud/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]
Copy link
Member

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

Copy link
Contributor Author

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 mockStore

p.s. My knowledge of GO isn't deep, so if I sound too naive, I can skip this problem and take on another one 🙂

Copy link
Member

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 in libs/header/mocks/store.go if they are necessary/useful :) So no need to alias the type here. We'd like to keep MockStore and all its methods within the scope of the libs/header/mocks package anyway.

Copy link
Member

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!

Copy link
Contributor Author

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. 🙂


// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use mocks.NewStore instead. It already implements header gen, when testsuite is passed to it as Generator.

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 }
Expand Down