aboutsummaryrefslogtreecommitdiffstats
path: root/eth/handler_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-12-16 01:22:48 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-12-16 14:44:13 +0800
commite51eeb81044c5cfc9416da4edce6da25b90acdb3 (patch)
treed81e91ce90b50cbc764ffc59e349f6e8785baad4 /eth/handler_test.go
parentb9aedeab0b1cf56860f5ca53333a4f348395259c (diff)
downloaddexon-e51eeb81044c5cfc9416da4edce6da25b90acdb3.tar.gz
dexon-e51eeb81044c5cfc9416da4edce6da25b90acdb3.tar.zst
dexon-e51eeb81044c5cfc9416da4edce6da25b90acdb3.zip
eth: fix #2076, where end of hash query was interpreted number query
Diffstat (limited to 'eth/handler_test.go')
-rw-r--r--eth/handler_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/eth/handler_test.go b/eth/handler_test.go
index ab2ce54b1..148d56cc6 100644
--- a/eth/handler_test.go
+++ b/eth/handler_test.go
@@ -301,6 +301,15 @@ func testGetBlockHeaders(t *testing.T, protocol int) {
pm.blockchain.GetBlockByNumber(1).Hash(),
},
},
+ // Check a corner case where requesting more can iterate past the endpoints
+ {
+ &getBlockHeadersData{Origin: hashOrNumber{Number: 2}, Amount: 5, Reverse: true},
+ []common.Hash{
+ pm.blockchain.GetBlockByNumber(2).Hash(),
+ pm.blockchain.GetBlockByNumber(1).Hash(),
+ pm.blockchain.GetBlockByNumber(0).Hash(),
+ },
+ },
// Check that non existing headers aren't returned
{
&getBlockHeadersData{Origin: hashOrNumber{Hash: unknown}, Amount: 1},
@@ -322,6 +331,17 @@ func testGetBlockHeaders(t *testing.T, protocol int) {
if err := p2p.ExpectMsg(peer.app, 0x04, headers); err != nil {
t.Errorf("test %d: headers mismatch: %v", i, err)
}
+ // If the test used number origins, repeat with hashes as the too
+ if tt.query.Origin.Hash == (common.Hash{}) {
+ if origin := pm.blockchain.GetBlockByNumber(tt.query.Origin.Number); origin != nil {
+ tt.query.Origin.Hash, tt.query.Origin.Number = origin.Hash(), 0
+
+ p2p.Send(peer.app, 0x03, tt.query)
+ if err := p2p.ExpectMsg(peer.app, 0x04, headers); err != nil {
+ t.Errorf("test %d: headers mismatch: %v", i, err)
+ }
+ }
+ }
}
}