From 7648ebf57eeceedcb3e838fb8dc7f7ef532428d2 Mon Sep 17 00:00:00 2001 From: mdr0id Date: Wed, 4 Dec 2019 08:04:42 -0800 Subject: [PATCH] update to py3 conventions, BUG with last assert_equal --- qa/rpc-tests/addressindex.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index b4562f9ef..04d19d60a 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright (c) 2019 The Zcash developers # Distributed under the MIT software license, see the accompanying # file COPYING or https://www.opensource.org/licenses/mit-license.php . @@ -13,7 +13,6 @@ # getaddressutxos # getaddressmempool -import sys; assert sys.version_info < (3,), ur"This script does not run under Python 3. Please use Python 2.7.x." from test_framework.test_framework import BitcoinTestFramework @@ -40,7 +39,7 @@ from test_framework.mininode import ( CTxIn, CTxOut, COutPoint, ) -from binascii import hexlify +from binascii import unhexlify, hexlify class AddressIndexTest(BitcoinTestFramework): @@ -252,7 +251,7 @@ class AddressIndexTest(BitcoinTestFramework): # Ensure the change from that transaction appears tx = self.nodes[0].getrawtransaction(txid, 1) - change_vout = filter(lambda v: v['valueZat'] != 3 * COIN, tx['vout']) + change_vout = list(filter(lambda v: v['valueZat'] != 3 * COIN, tx['vout'])) change = change_vout[0]['scriptPubKey']['addresses'][0] bal = self.nodes[2].getaddressbalance(change) assert(bal['received'] > 0) @@ -323,7 +322,7 @@ class AddressIndexTest(BitcoinTestFramework): # so for comparison, remove the 4 (and -4 for output) from the # deltas list deltas = self.nodes[1].getaddressdeltas({'addresses': [addr1]}) - deltas = filter(lambda d: abs(d['satoshis']) != 4 * COIN, deltas) + deltas = list(filter(lambda d: abs(d['satoshis']) != 4 * COIN, deltas)) assert_equal(len(utxos), len(deltas)) for i in range(len(utxos)): assert_equal(utxos[i]['address'], addr1) @@ -334,13 +333,13 @@ class AddressIndexTest(BitcoinTestFramework): # Check that outputs with the same address in the same tx return one txid # (can't use createrawtransaction() as it combines duplicate addresses) addr = "t2LMJ6Arw9UWBMWvfUr2QLHM4Xd9w53FftS" - addressHash = "97643ce74b188f4fb6bbbb285e067a969041caf2".decode('hex') + addressHash =unhexlify("97643ce74b188f4fb6bbbb285e067a969041caf2") scriptPubKey = CScript([OP_HASH160, addressHash, OP_EQUAL]) # Add an unrecognized script type to vout[], a legal script that pays, # but won't modify the addressindex (since the address can't be extracted). # (This extra output has no effect on the rest of the test.) scriptUnknown = CScript([OP_HASH160, OP_DUP, OP_DROP, addressHash, OP_EQUAL]) - unspent = filter(lambda u: u['amount'] >= 4, self.nodes[0].listunspent()) + unspent = list(filter(lambda u: u['amount'] >= 4, self.nodes[0].listunspent())) tx = CTransaction() tx.vin = [CTxIn(COutPoint(int(unspent[0]['txid'], 16), unspent[0]['vout']))] tx.vout = [