diff options
author | Suhas Daftuar <sdaftuar@gmail.com> | 2022-01-26 19:18:27 -0500 |
---|---|---|
committer | Suhas Daftuar <sdaftuar@gmail.com> | 2022-02-22 11:34:05 -0500 |
commit | a35f963edf1a14ee572abea106fb0147575e4694 (patch) | |
tree | 4a0037170d2288d5203cd74ca547036df2c92e27 /test | |
parent | ef6dbe6863d92710fd2da7781e5b2aac87578751 (diff) | |
download | bitcoin-a35f963edf1a14ee572abea106fb0147575e4694.tar.xz |
Add test for getheaders behavior
Expect responses to a getheaders iff the node has a chain with more than nMinimumChainWork
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/feature_minchainwork.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/functional/feature_minchainwork.py b/test/functional/feature_minchainwork.py index 489a729cfc..f6432ed20e 100755 --- a/test/functional/feature_minchainwork.py +++ b/test/functional/feature_minchainwork.py @@ -17,6 +17,7 @@ only succeeds past a given node once its nMinimumChainWork has been exceeded. import time +from test_framework.p2p import P2PInterface, msg_getheaders from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal @@ -41,6 +42,9 @@ class MinimumChainWorkTest(BitcoinTestFramework): for i in range(self.num_nodes-1): self.connect_nodes(i+1, i) + # Set clock of node2 2 days ahead, to keep it in IBD during this test. + self.nodes[2].setmocktime(int(time.time()) + 48*60*60) + def run_test(self): # Start building a chain on node0. node2 shouldn't be able to sync until node1's # minchainwork is exceeded @@ -71,6 +75,15 @@ class MinimumChainWorkTest(BitcoinTestFramework): assert self.nodes[1].getbestblockhash() != self.nodes[0].getbestblockhash() assert_equal(self.nodes[2].getblockcount(), starting_blockcount) + self.log.info("Check that getheaders requests to node2 are ignored") + peer = self.nodes[2].add_p2p_connection(P2PInterface()) + msg = msg_getheaders() + msg.locator.vHave = [int(self.nodes[2].getbestblockhash(), 16)] + msg.hashstop = 0 + peer.send_and_ping(msg) + time.sleep(5) + assert "headers" not in peer.last_message + self.log.info("Generating one more block") self.generate(self.nodes[0], 1) @@ -85,5 +98,13 @@ class MinimumChainWorkTest(BitcoinTestFramework): self.sync_all() self.log.info(f"Blockcounts: {[n.getblockcount() for n in self.nodes]}") + self.log.info("Test that getheaders requests to node2 are not ignored") + peer.send_and_ping(msg) + assert "headers" in peer.last_message + + # Verify that node2 is in fact still in IBD (otherwise this test may + # not be exercising the logic we want!) + assert_equal(self.nodes[2].getblockchaininfo()['initialblockdownload'], True) + if __name__ == '__main__': MinimumChainWorkTest().main() |