11#!/usr/bin/env python3
2- # Copyright (c) 2021-2024 The Zcash developers
2+ # Copyright (c) 2021-2025 The Zcash developers
33# Distributed under the MIT software license, see the accompanying
44# file COPYING or https://www.opensource.org/licenses/mit-license.php .
55
88 BLOSSOM_BRANCH_ID ,
99 CANOPY_BRANCH_ID ,
1010 HEARTWOOD_BRANCH_ID ,
11+ NU5_BRANCH_ID ,
1112 OVERWINTER_BRANCH_ID ,
1213 SAPLING_BRANCH_ID ,
1314 assert_equal ,
@@ -32,6 +33,7 @@ def setup_network(self, split=False):
3233 nuparams (BLOSSOM_BRANCH_ID , 1 ),
3334 nuparams (HEARTWOOD_BRANCH_ID , 1 ),
3435 nuparams (CANOPY_BRANCH_ID , 1 ),
36+ nuparams (NU5_BRANCH_ID , 110 ),
3537 '-allowdeprecated=getnewaddress' ,
3638 '-allowdeprecated=z_getnewaddress' ,
3739 ]])
@@ -85,5 +87,51 @@ def run_test (self):
8587 # "getbalance '' 0" should count both outputs. The bug failed here.
8688 assert_equal (Decimal (node .getbalance ('' , 0 )), Decimal ('12.5' ) - coinbase_fee - fee )
8789
90+ # Mine the transaction; we get another coinbase output.
91+ node .generate (8 )
92+ self .sync_all ()
93+ assert_equal (Decimal (node .getbalance ('' , 0 )), Decimal ('62.5' ) - coinbase_fee - fee )
94+
95+ # Send all available funds to an Orchard UA.
96+ acct = node .z_getnewaccount ()['account' ]
97+ orchard_ua = node .z_getaddressforaccount (acct , ['orchard' ])['address' ]
98+ recipients = [{'address' : orchard_ua , 'amount' : Decimal ('6.25' ) - coinbase_fee - 2 * fee }]
99+ # minconf = 1 is requires for `TransactionEffects::ApproveAndBuild`
100+ # to use an Orchard anchor.
101+ opid = node .z_sendmany (taddr , recipients , 1 , fee , 'AllowRevealedSenders' )
102+ wait_and_assert_operationid_status (node , opid )
103+ self .sync_all ()
104+ assert_equal (Decimal (node .getbalance ('' , 0 )), Decimal ('62.5' ) - Decimal ('6.25' ))
105+
106+ # Mine the transaction; we get another coinbase output.
107+ node .generate (1 )
108+ self .sync_all ()
109+ assert_equal (Decimal (node .getbalance ('' , 0 )), Decimal ('68.75' ) - Decimal ('6.25' ))
110+
111+ # Now send the funds back to a new t-address.
112+ taddr = node .getnewaddress ()
113+ recipients = [{'address' : taddr , 'amount' : Decimal ('6.25' ) - coinbase_fee - 3 * fee }]
114+ # TODO: this fails for ZIP_317_FEE due to a dust threshold problem:
115+ # "Insufficient funds: have 6.24985, need 0.00000054 more to surpass the dust
116+ # threshold and avoid being forced to over-pay the fee. Alternatively, you could
117+ # specify a fee of 0.0001 to allow overpayment of the conventional fee and have
118+ # this transaction proceed.; note that coinbase outputs will not be selected if
119+ # you specify ANY_TADDR, any transparent recipients are included, or if the
120+ # `privacyPolicy` parameter is not set to `AllowRevealedSenders` or weaker."
121+ opid = node .z_sendmany (orchard_ua , recipients , 1 , fee , 'AllowRevealedRecipients' )
122+ wait_and_assert_operationid_status (node , opid )
123+ self .sync_all ()
124+
125+ # At this point we have created the conditions for the bug fixed in
126+ # https://github.com/zcash/zcash/pull/5325.
127+
128+ # listunspent should show the coinbase outputs, and optionally the
129+ # newly-received unshielding output.
130+ assert_equal (len (node .listunspent ()), 10 )
131+ assert_equal (len (node .listunspent (0 )), 11 )
132+
133+ # "getbalance '' 0" should count both outputs. The Orchard bug failed here.
134+ assert_equal (Decimal (node .getbalance ('' , 0 )), Decimal ('68.75' ) - coinbase_fee - 3 * fee )
135+
88136if __name__ == '__main__' :
89137 WalletIsFromMe ().main ()
0 commit comments