Browse Source

test: Fetch coinbase address from coinbase UTXOs

After upstream PR bitcoin/bitcoin#5994, the first call to getnewaddress after
startup does not return the address being used by the miner.
pull/245/head
Jack Grigg 6 years ago
parent
commit
b0f1d643aa
No known key found for this signature in database GPG Key ID: 1B8D649257DB0829
  1. 3
      qa/rpc-tests/finalsaplingroot.py
  2. 5
      qa/rpc-tests/mempool_nu_activation.py
  3. 5
      qa/rpc-tests/mempool_tx_input_limit.py
  4. 5
      qa/rpc-tests/paymentdisclosure.py
  5. 2
      qa/rpc-tests/signrawtransaction_offline.py
  6. 9
      qa/rpc-tests/test_framework/util.py
  7. 5
      qa/rpc-tests/wallet_1941.py
  8. 4
      qa/rpc-tests/wallet_anchorfork.py
  9. 13
      qa/rpc-tests/wallet_listnotes.py
  10. 6
      qa/rpc-tests/wallet_nullifiers.py
  11. 5
      qa/rpc-tests/wallet_overwintertx.py
  12. 3
      qa/rpc-tests/wallet_persistence.py
  13. 5
      qa/rpc-tests/wallet_protectcoinbase.py
  14. 20
      qa/rpc-tests/wallet_sapling.py
  15. 16
      qa/rpc-tests/wallet_shieldcoinbase.py
  16. 5
      qa/rpc-tests/wallet_treestate.py

3
qa/rpc-tests/finalsaplingroot.py

@ -9,6 +9,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
connect_nodes_bi,
get_coinbase_address,
initialize_chain_clean,
start_nodes,
wait_and_assert_operationid_status,
@ -56,7 +57,7 @@ class FinalSaplingRootTest(BitcoinTestFramework):
assert_equal(blk["finalsaplingroot"], SAPLING_TREE_EMPTY_ROOT)
# Node 0 shields some funds
taddr0 = self.nodes[0].getnewaddress()
taddr0 = get_coinbase_address(self.nodes[0], 100)
saplingAddr0 = self.nodes[0].z_getnewaddress('sapling')
recipients = []
recipients.append({"address": saplingAddr0, "amount": Decimal('20')})

5
qa/rpc-tests/mempool_nu_activation.py

@ -7,7 +7,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
start_node, connect_nodes, wait_and_assert_operationid_status
start_node, connect_nodes, wait_and_assert_operationid_status, \
get_coinbase_address
from test_framework.authproxy import JSONRPCException
from decimal import Decimal
@ -43,7 +44,7 @@ class MempoolUpgradeActivationTest(BitcoinTestFramework):
self.sync_all()
# Shield some ZEC
node1_taddr = self.nodes[1].getnewaddress()
node1_taddr = get_coinbase_address(self.nodes[1], 97)
node0_zaddr = self.nodes[0].z_getnewaddress('sprout')
recipients = [{'address': node0_zaddr, 'amount': Decimal('10')}]
myopid = self.nodes[1].z_sendmany(node1_taddr, recipients, 1, Decimal('0'))

5
qa/rpc-tests/mempool_tx_input_limit.py

@ -8,7 +8,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, initialize_chain_clean, \
start_node, connect_nodes, wait_and_assert_operationid_status
start_node, connect_nodes, wait_and_assert_operationid_status, \
get_coinbase_address
from decimal import Decimal
@ -50,7 +51,7 @@ class MempoolTxInputLimitTest(BitcoinTestFramework):
node0_zaddr = self.nodes[0].z_getnewaddress('sprout')
# Send three inputs from node 0 taddr to zaddr to get out of coinbase
node0_taddr = self.nodes[0].getnewaddress()
node0_taddr = get_coinbase_address(self.nodes[0], 3)
recipients = []
recipients.append({"address":node0_zaddr, "amount":Decimal('30.0')-Decimal('0.0001')}) # utxo amount less fee
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients)

