2019-12-04 07:29:16 -08:00
|
|
|
#!/usr/bin/env python3
|
2018-08-28 17:16:04 -07:00
|
|
|
# Copyright (c) 2018 The Zcash developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
2019-07-18 07:16:09 -07:00
|
|
|
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2018-08-28 17:16:04 -07:00
|
|
|
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2018-03-10 02:19:44 -08:00
|
|
|
from test_framework.util import (
|
2022-03-31 19:44:56 -07:00
|
|
|
NU5_BRANCH_ID,
|
2018-03-10 02:19:44 -08:00
|
|
|
assert_equal,
|
2022-04-01 08:51:05 -07:00
|
|
|
assert_true,
|
2022-03-31 19:44:56 -07:00
|
|
|
get_coinbase_address,
|
|
|
|
nuparams,
|
|
|
|
start_nodes,
|
2018-03-10 02:19:44 -08:00
|
|
|
wait_and_assert_operationid_status,
|
2020-12-17 11:39:58 -08:00
|
|
|
DEFAULT_FEE
|
2018-03-10 02:19:44 -08:00
|
|
|
)
|
2018-08-28 17:16:04 -07:00
|
|
|
|
|
|
|
from decimal import Decimal
|
|
|
|
|
2018-09-28 22:11:05 -07:00
|
|
|
# Test wallet z_listunspent behaviour across network upgrades
|
2018-08-28 17:16:04 -07:00
|
|
|
class WalletListNotes(BitcoinTestFramework):
|
2022-08-24 10:21:36 -07:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.cache_behavior = 'sprout'
|
|
|
|
|
2022-03-31 19:44:56 -07:00
|
|
|
def setup_nodes(self):
|
|
|
|
return start_nodes(4, self.options.tmpdir, [[
|
|
|
|
nuparams(NU5_BRANCH_ID, 215),
|
2022-12-02 21:49:43 -08:00
|
|
|
'-allowdeprecated=z_getnewaddress',
|
2022-08-24 10:21:36 -07:00
|
|
|
'-allowdeprecated=z_getbalance',
|
2022-12-02 21:49:43 -08:00
|
|
|
'-allowdeprecated=z_gettotalbalance',
|
2022-03-31 19:44:56 -07:00
|
|
|
]] * 4)
|
2018-08-28 17:16:04 -07:00
|
|
|
|
|
|
|
def run_test(self):
|
2022-03-31 19:44:56 -07:00
|
|
|
# Current height = 200 -> Sapling
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(200, self.nodes[0].getblockcount())
|
2022-08-24 10:21:36 -07:00
|
|
|
sproutzaddr = self.nodes[0].listaddresses()[0]['sprout']['addresses'][0]
|
|
|
|
receive_amount_1 = self.nodes[0].z_getbalance(sproutzaddr)
|
2019-07-19 05:10:13 -07:00
|
|
|
|
|
|
|
# Set current height to 201
|
2018-08-28 17:16:04 -07:00
|
|
|
self.nodes[0].generate(1)
|
|
|
|
self.sync_all()
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(201, self.nodes[0].getblockcount())
|
|
|
|
|
2021-12-28 08:30:02 -08:00
|
|
|
# Send 1.0 minus default fee from sproutzaddr to a new Sapling zaddr
|
|
|
|
saplingzaddr = self.nodes[0].z_getnewaddress('sapling')
|
|
|
|
receive_amount_2 = Decimal('1.0')
|
|
|
|
change_amount_2 = receive_amount_1 - receive_amount_2 - DEFAULT_FEE
|
2022-12-02 21:49:43 -08:00
|
|
|
assert_equal('sapling', self.nodes[0].z_validateaddress(saplingzaddr)['address_type'])
|
2021-12-28 08:30:02 -08:00
|
|
|
recipients = [{"address": saplingzaddr, "amount":receive_amount_2}]
|
2022-12-02 21:49:43 -08:00
|
|
|
myopid = self.nodes[0].z_sendmany(sproutzaddr, recipients, 1, DEFAULT_FEE, 'AllowRevealedAmounts')
|
2018-08-28 17:16:04 -07:00
|
|
|
txid_2 = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
2018-09-11 13:51:38 -07:00
|
|
|
self.sync_all()
|
2020-12-17 11:39:58 -08:00
|
|
|
|
2018-08-28 17:16:04 -07:00
|
|
|
# list unspent, allowing 0conf txs
|
|
|
|
unspent_tx = self.nodes[0].z_listunspent(0)
|
|
|
|
assert_equal(len(unspent_tx), 2)
|
2018-09-11 13:51:38 -07:00
|
|
|
# sort low-to-high by amount (order of returned entries is not guaranteed)
|
|
|
|
unspent_tx = sorted(unspent_tx, key=lambda k: k['amount'])
|
|
|
|
assert_equal(txid_2, unspent_tx[0]['txid'])
|
2022-03-28 20:21:26 -07:00
|
|
|
assert_equal('sapling', unspent_tx[0]['pool'])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(True, unspent_tx[0]['spendable'])
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(saplingzaddr, unspent_tx[0]['address'])
|
|
|
|
assert_equal(receive_amount_2, unspent_tx[0]['amount'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(False, unspent_tx[0]['change'])
|
2018-09-11 13:51:38 -07:00
|
|
|
|
|
|
|
assert_equal(txid_2, unspent_tx[1]['txid'])
|
2022-03-28 20:21:26 -07:00
|
|
|
assert_equal('sprout', unspent_tx[1]['pool'])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(True, unspent_tx[1]['spendable'])
|
|
|
|
assert_equal(sproutzaddr, unspent_tx[1]['address'])
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(change_amount_2, unspent_tx[1]['amount'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(True, unspent_tx[1]['change'])
|
2018-09-11 13:51:38 -07:00
|
|
|
|
2021-12-28 08:30:02 -08:00
|
|
|
unspent_tx_filter = self.nodes[0].z_listunspent(0, 9999, False, [saplingzaddr])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(1, len(unspent_tx_filter))
|
|
|
|
assert_equal(unspent_tx[0], unspent_tx_filter[0])
|
|
|
|
|
|
|
|
unspent_tx_filter = self.nodes[0].z_listunspent(0, 9999, False, [sproutzaddr])
|
|
|
|
assert_equal(1, len(unspent_tx_filter))
|
|
|
|
assert_equal(unspent_tx[1], unspent_tx_filter[0])
|
2019-07-19 05:10:13 -07:00
|
|
|
|
2021-12-28 08:30:02 -08:00
|
|
|
self.nodes[0].generate(1)
|
|
|
|
self.sync_all()
|
2018-09-11 13:51:38 -07:00
|
|
|
|
2021-12-28 08:30:02 -08:00
|
|
|
# Send 2.0 minus default fee to a new sapling zaddr
|
|
|
|
saplingzaddr2 = self.nodes[0].z_getnewaddress('sapling')
|
|
|
|
receive_amount_3 = Decimal('2.0')
|
|
|
|
change_amount_3 = change_amount_2 - receive_amount_3 - DEFAULT_FEE
|
|
|
|
recipients = [{"address": saplingzaddr2, "amount":receive_amount_3}]
|
2022-12-02 21:49:43 -08:00
|
|
|
myopid = self.nodes[0].z_sendmany(sproutzaddr, recipients, 1, DEFAULT_FEE, 'AllowRevealedAmounts')
|
2018-09-11 13:51:38 -07:00
|
|
|
txid_3 = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
|
|
|
self.sync_all()
|
|
|
|
unspent_tx = self.nodes[0].z_listunspent(0)
|
|
|
|
assert_equal(3, len(unspent_tx))
|
|
|
|
|
|
|
|
# low-to-high in amount
|
|
|
|
unspent_tx = sorted(unspent_tx, key=lambda k: k['amount'])
|
|
|
|
|
|
|
|
assert_equal(txid_2, unspent_tx[0]['txid'])
|
2022-03-28 20:21:26 -07:00
|
|
|
assert_equal('sapling', unspent_tx[0]['pool'])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(True, unspent_tx[0]['spendable'])
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(saplingzaddr, unspent_tx[0]['address'])
|
|
|
|
assert_equal(receive_amount_2, unspent_tx[0]['amount'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(False, unspent_tx[0]['change'])
|
2018-09-11 13:51:38 -07:00
|
|
|
|
|
|
|
assert_equal(txid_3, unspent_tx[1]['txid'])
|
2022-03-28 20:21:26 -07:00
|
|
|
assert_equal('sapling', unspent_tx[1]['pool'])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(True, unspent_tx[1]['spendable'])
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(saplingzaddr2, unspent_tx[1]['address'])
|
|
|
|
assert_equal(receive_amount_3, unspent_tx[1]['amount'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(False, unspent_tx[1]['change'])
|
2018-09-11 13:51:38 -07:00
|
|
|
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(txid_3, unspent_tx[2]['txid'])
|
2022-03-28 20:21:26 -07:00
|
|
|
assert_equal('sprout', unspent_tx[2]['pool'])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(True, unspent_tx[2]['spendable'])
|
|
|
|
assert_equal(sproutzaddr, unspent_tx[2]['address'])
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(change_amount_3, unspent_tx[2]['amount'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(True, unspent_tx[2]['change'])
|
2018-09-11 13:51:38 -07:00
|
|
|
|
2020-12-21 08:08:58 -08:00
|
|
|
unspent_tx_filter = self.nodes[0].z_listunspent(0, 9999, False, [saplingzaddr])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(1, len(unspent_tx_filter))
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(unspent_tx[0], unspent_tx_filter[0])
|
2018-09-11 13:51:38 -07:00
|
|
|
|
|
|
|
# test that pre- and post-sapling can be filtered in a single call
|
2020-12-21 08:08:58 -08:00
|
|
|
unspent_tx_filter = self.nodes[0].z_listunspent(0, 9999, False,
|
2018-09-11 13:51:38 -07:00
|
|
|
[sproutzaddr, saplingzaddr])
|
|
|
|
assert_equal(2, len(unspent_tx_filter))
|
|
|
|
unspent_tx_filter = sorted(unspent_tx_filter, key=lambda k: k['amount'])
|
2021-12-28 08:30:02 -08:00
|
|
|
assert_equal(unspent_tx[0], unspent_tx_filter[0])
|
2018-09-11 13:51:38 -07:00
|
|
|
assert_equal(unspent_tx[2], unspent_tx_filter[1])
|
|
|
|
|
|
|
|
# so far, this node has no watchonly addresses, so results are the same
|
2020-12-21 08:08:58 -08:00
|
|
|
unspent_tx_watchonly = self.nodes[0].z_listunspent(0, 9999, True)
|
2018-09-11 13:51:38 -07:00
|
|
|
unspent_tx_watchonly = sorted(unspent_tx_watchonly, key=lambda k: k['amount'])
|
|
|
|
assert_equal(unspent_tx, unspent_tx_watchonly)
|
|
|
|
|
|
|
|
# TODO: use z_exportviewingkey, z_importviewingkey to test includeWatchonly
|
|
|
|
# but this requires Sapling support for those RPCs
|
2018-08-28 17:16:04 -07:00
|
|
|
|
2022-03-31 19:44:56 -07:00
|
|
|
# Set current height to 215 -> NU5
|
2022-08-24 10:21:36 -07:00
|
|
|
self.nodes[0].generate(13)
|
2022-03-31 19:44:56 -07:00
|
|
|
self.sync_all()
|
|
|
|
assert_equal(215, self.nodes[0].getblockcount())
|
|
|
|
|
|
|
|
# Create an Orchard note.
|
|
|
|
account0 = self.nodes[0].z_getnewaccount()['account']
|
|
|
|
ua0 = self.nodes[0].z_getaddressforaccount(account0)['address']
|
|
|
|
receive_amount_4 = Decimal('10.0')
|
|
|
|
recipients = [{"address": ua0, "amount": receive_amount_4}]
|
|
|
|
myopid = self.nodes[0].z_sendmany(get_coinbase_address(self.nodes[0]), recipients, 1, 0, 'AllowRevealedSenders')
|
|
|
|
txid_4 = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
unspent_tx = self.nodes[0].z_listunspent(0)
|
|
|
|
assert_equal(4, len(unspent_tx))
|
|
|
|
# low-to-high in amount
|
|
|
|
unspent_tx = sorted(unspent_tx, key=lambda k: k['amount'])
|
|
|
|
|
|
|
|
assert_equal(txid_2, unspent_tx[0]['txid'])
|
|
|
|
assert_equal('sapling', unspent_tx[0]['pool'])
|
|
|
|
assert_equal(True, unspent_tx[0]['spendable'])
|
2022-04-01 08:51:05 -07:00
|
|
|
assert_true('account' not in unspent_tx[0])
|
2022-03-31 19:44:56 -07:00
|
|
|
assert_equal(saplingzaddr, unspent_tx[0]['address'])
|
|
|
|
assert_equal(receive_amount_2, unspent_tx[0]['amount'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(False, unspent_tx[0]['change'])
|
2022-03-31 19:44:56 -07:00
|
|
|
|
|
|
|
assert_equal(txid_3, unspent_tx[1]['txid'])
|
|
|
|
assert_equal('sapling', unspent_tx[1]['pool'])
|
|
|
|
assert_equal(True, unspent_tx[1]['spendable'])
|
2022-04-01 08:51:05 -07:00
|
|
|
assert_true('account' not in unspent_tx[1])
|
2022-03-31 19:44:56 -07:00
|
|
|
assert_equal(saplingzaddr2, unspent_tx[1]['address'])
|
|
|
|
assert_equal(receive_amount_3, unspent_tx[1]['amount'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(False, unspent_tx[1]['change'])
|
2022-03-31 19:44:56 -07:00
|
|
|
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(txid_4, unspent_tx[2]['txid'])
|
|
|
|
assert_equal('orchard', unspent_tx[2]['pool'])
|
2022-03-31 19:44:56 -07:00
|
|
|
assert_equal(True, unspent_tx[2]['spendable'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(account0, unspent_tx[2]['account'])
|
|
|
|
assert_equal(ua0, unspent_tx[2]['address'])
|
|
|
|
assert_equal(receive_amount_4, unspent_tx[2]['amount'])
|
|
|
|
assert_equal(False, unspent_tx[2]['change'])
|
2022-03-31 19:44:56 -07:00
|
|
|
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_equal(txid_3, unspent_tx[3]['txid'])
|
|
|
|
assert_equal('sprout', unspent_tx[3]['pool'])
|
2022-03-31 19:44:56 -07:00
|
|
|
assert_equal(True, unspent_tx[3]['spendable'])
|
2022-08-24 10:21:36 -07:00
|
|
|
assert_true('account' not in unspent_tx[3])
|
|
|
|
assert_equal(sproutzaddr, unspent_tx[3]['address'])
|
|
|
|
assert_equal(change_amount_3, unspent_tx[3]['amount'])
|
|
|
|
assert_equal(True, unspent_tx[3]['change'])
|
2022-03-31 19:44:56 -07:00
|
|
|
|
2018-08-28 17:16:04 -07:00
|
|
|
if __name__ == '__main__':
|
2018-09-11 13:51:38 -07:00
|
|
|
WalletListNotes().main()
|