Skip to content

Commit 0ca4c8b

Browse files
author
sanket1729
committed
Changed functional tests which do not require wallets to run without
skipping .Addreses bitcoin#14216. Changed get_deterministic_priv_key() to a named tuple
1 parent 3832c25 commit 0ca4c8b

22 files changed

+58
-107
lines changed

test/functional/example_test.py

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def set_test_params(self):
8585

8686
# self.log.info("I've finished set_test_params") # Oops! Can't run self.log before run_test()
8787

88+
# Use skip_test_if_missing_module() to skip the test if your test requires certain modules to be present.
89+
# This test uses generate which requires wallet to be compiled
8890
def skip_test_if_missing_module(self):
8991
self.skip_if_no_wallet()
9092

test/functional/feature_block.py

-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ def set_test_params(self):
7575
self.setup_clean_chain = True
7676
self.extra_args = [[]]
7777

78-
def skip_test_if_missing_module(self):
79-
self.skip_if_no_wallet()
80-
8178
def run_test(self):
8279
node = self.nodes[0] # convenience reference to the node
8380

test/functional/feature_blocksdir.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ def set_test_params(self):
1616
self.setup_clean_chain = True
1717
self.num_nodes = 1
1818

19-
def skip_test_if_missing_module(self):
20-
self.skip_if_no_wallet()
21-
2219
def run_test(self):
2320
self.stop_node(0)
2421
shutil.rmtree(self.nodes[0].datadir)
@@ -30,7 +27,7 @@ def run_test(self):
3027
self.log.info("Starting with existing blocksdir ...")
3128
self.start_node(0, ["-blocksdir=" + blocksdir_path])
3229
self.log.info("mining blocks..")
33-
self.nodes[0].generate(10)
30+
self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
3431
assert os.path.isfile(os.path.join(blocksdir_path, "regtest", "blocks", "blk00000.dat"))
3532
assert os.path.isdir(os.path.join(self.nodes[0].datadir, "regtest", "blocks", "index"))
3633

test/functional/feature_logging.py

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ def set_test_params(self):
1515
self.num_nodes = 1
1616
self.setup_clean_chain = True
1717

18-
def skip_test_if_missing_module(self):
19-
self.skip_if_no_wallet()
20-
2118
def relative_log_path(self, name):
2219
return os.path.join(self.nodes[0].datadir, "regtest", name)
2320

test/functional/feature_minchainwork.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ def set_test_params(self):
3131
self.extra_args = [[], ["-minimumchainwork=0x65"], ["-minimumchainwork=0x65"]]
3232
self.node_min_work = [0, 101, 101]
3333

34-
def skip_test_if_missing_module(self):
35-
self.skip_if_no_wallet()
36-
3734
def setup_network(self):
3835
# This test relies on the chain setup being:
3936
# node0 <- node1 <- node2
@@ -54,7 +51,8 @@ def run_test(self):
5451

5552
num_blocks_to_generate = int((self.node_min_work[1] - starting_chain_work) / REGTEST_WORK_PER_BLOCK)
5653
self.log.info("Generating %d blocks on node0", num_blocks_to_generate)
57-
hashes = self.nodes[0].generate(num_blocks_to_generate)
54+
hashes = self.nodes[0].generatetoaddress(num_blocks_to_generate,
55+
self.nodes[0].get_deterministic_priv_key().address)
5856

5957
self.log.info("Node0 current chain work: %s", self.nodes[0].getblockheader(hashes[-1])['chainwork'])
6058

@@ -75,7 +73,7 @@ def run_test(self):
7573
assert_equal(self.nodes[2].getblockcount(), starting_blockcount)
7674

7775
self.log.info("Generating one more block")
78-
self.nodes[0].generate(1)
76+
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
7977

8078
self.log.info("Verifying nodes are all synced")
8179

test/functional/feature_reindex.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ def set_test_params(self):
1818
self.setup_clean_chain = True
1919
self.num_nodes = 1
2020

