33# Distributed under the MIT software license, see the accompanying
44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
6- from time import sleep
7- import urllib
8-
9- from test_framework .authproxy import JSONRPCException
10- from test_framework .messages import COutPoint
116from test_framework .test_framework import PivxTestFramework
127from test_framework .util import (
138 sync_blocks ,
1611 connect_nodes_bi ,
1712 connect_nodes_clique ,
1813 disconnect_nodes ,
19- bytes_to_hex_str ,
2014 set_node_times ,
2115 DecimalAmt ,
2216)
@@ -92,16 +86,18 @@ def findUtxoInList(txid, vout, utxo_list):
9286 self .log .info ("Balances ok." )
9387
9488 # create the raw zerocoin spend txes
89+ addy = self .nodes [2 ].getnewaddress ()
9590 self .log .info ("Creating the raw zerocoin public spends..." )
9691 mints = self .nodes [2 ].listmintedzerocoins (True , True )
97- tx_A0 = self .nodes [2 ].createrawzerocoinspend (mints [0 ]["serial hash" ])
98- tx_A1 = self .nodes [2 ].createrawzerocoinspend (mints [1 ]["serial hash" ])
92+ tx_A0 = self .nodes [2 ].createrawzerocoinspend (mints [0 ]["serial hash" ], addy )
93+ tx_A1 = self .nodes [2 ].createrawzerocoinspend (mints [1 ]["serial hash" ], addy )
9994 # Spending same coins to different recipients to get different txids
100- my_addy = "yAVWM5urwaTyhiuFQHP2aP47rdZsLUG5PH"
101- tx_B0 = self .nodes [2 ].createrawzerocoinspend (mints [0 ]["serial hash" ], my_addy )
102- tx_B1 = self .nodes [2 ].createrawzerocoinspend (mints [1 ]["serial hash" ], my_addy )
95+ new_addy = "yAVWM5urwaTyhiuFQHP2aP47rdZsLUG5PH"
96+ tx_B0 = self .nodes [2 ].createrawzerocoinspend (mints [0 ]["serial hash" ], new_addy )
97+ tx_B1 = self .nodes [2 ].createrawzerocoinspend (mints [1 ]["serial hash" ], new_addy )
10398
10499 # Disconnect nodes
100+ minted_amount = mints [0 ]["denomination" ] + mints [1 ]["denomination" ]
105101 self .disconnect_all ()
106102
107103 # Stake one block with node-0 and save the stake input
@@ -126,8 +122,8 @@ def findUtxoInList(txid, vout, utxo_list):
126122 stakeinput ["txid" ][:9 ], stakeinput ["txid" ][- 4 :], stakeinput ["vout" ]))
127123
128124 # Relay zerocoin spends
129- txid_A0 = self .nodes [0 ].sendrawtransaction (tx_A0 )
130- txid_A1 = self .nodes [0 ].sendrawtransaction (tx_A1 )
125+ self .nodes [0 ].sendrawtransaction (tx_A0 )
126+ self .nodes [0 ].sendrawtransaction (tx_A1 )
131127
132128 # Stake 10 more blocks with node-0 and check balances
133129 self .log .info ("Staking 10 more blocks with node 0..." )
@@ -138,10 +134,14 @@ def findUtxoInList(txid, vout, utxo_list):
138134 self .log .info ("Balance for node 0 checks out." )
139135
140136 # Connect with node 2, sync and check zerocoin balance
137+ self .log .info ("Reconnecting node 0 and node 2" )
141138 connect_nodes_bi (self .nodes , 0 , 2 )
142139 sync_blocks ([self .nodes [i ] for i in [0 , 2 ]])
143- assert_equal (self .get_tot_balance (2 ), initial_balance [2 ] + DecimalAmt (6666 ))
144- assert_equal (self .nodes [2 ].getzerocoinbalance ()['Total' ], DecimalAmt (0 ))
140+ self .log .info ("Resetting zerocoin mints on node 2" )
141+ self .nodes [2 ].resetmintzerocoin (True )
142+ assert_equal (self .get_tot_balance (2 ), initial_balance [2 ] + DecimalAmt (minted_amount ))
143+ assert_equal (self .nodes [2 ].getzerocoinbalance ()['Total' ], DecimalAmt (6666 - minted_amount ))
144+ self .log .info ("Balance for node 2 checks out." )
145145
146146 # Double spending txes not possible
147147 assert_raises_rpc_error (- 26 , "bad-txns-invalid-zpiv" ,
@@ -150,25 +150,26 @@ def findUtxoInList(txid, vout, utxo_list):
150150 self .nodes [0 ].sendrawtransaction , tx_B1 )
151151
152152 # verify that the stakeinput can't be spent
153+ stakeinput_tx_json = self .nodes [0 ].getrawtransaction (stakeinput ["txid" ], True )
154+ stakeinput_amount = float (stakeinput_tx_json ["vout" ][int (stakeinput ["vout" ])]["value" ])
153155 rawtx_unsigned = self .nodes [0 ].createrawtransaction (
154- [{"txid" : str ( stakeinput ["txid" ]) , "vout" : int (stakeinput ["vout" ])}],
155- {"xxncEuJK27ygNh7imNfaX8JV6ZQUnoBqzN" : 249.99 })
156+ [{"txid" : stakeinput ["txid" ], "vout" : int (stakeinput ["vout" ])}],
157+ {"xxncEuJK27ygNh7imNfaX8JV6ZQUnoBqzN" : ( stakeinput_amount - 0.01 ) })
156158 rawtx = self .nodes [0 ].signrawtransaction (rawtx_unsigned )
157159 assert (rawtx ["complete" ])
158- assert_raises_rpc_error (- 25 , "Missing inputs" , self .nodes [0 ].sendrawtransaction , rawtx ["hex" ])
160+ assert_raises_rpc_error (- 26 , "bad-txns- inputs-spent" , self .nodes [0 ].sendrawtransaction , rawtx ["hex" ])
159161
160162 # Spend tx_B0 and tx_B1 on the other chain
161- txid_B0 = self .nodes [1 ].sendrawtransaction (tx_B0 )
162- txid_B1 = self .nodes [1 ].sendrawtransaction (tx_B1 )
163+ self .nodes [1 ].sendrawtransaction (tx_B0 )
164+ self .nodes [1 ].sendrawtransaction (tx_B1 )
163165
164166 # Stake 12 blocks with node-1
165167 set_node_times (self .nodes , block_time_1 )
166168 self .log .info ("Staking 12 blocks with node 1..." )
167169 for i in range (12 ):
168170 block_time_1 = self .generate_pos (1 , block_time_1 )
169171 expected_balance_1 = initial_balance [1 ] + DecimalAmt (12 * 250.0 )
170- w_info = self .nodes [1 ].getwalletinfo ()
171- assert_equal (w_info ["balance" ] + w_info ["immature_balance" ], expected_balance_1 )
172+ assert_equal (self .get_tot_balance (1 ), expected_balance_1 )
172173 self .log .info ("Balance for node 1 checks out." )
173174
174175 # re-connect and sync nodes and check that node-0 and node-2 get on the other chain
@@ -180,19 +181,8 @@ def findUtxoInList(txid, vout, utxo_list):
180181 for i in [0 , 2 ]:
181182 assert_equal (self .nodes [i ].getbestblockhash (), new_best_hash )
182183
183- # check that old zc spends have been removed and new one are present
184- for i in range (self .num_nodes ):
185- print (i )
186- try :
187- print (self .nodes [i ].getrawtransaction (txid_A0 ))
188- print (self .nodes [i ].getrawtransaction (txid_A1 ))
189- except Exception as e :
190- print (str (e ))
191-
192184 # check balance of node-0
193- balance_0 = initial_balance [0 ]
194- w_info = self .nodes [0 ].getwalletinfo ()
195- assert_equal (w_info ["balance" ] + w_info ["immature_balance" ], initial_balance [0 ])
185+ assert_equal (self .get_tot_balance (0 ), initial_balance [0 ])
196186 self .log .info ("Balance for node 0 checks out." )
197187
198188 # check that NOW the original stakeinput is present and spendable
0 commit comments