aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/test_framework
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2016-03-19 21:36:32 +0100
committerMarcoFalke <falke.marco@gmail.com>2016-03-31 18:35:17 +0200
commitfa524d9ddbad0a03f9eb974100fb3b6001045645 (patch)
tree35e826d3fc5015df5e86989b68a1cec847c105b1 /qa/rpc-tests/test_framework
parent28ad4d9fc2be102786a8c6c32ebecb466b2a03dd (diff)
[qa] Use python2/3 syntax
Diffstat (limited to 'qa/rpc-tests/test_framework')
-rw-r--r--qa/rpc-tests/test_framework/blockstore.py7
-rw-r--r--qa/rpc-tests/test_framework/blocktools.py4
-rwxr-xr-xqa/rpc-tests/test_framework/comptool.py6
-rwxr-xr-xqa/rpc-tests/test_framework/mininode.py51
-rw-r--r--qa/rpc-tests/test_framework/socks5.py2
-rwxr-xr-xqa/rpc-tests/test_framework/test_framework.py4
6 files changed, 38 insertions, 36 deletions
diff --git a/qa/rpc-tests/test_framework/blockstore.py b/qa/rpc-tests/test_framework/blockstore.py
index b9775b477c..73d9ffbb2f 100644
--- a/qa/rpc-tests/test_framework/blockstore.py
+++ b/qa/rpc-tests/test_framework/blockstore.py
@@ -3,8 +3,9 @@
# and for constructing a getheaders message
#
-from mininode import *
+from .mininode import *
import dbm
+from io import BytesIO
class BlockStore(object):
def __init__(self, datadir):
@@ -21,7 +22,7 @@ class BlockStore(object):
serialized_block = self.blockDB[repr(blockhash)]
except KeyError:
return None
- f = cStringIO.StringIO(serialized_block)
+ f = BytesIO(serialized_block)
ret = CBlock()
ret.deserialize(f)
ret.calc_sha256()
@@ -115,7 +116,7 @@ class TxStore(object):
serialized_tx = self.txDB[repr(txhash)]
except KeyError:
return None
- f = cStringIO.StringIO(serialized_tx)
+ f = BytesIO(serialized_tx)
ret = CTransaction()
ret.deserialize(f)
ret.calc_sha256()
diff --git a/qa/rpc-tests/test_framework/blocktools.py b/qa/rpc-tests/test_framework/blocktools.py
index b075f69c47..425e6dcdde 100644
--- a/qa/rpc-tests/test_framework/blocktools.py
+++ b/qa/rpc-tests/test_framework/blocktools.py
@@ -4,8 +4,8 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
-from mininode import *
-from script import CScript, OP_TRUE, OP_CHECKSIG
+from .mininode import *
+from .script import CScript, OP_TRUE, OP_CHECKSIG
# Create a block (with regtest difficulty)
def create_block(hashprev, coinbase, nTime=None):
diff --git a/qa/rpc-tests/test_framework/comptool.py b/qa/rpc-tests/test_framework/comptool.py
index f19edbf069..6279070fbc 100755
--- a/qa/rpc-tests/test_framework/comptool.py
+++ b/qa/rpc-tests/test_framework/comptool.py
@@ -4,9 +4,9 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
-from mininode import *
-from blockstore import BlockStore, TxStore
-from util import p2p_port
+from .mininode import *
+from .blockstore import BlockStore, TxStore
+from .util import p2p_port
'''
This is a tool for comparing two or more bitcoinds to each other
diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py
index 20386c642c..07d1827dfe 100755
--- a/qa/rpc-tests/test_framework/mininode.py
+++ b/qa/rpc-tests/test_framework/mininode.py
@@ -24,7 +24,8 @@ import binascii
import time
import sys
import random
-import cStringIO
+from io import BytesIO
+from codecs import encode
import hashlib
from threading import RLock
from threading import Thread
@@ -75,12 +76,12 @@ def deser_string(f):
def ser_string(s):
if len(s) < 253:
- return chr(len(s)) + s
+ return struct.pack("B", len(s)) + s
elif len(s) < 0x10000:
- return chr(253) + struct.pack("<H", len(s)) + s
+ return struct.pack("B", 253) + struct.pack("<H", len(s)) + s
elif len(s) < 0x100000000L:
- return chr(254) + struct.pack("<I", len(s)) + s
- return chr(255) + struct.pack("<Q", len(s)) + s
+ return struct.pack("B", 254) + struct.pack("<I", len(s)) + s
+ return struct.pack("B", 255) + struct.pack("<Q", len(s)) + s
def deser_uint256(f):
@@ -132,13 +133,13 @@ def deser_vector(f, c):
def ser_vector(l):
r = ""
if len(l) < 253:
- r = chr(len(l))
+ r = struct.pack("B", len(l))
elif len(l) < 0x10000:
- r = chr(253) + struct.pack("<H", len(l))
+ r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
- r = chr(254) + struct.pack("<I", len(l))
+ r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
- r = chr(255) + struct.pack("<Q", len(l))
+ r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for i in l:
r += i.serialize()
return r
@@ -162,13 +163,13 @@ def deser_uint256_vector(f):
def ser_uint256_vector(l):
r = ""
if len(l) < 253:
- r = chr(len(l))
+ r = struct.pack("B", len(l))
elif len(l) < 0x10000:
- r = chr(253) + struct.pack("<H", len(l))
+ r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
- r = chr(254) + struct.pack("<I", len(l))
+ r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
- r = chr(255) + struct.pack("<Q", len(l))
+ r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for i in l:
r += ser_uint256(i)
return r
@@ -192,13 +193,13 @@ def deser_string_vector(f):
def ser_string_vector(l):
r = ""
if len(l) < 253:
- r = chr(len(l))
+ r = struct.pack("B", len(l))
elif len(l) < 0x10000:
- r = chr(253) + struct.pack("<H", len(l))
+ r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
- r = chr(254) + struct.pack("<I", len(l))
+ r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
- r = chr(255) + struct.pack("<Q", len(l))
+ r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for sv in l:
r += ser_string(sv)
return r
@@ -222,20 +223,20 @@ def deser_int_vector(f):
def ser_int_vector(l):
r = ""
if len(l) < 253:
- r = chr(len(l))
+ r = struct.pack("B", len(l))
elif len(l) < 0x10000:
- r = chr(253) + struct.pack("<H", len(l))
+ r = struct.pack("B", 253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
- r = chr(254) + struct.pack("<I", len(l))
+ r = struct.pack("B", 254) + struct.pack("<I", len(l))
else:
- r = chr(255) + struct.pack("<Q", len(l))
+ r = struct.pack("B", 255) + struct.pack("<Q", len(l))
for i in l:
r += struct.pack("<i", i)
return r
# Deserialize from a hex string representation (eg from RPC)
def FromHex(obj, hex_string):
- obj.deserialize(cStringIO.StringIO(binascii.unhexlify(hex_string)))
+ obj.deserialize(BytesIO(binascii.unhexlify(hex_string)))
return obj
# Convert a binary-serializable object to hex (eg for submission via RPC)
@@ -423,7 +424,7 @@ class CTransaction(object):
def calc_sha256(self):
if self.sha256 is None:
self.sha256 = uint256_from_str(hash256(self.serialize()))
- self.hash = hash256(self.serialize())[::-1].encode('hex_codec')
+ self.hash = encode(hash256(self.serialize())[::-1], 'hex')
def is_valid(self):
self.calc_sha256()
@@ -492,7 +493,7 @@ class CBlockHeader(object):
r += struct.pack("<I", self.nBits)
r += struct.pack("<I", self.nNonce)
self.sha256 = uint256_from_str(hash256(r))
- self.hash = hash256(r)[::-1].encode('hex_codec')
+ self.hash = encode(hash256(r)[::-1], 'hex')
def rehash(self):
self.sha256 = None
@@ -1281,7 +1282,7 @@ class NodeConn(asyncore.dispatcher):
raise ValueError("got bad checksum " + repr(self.recvbuf))
self.recvbuf = self.recvbuf[4+12+4+4+msglen:]
if command in self.messagemap:
- f = cStringIO.StringIO(msg)
+ f = BytesIO(msg)
t = self.messagemap[command]()
t.deserialize(f)
self.got_message(t)
diff --git a/qa/rpc-tests/test_framework/socks5.py b/qa/rpc-tests/test_framework/socks5.py
index 1dbfb98d5d..12327a6c5f 100644
--- a/qa/rpc-tests/test_framework/socks5.py
+++ b/qa/rpc-tests/test_framework/socks5.py
@@ -117,7 +117,7 @@ class Socks5Connection(object):
self.serv.queue.put(cmdin)
print('Proxy: ', cmdin)
# Fall through to disconnect
- except Exception,e:
+ except Exception as e:
traceback.print_exc(file=sys.stderr)
self.serv.queue.put(e)
finally:
diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py
index 584f318d0b..19ee472609 100755
--- a/qa/rpc-tests/test_framework/test_framework.py
+++ b/qa/rpc-tests/test_framework/test_framework.py
@@ -26,7 +26,7 @@ from .util import (
check_json_precision,
initialize_chain_clean,
)
-from authproxy import AuthServiceProxy, JSONRPCException
+from .authproxy import AuthServiceProxy, JSONRPCException
class BitcoinTestFramework(object):
@@ -140,7 +140,7 @@ class BitcoinTestFramework(object):
print("JSONRPC error: "+e.error['message'])
traceback.print_tb(sys.exc_info()[2])
except AssertionError as e:
- print("Assertion failed: "+e.message)
+ print("Assertion failed: "+ str(e))
traceback.print_tb(sys.exc_info()[2])
except Exception as e:
print("Unexpected exception caught during testing: "+str(e))