@@ -70,6 +70,7 @@ func (s *Suite) EthTests() []utesting.Test {
70
70
{Name : "Status" , Fn : s .TestStatus },
71
71
// get block headers
72
72
{Name : "GetBlockHeaders" , Fn : s .TestGetBlockHeaders },
73
+ {Name : "GetNonexistentBlockHeaders" , Fn : s .TestGetNonexistentBlockHeaders },
73
74
{Name : "SimultaneousRequests" , Fn : s .TestSimultaneousRequests },
74
75
{Name : "SameRequestID" , Fn : s .TestSameRequestID },
75
76
{Name : "ZeroRequestID" , Fn : s .TestZeroRequestID },
@@ -158,6 +159,56 @@ func (s *Suite) TestGetBlockHeaders(t *utesting.T) {
158
159
}
159
160
}
160
161
162
+ func (s * Suite ) TestGetNonexistentBlockHeaders (t * utesting.T ) {
163
+ t .Log (`This test sends GetBlockHeaders requests for nonexistent blocks (using max uint64 value)
164
+ to check if the node disconnects after receiving multiple invalid requests.` )
165
+
166
+ conn , err := s .dial ()
167
+ if err != nil {
168
+ t .Fatalf ("dial failed: %v" , err )
169
+ }
170
+ defer conn .Close ()
171
+
172
+ if err := conn .peer (s .chain , nil ); err != nil {
173
+ t .Fatalf ("peering failed: %v" , err )
174
+ }
175
+
176
+ // Create request with max uint64 value for a nonexistent block
177
+ badReq := & eth.GetBlockHeadersPacket {
178
+ RequestId : uint64 (1 ),
179
+ GetBlockHeadersRequest : & eth.GetBlockHeadersRequest {
180
+ Origin : eth.HashOrNumber {Number : ^ uint64 (0 )},
181
+ Amount : 1 ,
182
+ Skip : 0 ,
183
+ Reverse : false ,
184
+ },
185
+ }
186
+
187
+ // Send the request 10 times
188
+ for i := 0 ; i < 10 ; i ++ {
189
+ if err := conn .Write (ethProto , eth .GetBlockHeadersMsg , badReq ); err != nil {
190
+ if err == errDisc {
191
+ t .Logf ("peer disconnected after %d requests" , i + 1 )
192
+ return
193
+ }
194
+ t .Fatalf ("write failed: %v" , err )
195
+ }
196
+ time .Sleep (10 * time .Millisecond )
197
+ }
198
+
199
+ // Check if peer disconnects
200
+ code , _ , err := conn .Read ()
201
+ if err == errDisc {
202
+ t .Logf ("peer disconnected after all requests" )
203
+ return
204
+ }
205
+ if code == discMsg {
206
+ t .Logf ("received disconnect message" )
207
+ return
208
+ }
209
+ t .Fatalf ("peer did not disconnect after receiving invalid requests" )
210
+ }
211
+
161
212
func (s * Suite ) TestSimultaneousRequests (t * utesting.T ) {
162
213
t .Log (`This test requests blocks headers from the node, performing two requests
163
214
concurrently, with different request IDs.` )
0 commit comments