Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-get-invalid-block.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2019 The Bitcoin developers | # Copyright (c) 2019 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test requesting invalid blocks behaves safely.""" | """Test requesting invalid blocks behaves safely.""" | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CInv, | CInv, | ||||
msg_getblocks, | msg_getblocks, | ||||
msg_getdata, | msg_getdata, | ||||
msg_getheaders, | msg_getheaders, | ||||
MSG_BLOCK, | MSG_BLOCK, | ||||
MSG_CMPCTBLOCK, | MSG_CMPCT_BLOCK, | ||||
) | ) | ||||
from test_framework.mininode import mininode_lock, P2PInterface | from test_framework.mininode import mininode_lock, P2PInterface | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal | ||||
class GetInvalidBlockTest(BitcoinTestFramework): | class GetInvalidBlockTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
Show All 34 Lines | def run_test(self): | ||||
with node.assert_debug_log(expected_msgs=["ignoring request from peer=0 for old block that isn't in the main chain"]): | with node.assert_debug_log(expected_msgs=["ignoring request from peer=0 for old block that isn't in the main chain"]): | ||||
msg = msg_getdata() | msg = msg_getdata() | ||||
msg.inv.append(CInv(MSG_BLOCK, block_hash)) | msg.inv.append(CInv(MSG_BLOCK, block_hash)) | ||||
node.p2p.send_message(msg) | node.p2p.send_message(msg) | ||||
node.p2p.sync_with_ping() | node.p2p.sync_with_ping() | ||||
with node.assert_debug_log(expected_msgs=["ignoring request from peer=0 for old block that isn't in the main chain"]): | with node.assert_debug_log(expected_msgs=["ignoring request from peer=0 for old block that isn't in the main chain"]): | ||||
msg = msg_getdata() | msg = msg_getdata() | ||||
msg.inv.append(CInv(MSG_CMPCTBLOCK, block_hash)) | msg.inv.append(CInv(MSG_CMPCT_BLOCK, block_hash)) | ||||
node.p2p.send_message(msg) | node.p2p.send_message(msg) | ||||
node.p2p.sync_with_ping() | node.p2p.sync_with_ping() | ||||
with node.assert_debug_log(expected_msgs=["ignoring request from peer=0 for old block header that isn't in the main chain"]): | with node.assert_debug_log(expected_msgs=["ignoring request from peer=0 for old block header that isn't in the main chain"]): | ||||
msg = msg_getheaders() | msg = msg_getheaders() | ||||
msg.hashstop = block_hash | msg.hashstop = block_hash | ||||
node.p2p.send_message(msg) | node.p2p.send_message(msg) | ||||
node.p2p.sync_with_ping() | node.p2p.sync_with_ping() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
GetInvalidBlockTest().main() | GetInvalidBlockTest().main() |