[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
pull/643/head
John Newbery 6 years ago
parent be992701b0
commit c269209336

@ -11,6 +11,7 @@ from test_framework.util import (
assert_array_result, assert_array_result,
assert_equal, assert_equal,
assert_fee_amount, assert_fee_amount,
assert_greater_than,
assert_raises_rpc_error, assert_raises_rpc_error,
connect_nodes_bi, connect_nodes_bi,
sync_blocks, sync_blocks,
@ -92,13 +93,13 @@ class WalletTest(BitcoinTestFramework):
assert_equal(txout['value'], 50) assert_equal(txout['value'], 50)
# Send 21 BTC from 0 to 2 using sendtoaddress call. # Send 21 BTC from 0 to 2 using sendtoaddress call.
# Locked memory should use at least 32 bytes to sign each transaction # Locked memory should increase to sign transactions
self.log.info("test getmemoryinfo") self.log.info("test getmemoryinfo")
memory_before = self.nodes[0].getmemoryinfo() memory_before = self.nodes[0].getmemoryinfo()
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11) self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10) mempool_txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
memory_after = self.nodes[0].getmemoryinfo() memory_after = self.nodes[0].getmemoryinfo()
assert(memory_before['locked']['used'] + 64 <= memory_after['locked']['used']) assert_greater_than(memory_after['locked']['used'], memory_before['locked']['used'])
self.log.info("test gettxout (second part)") self.log.info("test gettxout (second part)")
# utxo spent in mempool should be visible if you exclude mempool # utxo spent in mempool should be visible if you exclude mempool

@ -73,11 +73,10 @@ class KeyPoolTest(BitcoinTestFramework):
time.sleep(1.1) time.sleep(1.1)
assert_equal(nodes[0].getwalletinfo()["unlocked_until"], 0) assert_equal(nodes[0].getwalletinfo()["unlocked_until"], 0)
# drain them by mining # drain the keypool
nodes[0].generate(1) for _ in range(3):
nodes[0].generate(1) nodes[0].getnewaddress()
nodes[0].generate(1) assert_raises_rpc_error(-12, "Keypool ran out", nodes[0].getnewaddress)
assert_raises_rpc_error(-12, "Keypool ran out", nodes[0].generate, 1)
nodes[0].walletpassphrase('test', 100) nodes[0].walletpassphrase('test', 100)
nodes[0].keypoolrefill(100) nodes[0].keypoolrefill(100)

@ -29,8 +29,8 @@ class WalletLabelsTest(BitcoinTestFramework):
# Note each time we call generate, all generated coins go into # Note each time we call generate, all generated coins go into
# the same address, so we call twice to get two addresses w/50 each # the same address, so we call twice to get two addresses w/50 each
node.generate(1) node.generatetoaddress(nblocks=1, address=node.getnewaddress(label='coinbase'))
node.generate(101) node.generatetoaddress(nblocks=101, address=node.getnewaddress(label='coinbase'))
assert_equal(node.getbalance(), 100) assert_equal(node.getbalance(), 100)
# there should be 2 address groups # there should be 2 address groups
@ -42,8 +42,9 @@ class WalletLabelsTest(BitcoinTestFramework):
linked_addresses = set() linked_addresses = set()
for address_group in address_groups: for address_group in address_groups:
assert_equal(len(address_group), 1) assert_equal(len(address_group), 1)
assert_equal(len(address_group[0]), 2) assert_equal(len(address_group[0]), 3)
assert_equal(address_group[0][1], 50) assert_equal(address_group[0][1], 50)
assert_equal(address_group[0][2], 'coinbase')
linked_addresses.add(address_group[0][0]) linked_addresses.add(address_group[0][0])
# send 50 from each address to a third address not in this wallet # send 50 from each address to a third address not in this wallet
@ -77,7 +78,7 @@ class WalletLabelsTest(BitcoinTestFramework):
label.verify(node) label.verify(node)
# Check all labels are returned by listlabels. # Check all labels are returned by listlabels.
assert_equal(node.listlabels(), [label.name for label in labels]) assert_equal(node.listlabels(), sorted(['coinbase'] + [label.name for label in labels]))
# Send a transaction to each label. # Send a transaction to each label.
for label in labels: for label in labels:

@ -125,7 +125,7 @@ class MultiWalletTest(BitcoinTestFramework):
self.start_node(0, ['-wallet=w4', '-wallet=w5']) self.start_node(0, ['-wallet=w4', '-wallet=w5'])
assert_equal(set(node.listwallets()), {"w4", "w5"}) assert_equal(set(node.listwallets()), {"w4", "w5"})
w5 = wallet("w5") w5 = wallet("w5")
w5.generate(1) node.generatetoaddress(nblocks=1, address=w5.getnewaddress())
# now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded # now if wallets/ exists again, but the rootdir is specified as the walletdir, w4 and w5 should still be loaded
os.rename(wallet_dir2, wallet_dir()) os.rename(wallet_dir2, wallet_dir())
@ -147,7 +147,7 @@ class MultiWalletTest(BitcoinTestFramework):
wallet_bad = wallet("bad") wallet_bad = wallet("bad")
# check wallet names and balances # check wallet names and balances
wallets[0].generate(1) node.generatetoaddress(nblocks=1, address=wallets[0].getnewaddress())
for wallet_name, wallet in zip(wallet_names, wallets): for wallet_name, wallet in zip(wallet_names, wallets):
info = wallet.getwalletinfo() info = wallet.getwalletinfo()
assert_equal(info['immature_balance'], 50 if wallet is wallets[0] else 0) assert_equal(info['immature_balance'], 50 if wallet is wallets[0] else 0)
@ -160,7 +160,7 @@ class MultiWalletTest(BitcoinTestFramework):
assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo) assert_raises_rpc_error(-19, "Wallet file not specified", node.getwalletinfo)
w1, w2, w3, w4, *_ = wallets w1, w2, w3, w4, *_ = wallets
w1.generate(101) node.generatetoaddress(nblocks=101, address=w1.getnewaddress())
assert_equal(w1.getbalance(), 100) assert_equal(w1.getbalance(), 100)
assert_equal(w2.getbalance(), 0) assert_equal(w2.getbalance(), 0)
assert_equal(w3.getbalance(), 0) assert_equal(w3.getbalance(), 0)
@ -169,7 +169,7 @@ class MultiWalletTest(BitcoinTestFramework):
w1.sendtoaddress(w2.getnewaddress(), 1) w1.sendtoaddress(w2.getnewaddress(), 1)
w1.sendtoaddress(w3.getnewaddress(), 2) w1.sendtoaddress(w3.getnewaddress(), 2)
w1.sendtoaddress(w4.getnewaddress(), 3) w1.sendtoaddress(w4.getnewaddress(), 3)
w1.generate(1) node.generatetoaddress(nblocks=1, address=w1.getnewaddress())
assert_equal(w2.getbalance(), 1) assert_equal(w2.getbalance(), 1)
assert_equal(w3.getbalance(), 2) assert_equal(w3.getbalance(), 2)
assert_equal(w4.getbalance(), 3) assert_equal(w4.getbalance(), 3)

Loading…
Cancel
Save