5
5
"""Test the getblockfrompeer RPC."""
6
6
7
7
from test_framework .authproxy import JSONRPCException
8
+ from test_framework .messages import NODE_WITNESS
9
+ from test_framework .p2p import (
10
+ P2P_SERVICES ,
11
+ P2PInterface ,
12
+ )
8
13
from test_framework .test_framework import BitcoinTestFramework
9
14
from test_framework .util import (
10
15
assert_equal ,
@@ -58,6 +63,13 @@ def run_test(self):
58
63
self .log .info ("Non-existent peer generates error" )
59
64
assert_raises_rpc_error (- 1 , "Peer does not exist" , self .nodes [0 ].getblockfrompeer , short_tip , peer_0_peer_1_id + 1 )
60
65
66
+ self .log .info ("Fetching from pre-segwit peer generates error" )
67
+ self .nodes [0 ].add_p2p_connection (P2PInterface (), services = P2P_SERVICES & ~ NODE_WITNESS )
68
+ peers = self .nodes [0 ].getpeerinfo ()
69
+ assert_equal (len (peers ), 2 )
70
+ presegwit_peer_id = peers [1 ]["id" ]
71
+ assert_raises_rpc_error (- 1 , "Pre-SegWit peer" , self .nodes [0 ].getblockfrompeer , short_tip , presegwit_peer_id )
72
+
61
73
self .log .info ("Successful fetch" )
62
74
result = self .nodes [0 ].getblockfrompeer (short_tip , peer_0_peer_1_id )
63
75
self .wait_until (lambda : self .check_for_block (short_tip ), timeout = 1 )
@@ -66,5 +78,6 @@ def run_test(self):
66
78
self .log .info ("Don't fetch blocks we already have" )
67
79
assert_raises_rpc_error (- 1 , "Block already downloaded" , self .nodes [0 ].getblockfrompeer , short_tip , peer_0_peer_1_id )
68
80
81
+
69
82
if __name__ == '__main__' :
70
83
GetBlockFromPeerTest ().main ()
0 commit comments