-
Notifications
You must be signed in to change notification settings - Fork 214
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
base: main
Are you sure you want to change the base?
Conversation
a5d2941
to
e0b4b25
Compare
3cd5b0a
to
bd5ccfa
Compare
Codecov ReportAttention: Patch coverage is
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. 🚀 New features to boost your workflow:
|
time.Sleep(10 * time.Millisecond) | ||
cancel() | ||
}() | ||
sync.Run(ctx) |
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.
Error is not asserted
host := mocks.NewMockHost(mockCtrl) | ||
sync := New(bc, host, &utils.Sepolia, utils.NewNopZapLogger()) | ||
client := mocks.NewMockClient(mockCtrl) |
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.
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) |
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 should use eventually
with the assertions below instead.
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