21-
def skip_test_if_missing_module(self):
22-
self.skip_if_no_wallet()
23-
2421
def reindex(self, justchainstate=False):
25-
self.nodes[0].generate(3)
22+
self.nodes[0].generatetoaddress(3, self.nodes[0].get_deterministic_priv_key().address)
2623
blockcount = self.nodes[0].getblockcount()
2724
self.stop_nodes()
2825
extra_args = [["-reindex-chainstate" if justchainstate else "-reindex"]]

test/functional/feature_versionbits_warning.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ def set_test_params(self):
3131
self.setup_clean_chain = True
3232
self.num_nodes = 1
3333

34-
def skip_test_if_missing_module(self):
35-
self.skip_if_no_wallet()
36-
3734
def setup_network(self):
3835
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
3936
# Open and close to create zero-length file
@@ -68,13 +65,14 @@ def run_test(self):
6865
node = self.nodes[0]
6966
node.add_p2p_connection(P2PInterface())
7067

68+
node_deterministic_address = node.get_deterministic_priv_key().address
7169
# Mine one period worth of blocks
72-
node.generate(VB_PERIOD)
70+
node.generatetoaddress(VB_PERIOD, node_deterministic_address)
7371

7472
self.log.info("Check that there is no warning if previous VB_BLOCKS have <VB_THRESHOLD blocks with unknown versionbits version.")
7573
# Build one period of blocks with < VB_THRESHOLD blocks signaling some unknown bit
7674
self.send_blocks_with_version(node.p2p, VB_THRESHOLD - 1, VB_UNKNOWN_VERSION)
77-
node.generate(VB_PERIOD - VB_THRESHOLD + 1)
75+
node.generatetoaddress(VB_PERIOD - VB_THRESHOLD + 1, node_deterministic_address)
7876

7977
# Check that we're not getting any versionbit-related errors in get*info()
8078
assert(not VB_PATTERN.match(node.getmininginfo()["warnings"]))
@@ -83,7 +81,7 @@ def run_test(self):
8381
self.log.info("Check that there is a warning if >50 blocks in the last 100 were an unknown version")
8482
# Build one period of blocks with VB_THRESHOLD blocks signaling some unknown bit
8583
self.send_blocks_with_version(node.p2p, VB_THRESHOLD, VB_UNKNOWN_VERSION)
86-
node.generate(VB_PERIOD - VB_THRESHOLD)
84+
node.generatetoaddress(VB_PERIOD - VB_THRESHOLD, node_deterministic_address)
8785

8886
# Check that get*info() shows the 51/100 unknown block version error.
8987
assert(WARN_UNKNOWN_RULES_MINED in node.getmininginfo()["warnings"])
@@ -92,16 +90,16 @@ def run_test(self):
9290
self.log.info("Check that there is a warning if previous VB_BLOCKS have >=VB_THRESHOLD blocks with unknown versionbits version.")
9391
# Mine a period worth of expected blocks so the generic block-version warning
9492
# is cleared. This will move the versionbit state to ACTIVE.
95-
node.generate(VB_PERIOD)
93+
node.generatetoaddress(VB_PERIOD, node_deterministic_address)
9694

9795
# Stop-start the node. This is required because bitcoind will only warn once about unknown versions or unknown rules activating.
9896
self.restart_node(0)
9997

10098
# Generating one block guarantees that we'll get out of IBD
101-
node.generate(1)
99+
node.generatetoaddress(1, node_deterministic_address)
102100
wait_until(lambda: not node.getblockchaininfo()['initialblockdownload'], timeout=10, lock=mininode_lock)
103101
# Generating one more block will be enough to generate an error.
104-
node.generate(1)
102+
node.generatetoaddress(1, node_deterministic_address)
105103
# Check that get*info() shows the versionbits unknown rules warning
106104
assert(WARN_UNKNOWN_RULES_ACTIVE in node.getmininginfo()["warnings"])
107105
assert(WARN_UNKNOWN_RULES_ACTIVE in node.getnetworkinfo()["warnings"])

test/functional/mining_basic.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ def set_test_params(self):
3838
self.num_nodes = 2
3939
self.setup_clean_chain = False
4040

