clean-up imports, keep string notation consistent, remove spacing

This commit is contained in:
mdr0id 2019-12-09 21:14:55 -08:00
parent 5ae91f2dcb
commit 7b81c00ee4
12 changed files with 34 additions and 33 deletions

View File

@ -5,7 +5,7 @@
#
from test_framework.test_framework import ComparisonTestFramework
from test_framework.util import start_nodes, hex_str_to_bytes
from test_framework.util import start_nodes
from test_framework.mininode import CTransaction, NetworkThread
from test_framework.blocktools import create_coinbase, create_block
from test_framework.comptool import TestInstance, TestManager
@ -47,7 +47,7 @@ class BIP65Test(ComparisonTestFramework):
rawtx = node.createrawtransaction(inputs, outputs)
signresult = node.signrawtransaction(rawtx)
tx = CTransaction()
f = BytesIO(hex_str_to_bytes(signresult['hex']))
f = BytesIO(unhexlify(signresult['hex']))
tx.deserialize(f)
return tx

View File

@ -53,7 +53,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.sync_all()
self.nodes[0].generate(1)
self.sync_all()
###############
# simple test #
###############

View File

@ -8,12 +8,12 @@
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.util import assert_equal, start_nodes
import base64
import http
import urllib.parse
from http.client import HTTPConnection
from urllib.parse import urlparse
class HTTPBasicsTest (BitcoinTestFramework):
def setup_nodes(self):

View File

@ -11,7 +11,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, connect_nodes_bi, p2p_port
import time
import urllib
from urllib.parse import urlparse
class NodeHandlingTest (BitcoinTestFramework):
def run_test(self):
@ -45,7 +45,7 @@ class NodeHandlingTest (BitcoinTestFramework):
###########################
# RPC disconnectnode test #
###########################
url = urllib.parse.urlparse(self.nodes[1].url)
url = urlparse(self.nodes[1].url)
self.nodes[0].disconnectnode(url.hostname+":"+str(p2p_port(1)))
time.sleep(2) #disconnecting a node needs a little bit of time
for node in self.nodes[0].getpeerinfo():

View File

@ -18,8 +18,8 @@ import io
from codecs import encode
from decimal import Decimal
import http.client
import urllib.parse
from http.client import HTTPConnection
from urllib.parse import urlparse
def deser_uint256(f):

View File