5
qa/rpc-tests/paymentdisclosure.py

@ -8,7 +8,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, initialize_chain_clean, \
start_node, connect_nodes_bi, wait_and_assert_operationid_status
start_node, connect_nodes_bi, wait_and_assert_operationid_status, \
get_coinbase_address
from decimal import Decimal
@ -48,7 +49,7 @@ class PaymentDisclosureTest (BitcoinTestFramework):
assert_equal(self.nodes[1].getbalance(), 10)
assert_equal(self.nodes[2].getbalance(), 30)
mytaddr = self.nodes[0].getnewaddress()
mytaddr = get_coinbase_address(self.nodes[0], 4)
myzaddr = self.nodes[0].z_getnewaddress('sprout')
# Check that Node 2 has payment disclosure disabled.

2
qa/rpc-tests/signrawtransaction_offline.py

@ -27,12 +27,12 @@ class SignOfflineTest (BitcoinTestFramework):
assert_equal(0, len(offline_node.getpeerinfo())) # make sure node 1 has no peers
privkeys = [self.nodes[0].dumpprivkey(self.nodes[0].getnewaddress())]
taddr = self.nodes[0].getnewaddress()
tx = self.nodes[0].listunspent()[0]
txid = tx['txid']
scriptpubkey = tx['scriptPubKey']
privkeys = [self.nodes[0].dumpprivkey(tx['address'])]
create_inputs = [{'txid': txid, 'vout': 0}]
sign_inputs = [{'txid': txid, 'vout': 0, 'scriptPubKey': scriptpubkey, 'amount': 10}]

9
qa/rpc-tests/test_framework/util.py

