1- #!/usr/bin/env python2
1+ #!/usr/bin/env python3
22# Copyright (c) 2014-2015 The Bitcoin Core developers
33# Distributed under the MIT software license, see the accompanying
44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -36,7 +36,7 @@ def setup_network(self):
3636 self .sync_all ()
3737
3838 def run_test (self ):
39- print "Mining blocks..."
39+ print ( "Mining blocks..." )
4040 self .nodes [0 ].generate (105 )
4141 self .sync_all ()
4242
@@ -50,7 +50,7 @@ def run_test(self):
5050 assert_equal (balance0 ["balance" ], 0 )
5151
5252 # Check p2pkh and p2sh address indexes
53- print "Testing p2pkh and p2sh address index..."
53+ print ( "Testing p2pkh and p2sh address index..." )
5454
5555 txid0 = self .nodes [0 ].sendtoaddress ("yMNJePdcKvXtWWQnFYHNeJ5u8TF2v1dfK4" , 10 )
5656 self .nodes [0 ].generate (1 )
@@ -85,7 +85,7 @@ def run_test(self):
8585 assert_equal (txidsb [2 ], txidb2 )
8686
8787 # Check that limiting by height works
88- print "Testing querying txids by range of block heights.."
88+ print ( "Testing querying txids by range of block heights.." )
8989 height_txids = self .nodes [1 ].getaddresstxids ({
9090 "addresses" : ["93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB" ],
9191 "start" : 105 ,
@@ -110,8 +110,8 @@ def run_test(self):
110110 assert_equal (balance0 ["balance" ], 45 * 100000000 )
111111
112112 # Check that outputs with the same address will only return one txid
113- print "Testing for txid uniqueness..."
114- addressHash = "FE30B718DCF0BF8A2A686BF1820C073F8B2C3B37" . decode ( "hex " )
113+ print ( "Testing for txid uniqueness..." )
114+ addressHash = binascii . unhexlify ( "FE30B718DCF0BF8A2A686BF1820C073F8B2C3B37 " )
115115 scriptPubKey = CScript ([OP_HASH160 , addressHash , OP_EQUAL ])
116116 unspent = self .nodes [0 ].listunspent ()
117117 tx = CTransaction ()
@@ -130,22 +130,22 @@ def run_test(self):
130130 assert_equal (txidsmany [3 ], sent_txid )
131131
132132 # Check that balances are correct
133- print "Testing balances..."
133+ print ( "Testing balances..." )
134134 balance0 = self .nodes [1 ].getaddressbalance ("93bVhahvUKmQu8gu9g3QnPPa2cxFK98pMB" )
135135 assert_equal (balance0 ["balance" ], 45 * 100000000 + 21 )
136136
137137 # Check that balances are correct after spending
138- print "Testing balances after spending..."
138+ print ( "Testing balances after spending..." )
139139 privkey2 = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
140140 address2 = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
141- addressHash2 = "C5E4FB9171C22409809A3E8047A29C83886E325D" . decode ( "hex " )
141+ addressHash2 = binascii . unhexlify ( "C5E4FB9171C22409809A3E8047A29C83886E325D " )
142142 scriptPubKey2 = CScript ([OP_DUP , OP_HASH160 , addressHash2 , OP_EQUALVERIFY , OP_CHECKSIG ])
143143 self .nodes [0 ].importprivkey (privkey2 )
144144
145145 unspent = self .nodes [0 ].listunspent ()
146146 tx = CTransaction ()
147147 tx .vin = [CTxIn (COutPoint (int (unspent [0 ]["txid" ], 16 ), unspent [0 ]["vout" ]))]
148- amount = unspent [0 ]["amount" ] * 100000000
148+ amount = int ( unspent [0 ]["amount" ] * 100000000 )
149149 tx .vout = [CTxOut (amount , scriptPubKey2 )]
150150 tx .rehash ()
151151 signed_tx = self .nodes [0 ].signrawtransaction (binascii .hexlify (tx .serialize ()).decode ("utf-8" ))
@@ -188,13 +188,13 @@ def run_test(self):
188188 assert_equal (len (deltas ), 1 )
189189
190190 # Check that unspent outputs can be queried
191- print "Testing utxos..."
191+ print ( "Testing utxos..." )
192192 utxos = self .nodes [1 ].getaddressutxos ({"addresses" : [address2 ]})
193193 assert_equal (len (utxos ), 1 )
194194 assert_equal (utxos [0 ]["satoshis" ], change_amount )
195195
196196 # Check that indexes will be updated with a reorg
197- print "Testing reorg..."
197+ print ( "Testing reorg..." )
198198
199199 best_hash = self .nodes [0 ].getbestblockhash ()
200200 self .nodes [0 ].invalidateblock (best_hash )
@@ -228,19 +228,19 @@ def run_test(self):
228228 assert_equal (utxos3 [2 ]["height" ], 265 )
229229
230230 # Check mempool indexing
231- print "Testing mempool indexing..."
231+ print ( "Testing mempool indexing..." )
232232
233233 privKey3 = "cRyrMvvqi1dmpiCmjmmATqjAwo6Wu7QTjKu1ABMYW5aFG4VXW99K"
234234 address3 = "yWB15aAdpeKuSaQHFVJpBDPbNSLZJSnDLA"
235- addressHash3 = "6C186B3A308A77C779A9BB71C3B5A7EC28232A13" . decode ( "hex " )
235+ addressHash3 = binascii . unhexlify ( "6C186B3A308A77C779A9BB71C3B5A7EC28232A13 " )
236236 scriptPubKey3 = CScript ([OP_DUP , OP_HASH160 , addressHash3 , OP_EQUALVERIFY , OP_CHECKSIG ])
237237 # address4 = "2N8oFVB2vThAKury4vnLquW2zVjsYjjAkYQ"
238238 scriptPubKey4 = CScript ([OP_HASH160 , addressHash3 , OP_EQUAL ])
239239 unspent = self .nodes [2 ].listunspent ()
240240
241241 tx = CTransaction ()
242242 tx .vin = [CTxIn (COutPoint (int (unspent [0 ]["txid" ], 16 ), unspent [0 ]["vout" ]))]
243- amount = unspent [0 ]["amount" ] * 100000000
243+ amount = int ( unspent [0 ]["amount" ] * 100000000 )
244244 tx .vout = [CTxOut (amount , scriptPubKey3 )]
245245 tx .rehash ()
246246 signed_tx = self .nodes [2 ].signrawtransaction (binascii .hexlify (tx .serialize ()).decode ("utf-8" ))
@@ -249,12 +249,12 @@ def run_test(self):
249249
250250 tx2 = CTransaction ()
251251 tx2 .vin = [CTxIn (COutPoint (int (unspent [1 ]["txid" ], 16 ), unspent [1 ]["vout" ]))]
252- amount = unspent [1 ]["amount" ] * 100000000
252+ amount = int ( unspent [1 ]["amount" ] * 100000000 )
253253 tx2 .vout = [
254- CTxOut (amount / 4 , scriptPubKey3 ),
255- CTxOut (amount / 4 , scriptPubKey3 ),
256- CTxOut (amount / 4 , scriptPubKey4 ),
257- CTxOut (amount / 4 , scriptPubKey4 )
254+ CTxOut (int ( amount / 4 ) , scriptPubKey3 ),
255+ CTxOut (int ( amount / 4 ) , scriptPubKey3 ),
256+ CTxOut (int ( amount / 4 ) , scriptPubKey4 ),
257+ CTxOut (int ( amount / 4 ) , scriptPubKey4 )
258258 ]
259259 tx2 .rehash ()
260260 signed_tx2 = self .nodes [2 ].signrawtransaction (binascii .hexlify (tx2 .serialize ()).decode ("utf-8" ))
@@ -281,7 +281,7 @@ def run_test(self):
281281 CTxIn (COutPoint (int (memtxid2 , 16 ), 0 )),
282282 CTxIn (COutPoint (int (memtxid2 , 16 ), 1 ))
283283 ]
284- tx .vout = [CTxOut (amount / 2 - 10000 , scriptPubKey2 )]
284+ tx .vout = [CTxOut (int ( amount / 2 - 10000 ) , scriptPubKey2 )]
285285 tx .rehash ()
286286 self .nodes [2 ].importprivkey (privKey3 )
287287 signed_tx3 = self .nodes [2 ].signrawtransaction (binascii .hexlify (tx .serialize ()).decode ("utf-8" ))
@@ -298,7 +298,7 @@ def run_test(self):
298298 # sending and receiving to the same address
299299 privkey1 = "cMvZn1pVWntTEcsK36ZteGQXRAcZ8CoTbMXF1QasxBLdnTwyVQCc"
300300 address1 = "yM9Eed1bxjy7tYxD3yZDHxjcVT48WdRoB1"
301- address1hash = "0909C84A817651502E020AAD0FBCAE5F656E7D8A" . decode ( "hex " )
301+ address1hash = binascii . unhexlify ( "0909C84A817651502E020AAD0FBCAE5F656E7D8A " )
302302 address1script = CScript ([OP_DUP , OP_HASH160 , address1hash , OP_EQUALVERIFY , OP_CHECKSIG ])
303303
304304 self .nodes [0 ].sendtoaddress (address1 , 10 )
@@ -312,7 +312,7 @@ def run_test(self):
312312 tx .vin = [
313313 CTxIn (COutPoint (int (utxos [0 ]["txid" ], 16 ), utxos [0 ]["outputIndex" ]))
314314 ]
315- amount = utxos [0 ]["satoshis" ] - 10000
315+ amount = int ( utxos [0 ]["satoshis" ] - 10000 )
316316 tx .vout = [CTxOut (amount , address1script )]
317317 tx .rehash ()
318318 self .nodes [0 ].importprivkey (privkey1 )
@@ -323,7 +323,7 @@ def run_test(self):
323323 mempool_deltas = self .nodes [2 ].getaddressmempool ({"addresses" : [address1 ]})
324324 assert_equal (len (mempool_deltas ), 2 )
325325
326- print "Passed\n "
326+ print ( "Passed\n " )
327327
328328
329329if __name__ == '__main__' :
0 commit comments