add tests for node data request

pull/4465/head
“GheisMohammadi” 1 year ago
parent 8d66bdf078
commit 917a3019e2
No known key found for this signature in database
GPG Key ID: 15073AED3829FE90
  1. 25
      p2p/stream/protocols/sync/stream_test.go

@ -51,14 +51,14 @@ var (
testGetReceiptsRequest = syncpb.MakeGetReceiptsRequest(testGetReceipts)
testGetReceiptsRequestMsg = syncpb.MakeMessageFromRequest(testGetReceiptsRequest)
testGetNodeData = []common.Hash{
testGetNodes = []common.Hash{
numberToHash(1),
numberToHash(2),
numberToHash(3),
numberToHash(4),
numberToHash(5),
}
testGetNodeDataRequest = syncpb.MakeGetNodeDataRequest(testGetNodeData)
testGetNodeDataRequest = syncpb.MakeGetNodeDataRequest(testGetNodes)
testGetNodeDataRequestMsg = syncpb.MakeMessageFromRequest(testGetNodeDataRequest)
maxBytes = uint64(500)
@ -296,6 +296,27 @@ func TestSyncStream_HandleGetTrieNodes(t *testing.T) {
}
}
func TestSyncStream_HandleGetNodeData(t *testing.T) {
st, remoteSt := makeTestSyncStream()
go st.run()
defer close(st.closeC)
req := testGetNodeDataRequestMsg
b, _ := protobuf.Marshal(req)
err := remoteSt.WriteBytes(b)
if err != nil {
t.Fatal(err)
}
time.Sleep(200 * time.Millisecond)
receivedBytes, _ := remoteSt.ReadBytes()
if err := checkGetNodeDataResult(receivedBytes, testGetBlockByHashes); err != nil {
t.Fatal(err)
}
}
func makeTestSyncStream() (*syncStream, *testRemoteBaseStream) {
localRaw, remoteRaw := makePairP2PStreams()
remote := newTestRemoteBaseStream(remoteRaw)

Loading…
Cancel
Save