Skip to content

Commit 69dd8f4

Browse files
committed
Python 3 fixes/porting in rpc tests
1 parent 2924b34 commit 69dd8f4

File tree

8 files changed

+47
-49
lines changed

8 files changed

+47
-49
lines changed

qa/rpc-tests/addressindex.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

329329
if __name__ == '__main__':

qa/rpc-tests/disablewallet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def run_test (self):
3333
# Checking mining to an address without a wallet
3434
try:
3535
self.nodes[0].generatetoaddress(1, 'ycwedq2f3sz2Yf9JqZsBCQPxp18WU3Hp4J')
36-
except JSONRPCException,e:
36+
except JSONRPCException as e:
3737
assert("Invalid address" not in e.error['message'])
3838
assert("ProcessNewBlock, block not accepted" not in e.error['message'])
3939
assert("Couldn't create new block" not in e.error['message'])
4040

4141
try:
4242
self.nodes[0].generatetoaddress(1, '7TSBtVu959hGEGPKyHjJz9k55RpWrPffXz')
4343
raise AssertionError("Must not mine to invalid address!")
44-
except JSONRPCException,e:
44+
except JSONRPCException as e:
4545
assert("Invalid address" in e.error['message'])
4646

4747
if __name__ == '__main__':

qa/rpc-tests/fundrawtransaction-hd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.
@@ -25,7 +25,7 @@ def setup_network(self, split=False):
2525
self.sync_all()
2626

2727
def run_test(self):
28-
print "Mining blocks..."
28+
print("Mining blocks...")
2929

3030
min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee']
3131
# This test is not meant to test fee estimation and we'd like

qa/rpc-tests/keypool-hd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.

qa/rpc-tests/spentindex.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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,23 +36,23 @@ 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

4343
chain_height = self.nodes[1].getblockcount()
4444
assert_equal(chain_height, 105)
4545

4646
# Check that
47-
print "Testing spent index..."
47+
print("Testing spent index...")
4848

4949
privkey = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
5050
address = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
51-
addressHash = "C5E4FB9171C22409809A3E8047A29C83886E325D".decode("hex")
51+
addressHash = binascii.unhexlify("C5E4FB9171C22409809A3E8047A29C83886E325D")
5252
scriptPubKey = CScript([OP_DUP, OP_HASH160, addressHash, OP_EQUALVERIFY, OP_CHECKSIG])
5353
unspent = self.nodes[0].listunspent()
5454
tx = CTransaction()
55-
amount = unspent[0]["amount"] * 100000000
55+
amount = int(unspent[0]["amount"] * 100000000)
5656
tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
5757
tx.vout = [CTxOut(amount, scriptPubKey)]
5858
tx.rehash()
@@ -62,15 +62,15 @@ def run_test(self):
6262
self.nodes[0].generate(1)
6363
self.sync_all()
6464

65-
print "Testing getspentinfo method..."
65+
print("Testing getspentinfo method...")
6666

6767
# Check that the spentinfo works standalone
6868
info = self.nodes[1].getspentinfo({"txid": unspent[0]["txid"], "index": unspent[0]["vout"]})
6969
assert_equal(info["txid"], txid)
7070
assert_equal(info["index"], 0)
7171
assert_equal(info["height"], 106)
7272

73-
print "Testing getrawtransaction method..."
73+
print("Testing getrawtransaction method...")
7474

7575
# Check that verbose raw transaction includes spent info
7676
txVerbose = self.nodes[3].getrawtransaction(unspent[0]["txid"], 1)
@@ -86,7 +86,7 @@ def run_test(self):
8686
# Check that verbose raw transaction includes address values and input values
8787
privkey2 = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
8888
address2 = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
89-
addressHash2 = "C5E4FB9171C22409809A3E8047A29C83886E325D".decode("hex")
89+
addressHash2 = binascii.unhexlify("C5E4FB9171C22409809A3E8047A29C83886E325D")
9090
scriptPubKey2 = CScript([OP_DUP, OP_HASH160, addressHash2, OP_EQUALVERIFY, OP_CHECKSIG])
9191
tx2 = CTransaction()
9292
tx2.vin = [CTxIn(COutPoint(int(txid, 16), 0))]
@@ -112,7 +112,7 @@ def run_test(self):
112112
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
113113
assert_equal(txVerbose4["vin"][0]["valueSat"], amount)
114114

115-
print "Passed\n"
115+
print("Passed\n")
116116

117117

118118
if __name__ == '__main__':

qa/rpc-tests/timestampindex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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.
@@ -35,16 +35,16 @@ def setup_network(self):
3535
self.sync_all()
3636

3737
def run_test(self):
38-
print "Mining 5 blocks..."
38+
print("Mining 5 blocks...")
3939
blockhashes = self.nodes[0].generate(5)
4040
low = self.nodes[0].getblock(blockhashes[0])["time"]
4141
high = self.nodes[0].getblock(blockhashes[4])["time"]
4242
self.sync_all()
43-
print "Checking timestamp index..."
43+
print("Checking timestamp index...")
4444
hashes = self.nodes[1].getblockhashes(high, low)
4545
assert_equal(len(hashes), 5)
4646
assert_equal(sorted(blockhashes), sorted(hashes))
47-
print "Passed\n"
47+
print("Passed\n")
4848

4949

5050
if __name__ == '__main__':

qa/rpc-tests/txindex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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,14 +36,14 @@ 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

4343
chain_height = self.nodes[1].getblockcount()
4444
assert_equal(chain_height, 105)
4545

46-
print "Testing transaction index..."
46+
print("Testing transaction index...")
4747

4848
privkey = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
4949
address = "yeMpGzMj3rhtnz48XsfpB8itPHhHtgxLc3"
@@ -66,7 +66,7 @@ def run_test(self):
6666
assert_equal(verbose["vout"][0]["valueSat"], 5000000000);
6767
assert_equal(verbose["vout"][0]["value"], 50);
6868

69-
print "Passed\n"
69+
print("Passed\n")
7070

7171

7272
if __name__ == '__main__':

qa/rpc-tests/wallet-hd.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#!/usr/bin/env python2
2-
# coding=utf-8
3-
# ^^^^^^^^^^^^ TODO remove when supporting only Python3
1+
#!/usr/bin/env python3
42
# Copyright (c) 2016 The Bitcoin Core developers
53
# Distributed under the MIT software license, see the accompanying
64
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

0 commit comments

Comments
 (0)