update test_framework modules

This commit is contained in:
mdr0id 2019-11-20 12:12:46 -08:00
parent 3dde472c96
commit bda88213a6
11 changed files with 144 additions and 161 deletions

View File

@ -34,18 +34,12 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
try:
import http.client as httplib
except ImportError:
import httplib
import http.client
import base64
import decimal
import json
from pyutil import jsonutil as json
import logging
try:
import urllib.parse as urlparse
except ImportError:
import urlparse
import urllib.parse
USER_AGENT = "AuthServiceProxy/0.1"
@ -59,22 +53,14 @@ class JSONRPCException(Exception):
self.error = rpc_error
def EncodeDecimal(o):
if isinstance(o, decimal.Decimal):
return round(o, 8)
raise TypeError(repr(o) + " is not JSON serializable")
class AuthServiceProxy(object):
class AuthServiceProxy():
__id_count = 0
def __init__(self, service_url, service_name=None, timeout=HTTP_TIMEOUT, connection=None):
self.__service_url = service_url
self.__service_name = service_name
self.__url = urlparse.urlparse(service_url)
if self.__url.port is None:
port = 80
else:
port = self.__url.port
self.__url = urllib.parse.urlparse(service_url)
(user, passwd) = (self.__url.username, self.__url.password)
try:
user = user.encode('utf8')
@ -87,17 +73,21 @@ class AuthServiceProxy(object):
authpair = user + b':' + passwd
self.__auth_header = b'Basic ' + base64.b64encode(authpair)
if connection:
# Callables re-use the connection of the original proxy
self.__conn = connection
elif self.__url.scheme == 'https':
self.__conn = httplib.HTTPSConnection(self.__url.hostname, port,
None, None, False,
timeout)
else:
self.__conn = httplib.HTTPConnection(self.__url.hostname, port,
False, timeout)
self.timeout = timeout
self._set_conn(connection)
def _set_conn(self, connection=None):
port = 80 if self.__url.port is None else self.__url.port
if connection:
self.__conn = connection
self.timeout = connection.timeout
elif self.__url.scheme == 'https':
self.__conn = http.client.HTTPSConnection(self.__url.hostname, port, timeout=self.timeout)
else:
self.__conn = http.client.HTTPConnection(self.__url.hostname, port, timeout=self.timeout)
def __getattr__(self, name):
if name.startswith('__') and name.endswith('__'):
# Python internal stuff
@ -105,7 +95,7 @@ class AuthServiceProxy(object):
if self.__service_name is not None:
name = "%s.%s" % (self.__service_name, name)
return AuthServiceProxy(self.__service_url, name, connection=self.__conn)
def _request(self, method, path, postdata):
'''
Do a HTTP request, with retry if we get disconnected (e.g. due to a timeout).
@ -120,12 +110,10 @@ class AuthServiceProxy(object):
return self._get_response()
except Exception as e:
# If connection was closed, try again.
# Python 2.7 error message was changed in https://github.com/python/cpython/pull/2825
# Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset.
# ConnectionResetError happens on FreeBSD with Python 3.4.
# These classes don't exist in Python 2.x, so we can't refer to them directly.
if ((isinstance(e, httplib.BadStatusLine)
and e.line in ("''", "No status line received - the server has closed the connection"))
if ((isinstance(e, http.client.BadStatusLine) and e.line == "''")
or e.__class__.__name__ in ('BrokenPipeError', 'ConnectionResetError')):
self.__conn.close()
self.__conn.request(method, path, postdata, headers)
@ -137,11 +125,11 @@ class AuthServiceProxy(object):
AuthServiceProxy.__id_count += 1
log.debug("-%s-> %s %s"%(AuthServiceProxy.__id_count, self.__service_name,
json.dumps(args, default=EncodeDecimal)))
json.dumps(args)))
postdata = json.dumps({'version': '1.1',
'method': self.__service_name,
'params': args,
'id': AuthServiceProxy.__id_count}, default=EncodeDecimal)
'id': AuthServiceProxy.__id_count})
response = self._request('POST', self.__url.path, postdata)
if response['error'] is not None:
raise JSONRPCException(response['error'])
@ -152,7 +140,7 @@ class AuthServiceProxy(object):
return response['result']
def _batch(self, rpc_call_list):
postdata = json.dumps(list(rpc_call_list), default=EncodeDecimal)
postdata = json.dumps(list(rpc_call_list))
log.debug("--> "+postdata)
return self._request('POST', self.__url.path, postdata)
@ -165,7 +153,7 @@ class AuthServiceProxy(object):
responsedata = http_response.read().decode('utf8')
response = json.loads(responsedata, parse_float=decimal.Decimal)
if "error" in response and response["error"] is None:
log.debug("<-%s- %s"%(response["id"], json.dumps(response["result"], default=EncodeDecimal)))
log.debug("<-%s- %s"%(response["id"], json.dumps(response["result"])))
else:
log.debug("<-- "+responsedata)
return response

View File

@ -10,8 +10,6 @@
"""Bignum routines"""
from __future__ import absolute_import, division, print_function, unicode_literals
import struct

View File

@ -6,12 +6,12 @@
from mininode import CBlock, CBlockHeader, CBlockLocator, CTransaction, msg_block, msg_headers, msg_tx
import sys
import cStringIO
import dbm
import io
import anydbm
class BlockStore(object):
class BlockStore():
def __init__(self, datadir):
self.blockDB = dbm.open(datadir + "/blocks", 'c')
self.blockDB = anydbm.open(datadir + "/blocks", 'c')
self.currentBlock = 0L
def close(self):
@ -23,7 +23,7 @@ class BlockStore(object):
serialized_block = self.blockDB[repr(blockhash)]
except KeyError:
return None
f = cStringIO.StringIO(serialized_block)
f = io.StringIO(serialized_block)
ret = CBlock()
ret.deserialize(f)
ret.calc_sha256()
@ -62,7 +62,7 @@ class BlockStore(object):
try:
self.blockDB[repr(block.sha256)] = bytes(block.serialize())
except TypeError as e:
print "Unexpected error: ", sys.exc_info()[0], e.args
print("Unexpected error: ", sys.exc_info()[0], e.args)
self.currentBlock = block.sha256
def get_blocks(self, inv):
@ -96,7 +96,7 @@ class BlockStore(object):
class TxStore(object):
def __init__(self, datadir):
self.txDB = dbm.open(datadir + "/transactions", 'c')
self.txDB = anydbm.open(datadir + "/transactions", 'c')
def close(self):
self.txDB.close()
@ -107,7 +107,7 @@ class TxStore(object):
serialized_tx = self.txDB[repr(txhash)]
except KeyError:
return None
f = cStringIO.StringIO(serialized_tx)
f = io.StringIO(serialized_tx)
ret = CTransaction()
ret.deserialize(f)
ret.calc_sha256()
@ -118,7 +118,7 @@ class TxStore(object):
try:
self.txDB[repr(tx.sha256)] = bytes(tx.serialize())
except TypeError as e:
print "Unexpected error: ", sys.exc_info()[0], e.args
print("Unexpected error: ", sys.exc_info()[0], e.args)
def get_transactions(self, inv):
responses = []

View File

@ -140,13 +140,13 @@ class TestNode(NodeConnCB):
# across all connections. (If outcome of final tx is specified as true
# or false, then only the last tx is tested against outcome.)
class TestInstance(object):
class TestInstance():
def __init__(self, objects=None, sync_every_block=True, sync_every_tx=False):
self.blocks_and_transactions = objects if objects else []
self.sync_every_block = sync_every_block
self.sync_every_tx = sync_every_tx
class TestManager(object):
class TestManager():
def __init__(self, testgen, datadir):
self.test_generator = testgen
@ -335,7 +335,7 @@ class TestManager(object):
if (not self.check_mempool(tx.sha256, tx_outcome)):
raise AssertionError("Mempool test failed at test %d" % test_number)
print "Test %d: PASS" % test_number, [ c.rpc.getblockcount() for c in self.connections ]
print("Test %d: PASS" % test_number, [ c.rpc.getblockcount() for c in self.connections ])
test_number += 1
[ c.disconnect_node() for c in self.connections ]

View File

@ -24,7 +24,7 @@ def expand_array(inp, out_len, bit_len, byte_pad=0):
acc_value = 0;
j = 0
for i in xrange(len(inp)):
for i in range(len(inp)):
acc_value = ((acc_value << 8) & word_mask) | inp[i]
acc_bits += 8
@ -32,7 +32,7 @@ def expand_array(inp, out_len, bit_len, byte_pad=0):
# output element.
if acc_bits >= bit_len:
acc_bits -= bit_len
for x in xrange(byte_pad, out_width):
for x in range(byte_pad, out_width):
out[j+x] = (
# Big-endian
acc_value >> (acc_bits+(8*(out_width-x-1)))
@ -59,12 +59,12 @@ def compress_array(inp, out_len, bit_len, byte_pad=0):
acc_value = 0;
j = 0
for i in xrange(out_len):
for i in range(out_len):
# When we have fewer than 8 bits left in the accumulator, read the next
# input element.
if acc_bits < 8:
acc_value = ((acc_value << bit_len) & word_mask) | inp[j]
for x in xrange(byte_pad, in_width):
for x in range(byte_pad, in_width):
acc_value = acc_value | (
(
# Apply bit_len_mask across byte boundaries
@ -135,7 +135,7 @@ def gbp_basic(digest, n, k):
indices_per_hash_output = 512/n
# 1) Generate first list
if DEBUG: print 'Generating first list'
if DEBUG: print('Generating first list')
X = []
tmp_hash = ''
for i in range(0, 2**(collision_length+1)):
@ -153,16 +153,16 @@ def gbp_basic(digest, n, k):
# 3) Repeat step 2 until 2n/(k+1) bits remain
for i in range(1, k):
if DEBUG: print 'Round %d:' % i
if DEBUG:print('Round %d:' % i)
# 2a) Sort the list
if DEBUG: print '- Sorting list'
if DEBUG: print('- Sorting list')
X.sort(key=itemgetter(0))
if DEBUG and VERBOSE:
for Xi in X[-32:]:
print '%s %s' % (print_hash(Xi[0]), Xi[1])
print('%s %s' % (print_hash(Xi[0]), Xi[1]))
if DEBUG: print '- Finding collisions'
if DEBUG: print('- Finding collisions')
Xc = []
while len(X) > 0:
# 2b) Find next set of unordered pairs with collisions on first n/(k+1) bits
@ -192,13 +192,13 @@ def gbp_basic(digest, n, k):
# k+1) Find a collision on last 2n(k+1) bits
if DEBUG:
print 'Final round:'
print '- Sorting list'
print('Final round:')
print('- Sorting list')
X.sort(key=itemgetter(0))
if DEBUG and VERBOSE:
for Xi in X[-32:]:
print '%s %s' % (print_hash(Xi[0]), Xi[1])
if DEBUG: print '- Finding collisions'
print('%s %s' % (print_hash(Xi[0]), Xi[1]))
if DEBUG: print('- Finding collisions')
solns = []
while len(X) > 0:
j = 1
@ -213,9 +213,9 @@ def gbp_basic(digest, n, k):
res = xor(X[-1-l][0], X[-1-m][0])
if count_zeroes(res) == 8*hash_length and distinct_indices(X[-1-l][1], X[-1-m][1]):
if DEBUG and VERBOSE:
print 'Found solution:'
print '- %s %s' % (print_hash(X[-1-l][0]), X[-1-l][1])
print '- %s %s' % (print_hash(X[-1-m][0]), X[-1-m][1])
print('Found solution:')
print('- %s %s' % (print_hash(X[-1-l][0]), X[-1-l][1]))
print('- %s %s' % (print_hash(X[-1-m][0]), X[-1-m][1]))
if X[-1-l][1][0] < X[-1-m][1][0]:
solns.append(list(X[-1-l][1] + X[-1-m][1]))
else:
@ -235,8 +235,8 @@ def gbp_validate(digest, minimal, n, k):
solution_width = (1 << k)*(collision_length+1)//8
if len(minimal) != solution_width:
print 'Invalid solution length: %d (expected %d)' % \
(len(minimal), solution_width)
print('Invalid solution length: %d (expected %d)' % \
(len(minimal), solution_width))
return False
X = []
@ -256,23 +256,23 @@ def gbp_validate(digest, minimal, n, k):
Xc = []
for i in range(0, len(X), 2):
if not has_collision(X[i][0], X[i+1][0], r, collision_length):
print 'Invalid solution: invalid collision length between StepRows'
print('Invalid solution: invalid collision length between StepRows')
return False
if X[i+1][1][0] < X[i][1][0]:
print 'Invalid solution: Index tree incorrectly ordered'
print('Invalid solution: Index tree incorrectly ordered')
return False
if not distinct_indices(X[i][1], X[i+1][1]):
print 'Invalid solution: duplicate indices'
print('Invalid solution: duplicate indices')
return False
Xc.append((xor(X[i][0], X[i+1][0]), X[i][1] + X[i+1][1]))
X = Xc
if len(X) != 1:
print 'Invalid solution: incorrect length after end of rounds: %d' % len(X)
print('Invalid solution: incorrect length after end of rounds: %d' % len(X))
return False
if count_zeroes(X[0][0]) != 8*hash_length:
print 'Invalid solution: incorrect number of zeroes: %d' % count_zeroes(X[0][0])
print('Invalid solution: incorrect number of zeroes: %d' % count_zeroes(X[0][0]))
return False
return True

View File

@ -24,7 +24,7 @@ import binascii
import time
import sys
import random
import cStringIO
import io
import hashlib
from threading import RLock
from threading import Thread
@ -32,7 +32,7 @@ import logging
import copy
from pyblake2 import blake2b
from .equihash import (
from test_framework.equihash import (
gbp_basic,
gbp_validate,
hash_nonce,
@ -100,14 +100,14 @@ def ser_string(s):
return chr(len(s)) + s
elif len(s) < 0x10000:
return chr(253) + struct.pack("<H", len(s)) + s
elif len(s) < 0x100000000L:
elif len(s) < 0x100000000:
return chr(254) + struct.pack("<I", len(s)) + s
return chr(255) + struct.pack("<Q", len(s)) + s
def deser_uint256(f):
r = 0L
for i in xrange(8):
r = 0
for i in range(8):
t = struct.unpack("<I", f.read(4))[0]
r += t << (i * 32)
return r
@ -115,23 +115,23 @@ def deser_uint256(f):
def ser_uint256(u):
rs = ""
for i in xrange(8):
rs += struct.pack("<I", u & 0xFFFFFFFFL)
for i in range(8):
rs += struct.pack("<I", u & 0xFFFFFFFF)
u >>= 32
return rs
def uint256_from_str(s):
r = 0L
r = 0
t = struct.unpack("<IIIIIIII", s[:32])
for i in xrange(8):
for i in range(8):
r += t[i] << (i * 32)
return r
def uint256_from_compact(c):
nbytes = (c >> 24) & 0xFF
v = (c & 0xFFFFFFL) << (8 * (nbytes - 3))
v = (c & 0xFFFFFF) << (8 * (nbytes - 3))
return v
@ -144,7 +144,7 @@ def deser_vector(f, c):
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
r = []
for i in xrange(nit):
for i in range(nit):
t = c()
t.deserialize(f)
r.append(t)
@ -157,7 +157,7 @@ def ser_vector(l):
r = chr(len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
elif len(l) < 0x100000000:
r = chr(254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
@ -175,7 +175,7 @@ def deser_uint256_vector(f):
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
r = []
for i in xrange(nit):
for i in range(nit):
t = deser_uint256(f)
r.append(t)
return r
@ -187,7 +187,7 @@ def ser_uint256_vector(l):
r = chr(len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
elif len(l) < 0x100000000:
r = chr(254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
@ -205,7 +205,7 @@ def deser_string_vector(f):
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
r = []
for i in xrange(nit):
for i in range(nit):
t = deser_string(f)
r.append(t)
return r
@ -217,7 +217,7 @@ def ser_string_vector(l):
r = chr(len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
elif len(l) < 0x100000000:
r = chr(254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
@ -235,7 +235,7 @@ def deser_int_vector(f):
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
r = []
for i in xrange(nit):
for i in range(nit):
t = struct.unpack("<i", f.read(4))[0]
r.append(t)
return r
@ -247,7 +247,7 @@ def ser_int_vector(l):
r = chr(len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
elif len(l) < 0x100000000:
r = chr(254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
@ -265,7 +265,7 @@ def deser_char_vector(f):
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
r = []
for i in xrange(nit):
for i in range(nit):
t = struct.unpack("<B", f.read(1))[0]
r.append(t)
return r
@ -277,7 +277,7 @@ def ser_char_vector(l):
r = chr(len(l))
elif len(l) < 0x10000:
r = chr(253) + struct.pack("<H", len(l))
elif len(l) < 0x100000000L:
elif len(l) < 0x100000000:
r = chr(254) + struct.pack("<I", len(l))
else:
r = chr(255) + struct.pack("<Q", len(l))
@ -288,7 +288,7 @@ def ser_char_vector(l):
# Objects that map to bitcoind objects, which can be serialized/deserialized
class CAddress(object):
class CAddress():
def __init__(self):
self.nServices = 1
self.pchReserved = "\x00" * 10 + "\xff" * 2
@ -314,13 +314,13 @@ class CAddress(object):
self.ip, self.port)
class CInv(object):
class CInv():
typemap = {
0: "Error",
1: "TX",
2: "Block"}
def __init__(self, t=0, h=0L):
def __init__(self, t=0, h=0):
self.type = t
self.hash = h
@ -339,7 +339,7 @@ class CInv(object):
% (self.typemap[self.type], self.hash)
class CBlockLocator(object):
class CBlockLocator():
def __init__(self):
self.nVersion = SPROUT_PROTO_VERSION
self.vHave = []
@ -359,7 +359,7 @@ class CBlockLocator(object):
% (self.nVersion, self.vHave)
class SpendDescription(object):
class SpendDescription():
def __init__(self):
self.cv = None
self.anchor = None
@ -391,7 +391,7 @@ class SpendDescription(object):
% (self.cv, self.anchor, self.nullifier, self.rk, self.zkproof, self.spendauthsig)
class OutputDescription(object):
class OutputDescription():
def __init__(self):
self.cv = None
self.cmu = None
@ -426,7 +426,7 @@ class OutputDescription(object):
G1_PREFIX_MASK = 0x02
G2_PREFIX_MASK = 0x0a
class ZCProof(object):
class ZCProof():
def __init__(self):
self.g_A = None
self.g_A_prime = None
@ -507,7 +507,7 @@ ZC_NOTECIPHERTEXT_SIZE = (
NOTEENCRYPTION_AUTH_BYTES
)
class JSDescription(object):
class JSDescription():
def __init__(self):
self.vpub_old = 0
self.vpub_new = 0
@ -571,7 +571,7 @@ class JSDescription(object):
self.onetimePubKey, self.randomSeed, self.proof)
class COutPoint(object):
class COutPoint():
def __init__(self, hash=0, n=0):
self.hash = hash
self.n = n
@ -590,7 +590,7 @@ class COutPoint(object):
return "COutPoint(hash=%064x n=%i)" % (self.hash, self.n)
class CTxIn(object):
class CTxIn():
def __init__(self, outpoint=None, scriptSig="", nSequence=0):
if outpoint is None:
self.prevout = COutPoint()
@ -618,7 +618,7 @@ class CTxIn(object):
self.nSequence)
class CTxOut(object):
class CTxOut():
def __init__(self, nValue=0, scriptPubKey=""):
self.nValue = nValue
self.scriptPubKey = scriptPubKey
@ -639,7 +639,7 @@ class CTxOut(object):
binascii.hexlify(self.scriptPubKey))
class CTransaction(object):
class CTransaction():
def __init__(self, tx=None):
if tx is None:
self.fOverwintered = True
@ -756,7 +756,7 @@ class CTransaction(object):
def is_valid(self):
self.calc_sha256()
for tout in self.vout:
if tout.nValue < 0 or tout.nValue > 21000000L * 100000000L:
if tout.nValue < 0 or tout.nValue > 2100000 * 100000000:
return False
return True
@ -778,7 +778,7 @@ class CTransaction(object):
return r
class CBlockHeader(object):
class CBlockHeader():
def __init__(self, header=None):
if header is None:
self.set_null()
@ -878,7 +878,7 @@ class CBlock(CBlockHeader):
hashes.append(ser_uint256(tx.sha256))
while len(hashes) > 1:
newhashes = []
for i in xrange(0, len(hashes), 2):
for i in range(0, len(hashes), 2):
i2 = min(i+1, len(hashes)-1)
newhashes.append(hash256(hashes[i] + hashes[i2]))
hashes = newhashes
@ -929,7 +929,7 @@ class CBlock(CBlockHeader):
self.nNonce, self.nSolution, self.vtx)
class CUnsignedAlert(object):
class CUnsignedAlert():
def __init__(self):
self.nVersion = 1
self.nRelayUntil = 0
@ -984,7 +984,7 @@ class CUnsignedAlert(object):
self.strComment, self.strStatusBar, self.strReserved)
class CAlert(object):
class CAlert():
def __init__(self):
self.vchMsg = ""
self.vchSig = ""
@ -1005,7 +1005,7 @@ class CAlert(object):
# Objects that correspond to messages on the wire
class msg_version(object):
class msg_version():
command = "version"
def __init__(self, protocol_version=SPROUT_PROTO_VERSION):
@ -1060,7 +1060,7 @@ class msg_version(object):
self.strSubVer, self.nStartingHeight)
class msg_verack(object):
class msg_verack():
command = "verack"
def __init__(self):
@ -1076,7 +1076,7 @@ class msg_verack(object):
return "msg_verack()"
class msg_addr(object):
class msg_addr():
command = "addr"
def __init__(self):
@ -1092,7 +1092,7 @@ class msg_addr(object):
return "msg_addr(addrs=%r)" % (self.addrs,)
class msg_alert(object):
class msg_alert():
command = "alert"
def __init__(self):
@ -1111,7 +1111,7 @@ class msg_alert(object):
return "msg_alert(alert=%r)" % (self.alert,)
class msg_inv(object):
class msg_inv():
command = "inv"
def __init__(self, inv=None):
@ -1130,7 +1130,7 @@ class msg_inv(object):
return "msg_inv(inv=%r)" % (self.inv,)
class msg_getdata(object):
class msg_getdata():
command = "getdata"
def __init__(self):
@ -1146,7 +1146,7 @@ class msg_getdata(object):
return "msg_getdata(inv=%r)" % (self.inv,)
class msg_notfound(object):
class msg_notfound():
command = "notfound"
def __init__(self):
@ -1162,12 +1162,12 @@ class msg_notfound(object):
return "msg_notfound(inv=%r)" % (self.inv,)
class msg_getblocks(object):
class msg_getblocks():
command = "getblocks"
def __init__(self):
self.locator = CBlockLocator()
self.hashstop = 0L
self.hashstop = 0
def deserialize(self, f):
self.locator = CBlockLocator()
@ -1185,7 +1185,7 @@ class msg_getblocks(object):
% (self.locator, self.hashstop)
class msg_tx(object):
class msg_tx():
command = "tx"
def __init__(self, tx=CTransaction()):
@ -1201,7 +1201,7 @@ class msg_tx(object):
return "msg_tx(tx=%r)" % (self.tx,)
class msg_block(object):
class msg_block():
command = "block"
def __init__(self, block=None):
@ -1220,7 +1220,7 @@ class msg_block(object):
return "msg_block(block=%r)" % (self.block,)
class msg_getaddr(object):
class msg_getaddr():
command = "getaddr"
def __init__(self):
@ -1236,7 +1236,7 @@ class msg_getaddr(object):
return "msg_getaddr()"
class msg_ping_prebip31(object):
class msg_ping_prebip31():
command = "ping"
def __init__(self):
@ -1252,10 +1252,10 @@ class msg_ping_prebip31(object):
return "msg_ping() (pre-bip31)"
class msg_ping(object):
class msg_ping():
command = "ping"
def __init__(self, nonce=0L):
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
@ -1270,10 +1270,10 @@ class msg_ping(object):
return "msg_ping(nonce=%08x)" % self.nonce
class msg_pong(object):
class msg_pong():
command = "pong"
def __init__(self, nonce=0L):
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
@ -1288,7 +1288,7 @@ class msg_pong(object):
return "msg_pong(nonce=%08x)" % self.nonce
class msg_mempool(object):
class msg_mempool():
command = "mempool"
def __init__(self):
@ -1308,12 +1308,12 @@ class msg_mempool(object):
# number of entries
# vector of hashes
# hash_stop (hash of last desired block header, 0 to get as many as possible)
class msg_getheaders(object):
class msg_getheaders():
command = "getheaders"
def __init__(self):
self.locator = CBlockLocator()
self.hashstop = 0L
self.hashstop = 0
def deserialize(self, f):
self.locator = CBlockLocator()
@ -1333,7 +1333,7 @@ class msg_getheaders(object):
# headers message has
# <count> <vector of block headers>
class msg_headers(object):
class msg_headers():
command = "headers"
def __init__(self):
@ -1353,14 +1353,14 @@ class msg_headers(object):
return "msg_headers(headers=%r)" % (self.headers,)
class msg_reject(object):
class msg_reject():
command = "reject"
def __init__(self):
self.message = ""
self.code = ""
self.reason = ""
self.data = 0L
self.data = 0
def deserialize(self, f):
self.message = deser_string(f)
@ -1382,7 +1382,7 @@ class msg_reject(object):
% (self.message, self.code, self.reason, self.data)
class msg_filteradd(object):
class msg_filteradd():
command = "filteradd"
def __init__(self):
@ -1398,7 +1398,7 @@ class msg_filteradd(object):
return "msg_filteradd(data=%r)" % (self.data,)
class msg_filterclear(object):
class msg_filterclear():
command = "filterclear"
def __init__(self):
@ -1416,7 +1416,7 @@ class msg_filterclear(object):
# This is what a callback should look like for NodeConn
# Reimplement the on_* functions to provide handling for events
class NodeConnCB(object):
class NodeConnCB():
def __init__(self):
self.verack_received = False
@ -1448,8 +1448,8 @@ class NodeConnCB(object):
try:
self.cbmap[message.command](conn, message)
except:
print "ERROR delivering %r (%s)" % (message,
sys.exc_info()[0])
print("ERROR delivering %r (%s)" % (message,
sys.exc_info()[0]))
def on_version(self, conn, message):
if message.nVersion >= 209:
@ -1540,8 +1540,8 @@ class NodeConn(asyncore.dispatcher):
vt.addrFrom.ip = "0.0.0.0"
vt.addrFrom.port = 0
self.send_message(vt, True)
print 'MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' \
+ str(dstport) + ' using version ' + str(protocol_version)
print('MiniNode: Connecting to Bitcoin Node IP # ' + dstaddr + ':' \
+ str(dstport) + ' using version ' + str(protocol_version))
try:
self.connect((dstaddr, dstport))
@ -1625,7 +1625,7 @@ class NodeConn(asyncore.dispatcher):
raise ValueError("got bad checksum %r" % (self.recvbuf,))
self.recvbuf = self.recvbuf[4+12+4+4+msglen:]
if command in self.messagemap:
f = cStringIO.StringIO(msg)
f = io.StringIO(msg)
t = self.messagemap[command]()
t.deserialize(f)
self.got_message(t)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# Copyright (c) 2014 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php .

View File

@ -1,4 +1,3 @@
#
# script.py
#
# This file is modified from python-bitcoinlib.
@ -12,8 +11,6 @@
Functionality to build scripts, as well as SignatureHash().
"""
from __future__ import absolute_import, division, print_function, unicode_literals
from test_framework.mininode import CTransaction, CTxOut, hash256
import sys

View File

@ -4,8 +4,8 @@
'''
Dummy Socks5 server for testing.
'''
from __future__ import print_function, division, unicode_literals
import socket, threading, Queue
import socket, threading
import traceback, sys
### Protocol constants
@ -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:
@ -132,7 +132,7 @@ class Socks5Server(object):
self.s.listen(5)
self.running = False
self.thread = None
self.queue = Queue.Queue() # report connections and exceptions to client
self.queue = queue.Queue() # report connections and exceptions to client
def run(self):
while self.running:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# Copyright (c) 2014 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
@ -13,8 +13,8 @@ import shutil
import tempfile
import traceback
from authproxy import JSONRPCException
from util import assert_equal, check_json_precision, \
from .authproxy import JSONRPCException
from .util import assert_equal, check_json_precision, \
initialize_chain, initialize_chain_clean, \
start_nodes, connect_nodes_bi, stop_nodes, \
sync_blocks, sync_mempools, wait_bitcoinds
@ -172,7 +172,7 @@ class ComparisonTestFramework(BitcoinTestFramework):
help="bitcoind binary to use for reference nodes (if any)")
def setup_chain(self):
print "Initializing test directory "+self.options.tmpdir
print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self):

View File

@ -21,7 +21,7 @@ import subprocess
import time
import re
from authproxy import AuthServiceProxy
from .authproxy import AuthServiceProxy
PRE_BLOSSOM_BLOCK_TARGET_SPACING = 150
POST_BLOSSOM_BLOCK_TARGET_SPACING = 75
@ -147,11 +147,11 @@ def initialize_chain(test_dir):
args.append("-connect=127.0.0.1:"+str(p2p_port(0)))
bitcoind_processes[i] = subprocess.Popen(args)
if os.getenv("PYTHON_DEBUG", ""):
print "initialize_chain: bitcoind started, calling bitcoin-cli -rpcwait getblockcount"
print("initialize_chain: bitcoind started, calling bitcoin-cli -rpcwait getblockcount")
subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir,
"-rpcwait", "getblockcount"], stdout=devnull)
if os.getenv("PYTHON_DEBUG", ""):
print "initialize_chain: bitcoin-cli -rpcwait getblockcount completed"
print("initialize_chain: bitcoin-cli -rpcwait getblockcount completed")
devnull.close()
rpcs = []
for i in range(4):
@ -239,12 +239,12 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
bitcoind_processes[i] = subprocess.Popen(args)
devnull = open("/dev/null", "w+")
if os.getenv("PYTHON_DEBUG", ""):
print "start_node: bitcoind started, calling bitcoin-cli -rpcwait getblockcount"
print("start_node: bitcoind started, calling bitcoin-cli -rpcwait getblockcount")
subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir] +
_rpchost_to_args(rpchost) +
["-rpcwait", "getblockcount"], stdout=devnull)
if os.getenv("PYTHON_DEBUG", ""):
print "start_node: calling bitcoin-cli -rpcwait getblockcount returned"
print("start_node: calling bitcoin-cli -rpcwait getblockcount returned")
devnull.close()
url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i))
if timewait is not None:
@ -442,7 +442,7 @@ def fail(message=""):
def wait_and_assert_operationid_status_result(node, myopid, in_status='success', in_errormsg=None, timeout=300):
print('waiting for async operation {}'.format(myopid))
result = None
for _ in xrange(1, timeout):
for _ in range(1, timeout):
results = node.z_getoperationresult([myopid])
if len(results) > 0:
result = results[0]