@ -34,8 +34,8 @@ class ShorterBlockTimes(BitcoinTestFramework):
node0_taddr = get_coinbase_address(self.nodes[0])
node0_zaddr = self.nodes[0].z_getnewaddress('sapling')
recipients = [{'address': node0_zaddr, 'amount': Decimal("10.0")}]
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal("0.0"))
recipients = [{'address': node0_zaddr, 'amount': Decimal('10.0')}]
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0.0'))
txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
assert_equal(105, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # Blossom activation - 1
self.sync_all()

View File

@ -33,12 +33,12 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
import http.client as httplib
import base64
import decimal
import json
import logging
import urllib.parse
from http.client import HTTPConnection, HTTPSConnection, BadStatusLine
from urllib.parse import urlparse
USER_AGENT = "AuthServiceProxy/0.1"
@ -53,7 +53,7 @@ class JSONRPCException(Exception):
def EncodeDecimal(o):
if isinstance(o, decimal.Decimal):
return float(o)
round(o,8)
raise TypeError(repr(o) + " is not JSON serializable")
@ -63,7 +63,7 @@ class AuthServiceProxy():
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 = urllib.parse.urlparse(service_url)
self.__url = urlparse(service_url)
if self.__url.port is None:
port = 80
else:
@ -84,10 +84,10 @@ class AuthServiceProxy():
self.__conn = connection
self.timeout = connection.timeout
elif self.__url.scheme == 'https':
self.__conn = httplib.HTTPSConnection(self.__url.hostname, port,
self.__conn = HTTPSConnection(self.__url.hostname, port,
timeout=timeout)
else:
self.__conn = httplib.HTTPConnection(self.__url.hostname, port, timeout=timeout)
self.__conn = HTTPConnection(self.__url.hostname, port, timeout=timeout)
def _set_conn(self, connection=None):
@ -109,7 +109,7 @@ class AuthServiceProxy():
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).
@ -123,7 +123,7 @@ class AuthServiceProxy():
self.__conn.request(method, path, postdata, headers)
return self._get_response()
except Exception as e:
if ((isinstance(e, httplib.BadStatusLine)
if ((isinstance(e, BadStatusLine)
and e.line in ("''", "No status line received - the server has closed the connection"))
or e.__class__.__name__ in ('BrokenPipeError', 'ConnectionResetError')):
self.__conn.close()
@ -151,7 +151,7 @@ class AuthServiceProxy():
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), default=EncodeDecimal)
log.debug("--> "+postdata)
return self._request('POST', self.__url.path, postdata)

View File

@ -161,7 +161,7 @@ class TestManager():
# Create a p2p connection to each node
test_node = TestNode(self.block_store, self.tx_store)
self.test_nodes.append(test_node)
self.connections.append(NodeConn("127.0.0.1", p2p_port(i), nodes[i], test_node))
self.connections.append(NodeConn('127.0.0.1', p2p_port(i), nodes[i], test_node))
# Make sure the TestNode (callback class) has a reference to its
# associated NodeConn
test_node.add_connection(self.connections[-1])

View File

@ -154,7 +154,7 @@ 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')

View File

@ -353,7 +353,7 @@ class CBlockLocator(object):
return r
def __repr__(self):
return "CBlockLocator(nVersion=%i vHave=%s)" \
return "CBlockLocator(nVersion=%i vHave=%r)" \
% (self.nVersion, repr(self.vHave))
@ -611,7 +611,7 @@ class CTxIn(object):
def __repr__(self):
return "CTxIn(prevout=%s scriptSig=%s nSequence=%i)" \
% (repr(self.prevout), hexlify(self.scriptSig),
% (self.prevout, hexlify(self.scriptSig),
self.nSequence)
@ -674,7 +674,7 @@ class CTransaction(object):
self.hash = None
def deserialize(self, f):
header = struct.unpack("<i", f.read(4))[0]
header = struct.unpack("<I", f.read(4))[0]
self.fOverwintered = bool(header >> 31)
self.nVersion = header & 0x7FFFFFFF
self.nVersionGroupId = (struct.unpack("<I", f.read(4))[0]
@ -753,7 +753,7 @@ class CTransaction(object):
def is_valid(self):
self.calc_sha256()
for tout in self.vout:
if tout.nValue < 0 or tout.nValue > 2100000 * 100000000:
if tout.nValue < 0 or tout.nValue > 21000000 * 100000000:
return False
return True
@ -1053,7 +1053,7 @@ class msg_version(object):
def __repr__(self):
return 'msg_version(nVersion=%i nServices=%i nTime=%s addrTo=%s addrFrom=%s nNonce=0x%016X strSubVer=%s nStartingHeight=%i)' \
% (self.nVersion, self.nServices, time.ctime(self.nTime),
repr(self.addrTo), repr(self.addrFrom), self.nNonce,
self.addrTo, self.addrFrom, self.nNonce,
self.strSubVer, self.nStartingHeight)
@ -1086,7 +1086,7 @@ class msg_addr(object):
return ser_vector(self.addrs)
def __repr__(self):
return "msg_addr(addrs=%s)" % (repr(self.addrs))
return "msg_addr(addrs=%r)" % (self.addrs,)
class msg_alert(object):

View File

@ -41,9 +41,9 @@ class CScriptOp(int):
def encode_op_pushdata(d):
"""Encode a PUSHDATA op, returning bytes"""
if len(d) < 0x4c:
return b'' + struct.pack(b'<B', len(d)) + d # OP_PUSHDATA
return b'' + struct.pack(b'B', len(d)) + d # OP_PUSHDATA
elif len(d) <= 0xff:
return b'\x4c' + struct.pack(b'<B', len(d)) + d # OP_PUSHDATA1
return b'\x4c' + struct.pack(b'B', len(d)) + d # OP_PUSHDATA1
elif len(d) <= 0xffff:
return b'\x4d' + struct.pack(b'<H', len(d)) + d # OP_PUSHDATA2
elif len(d) <= 0xffffffff:
@ -774,7 +774,7 @@ class CScript(bytes):
# need to change
def _repr(o):
if isinstance(o, bytes):
return "x('%s')" % o.hex().decode('utf8')
return "x('%s')" % o.hex().decode('ascii')
else:
return repr(o)

View File

@ -6,7 +6,8 @@
from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than, start_nodes,\
initialize_chain_clean, connect_nodes_bi, wait_and_assert_operationid_status, wait_and_assert_operationid_status_result
initialize_chain_clean, connect_nodes_bi, wait_and_assert_operationid_status, \
wait_and_assert_operationid_status_result
from functools import reduce
import logging