Skip to content

Commit 4901c00

Browse files
author
MarcoFalke
committed
Merge #14236: qa: generate --> generatetoaddress change to allow tests run without wallet
0ca4c8b Changed functional tests which do not require wallets to run without (sanket1729) Pull request description: Addresses #14216 . Changed Changed `get_deterministic_priv_key()` to return named tuple`(address, key)` I have tried to be exhaustive as possible in maximum coverage for non-wallet mode without affecting any coverage for wallet mode. However, I could not check the tests in wallet mode because of timeout issues. Hopefully, travis job checks those. Tests `feature_block.py`, `feature_logging.py` and `feature_reindex.py` were skipping despite having no direct dependency on any wallet functions. So, I have also disabled the `skip_test_no_wallet()` for those files too. Tree-SHA512: 8f84bd8400a732d4266c7518d5cbcf1eb761f623a64a74849e0470142c8ef22cb75364474ddae75d9213c3d16659a52917b5ed979a313695da6abd16c4fd7445
2 parents 2d4749b + 0ca4c8b commit 4901c00

22 files changed

+58
-107
lines changed

test/functional/example_test.py

Lines changed: 2 additions & 0 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 7 additions & 9 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 1 addition & 4 deletions
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)

0 commit comments

Comments
 (0)