41-
def skip_test_if_missing_module(self):
42-
self.skip_if_no_wallet()
43-
4441
def run_test(self):
4542
node = self.nodes[0]
4643

@@ -61,7 +58,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
6158
assert_equal(mining_info['pooledtx'], 0)
6259

6360
# Mine a block to leave initial block download
64-
node.generate(1)
61+
node.generatetoaddress(1, node.get_deterministic_priv_key().address)
6562
tmpl = node.getblocktemplate()
6663
self.log.info("getblocktemplate: Test capability advertised")
6764
assert 'proposal' in tmpl['capabilities']
@@ -212,7 +209,7 @@ def chain_tip(b_hash, *, status='headers-only', branchlen=1):
212209
assert chain_tip(block.hash, status='active', branchlen=0) in node.getchaintips()
213210

214211
# Building a few blocks should give the same results
215-
node.generate(10)
212+
node.generatetoaddress(10, node.get_deterministic_priv_key().address)
216213
assert_raises_rpc_error(-25, 'time-too-old', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block_time).serialize())))
217214
assert_raises_rpc_error(-25, 'bad-prevblk', lambda: node.submitheader(hexdata=b2x(CBlockHeader(bad_block2).serialize())))
218215
node.submitheader(hexdata=b2x(CBlockHeader(block).serialize()))

test/functional/p2p_fingerprint.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ def set_test_params(self):
3030
self.setup_clean_chain = True
3131
self.num_nodes = 1
3232

33-
def skip_test_if_missing_module(self):
34-
self.skip_if_no_wallet()
35-
3633
# Build a chain of blocks on top of given one
3734
def build_chain(self, nblocks, prev_hash, prev_height, prev_median_time):
3835
blocks = []
@@ -83,7 +80,7 @@ def run_test(self):
8380
self.nodes[0].setmocktime(int(time.time()) - 60 * 24 * 60 * 60)
8481

8582
# Generating a chain of 10 blocks
86-
block_hashes = self.nodes[0].generate(nblocks=10)
83+
block_hashes = self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
8784

8885
# Create longer chain starting 2 blocks before current tip
8986
height = len(block_hashes) - 2
@@ -114,7 +111,7 @@ def run_test(self):
114111

115112
# Longest chain is extended so stale is much older than chain tip
116113
self.nodes[0].setmocktime(0)
117-
tip = self.nodes[0].generate(nblocks=1)[0]
114+
tip = self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0]
118115
assert_equal(self.nodes[0].getblockcount(), 14)
119116

120117
# Send getdata & getheaders to refresh last received getheader message

test/functional/p2p_invalid_block.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ def set_test_params(self):
2424
self.setup_clean_chain = True
2525
self.extra_args = [["-whitelist=127.0.0.1"]]
2626

27-
def skip_test_if_missing_module(self):
28-
self.skip_if_no_wallet()
29-
3027
def run_test(self):
3128
# Add p2p connection to node0
3229
node = self.nodes[0] # convenience reference to the node
@@ -48,7 +45,7 @@ def run_test(self):
4845
node.p2p.send_blocks_and_test([block1], node, success=True)
4946

5047
self.log.info("Mature the block.")
51-
node.generate(100)
48+
node.generatetoaddress(100, node.get_deterministic_priv_key().address)
5249

5350
best_block = node.getblock(node.getbestblockhash())
5451
tip = int(node.getbestblockhash(), 16)

test/functional/p2p_invalid_locator.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ def set_test_params(self):
1515
self.num_nodes = 1
1616
self.setup_clean_chain = False
1717

18-
def skip_test_if_missing_module(self):
19-
self.skip_if_no_wallet()
20-
2118
def run_test(self):
2219
node = self.nodes[0] # convenience reference to the node
23-
node.generate(1) # Get node out of IBD
20+
node.generatetoaddress(1, node.get_deterministic_priv_key().address) # Get node out of IBD
2421

2522
self.log.info('Test max locator size')
2623
block_count = node.getblockcount()

