[qa] Use python2/3 syntax

This commit is contained in:
MarcoFalke 2016-03-19 21:36:32 +01:00 committed by Jack Grigg
parent 845b31a760
commit 65a6249d41
7 changed files with 14 additions and 15 deletions

View File

@ -32,13 +32,13 @@ import re
from tests_config import * from tests_config import *
#If imported values are not defined then set to zero (or disabled) #If imported values are not defined then set to zero (or disabled)
if not vars().has_key('ENABLE_WALLET'): if 'ENABLE_WALLET' not in vars():
ENABLE_WALLET=0 ENABLE_WALLET=0
if not vars().has_key('ENABLE_BITCOIND'): if 'ENABLE_BITCOIND' not in vars():
ENABLE_BITCOIND=0 ENABLE_BITCOIND=0
if not vars().has_key('ENABLE_UTILS'): if 'ENABLE_UTILS' not in vars():
ENABLE_UTILS=0 ENABLE_UTILS=0
if not vars().has_key('ENABLE_ZMQ'): if 'ENABLE_ZMQ' not in vars():
ENABLE_ZMQ=0 ENABLE_ZMQ=0
# python-zmq may not be installed. Handle this gracefully and with some helpful info # python-zmq may not be installed. Handle this gracefully and with some helpful info

View File

@ -11,7 +11,7 @@ from test_framework.blocktools import create_coinbase, create_block
from test_framework.comptool import TestInstance, TestManager from test_framework.comptool import TestInstance, TestManager
from test_framework.script import CScript from test_framework.script import CScript
from binascii import unhexlify from binascii import unhexlify
import io from io import BytesIO
''' '''
@ -47,7 +47,7 @@ class BIP66Test(ComparisonTestFramework):
rawtx = node.createrawtransaction(inputs, outputs) rawtx = node.createrawtransaction(inputs, outputs)
signresult = node.signrawtransaction(rawtx) signresult = node.signrawtransaction(rawtx)
tx = CTransaction() tx = CTransaction()
f = io.BytesIO(unhexlify(signresult['hex'])) f = BytesIO(unhexlify(signresult['hex']))
tx.deserialize(f) tx.deserialize(f)
return tx return tx

View File

@ -14,7 +14,7 @@ from test_framework.util import assert_equal, assert_greater_than, \
import struct import struct
import binascii import binascii
import json import json
import io from io import BytesIO
from codecs import encode from codecs import encode
from decimal import Decimal from decimal import Decimal
@ -145,7 +145,7 @@ class RESTTest (BitcoinTestFramework):
binaryRequest += struct.pack("i", 0); binaryRequest += struct.pack("i", 0);
bin_response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', binaryRequest) bin_response = http_post_call(url.hostname, url.port, '/rest/getutxos'+self.FORMAT_SEPARATOR+'bin', binaryRequest)
output = io.BytesIO() output = BytesIO()
output.write(bin_response) output.write(bin_response)
output.seek(0) output.seek(0)
chainHeight = struct.unpack("i", output.read(4))[0] chainHeight = struct.unpack("i", output.read(4))[0]

View File

@ -112,7 +112,7 @@ def check_estimates(node, fees_seen, max_invalid, print_estimates = True):
print([str(all_estimates[e-1]) for e in [1,2,3,6,15,25]]) print([str(all_estimates[e-1]) for e in [1,2,3,6,15,25]])
delta = 1.0e-6 # account for rounding error delta = 1.0e-6 # account for rounding error
last_e = max(fees_seen) last_e = max(fees_seen)
for e in filter(lambda x: x >= 0, all_estimates): for e in [x for x in all_estimates if x >= 0]:
# Estimates should be within the bounds of what transactions fees actually were: # Estimates should be within the bounds of what transactions fees actually were:
if float(e)+delta < min(fees_seen) or float(e)-delta > max(fees_seen): if float(e)+delta < min(fees_seen) or float(e)-delta > max(fees_seen):
raise AssertionError("Estimated fee (%f) out of range (%f,%f)" raise AssertionError("Estimated fee (%f) out of range (%f,%f)"

View File

@ -6,7 +6,7 @@
from .mininode import CBlock, CBlockHeader, CBlockLocator, CTransaction, msg_block, msg_headers, msg_tx from .mininode import CBlock, CBlockHeader, CBlockLocator, CTransaction, msg_block, msg_headers, msg_tx
import sys import sys
import io from io import BytesIO
import dbm.dumb as dbm import dbm.dumb as dbm
class BlockStore(): class BlockStore():
@ -24,7 +24,7 @@ class BlockStore():
serialized_block = self.blockDB[repr(blockhash)] serialized_block = self.blockDB[repr(blockhash)]
except KeyError: except KeyError:
return None return None
f = io.BytesIO(serialized_block) f = BytesIO(serialized_block)
ret = CBlock() ret = CBlock()
ret.deserialize(f) ret.deserialize(f)
ret.calc_sha256() ret.calc_sha256()
@ -118,7 +118,7 @@ class TxStore(object):
serialized_tx = self.txDB[repr(txhash)] serialized_tx = self.txDB[repr(txhash)]
except KeyError: except KeyError:
return None return None
f = io.BytesIO(serialized_tx) f = BytesIO(serialized_tx)
ret = CTransaction() ret = CTransaction()
ret.deserialize(f) ret.deserialize(f)
ret.calc_sha256() ret.calc_sha256()

View File

@ -757,9 +757,8 @@ class CTransaction(object):
self.calc_sha256() self.calc_sha256()
def calc_sha256(self): def calc_sha256(self):
serialized = self.serialize()
if self.sha256 is None: if self.sha256 is None:
self.sha256 = uint256_from_str(hash256(serialized)) self.sha256 = uint256_from_str(hash256(self.serialize()))
self.hash = hash256(self.serialize())[::-1].hex() self.hash = hash256(self.serialize())[::-1].hex()
def is_valid(self): def is_valid(self):