@ -419,3 +419,12 @@ def wait_and_assert_operationid_status(node, myopid, in_status='success', in_err
return result # if there was an error return the result
else:
return txid # otherwise return the txid
# Find a coinbase address on the node, filtering by the number of UTXOs it has.
# The default cached chain has one address per coinbase output.
def get_coinbase_address(node, expected_utxos):
addrs = [utxo['address'] for utxo in node.listunspent() if utxo['generated']]
assert(len(set(addrs)) > 0)
addrs = [a for a in set(addrs) if addrs.count(a) == expected_utxos]
assert(len(addrs) > 0)
return addrs[0]

5
qa/rpc-tests/wallet_1941.py

@ -10,7 +10,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
initialize_datadir, start_nodes, start_node, connect_nodes_bi, \
bitcoind_processes, wait_and_assert_operationid_status
bitcoind_processes, wait_and_assert_operationid_status, \
get_coinbase_address
from decimal import Decimal
@ -48,7 +49,7 @@ class Wallet1941RegressionTest (BitcoinTestFramework):
self.nodes[0].setmocktime(starttime)
self.nodes[0].generate(101)
mytaddr = self.nodes[0].getnewaddress() # where coins were mined
mytaddr = get_coinbase_address(self.nodes[0], 1)
myzaddr = self.nodes[0].z_getnewaddress('sprout')
# Send 10 coins to our zaddr.

4
qa/rpc-tests/wallet_anchorfork.py

@ -8,7 +8,7 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
start_nodes, stop_nodes, connect_nodes_bi, \
wait_and_assert_operationid_status, wait_bitcoinds
wait_and_assert_operationid_status, wait_bitcoinds, get_coinbase_address
from decimal import Decimal
class WalletAnchorForkTest (BitcoinTestFramework):
@ -45,7 +45,7 @@ class WalletAnchorForkTest (BitcoinTestFramework):
# At this point in time, commitment tree is the empty root
# Node 0 creates a joinsplit transaction
mytaddr0 = self.nodes[0].getnewaddress()
mytaddr0 = get_coinbase_address(self.nodes[0], 4)
myzaddr0 = self.nodes[0].z_getnewaddress('sprout')
recipients = []
recipients.append({"address":myzaddr0, "amount": Decimal('10.0') - Decimal('0.0001')})

13
qa/rpc-tests/wallet_listnotes.py

@ -6,7 +6,12 @@
import sys; assert sys.version_info < (3,), ur"This script does not run under Python 3. Please use Python 2.7.x."
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, start_nodes, wait_and_assert_operationid_status
from test_framework.util import (
assert_equal,
get_coinbase_address,
start_nodes,
wait_and_assert_operationid_status,
)
from decimal import Decimal
@ -35,12 +40,10 @@ class WalletListNotes(BitcoinTestFramework):
self.sync_all()
assert_equal(201, self.nodes[0].getblockcount())
mining_addr = self.nodes[0].listunspent()[0]['address']
# Shield coinbase funds (must be a multiple of 10, no change allowed pre-sapling)
receive_amount_10 = Decimal('10.0') - Decimal('0.0001')
recipients = [{"address":sproutzaddr, "amount":receive_amount_10}]
myopid = self.nodes[0].z_sendmany(mining_addr, recipients)
myopid = self.nodes[0].z_sendmany(get_coinbase_address(self.nodes[0], 1), recipients)
txid_1 = wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
@ -119,7 +122,7 @@ class WalletListNotes(BitcoinTestFramework):
# so send from coin base)
receive_amount_2 = Decimal('2.0') - Decimal('0.0001')
recipients = [{"address": saplingzaddr, "amount":receive_amount_2}]
myopid = self.nodes[0].z_sendmany(mining_addr, recipients)
myopid = self.nodes[0].z_sendmany(get_coinbase_address(self.nodes[0], 1), recipients)
txid_3 = wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
unspent_tx = self.nodes[0].z_listunspent(0)

6
qa/rpc-tests/wallet_nullifiers.py

@ -7,7 +7,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_true, bitcoind_processes, \
connect_nodes_bi, start_node, start_nodes, wait_and_assert_operationid_status
connect_nodes_bi, start_node, start_nodes, wait_and_assert_operationid_status, \
get_coinbase_address
from decimal import Decimal
@ -22,7 +23,8 @@ class WalletNullifiersTest (BitcoinTestFramework):
myzaddr0 = self.nodes[0].z_getnewaddress('sprout')
# send node 0 taddr to zaddr to get out of coinbase
mytaddr = self.nodes[0].getnewaddress()
# Tests using the default cached chain have one address per coinbase output
mytaddr = get_coinbase_address(self.nodes[0], 1)
recipients = []
recipients.append({"address":myzaddr0, "amount":Decimal('10.0')-Decimal('0.0001')}) # utxo amount less fee

5
qa/rpc-tests/wallet_overwintertx.py

@ -7,7 +7,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status, assert_greater_than
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status, \
assert_greater_than, get_coinbase_address
from test_framework.authproxy import JSONRPCException
from decimal import Decimal
@ -34,7 +35,7 @@ class WalletOverwinterTxTest (BitcoinTestFramework):
self.sync_all()
# Node 0 has reward from blocks 1 to 98 which are spendable.
taddr0 = self.nodes[0].getnewaddress()
taddr0 = get_coinbase_address(self.nodes[0], 98)
taddr1 = self.nodes[1].getnewaddress()
taddr2 = self.nodes[2].getnewaddress()
zaddr2 = self.nodes[2].z_getnewaddress('sprout')

3
qa/rpc-tests/wallet_persistence.py

@ -8,6 +8,7 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal, assert_true,
get_coinbase_address,
start_nodes, stop_nodes,
initialize_chain_clean, connect_nodes_bi, wait_bitcoinds,
wait_and_assert_operationid_status
@ -58,7 +59,7 @@ class WalletPersistenceTest (BitcoinTestFramework):
self.sync_all()
# Node 0 shields funds to Sapling address
taddr0 = self.nodes[0].getnewaddress()
taddr0 = get_coinbase_address(self.nodes[0], 101)
recipients = []
recipients.append({"address": sapling_addr, "amount": Decimal('20')})
myopid = self.nodes[0].z_sendmany(taddr0, recipients, 1, 0)

5
qa/rpc-tests/wallet_protectcoinbase.py

@ -9,7 +9,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.mininode import COIN
from test_framework.util import assert_equal, initialize_chain_clean, \
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status, \
get_coinbase_address
import sys
import timeit
@ -75,7 +76,7 @@ class WalletProtectCoinbaseTest (BitcoinTestFramework):
assert_equal("Coinbase funds can only be sent to a zaddr" in errorString, True)
# Prepare to send taddr->zaddr
mytaddr = self.nodes[0].getnewaddress()
mytaddr = get_coinbase_address(self.nodes[0], 4)
myzaddr = self.nodes[0].z_getnewaddress('sprout')
# Node 3 will test that watch only address utxos are not selected

20
qa/rpc-tests/wallet_sapling.py

@ -9,6 +9,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import (
assert_equal,
get_coinbase_address,
start_nodes,
wait_and_assert_operationid_status,
)
@ -34,18 +35,18 @@ class WalletSaplingTest(BitcoinTestFramework):
self.sync_all()
# Verify RPCs disallow Sapling value transfer if Sapling is not active
tmp_taddr = self.nodes[3].getnewaddress()
tmp_taddr = get_coinbase_address(self.nodes[3], 1)
tmp_zaddr = self.nodes[3].z_getnewaddress('sapling')
try:
recipients = []
recipients.append({"address": tmp_zaddr, "amount": Decimal('20')})
recipients.append({"address": tmp_zaddr, "amount": Decimal('10')})
self.nodes[3].z_sendmany(tmp_taddr, recipients, 1, 0)
raise AssertionError("Should have thrown an exception")
except JSONRPCException as e:
assert_equal("Invalid parameter, Sapling has not activated", e.error['message'])
try:
recipients = []
recipients.append({"address": tmp_taddr, "amount": Decimal('20')})
recipients.append({"address": tmp_taddr, "amount": Decimal('10')})
self.nodes[3].z_sendmany(tmp_zaddr, recipients, 1, 0)
raise AssertionError("Should have thrown an exception")
except JSONRPCException as e:
@ -75,9 +76,6 @@ class WalletSaplingTest(BitcoinTestFramework):
self.nodes[2].generate(2)
self.sync_all()
taddr0 = self.nodes[0].getnewaddress()
# Skip over the address containing node 1's coinbase
self.nodes[1].getnewaddress()
taddr1 = self.nodes[1].getnewaddress()
saplingAddr0 = self.nodes[0].z_getnewaddress('sapling')
saplingAddr1 = self.nodes[1].z_getnewaddress('sapling')
@ -95,10 +93,9 @@ class WalletSaplingTest(BitcoinTestFramework):
# Node 0 shields some funds
# taddr -> Sapling
# -> taddr (change)
recipients = []
recipients.append({"address": saplingAddr0, "amount": Decimal('20')})
myopid = self.nodes[0].z_sendmany(taddr0, recipients, 1, 0)
recipients.append({"address": saplingAddr0, "amount": Decimal('10')})
myopid = self.nodes[0].z_sendmany(get_coinbase_address(self.nodes[0], 1), recipients, 1, 0)
mytxid = wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
@ -107,6 +104,11 @@ class WalletSaplingTest(BitcoinTestFramework):
mempool = self.nodes[0].getrawmempool(True)
assert(Decimal(mempool[mytxid]['startingpriority']) == Decimal('1E+16'))
# Shield another coinbase UTXO
myopid = self.nodes[0].z_sendmany(get_coinbase_address(self.nodes[0], 1), recipients, 1, 0)
mytxid = wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
self.nodes[2].generate(1)
self.sync_all()

16
qa/rpc-tests/wallet_shieldcoinbase.py

@ -9,7 +9,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, initialize_chain_clean, \
start_node, connect_nodes_bi, sync_blocks, sync_mempools, \
wait_and_assert_operationid_status
wait_and_assert_operationid_status, get_coinbase_address
from decimal import Decimal
@ -46,17 +46,13 @@ class WalletShieldCoinbaseTest (BitcoinTestFramework):
print "Mining blocks..."
self.nodes[0].generate(1)
do_not_shield_taddr = self.nodes[0].getnewaddress()
self.nodes[0].generate(4)
walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo['immature_balance'], 50)
assert_equal(walletinfo['balance'], 0)
self.sync_all()
self.nodes[2].generate(1)
self.nodes[2].getnewaddress()
self.nodes[2].generate(1)
self.nodes[2].getnewaddress()
self.nodes[2].generate(1)
self.sync_all()
self.nodes[1].generate(101)
@ -65,8 +61,10 @@ class WalletShieldCoinbaseTest (BitcoinTestFramework):
assert_equal(self.nodes[1].getbalance(), 10)
assert_equal(self.nodes[2].getbalance(), 30)
do_not_shield_taddr = get_coinbase_address(self.nodes[0], 1)
# Prepare to send taddr->zaddr
mytaddr = self.nodes[0].getnewaddress()
mytaddr = get_coinbase_address(self.nodes[0], 4)
myzaddr = self.nodes[0].z_getnewaddress(self.addr_type)
# Shielding will fail when trying to spend from watch-only address
@ -145,7 +143,7 @@ class WalletShieldCoinbaseTest (BitcoinTestFramework):
self.sync_all()
self.nodes[1].generate(100)
self.sync_all()
mytaddr = self.nodes[0].getnewaddress()
mytaddr = get_coinbase_address(self.nodes[0], 800)
def verify_locking(first, second, limit):
result = self.nodes[0].z_shieldcoinbase(mytaddr, myzaddr, 0, limit)
@ -186,7 +184,7 @@ class WalletShieldCoinbaseTest (BitcoinTestFramework):
if self.addr_type == 'sprout':
# Verify maximum number of utxos which node 2 can shield is limited by option -mempooltxinputlimit
# This option is used when the limit parameter is set to 0.
mytaddr = self.nodes[2].getnewaddress()
mytaddr = get_coinbase_address(self.nodes[2], 20)
result = self.nodes[2].z_shieldcoinbase(mytaddr, myzaddr, Decimal('0.0001'), 0)
assert_equal(result["shieldingUTXOs"], Decimal('7'))
assert_equal(result["remainingUTXOs"], Decimal('13'))
@ -198,7 +196,7 @@ class WalletShieldCoinbaseTest (BitcoinTestFramework):
# Verify maximum number of utxos which node 0 can shield is set by default limit parameter of 50
self.nodes[0].generate(200)
self.sync_all()
mytaddr = self.nodes[0].getnewaddress()
mytaddr = get_coinbase_address(self.nodes[0], 100)
result = self.nodes[0].z_shieldcoinbase(mytaddr, myzaddr, Decimal('0.0001'))
assert_equal(result["shieldingUTXOs"], Decimal('50'))
assert_equal(result["remainingUTXOs"], Decimal('50'))

5
qa/rpc-tests/wallet_treestate.py

@ -7,7 +7,8 @@ import sys; assert sys.version_info < (3,), ur"This script does not run under Py
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, initialize_chain_clean, \
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status
start_nodes, connect_nodes_bi, wait_and_assert_operationid_status, \
get_coinbase_address
import time
from decimal import Decimal
@ -35,7 +36,7 @@ class WalletTreeStateTest (BitcoinTestFramework):
self.nodes[1].generate(101)
self.sync_all()
mytaddr = self.nodes[0].getnewaddress() # where coins were mined
mytaddr = get_coinbase_address(self.nodes[0], 100)
myzaddr = self.nodes[0].z_getnewaddress('sprout')
# Spend coinbase utxos to create three notes of 9.99990000 each

Loading…
Cancel
Save