test/functional/p2p_invalid_tx.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ def set_test_params(self):
2626
self.num_nodes = 1
2727
self.setup_clean_chain = True
2828

29-
def skip_test_if_missing_module(self):
30-
self.skip_if_no_wallet()
31-
3229
def bootstrap_p2p(self, *, num_connections=1):
3330
"""Add a P2P connection to the node.
3431
@@ -64,7 +61,7 @@ def run_test(self):
6461
node.p2p.send_blocks_and_test([block], node, success=True)
6562

6663
self.log.info("Mature the block.")
67-
self.nodes[0].generate(100)
64+
self.nodes[0].generatetoaddress(100, self.nodes[0].get_deterministic_priv_key().address)
6865

6966
# b'\x64' is OP_NOTIF
7067
# Transaction will be rejected with code 16 (REJECT_INVALID)

test/functional/p2p_leak.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ def set_test_params(self):
9393
self.num_nodes = 1
9494
self.extra_args = [['-banscore=' + str(banscore)]]
9595

96-
def skip_test_if_missing_module(self):
97-
self.skip_if_no_wallet()
98-
9996
def run_test(self):
10097
no_version_bannode = self.nodes[0].add_p2p_connection(CNodeNoVersionBan(), send_version=False, wait_for_verack=False)
10198
no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False)
@@ -106,7 +103,7 @@ def run_test(self):
106103
wait_until(lambda: no_verack_idlenode.version_received, timeout=10, lock=mininode_lock)
107104

108105
# Mine a block and make sure that it's not sent to the connected nodes
109-
self.nodes[0].generate(1)
106+
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
110107

111108
#Give the node enough time to possibly leak out a message
112109
time.sleep(5)

test/functional/p2p_node_network_limited.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ def set_test_params(self):
3434
self.num_nodes = 3
3535
self.extra_args = [['-prune=550', '-addrmantest'], [], []]
3636

37-
def skip_test_if_missing_module(self):
38-
self.skip_if_no_wallet()
39-
4037
def disconnect_all(self):
4138
disconnect_nodes(self.nodes[0], 1)
4239
disconnect_nodes(self.nodes[1], 0)
@@ -62,7 +59,7 @@ def run_test(self):
6259

6360
self.log.info("Mine enough blocks to reach the NODE_NETWORK_LIMITED range.")
6461
connect_nodes_bi(self.nodes, 0, 1)
65-
blocks = self.nodes[1].generate(292)
62+
blocks = self.nodes[1].generatetoaddress(292, self.nodes[1].get_deterministic_priv_key().address)
6663
sync_blocks([self.nodes[0], self.nodes[1]])
6764

6865
self.log.info("Make sure we can max retrieve block at tip-288.")
@@ -105,7 +102,7 @@ def run_test(self):
105102
self.disconnect_all()
106103

107104
# mine 10 blocks on node 0 (pruned node)
108-
self.nodes[0].generate(10)
105+
self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address)
109106

110107
# connect node1 (non pruned) with node0 (pruned) and check if the can sync
111108
connect_nodes_bi(self.nodes, 0, 1)

test/functional/p2p_sendheaders.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,12 @@ def set_test_params(self):
208208
self.setup_clean_chain = True
209209
self.num_nodes = 2
210210

211-
def skip_test_if_missing_module(self):
212-
self.skip_if_no_wallet()
213-
214211
def mine_blocks(self, count):
215212
"""Mine count blocks and return the new tip."""
216213

217214
# Clear out block announcements from each p2p listener
218215
[x.clear_block_announcements() for x in self.nodes[0].p2ps]
219-
self.nodes[0].generate(count)
216+
self.nodes[0].generatetoaddress(count, self.nodes[0].get_deterministic_priv_key().address)
220217
return int(self.nodes[0].getbestblockhash(), 16)
221218

222219
def mine_reorg(self, length):
@@ -226,7 +223,8 @@ def mine_reorg(self, length):
226223
to-be-reorged-out blocks are mined, so that we don't break later tests.
227224
return the list of block hashes newly mined."""
228225

