2022-09-21 19:10:28 -07:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# Copyright (c) 2016-2022 The Zcash developers
|
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
|
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
|
|
|
|
|
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
|
from test_framework.util import (
|
|
|
|
|
assert_equal,
|
|
|
|
|
get_coinbase_address,
|
|
|
|
|
nuparams,
|
|
|
|
|
start_nodes,
|
|
|
|
|
wait_and_assert_operationid_status,
|
|
|
|
|
NU5_BRANCH_ID
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
from decimal import Decimal
|
|
|
|
|
|
2022-11-17 10:46:50 -08:00
|
|
|
|
def unspent_total(unspent):
|
2022-11-21 20:15:07 -08:00
|
|
|
|
return sum((item['amount'] for item in unspent))
|
2022-11-17 10:46:50 -08:00
|
|
|
|
|
2022-09-21 19:10:28 -07:00
|
|
|
|
class WalletListUnspent(BitcoinTestFramework):
|
|
|
|
|
def setup_nodes(self):
|
|
|
|
|
return start_nodes(4, self.options.tmpdir, [[
|
|
|
|
|
nuparams(NU5_BRANCH_ID, 201),
|
|
|
|
|
]] * 4)
|
|
|
|
|
|
2022-11-21 20:35:06 -08:00
|
|
|
|
def matured_at_height(self, height):
|
2022-11-22 21:05:11 -08:00
|
|
|
|
return unspent_total(self.nodes[0].listunspent(1, 999999, [], False, {}, height))
|
2022-11-21 20:35:06 -08:00
|
|
|
|
|
2022-09-21 19:10:28 -07:00
|
|
|
|
def run_test(self):
|
2022-11-22 14:59:07 -08:00
|
|
|
|
def expected_matured_at_height(height):
|
|
|
|
|
return (height-200)*10 + 250
|
|
|
|
|
|
|
|
|
|
assert_equal(self.nodes[0].getbalance(), expected_matured_at_height(200))
|
|
|
|
|
assert_equal(self.nodes[1].getbalance(), expected_matured_at_height(200))
|
2022-09-21 19:10:28 -07:00
|
|
|
|
|
|
|
|
|
# Activate NU5
|
|
|
|
|
self.nodes[1].generate(1) # height 201
|
|
|
|
|
self.sync_all()
|
2022-11-22 14:59:07 -08:00
|
|
|
|
assert_equal(self.nodes[0].getbalance(), expected_matured_at_height(201))
|
2022-11-21 17:42:38 -08:00
|
|
|
|
# check balances from before the latest tx
|
2022-11-22 14:59:07 -08:00
|
|
|
|
assert_equal(self.nodes[0].getbalance("", 1, False, False, 200), expected_matured_at_height(200))
|
|
|
|
|
assert_equal(self.matured_at_height(200), expected_matured_at_height(200))
|
2022-09-21 19:10:28 -07:00
|
|
|
|
|
|
|
|
|
# Shield some coinbase funds so that they become spendable
|
|
|
|
|
n1acct = self.nodes[1].z_getnewaccount()['account']
|
|
|
|
|
n1uaddr = self.nodes[1].z_getaddressforaccount(n1acct)['address']
|
|
|
|
|
opid = self.nodes[0].z_sendmany(
|
|
|
|
|
get_coinbase_address(self.nodes[0]),
|
|
|
|
|
[{'address': n1uaddr, 'amount': 10}],
|
|
|
|
|
1, 0, 'AllowRevealedSenders')
|
|
|
|
|
wait_and_assert_operationid_status(self.nodes[0], opid)
|
|
|
|
|
|
|
|
|
|
self.sync_all()
|
|
|
|
|
self.nodes[1].generate(2)
|
|
|
|
|
self.sync_all() # height 203
|
2022-11-22 14:59:07 -08:00
|
|
|
|
assert_equal(self.nodes[0].getbalance(), expected_matured_at_height(203) - 10)
|
2022-09-21 19:10:28 -07:00
|
|
|
|
|
|
|
|
|
assert_equal(
|
|
|
|
|
self.nodes[1].z_getbalanceforaccount(n1acct, 1)['pools']['orchard']['valueZat'],
|
|
|
|
|
Decimal('1000000000'))
|
|
|
|
|
|
|
|
|
|
# Get a bare legacy transparent address for node 0
|
|
|
|
|
n0addr = self.nodes[0].getnewaddress()
|
|
|
|
|
|
|
|
|
|
# Send funds to the node 0 address so we have transparent funds to spend.
|
|
|
|
|
opid = self.nodes[1].z_sendmany(
|
|
|
|
|
n1uaddr,
|
|
|
|
|
[{'address': n0addr, 'amount': 10}],
|
|
|
|
|
1, 0, 'AllowRevealedRecipients')
|
|
|
|
|
wait_and_assert_operationid_status(self.nodes[1], opid)
|
|
|
|
|
|
|
|
|
|
self.sync_all()
|
|
|
|
|
self.nodes[1].generate(2)
|
|
|
|
|
self.sync_all() # height 205
|
2022-11-22 14:59:07 -08:00
|
|
|
|
assert_equal(self.nodes[0].getbalance(), expected_matured_at_height(205) - 10 + 10)
|
2022-09-21 19:10:28 -07:00
|
|
|
|
|
|
|
|
|
# We will then perform several spends, and then check the list of
|
|
|
|
|
# unspent notes as of various heights.
|
|
|
|
|
|
|
|
|
|
opid = self.nodes[0].z_sendmany(
|
|
|
|
|
'ANY_TADDR',
|
2022-11-21 17:42:38 -08:00
|
|
|
|
# FIXME: #6262 The amount here _should_ be 2, but because of a
|
|
|
|
|
# bug in the selector for `ANY_TADDR`, it’s selecting
|
|
|
|
|
# transparent coinbase, which also means we can’t have
|
|
|
|
|
# change. When that bug is fixed, the test should fail
|
|
|
|
|
# here, and we can switch it back to 2 (and cascade the
|
|
|
|
|
# corrected amounts mentioned below.
|
|
|
|
|
[{'address': n1uaddr, 'amount': 10}],
|
2022-09-21 19:10:28 -07:00
|
|
|
|
1, 0, 'AllowRevealedSenders')
|
|
|
|
|
wait_and_assert_operationid_status(self.nodes[0], opid)
|
|
|
|
|
|
|
|
|
|
self.nodes[0].generate(2)
|
|
|
|
|
self.sync_all() # height 207
|
2022-11-22 14:59:07 -08:00
|
|
|
|
# FIXME: #6262, should be `expected_matured_at_height(207) - 10 + 10 - 2`
|
|
|
|
|
assert_equal(self.nodes[0].getbalance(), expected_matured_at_height(207) - 10 + 10 - 10)
|
2022-09-21 19:10:28 -07:00
|
|
|
|
|
|
|
|
|
opid = self.nodes[0].z_sendmany(
|
|
|
|
|
'ANY_TADDR',
|
2022-11-21 17:42:38 -08:00
|
|
|
|
# FIXME: Should be 3 (see above)
|
|
|
|
|
[{'address': n1uaddr, 'amount': 10}],
|
2022-09-21 19:10:28 -07:00
|
|
|
|
1, 0, 'AllowRevealedSenders')
|
|
|
|
|
wait_and_assert_operationid_status(self.nodes[0], opid)
|
|
|
|
|
|
|
|
|
|
self.nodes[0].generate(2)
|
|
|
|
|
self.sync_all() # height 209
|
2022-11-22 14:59:07 -08:00
|
|
|
|
# FIXME: #6262, should be `expected_matured_at_height(209) - 10 + 10 - 2 - 3`
|
|
|
|
|
assert_equal(self.nodes[0].getbalance(), expected_matured_at_height(209) - 10 + 10 - 10 - 10)
|
2022-09-21 19:10:28 -07:00
|
|
|
|
|
|
|
|
|
opid = self.nodes[0].z_sendmany(
|
|
|
|
|
'ANY_TADDR',
|
2022-11-21 17:42:38 -08:00
|
|
|
|
# FIXME: Should be 5 (see above)
|
|
|
|
|
[{'address': n1uaddr, 'amount': 10}],
|
2022-09-21 19:10:28 -07:00
|
|
|
|
1, 0, 'AllowRevealedSenders')
|
|
|
|
|
wait_and_assert_operationid_status(self.nodes[0], opid)
|
|
|
|
|
|
|
|
|
|
self.nodes[0].generate(2)
|
|
|
|
|
self.sync_all() # height 211
|
2022-11-22 14:59:07 -08:00
|
|
|
|
# FIXME: #6262, should be `expected_matured_at_height(211) - 10 + 10 - 2 - 3 - 5`
|
|
|
|
|
assert_equal(self.nodes[0].getbalance(), expected_matured_at_height(211) - 10 + 10 - 10 - 10 - 10)
|
2022-11-21 17:42:38 -08:00
|
|
|
|
|
|
|
|
|
# check balances at various past points in the chain
|
2022-11-22 09:36:34 -08:00
|
|
|
|
# FIXME: #6262, change the comparison amounts when the above changes are made.
|
2022-11-22 14:59:07 -08:00
|
|
|
|
assert_equal(self.matured_at_height(205), expected_matured_at_height(205) - 10 + 10)
|
|
|
|
|
assert_equal(self.matured_at_height(207), expected_matured_at_height(207) - 10 + 10 - 10)
|
|
|
|
|
assert_equal(self.matured_at_height(209), expected_matured_at_height(209) - 10 + 10 - 10 - 10)
|
2022-11-22 15:44:27 -08:00
|
|
|
|
assert_equal(self.matured_at_height(211), expected_matured_at_height(211) - 10 + 10 - 10 - 10 - 10)
|
2022-09-21 19:10:28 -07:00
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
WalletListUnspent().main()
|