mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
test: remove last_{block,header}_equals() in p2p_fingerprint.py
Testing that requests to very old blocks / block headers fail can simply be done by checking that the node doesn't respond with any "blocks" / "headers" message at all. Also removes unnecessary sending of block/header requests and replaces time.sleep(3) with node0.sync_with_ping().
This commit is contained in:
parent
136d96b71f
commit
6b56c1f4d0
1 changed files with 10 additions and 22 deletions
|
@ -18,6 +18,7 @@ from test_framework.p2p import (
|
||||||
msg_block,
|
msg_block,
|
||||||
msg_getdata,
|
msg_getdata,
|
||||||
msg_getheaders,
|
msg_getheaders,
|
||||||
|
p2p_lock,
|
||||||
)
|
)
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import (
|
from test_framework.util import (
|
||||||
|
@ -57,18 +58,6 @@ class P2PFingerprintTest(BitcoinTestFramework):
|
||||||
msg.hashstop = block_hash
|
msg.hashstop = block_hash
|
||||||
node.send_message(msg)
|
node.send_message(msg)
|
||||||
|
|
||||||
# Check whether last block received from node has a given hash
|
|
||||||
def last_block_equals(self, expected_hash, node):
|
|
||||||
block_msg = node.last_message.get("block")
|
|
||||||
return block_msg and block_msg.block.rehash() == expected_hash
|
|
||||||
|
|
||||||
# Check whether last block header received from node has a given hash
|
|
||||||
def last_header_equals(self, expected_hash, node):
|
|
||||||
headers_msg = node.last_message.get("headers")
|
|
||||||
return (headers_msg and
|
|
||||||
headers_msg.headers and
|
|
||||||
headers_msg.headers[0].rehash() == expected_hash)
|
|
||||||
|
|
||||||
# Checks that stale blocks timestamped more than a month ago are not served
|
# Checks that stale blocks timestamped more than a month ago are not served
|
||||||
# by the node while recent stale blocks and old active chain blocks are.
|
# by the node while recent stale blocks and old active chain blocks are.
|
||||||
# This does not currently test that stale blocks timestamped within the
|
# This does not currently test that stale blocks timestamped within the
|
||||||
|
@ -109,24 +98,23 @@ class P2PFingerprintTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Longest chain is extended so stale is much older than chain tip
|
# Longest chain is extended so stale is much older than chain tip
|
||||||
self.nodes[0].setmocktime(0)
|
self.nodes[0].setmocktime(0)
|
||||||
tip = self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0]
|
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
|
||||||
assert_equal(self.nodes[0].getblockcount(), 14)
|
assert_equal(self.nodes[0].getblockcount(), 14)
|
||||||
|
|
||||||
# Send getdata & getheaders to refresh last received getheader message
|
|
||||||
block_hash = int(tip, 16)
|
|
||||||
self.send_block_request(block_hash, node0)
|
|
||||||
self.send_header_request(block_hash, node0)
|
|
||||||
node0.sync_with_ping()
|
node0.sync_with_ping()
|
||||||
|
|
||||||
# Request for very old stale block should now fail
|
# Request for very old stale block should now fail
|
||||||
|
with p2p_lock:
|
||||||
|
node0.last_message.pop("block", None)
|
||||||
self.send_block_request(stale_hash, node0)
|
self.send_block_request(stale_hash, node0)
|
||||||
time.sleep(3)
|
node0.sync_with_ping()
|
||||||
assert not self.last_block_equals(stale_hash, node0)
|
assert "block" not in node0.last_message
|
||||||
|
|
||||||
# Request for very old stale block header should now fail
|
# Request for very old stale block header should now fail
|
||||||
|
with p2p_lock:
|
||||||
|
node0.last_message.pop("headers", None)
|
||||||
self.send_header_request(stale_hash, node0)
|
self.send_header_request(stale_hash, node0)
|
||||||
time.sleep(3)
|
node0.sync_with_ping()
|
||||||
assert not self.last_header_equals(stale_hash, node0)
|
assert "headers" not in node0.last_message
|
||||||
|
|
||||||
# Verify we can fetch very old blocks and headers on the active chain
|
# Verify we can fetch very old blocks and headers on the active chain
|
||||||
block_hash = int(block_hashes[2], 16)
|
block_hash = int(block_hashes[2], 16)
|
||||||
|
|
Loading…
Reference in a new issue