Skip to content

tests: implement p2p sync tests #2982

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

rianhughes
Copy link
Contributor

@rianhughes rianhughes commented Jul 14, 2025

This PR implements a test for the P2P sync pkg. The test involves syncing a single empty block from a peer.

Todo: add a non-empty block test

@rianhughes rianhughes force-pushed the rianhughes/p2p-mock branch from a5d2941 to e0b4b25 Compare July 14, 2025 13:38
@rianhughes rianhughes force-pushed the rianhughes/p2p-mock branch from 3cd5b0a to bd5ccfa Compare July 14, 2025 13:40
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.

Project coverage is 72.66%. Comparing base (c303eb1) to head (bd5ccfa).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
p2p/sync/client.go 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2982      +/-   ##
==========================================
+ Coverage   71.77%   72.66%   +0.89%     
==========================================
  Files         267      269       +2     
  Lines       28811    28945     +134     
==========================================
+ Hits        20678    21033     +355     
+ Misses       6737     6474     -263     
- Partials     1396     1438      +42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

time.Sleep(10 * time.Millisecond)
cancel()
}()
sync.Run(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Error is not asserted

Comment on lines +32 to +34
host := mocks.NewMockHost(mockCtrl)
sync := New(bc, host, &utils.Sepolia, utils.NewNopZapLogger())
client := mocks.NewMockClient(mockCtrl)
Copy link
Contributor

@infrmtcs infrmtcs Jul 18, 2025

Choose a reason for hiding this comment

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

I'm strongly against using mock here because by using mock, it means there are a lot of things untested:

  • Non empty blocks.
  • p2p initialization is done correctly, given correct configuration (because host is mocked)
  • Server side: Query from database
  • Server side, client side: Block streaming
  • Server side, client side: Data serialization/deserialization with protobuf

I don't mean to insist that we need to write the tests for all of these above in this PR. What I meant is that instead of using mock here, we can at least have a simple test not using mock but cover most of the cases above. The idea is:

  • Start 2 p2p hosts, connect to each other via libp2p. Examples can be found in consensus tests.
  • One host plays the role of server. Store N blocks to its database.
  • The other host plays the role of client. Run the sync protocol and validate whether it can fetch all N blocks from the server host.
  • Assertions can be done easily but throughly, by verifying whether the stored blocks in client and server databases match exactly.


ctx, cancel := context.WithCancel(t.Context())
go func() {
time.Sleep(10 * time.Millisecond)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use eventually with the assertions below instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants