Suhas wrote this test to demonstrate a bug in invalidateblock back in 2015, and at some point between then and now it started passing, so best to just merge it so we don’t regress.
Closes #5806 (the original issue in which this test was written)
Suhas wrote this test to demonstrate a bug in invalidateblock back in 2015, and at some point between then and now it started passing, so best to just merge it so we don’t regress.
Closes #5806 (the original issue in which this test was written)
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
0@@ -0,0 +1,48 @@
1+#!/usr/bin/env python3
2+# Copyright (c) 2014 The Bitcoin Core developers
3+# Distributed under the MIT software license, see the accompanying
4+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+#
7+# Test invalidateblock
11+
12+class InvalidateBlockTest(BitcoinTestFramework):
13+ def set_test_params(self):
14+ self.num_nodes = 2
15+ self.setup_clean_chain = True
16+ self.extra_args = [['-debug', '-whitelist=127.0.0.1'],['-debug', '-whitelist=127.0.0.1']]
why -debug
? It’s on by default.
Please comment why -whitelist
is required
0@@ -0,0 +1,48 @@
1+#!/usr/bin/env python3
2+# Copyright (c) 2014 The Bitcoin Core developers
3+# Distributed under the MIT software license, see the accompanying
4+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+#
31+ self.nodes[1].invalidateblock(node1blocks[0])
32+
33+ if (self.nodes[0].getblockcount() != cnt):
34+ raise AssertionError("Failed to invalidate initial blocks")
35+
36+ # The test framework is a little dense wrt mining on nodes without wallets -
This comment is wrong. All nodes will generate to a deterministic address (whether wallet is enabled or not).
Other ways to achieve this:
sleep(1)
to get a new timestamp (and hence new block hash)setmocktime()
to get a new timestamp (and hence new block hash)~ probably not a good idea if you’re testing p2p behaviour.It’s not dense. It’s how we get tests to work with wallet enabled and disabled.
Can you remove the incorrect comment please?
Suhas wrote this test to demonstrate a bug in invalidateblock back
in 2015, and at some point between then and now it started passing,
so best to just merge it so we don't regress.
Closes #5806 (the original issue in which this test was written)
32+
33+ if (self.nodes[0].getblockcount() != cnt):
34+ raise AssertionError("Failed to invalidate initial blocks")
35+
36+ # The test framework uses a static per-node address which will generate
37+ # a deterministic block if we have no wallet.
generate
in the functional test framework will generate blocks to a hardcoded address.
11+
12+class InvalidateBlockTest(BitcoinTestFramework):
13+ def set_test_params(self):
14+ self.num_nodes = 2
15+ self.setup_clean_chain = True
16+ self.extra_args = [[],[]]
37+ # a deterministic block if we have no wallet.
38+ # Instead, mine on nodes[0], which will use a different hardcoded address
39+ # than the one we previously used, making this block unique.
40+ self.nodes[0].generate(17)
41+
42+ print("All blocks generated, trying to sync")
self.log.info()
rather than print
10+from test_framework.test_framework import BitcoinTestFramework
11+
12+class InvalidateBlockTest(BitcoinTestFramework):
13+ def set_test_params(self):
14+ self.num_nodes = 2
15+ self.setup_clean_chain = True
If you remove this line, you can also remove the following lines from run_test
:
0 self.nodes[0].generate(1) # Leave IBD
1 self.sync_all()
The test will run more quickly and it’ll be clearer to readers what the test is for.
🐙 This pull request conflicts with the target branch and needs rebase.