55# file COPYING or https://www.opensource.org/licenses/mit-license.php .
66
77from test_framework .test_framework import PivxTestFramework
8- from test_framework .authproxy import JSONRPCException
98from test_framework .util import (
109 assert_equal ,
10+ sync_mempools ,
1111 get_coinstake_address
1212)
1313
@@ -22,16 +22,18 @@ def set_test_params(self):
2222 saplingUpgrade = ['-nuparams=v5_dummy:1' ]
2323 self .extra_args = [saplingUpgrade , saplingUpgrade , saplingUpgrade , saplingUpgrade ]
2424
25- def check_tx_priority (self , mempool , mytxid ):
26- assert (Decimal (mempool [mytxid ]['startingpriority' ]) == Decimal ('1E+25' ))
25+ def check_tx_priority (self , txids ):
26+ sync_mempools (self .nodes )
27+ mempool = self .nodes [0 ].getrawmempool (True )
28+ for txid in txids :
29+ assert (Decimal (mempool [txid ]['startingpriority' ]) == Decimal ('1E+25' ))
2730
2831 def run_test (self ):
29- # generate 100 more to activate sapling in regtest
30- self .nodes [2 ].generate (12 )
32+ self . log . info ( "Mining 120 blocks..." )
33+ self .nodes [0 ].generate (120 )
3134 self .sync_all ()
32- self .nodes [0 ].generate (360 )
3335 # Sanity-check the test harness
34- assert_equal (self . nodes [ 0 ] .getblockcount (), 372 )
36+ assert_equal ([ x .getblockcount () for x in self . nodes ], [ 120 ] * self . num_nodes )
3537
3638 taddr1 = self .nodes [1 ].getnewaddress ()
3739 saplingAddr0 = self .nodes [0 ].getnewshieldedaddress ()
@@ -53,22 +55,22 @@ def run_test(self):
5355
5456 # Node 0 shields some funds
5557 # taddr -> Sapling
58+ self .log .info ("TX 1: shield funds from specified transparent address." )
5659 recipients = [{"address" : saplingAddr0 , "amount" : Decimal ('10' )}]
5760 mytxid1 = self .nodes [0 ].shielded_sendmany (get_coinstake_address (self .nodes [0 ]), recipients , 1 , fee )
5861
5962 # shield more funds automatically selecting the transparent inputs
63+ self .log .info ("TX 2: shield funds from any transparent address." )
6064 mytxid2 = self .nodes [0 ].shielded_sendmany ("from_transparent" , recipients , 1 , fee )
6165
6266 # shield more funds creating and then sending a raw transaction
67+ self .log .info ("TX 3: shield funds creating and sending raw transaction." )
6368 tx_json = self .nodes [0 ].raw_shielded_sendmany ("from_transparent" , recipients , 1 , fee )
6469 mytxid3 = self .nodes [0 ].sendrawtransaction (tx_json ["hex" ])
6570
6671 # Verify priority of tx is INF_PRIORITY, defined as 1E+25 (10000000000000000000000000)
67- self .sync_all ()
68- mempool = self .nodes [0 ].getrawmempool (True )
69- self .check_tx_priority (mempool , mytxid1 )
70- self .check_tx_priority (mempool , mytxid2 )
71- self .check_tx_priority (mempool , mytxid3 )
72+ self .check_tx_priority ([mytxid1 , mytxid2 , mytxid3 ])
73+ self .log .info ("Priority for tx1, tx2 and tx3 checks out" )
7274
7375 self .nodes [2 ].generate (1 )
7476 self .sync_all ()
@@ -77,44 +79,33 @@ def run_test(self):
7779 assert_equal (self .nodes [0 ].getshieldedbalance (saplingAddr0 ), Decimal ('30' ))
7880 assert_equal (self .nodes [1 ].getshieldedbalance (saplingAddr1 ), Decimal ('0' ))
7981 assert_equal (self .nodes [1 ].getreceivedbyaddress (taddr1 ), Decimal ('0' ))
82+ self .log .info ("Balances check out" )
8083
8184 # Node 0 sends some shielded funds to node 1
8285 # Sapling -> Sapling
8386 # -> Sapling (change)
87+ self .log .info ("TX 4: shielded transaction from specified sapling address." )
8488 recipients4 = [{"address" : saplingAddr1 , "amount" : Decimal ('10' )}]
8589 mytxid4 = self .nodes [0 ].shielded_sendmany (saplingAddr0 , recipients4 , 1 , fee )
86-
87- self .sync_all ()
88-
89- # Verify priority of tx is MAX_PRIORITY, defined as 1E+25 (10000000000000000000000000)
90- mempool = self .nodes [0 ].getrawmempool (True )
91- self .check_tx_priority (mempool , mytxid4 )
90+ self .check_tx_priority ([mytxid4 ])
9291
9392 self .nodes [2 ].generate (1 )
9493 self .sync_all ()
9594
9695 # Send more shielded funds (this time with automatic selection of the source)
96+ self .log .info ("TX 5: shielded transaction from any sapling address." )
9797 recipients5 = [{"address" : saplingAddr1 , "amount" : Decimal ('5' )}]
9898 mytxid5 = self .nodes [0 ].shielded_sendmany ("from_shielded" , recipients5 , 1 , fee )
99-
100- self .sync_all ()
101-
102- # Verify priority of tx is MAX_PRIORITY, defined as 1E+25 (10000000000000000000000000)
103- mempool = self .nodes [0 ].getrawmempool (True )
104- self .check_tx_priority (mempool , mytxid5 )
99+ self .check_tx_priority ([mytxid5 ])
105100
106101 self .nodes [2 ].generate (1 )
107102 self .sync_all ()
108103
109104 # Send more shielded funds (with create + send raw transaction)
105+ self .log .info ("TX 6: shielded raw transaction." )
110106 tx_json = self .nodes [0 ].raw_shielded_sendmany ("from_shielded" , recipients5 , 1 , fee )
111107 mytxid6 = self .nodes [0 ].sendrawtransaction (tx_json ["hex" ])
112-
113- self .sync_all ()
114-
115- # Verify priority of tx is MAX_PRIORITY, defined as 1E+25 (10000000000000000000000000)
116- mempool = self .nodes [0 ].getrawmempool (True )
117- self .check_tx_priority (mempool , mytxid6 )
108+ self .check_tx_priority ([mytxid6 ])
118109
119110 self .nodes [2 ].generate (1 )
120111 self .sync_all ()
@@ -123,19 +114,17 @@ def run_test(self):
123114 assert_equal (self .nodes [0 ].getshieldedbalance (saplingAddr0 ), Decimal ('7' )) # 30 received - (20 sent + 3 fee)
124115 assert_equal (self .nodes [1 ].getshieldedbalance (saplingAddr1 ), Decimal ('20' )) # 20 received
125116 assert_equal (self .nodes [1 ].getreceivedbyaddress (taddr1 ), Decimal ('0' ))
117+ self .log .info ("Balances check out" )
126118
127119 # Node 1 sends some shielded funds to node 0, as well as unshielding
128120 # Sapling -> Sapling
129121 # -> taddr
130122 # -> Sapling (change)
123+ self .log .info ("TX 7: deshield funds from specified sapling address." )
131124 recipients7 = [{"address" : saplingAddr0 , "amount" : Decimal ('8' )}]
132125 recipients7 .append ({"address" : taddr1 , "amount" : Decimal ('10' )})
133126 mytxid7 = self .nodes [1 ].shielded_sendmany (saplingAddr1 , recipients7 , 1 , fee )
134- self .sync_all ()
135-
136- # Verify priority of tx is MAX_PRIORITY, defined as 1E+25 (10000000000000000000000000)
137- mempool = self .nodes [1 ].getrawmempool (True )
138- self .check_tx_priority (mempool , mytxid7 )
127+ self .check_tx_priority ([mytxid7 ])
139128
140129 self .nodes [2 ].generate (1 )
141130 self .sync_all ()
@@ -144,6 +133,7 @@ def run_test(self):
144133 assert_equal (self .nodes [0 ].getshieldedbalance (saplingAddr0 ), Decimal ('15' )) # 7 prev balance + 8 received
145134 assert_equal (self .nodes [1 ].getshieldedbalance (saplingAddr1 ), Decimal ('1' )) # 20 prev balance - (18 sent + 1 fee)
146135 assert_equal (self .nodes [1 ].getreceivedbyaddress (taddr1 ), Decimal ('10' ))
136+ self .log .info ("Balances check out" )
147137
148138 # Verify existence of Sapling related JSON fields
149139 resp = self .nodes [0 ].getrawtransaction (mytxid7 , 1 )
@@ -165,8 +155,10 @@ def run_test(self):
165155 assert ('encCiphertext' in shieldedOutput )
166156 assert ('outCiphertext' in shieldedOutput )
167157 assert ('proof' in shieldedOutput )
158+ self .log .info ("Raw transaction decoding checks out" )
168159
169160 # Verify importing a spending key will update the nullifiers and witnesses correctly
161+ self .log .info ("Checking exporting/importing a spending key..." )
170162 sk0 = self .nodes [0 ].exportsaplingkey (saplingAddr0 )
171163 saplingAddrInfo0 = self .nodes [2 ].importsaplingkey (sk0 , "yes" )
172164 assert_equal (saplingAddrInfo0 ["address" ], saplingAddr0 )
@@ -177,6 +169,7 @@ def run_test(self):
177169 assert_equal (self .nodes [2 ].getshieldedbalance (saplingAddrInfo1 ["address" ]), Decimal ('1' ))
178170
179171 # Verify importing a viewing key will update the nullifiers and witnesses correctly
172+ self .log .info ("Checking exporting/importing a viewing key..." )
180173 extfvk0 = self .nodes [0 ].exportsaplingviewingkey (saplingAddr0 )
181174 saplingAddrInfo0 = self .nodes [3 ].importsaplingviewingkey (extfvk0 , "yes" )
182175 assert_equal (saplingAddrInfo0 ["address" ], saplingAddr0 )
@@ -185,15 +178,12 @@ def run_test(self):
185178 saplingAddrInfo1 = self .nodes [3 ].importsaplingviewingkey (extfvk1 , "yes" )
186179 assert_equal (saplingAddrInfo1 ["address" ], saplingAddr1 )
187180 assert_equal (self .nodes [3 ].getshieldedbalance (saplingAddrInfo1 ["address" ], 1 , True ), Decimal ('1' ))
188-
189- # Verify that getshieldedbalance only includes watch-only addresses when requested
190- shieldedBalance = self .nodes [3 ].getshieldedbalance ()
191181 # no balance in the wallet
192- assert_equal (shieldedBalance , Decimal ('0' ))
193-
194- shieldedBalance = self .nodes [3 ].getshieldedbalance ("*" , 1 , True )
182+ assert_equal (self .nodes [3 ].getshieldedbalance (), Decimal ('0' ))
195183 # watch only balance
196- assert_equal (shieldedBalance , Decimal ('16.00' ))
184+ assert_equal (self .nodes [3 ].getshieldedbalance ("*" , 1 , True ), Decimal ('16.00' ))
185+
186+ self .log .info ("All good." )
197187
198188if __name__ == '__main__' :
199189 WalletSaplingTest ().main ()
0 commit comments