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

Conversation

richardgreg
Copy link
Contributor

This change modifies the test file in the fraud pkg to make use of mockStore in libs/header/mocks.

Fixes: #1542

Signed-off-by: Richard Gregory richardgrecoson@gmail.com

Overview

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

This change modifies the test file in the fraud pkg to make use of
mockStore in libs/header/mocks.

Fixes: celestiaorg#1542

Signed-off-by: Richard Gregory <richardgrecoson@gmail.com>
@richardgreg
Copy link
Contributor Author

It was meant to be a straightforward modification, but a new change made it a little complicated, at least for me.

There are now two different header packages: celestia-node/libs/header and celestia-node/header
mockStore lives in /libs/header/mocks.

getter headerFetcher param in func NewProofService only accepts type header.ExtendedHeader.

@richardgreg
Copy link
Contributor Author

@distractedm1nd do you understand the issue I explained in the comments?

Copy link
Member

@Wondertan Wondertan left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this,@richardgreg, and sorry that it took us so much time to get here.

Also lint is broken + needs rebase

Comment on lines 45 to 59
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()
}
}
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.

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

@Wondertan
Copy link
Member

@richardgreg, gentle ping

@richardgreg
Copy link
Contributor Author

Hi @Wondertan, still here. I got your feedback; I'll update you tomorrow :)

@Wondertan
Copy link
Member

@richardgreg, gentle nudge

@richardgreg
Copy link
Contributor Author

Hi @Wondertan, I added a response here 3 days ago. Can I close this so someone else can work on it?

@renaynay renaynay added area:fraud kind:testing Related to unit tests kind:refactor Attached to refactoring PRs labels Mar 20, 2023
@Wondertan
Copy link
Member

Closing as it's now fixed by #2039

@Wondertan Wondertan closed this Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:fraud area:header Extended header kind:refactor Attached to refactoring PRs kind:testing Related to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fraud: use header/mocks.Store instead of custom mockStore
4 participants