diff --git a/cmake/utils/gen-ninja-deps.py b/cmake/utils/gen-ninja-deps.py --- a/cmake/utils/gen-ninja-deps.py +++ b/cmake/utils/gen-ninja-deps.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 -import subprocess -import os import argparse +import os +import subprocess parser = argparse.ArgumentParser(description='Produce a dep file from ninja.') parser.add_argument( diff --git a/share/qt/extract_strings_qt.py b/share/qt/extract_strings_qt.py --- a/share/qt/extract_strings_qt.py +++ b/share/qt/extract_strings_qt.py @@ -6,10 +6,10 @@ Extract _("...") strings for translation and convert to Qt stringdefs so that they can be picked up by Qt linguist. ''' -from subprocess import Popen, PIPE import operator import os import sys +from subprocess import PIPE, Popen OUT_CPP = "qt/bitcoinstrings.cpp" EMPTY = ['""'] diff --git a/share/rpcauth/rpcauth.py b/share/rpcauth/rpcauth.py --- a/share/rpcauth/rpcauth.py +++ b/share/rpcauth/rpcauth.py @@ -3,14 +3,13 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. +import hmac from argparse import ArgumentParser from base64 import urlsafe_b64encode from binascii import hexlify from getpass import getpass from os import urandom -import hmac - def generate_salt(size): """Create size byte hex salt""" diff --git a/src/test/data/generate_asmap.py b/src/test/data/generate_asmap.py --- a/src/test/data/generate_asmap.py +++ b/src/test/data/generate_asmap.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 # Copyright (c) 2020 The Bitcoin developers -from pathlib import Path import sys +from pathlib import Path def main(input_file, output_file): diff --git a/test/functional/combine_logs.py b/test/functional/combine_logs.py --- a/test/functional/combine_logs.py +++ b/test/functional/combine_logs.py @@ -10,7 +10,6 @@ If no argument is provided, the most recent test directory will be used.""" import argparse -from collections import defaultdict, namedtuple import heapq import itertools import os @@ -18,6 +17,7 @@ import re import sys import tempfile +from collections import defaultdict, namedtuple # N.B.: don't import any local modules here - this script must remain executable # without the parent module installed. diff --git a/test/functional/data/invalid_txs.py b/test/functional/data/invalid_txs.py --- a/test/functional/data/invalid_txs.py +++ b/test/functional/data/invalid_txs.py @@ -20,29 +20,27 @@ """ import abc - from typing import Optional + +from test_framework import script as sc +from test_framework.blocktools import create_tx_with_script from test_framework.messages import ( + MAX_MONEY, COutPoint, CTransaction, CTxIn, CTxOut, - MAX_MONEY, ) -from test_framework import script as sc -from test_framework.blocktools import create_tx_with_script -from test_framework.txtools import pad_tx - - from test_framework.script import ( - CScript, - OP_INVERT, - OP_2MUL, OP_2DIV, - OP_MUL, + OP_2MUL, + OP_INVERT, OP_LSHIFT, - OP_RSHIFT + OP_MUL, + OP_RSHIFT, + CScript, ) +from test_framework.txtools import pad_tx basic_p2sh = sc.CScript( [sc.OP_HASH160, sc.hash160(sc.CScript([sc.OP_0])), sc.OP_EQUAL]) diff --git a/test/functional/example_test.py b/test/functional/example_test.py --- a/test/functional/example_test.py +++ b/test/functional/example_test.py @@ -14,22 +14,11 @@ from collections import defaultdict # Avoid wildcard * imports if possible -from test_framework.blocktools import (create_block, create_coinbase) -from test_framework.messages import ( - CInv, - MSG_BLOCK, - msg_block, - msg_getdata -) -from test_framework.p2p import ( - P2PInterface, - p2p_lock, -) +from test_framework.blocktools import create_block, create_coinbase +from test_framework.messages import MSG_BLOCK, CInv, msg_block, msg_getdata +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - connect_nodes, -) +from test_framework.util import assert_equal, connect_nodes # P2PInterface is a class containing callbacks to be executed when a P2P # message is received from the node-under-test. Subclass P2PInterface and diff --git a/test/functional/test_framework/address.py b/test/functional/test_framework/address.py --- a/test/functional/test_framework/address.py +++ b/test/functional/test_framework/address.py @@ -7,7 +7,7 @@ import unittest from .script import CScript, hash160, hash256 -from .util import hex_str_to_bytes, assert_equal +from .util import assert_equal, hex_str_to_bytes ADDRESS_ECREG_UNSPENDABLE = 'ecregtest:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcrl5mqkt' ADDRESS_ECREG_UNSPENDABLE_DESCRIPTOR = 'addr(ecregtest:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcrl5mqkt)#u6xx93xc' diff --git a/test/functional/test_framework/authproxy.py b/test/functional/test_framework/authproxy.py --- a/test/functional/test_framework/authproxy.py +++ b/test/functional/test_framework/authproxy.py @@ -36,7 +36,6 @@ import base64 import decimal -from http import HTTPStatus import http.client import json import logging @@ -44,6 +43,7 @@ import socket import time import urllib.parse +from http import HTTPStatus HTTP_TIMEOUT = 30 USER_AGENT = "AuthServiceProxy/0.1" diff --git a/test/functional/test_framework/avatools.py b/test/functional/test_framework/avatools.py --- a/test/functional/test_framework/avatools.py +++ b/test/functional/test_framework/avatools.py @@ -5,33 +5,29 @@ """Utilities for avalanche tests.""" import struct -from typing import Any, Optional, List, Dict +from typing import Any, Dict, List, Optional from .authproxy import JSONRPCException from .key import ECKey from .messages import ( + NODE_AVALANCHE, + NODE_NETWORK, AvalancheDelegation, AvalancheProof, AvalancheResponse, CInv, CTransaction, FromHex, + TCPAvalancheResponse, + ToHex, hash256, msg_avahello, msg_avapoll, msg_tcpavaresponse, - NODE_AVALANCHE, - NODE_NETWORK, - TCPAvalancheResponse, - ToHex, ) from .p2p import P2PInterface, p2p_lock from .test_node import TestNode -from .util import ( - assert_equal, - satoshi_round, - wait_until_helper, -) +from .util import assert_equal, satoshi_round, wait_until_helper from .wallet_util import bytes_to_wif diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -6,22 +6,10 @@ import unittest -from .script import ( - CScript, - CScriptNum, - CScriptOp, - OP_1, - OP_CHECKSIG, - OP_DUP, - OP_EQUALVERIFY, - OP_HASH160, - OP_RETURN, - OP_TRUE, -) from .messages import ( - CBlock, COIN, XEC, + CBlock, COutPoint, CTransaction, CTxIn, @@ -29,6 +17,18 @@ FromHex, ToHex, ) +from .script import ( + OP_1, + OP_CHECKSIG, + OP_DUP, + OP_EQUALVERIFY, + OP_HASH160, + OP_RETURN, + OP_TRUE, + CScript, + CScriptNum, + CScriptOp, +) from .txtools import pad_tx from .util import assert_equal, satoshi_round diff --git a/test/functional/test_framework/coverage.py b/test/functional/test_framework/coverage.py --- a/test/functional/test_framework/coverage.py +++ b/test/functional/test_framework/coverage.py @@ -10,7 +10,6 @@ import os - REFERENCE_FILENAME = 'rpc_interface.txt' diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -18,21 +18,19 @@ Classes use __slots__ to ensure extraneous attributes aren't accidentally added by tests, compromising their intended effect. """ -from codecs import encode import copy import hashlib -from io import BytesIO import random import socket import struct import time import unittest - +from codecs import encode +from io import BytesIO from typing import List from test_framework.siphash import siphash256 -from test_framework.util import hex_str_to_bytes, assert_equal - +from test_framework.util import assert_equal, hex_str_to_bytes MIN_VERSION_SUPPORTED = 60001 # past bip-31 for ping/pong diff --git a/test/functional/test_framework/netutil.py b/test/functional/test_framework/netutil.py --- a/test/functional/test_framework/netutil.py +++ b/test/functional/test_framework/netutil.py @@ -8,12 +8,12 @@ """ import array -from binascii import unhexlify -from errno import ENOENT, EINVAL import os import socket import struct import sys +from binascii import unhexlify +from errno import EINVAL, ENOENT # STATE_ESTABLISHED = '01' # STATE_SYN_SENT = '02' @@ -171,6 +171,7 @@ Check for (local) IPv6 support. ''' import socket + # By using SOCK_DGRAM this will not actually make a connection, but it will # fail if there is no route to IPv6 localhost. have_ipv6 = True diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -21,25 +21,27 @@ a count of how many times each txid has been announced.""" import asyncio -from collections import defaultdict -from io import BytesIO import logging import struct import sys import threading +from collections import defaultdict +from io import BytesIO from test_framework.messages import ( - CBlockHeader, MAX_HEADERS_RESULTS, MIN_VERSION_SUPPORTED, + MSG_BLOCK, + MSG_TX, + MSG_TYPE_MASK, + NODE_NETWORK, + CBlockHeader, msg_addr, msg_addrv2, + msg_avahello, msg_avapoll, msg_avaproof, - msg_tcpavaresponse, - msg_avahello, msg_block, - MSG_BLOCK, msg_blocktxn, msg_cfcheckpt, msg_cfheaders, @@ -64,12 +66,10 @@ msg_sendaddrv2, msg_sendcmpct, msg_sendheaders, + msg_tcpavaresponse, msg_tx, - MSG_TX, - MSG_TYPE_MASK, msg_verack, msg_version, - NODE_NETWORK, sha256, ) from test_framework.util import wait_until_helper diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -10,7 +10,7 @@ import hashlib import struct import unittest -from typing import List, Dict +from typing import Dict, List from .messages import ( CTransaction, @@ -22,7 +22,6 @@ uint256_from_str, ) - MAX_SCRIPT_ELEMENT_SIZE = 520 OPCODE_NAMES: Dict["CScriptOp", str] = {} diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -6,7 +6,6 @@ import argparse import configparser -from enum import Enum import logging import os import pdb @@ -15,23 +14,24 @@ import sys import tempfile import time +from enum import Enum from typing import Optional +from . import coverage from .authproxy import JSONRPCException from .avatools import get_proof_ids -from . import coverage from .p2p import NetworkThread from .test_node import TestNode from .util import ( + MAX_NODES, + PortSeed, assert_equal, check_json_precision, connect_nodes, disconnect_nodes, get_datadir_path, initialize_datadir, - MAX_NODES, p2p_port, - PortSeed, rpc_port, wait_until_helper, ) diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -4,28 +4,29 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Class for bitcoind node under test""" +import collections import contextlib import decimal -from enum import Enum import errno import http.client import json import logging import os import re +import shlex import subprocess import sys import tempfile import time import urllib.parse -import collections -import shlex +from enum import Enum from .authproxy import JSONRPCException from .descriptors import descsum_create -from .messages import XEC, CTransaction, FromHex, MY_SUBVERSION +from .messages import MY_SUBVERSION, XEC, CTransaction, FromHex from .util import ( MAX_NODES, + EncodeDecimal, append_config, delete_cookie_file, get_auth_cookie, @@ -33,7 +34,6 @@ p2p_port, rpc_url, wait_until_helper, - EncodeDecimal, ) BITCOIND_PROC_WAIT_TIMEOUT = 60 diff --git a/test/functional/test_framework/txtools.py b/test/functional/test_framework/txtools.py --- a/test/functional/test_framework/txtools.py +++ b/test/functional/test_framework/txtools.py @@ -3,7 +3,7 @@ from .cdefs import MAX_TXOUT_PUBKEY_SCRIPT, MIN_TX_SIZE from .messages import CTransaction, CTxOut, FromHex, ToHex -from .script import CScript, OP_RETURN +from .script import OP_RETURN, CScript def pad_tx(tx, pad_to_size=MIN_TX_SIZE): diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -4,11 +4,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Helpful routines for regression testing.""" -from base64 import b64encode -from binascii import unhexlify -from decimal import Decimal, ROUND_DOWN -from io import BytesIO -from subprocess import CalledProcessError import inspect import json import logging @@ -17,6 +12,11 @@ import re import time import unittest +from base64 import b64encode +from binascii import unhexlify +from decimal import ROUND_DOWN, Decimal +from io import BytesIO +from subprocess import CalledProcessError from . import coverage from .authproxy import AuthServiceProxy, JSONRPCException diff --git a/test/functional/test_framework/wallet_util.py b/test/functional/test_framework/wallet_util.py --- a/test/functional/test_framework/wallet_util.py +++ b/test/functional/test_framework/wallet_util.py @@ -5,14 +5,9 @@ """Useful util functions for testing the wallet""" from collections import namedtuple -from test_framework.address import ( - byte_to_base58, - key_to_p2pkh, - script_to_p2sh, -) +from test_framework.address import byte_to_base58, key_to_p2pkh, script_to_p2sh from test_framework.key import ECKey from test_framework.script import ( - CScript, OP_2, OP_3, OP_CHECKMULTISIG, @@ -21,6 +16,7 @@ OP_EQUAL, OP_EQUALVERIFY, OP_HASH160, + CScript, hash160, ) from test_framework.util import hex_str_to_bytes diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -14,23 +14,23 @@ """ import argparse -from collections import deque import configparser import datetime +import json +import logging +import multiprocessing import os -import time +import re import shutil -import sys import subprocess +import sys import tempfile -import re -import logging -import xml.etree.ElementTree as ET -import json import threading -import multiprocessing -from queue import Queue, Empty +import time import unittest +import xml.etree.ElementTree as ET +from collections import deque +from queue import Empty, Queue # Formatting. Default colors to empty strings. BOLD, GREEN, RED, GREY = ("", ""), ("", ""), ("", ""), ("", "") diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py --- a/test/fuzz/test_runner.py +++ b/test/fuzz/test_runner.py @@ -6,12 +6,12 @@ """ import argparse -from concurrent.futures import ThreadPoolExecutor, as_completed import configparser import logging import os import subprocess import sys +from concurrent.futures import ThreadPoolExecutor, as_completed def main(): diff --git a/test/lint/check-doc.py b/test/lint/check-doc.py --- a/test/lint/check-doc.py +++ b/test/lint/check-doc.py @@ -11,10 +11,10 @@ Author: @MarcoFalke ''' -from subprocess import check_output -from pprint import PrettyPrinter import glob import re +from pprint import PrettyPrinter +from subprocess import check_output TOP_LEVEL = 'git rev-parse --show-toplevel' FOLDER_SRC = '/src/**/' diff --git a/test/lint/check-rpc-mappings.py b/test/lint/check-rpc-mappings.py --- a/test/lint/check-rpc-mappings.py +++ b/test/lint/check-rpc-mappings.py @@ -4,11 +4,11 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Check RPC argument consistency.""" -from collections import defaultdict import glob import os import re import sys +from collections import defaultdict # Source files (relative to root) to scan for dispatch tables SOURCE_PATTERNS = [