Skip to content

Commit c269209

Browse files
committed
[tests] Small fixups before deprecating generate
In advance of deprecating the generate RPC method, make some small changes to a small number of inidividual test cases: - make memory checking less prescriptive in wallet_basic.py - replace calls to generate with generatetoaddress in wallet_keypool.py - replace calls to generate with generatetoaddress and fixup label issues in wallet_labels.py - replace calls to generate with generatetoaddress in wallet_multiwallet.py
1 parent be99270 commit c269209

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

test/functional/wallet_basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
assert_array_result,
1212
assert_equal,
1313
assert_fee_amount,
14+
assert_greater_than,
1415
assert_raises_rpc_error,
1516
connect_nodes_bi,
1617
sync_blocks,
@@ -92,13 +93,13 @@ def run_test(self):
9293
assert_equal(txout['value'], 50)
9394

9495
# Send 21 BTC from 0 to 2 using sendtoaddress call.
95-
# Locked memory should use at least 32 bytes to sign each transaction
96+
# Locked memory should increase to sign transactions
9697
self.log.info("test getmemoryinfo")
9798
memory_before = self.nodes[0].getmemoryinfo()
9899
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
99100
mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
100101
memory_after = self.nodes[0].getmemoryinfo()
101-
assert(memory_before['locked']['used'] + 64 <= memory_after['locked']['used'])
102+
assert_greater_than(memory_after['locked']['used'], memory_before['locked']['used'])
102103

103104
self.log.info("test gettxout (second part)")
104105
# utxo spent in mempool should be visible if you exclude mempool

test/functional/wallet_keypool.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ def run_test(self):
7373
time.sleep(1.1)
7474
assert_equal(nodes[0].getwalletinfo()["unlocked_until"], 0)
7575

76-
# drain them by mining
77-
nodes[0].generate(1)
78-
nodes[0].generate(1)
79-
nodes[0].generate(1)
80-
assert_raises_rpc_error(-12, "Keypool ran out", nodes[0].generate, 1)
76+
# drain the keypool
77+
for _ in range(3):
78+
nodes[0].getnewaddress()
79+
assert_raises_rpc_error(-12, "Keypool ran out", nodes[0].getnewaddress)
8180

8281
nodes[0].walletpassphrase('test', 100)
8382
nodes[0].keypoolrefill(100)

test/functional/wallet_labels.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def run_test(self):
2929

3030
# Note each time we call generate, all generated coins go into
3131
# the same address, so we call twice to get two addresses w/50 each
32-
node.generate(1)
33-
node.generate(101)
32+
node.generatetoaddress(nblocks=1, address=node.getnewaddress(label='coinbase'))
33+
node.generatetoaddress(nblocks=101, address=node.getnewaddress(label='coinbase'))
3434
assert_equal(node.getbalance(), 100)
3535

3636
# there should be 2 address groups
@@ -42,8 +42,9 @@ def run_test(self):
4242
linked_addresses = set()
4343
for address_group in address_groups:
4444
assert_equal(len(address_group), 1)
45-
assert_equal(len(address_group[0]), 2)
45+
assert_equal(len(address_group[0]), 3)
4646
assert_equal(address_group[0][1], 50)
47+
assert_equal(address_group[0][2], 'coinbase')
4748
linked_addresses.add(address_group[0][0])
4849

4950
# send 50 from each address to a third address not in this wallet
@@ -77,7 +78,7 @@ def run_test(self):
7778
label.verify(node)
7879

7980
# Check all labels are returned by listlabels.
80-
assert_equal(node.listlabels(), [label.name for label in labels])
81+
assert_equal(node.listlabels(), sorted(['coinbase'] + [label.name for label in labels]))
8182

8283
# Send a transaction to each label.
8384
for label in labels:

test/functional/wallet_multiwallet.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def wallet_file(name):
125125
self.start_node(0, ['-wallet=w4', '-wallet=w5'])
126126
assert_equal(set(node.listwallets()), {"w4", "w5"})
127127
w5 = wallet("w5")
128-
w5.generate(1)
128+
node.generatetoaddress(nblocks=1, address=w5.getnewaddress())
129129

130130
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded
131131
os.rename(wallet_dir2, wallet_dir())
@@ -147,7 +147,7 @@ def wallet_file(name):
147147
wallet_bad = wallet("bad")
148148

149149
# check wallet names and balances
150-
wallets[0].generate(1)
150+
node.generatetoaddress(nblocks=1, address=wallets[0].getnewaddress())
151151
for wallet_name, wallet in zip(wallet_names, wallets):
152152
info = wallet.getwalletinfo()
153153
assert_equal(info['immature_balance'], 50 if wallet is wallets[0] else 0)
@@ -160,7 +160,7 @@ def wallet_file(name):
160160
assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo)
161161

162162
w1, w2, w3, w4, *_ = wallets
163-
w1.generate(101)
163+
node.generatetoaddress(nblocks=101, address=w1.getnewaddress())
164164
assert_equal(w1.getbalance(), 100)
165165
assert_equal(w2.getbalance(), 0)
166166
assert_equal(w3.getbalance(), 0)
@@ -169,7 +169,7 @@ def wallet_file(name):
169169
w1.sendtoaddress(w2.getnewaddress(), 1)
170170
w1.sendtoaddress(w3.getnewaddress(), 2)
171171
w1.sendtoaddress(w4.getnewaddress(), 3)
172-
w1.generate(1)
172+
node.generatetoaddress(nblocks=1, address=w1.getnewaddress())
173173
assert_equal(w2.getbalance(), 1)
174174
assert_equal(w3.getbalance(), 2)
175175
assert_equal(w4.getbalance(), 3)

0 commit comments

Comments
 (0)