229-
self.nodes[0].generate(length) # make sure all invalidated blocks are node0's
226+
# make sure all invalidated blocks are node0's
227+
self.nodes[0].generatetoaddress(length, self.nodes[0].get_deterministic_priv_key().address)
230228
sync_blocks(self.nodes, wait=0.1)
231229
for x in self.nodes[0].p2ps:
232230
x.wait_for_block_announcement(int(self.nodes[0].getbestblockhash(), 16))
@@ -235,7 +233,7 @@ def mine_reorg(self, length):
235233
tip_height = self.nodes[1].getblockcount()
236234
hash_to_invalidate = self.nodes[1].getblockhash(tip_height - (length - 1))
237235
self.nodes[1].invalidateblock(hash_to_invalidate)
238-
all_hashes = self.nodes[1].generate(length + 1) # Must be longer than the orig chain
236+
all_hashes = self.nodes[1].generatetoaddress(length + 1, self.nodes[1].get_deterministic_priv_key().address) # Must be longer than the orig chain
239237
sync_blocks(self.nodes, wait=0.1)
240238
return [int(x, 16) for x in all_hashes]
241239

@@ -254,7 +252,7 @@ def run_test(self):
254252
self.test_nonnull_locators(test_node, inv_node)
255253

256254
def test_null_locators(self, test_node, inv_node):
257-
tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0])
255+
tip = self.nodes[0].getblockheader(self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)[0])
258256
tip_hash = int(tip["hash"], 16)
259257

260258
inv_node.check_last_inv_announcement(inv=[tip_hash])

test/functional/p2p_unrequested_blocks.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ def set_test_params(self):
6666
self.num_nodes = 2
6767
self.extra_args = [[], ["-minimumchainwork=0x10"]]
6868

69-
def skip_test_if_missing_module(self):
70-
self.skip_if_no_wallet()
71-
7269
def setup_network(self):
7370
# Node0 will be used to test behavior of processing unrequested blocks
7471
# from peers which are not whitelisted, while Node1 will be used for
@@ -85,8 +82,8 @@ def run_test(self):
8582
min_work_node = self.nodes[1].add_p2p_connection(P2PInterface())
8683

8784
# 1. Have nodes mine a block (leave IBD)
88-
[ n.generate(1) for n in self.nodes ]
89-
tips = [ int("0x" + n.getbestblockhash(), 0) for n in self.nodes ]
85+
[n.generatetoaddress(1, n.get_deterministic_priv_key().address) for n in self.nodes]
86+
tips = [int("0x" + n.getbestblockhash(), 0) for n in self.nodes]
9087

9188
# 2. Send one block that builds on each tip.
9289
# This should be accepted by node0

test/functional/rpc_blockchain.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ class BlockchainTest(BitcoinTestFramework):
4848
def set_test_params(self):
4949
self.num_nodes = 1
5050

51-
def skip_test_if_missing_module(self):
52-
self.skip_if_no_wallet()
53-
5451
def run_test(self):
5552
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) # Set extra args with pruning after rescan is complete
5653

@@ -242,12 +239,12 @@ def _test_getnetworkhashps(self):
242239

243240
def _test_stopatheight(self):
244241
assert_equal(self.nodes[0].getblockcount(), 200)
245-
self.nodes[0].generate(6)
242+
self.nodes[0].generatetoaddress(6, self.nodes[0].get_deterministic_priv_key().address)
246243
assert_equal(self.nodes[0].getblockcount(), 206)
247244
self.log.debug('Node should not stop at this height')
248245
assert_raises(subprocess.TimeoutExpired, lambda: self.nodes[0].process.wait(timeout=3))
249246
try:
250-
self.nodes[0].generate(1)
247+
self.nodes[0].generatetoaddress(1, self.nodes[0].get_deterministic_priv_key().address)
251248
except (ConnectionError, http.client.BadStatusLine):
252249
pass # The node already shut down before response
253250
self.log.debug('Node should stop at this height...')

0 commit comments

Comments
 (0)