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/abc-get-invalid-block.py b/test/functional/abc-get-invalid-block.py --- a/test/functional/abc-get-invalid-block.py +++ b/test/functional/abc-get-invalid-block.py @@ -5,14 +5,14 @@ """Test requesting invalid blocks behaves safely.""" from test_framework.messages import ( + MSG_BLOCK, + MSG_CMPCT_BLOCK, CInv, msg_getblocks, msg_getdata, msg_getheaders, - MSG_BLOCK, - MSG_CMPCT_BLOCK, ) -from test_framework.p2p import p2p_lock, P2PInterface +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/abc-invalid-chains.py b/test/functional/abc-invalid-chains.py --- a/test/functional/abc-invalid-chains.py +++ b/test/functional/abc-invalid-chains.py @@ -5,13 +5,10 @@ import time -from test_framework.test_framework import BitcoinTestFramework +from test_framework.blocktools import create_block, create_coinbase from test_framework.p2p import P2PDataStore +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal -from test_framework.blocktools import ( - create_block, - create_coinbase, -) class InvalidChainsTest(BitcoinTestFramework): diff --git a/test/functional/abc-invalid-message.py b/test/functional/abc-invalid-message.py --- a/test/functional/abc-invalid-message.py +++ b/test/functional/abc-invalid-message.py @@ -11,11 +11,7 @@ import struct from test_framework.messages import NODE_NETWORK, msg_version -from test_framework.p2p import ( - p2p_lock, - msg_ping, - P2PInterface, -) +from test_framework.p2p import P2PInterface, msg_ping, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import wait_until diff --git a/test/functional/abc-mempool-coherence-on-activations.py b/test/functional/abc-mempool-coherence-on-activations.py --- a/test/functional/abc-mempool-coherence-on-activations.py +++ b/test/functional/abc-mempool-coherence-on-activations.py @@ -36,17 +36,16 @@ ) from test_framework.p2p import P2PDataStore from test_framework.script import ( - CScript, OP_CHECKSIG, OP_TRUE, SIGHASH_ALL, SIGHASH_FORKID, + CScript, SignatureHashForkId, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error - # ---Code specific to the activation used for this test--- # It might change depending on the activation code currently existing in the diff --git a/test/functional/abc-minimaldata.py b/test/functional/abc-minimaldata.py --- a/test/functional/abc-minimaldata.py +++ b/test/functional/abc-minimaldata.py @@ -27,14 +27,8 @@ FromHex, ToHex, ) -from test_framework.p2p import ( - P2PDataStore, -) -from test_framework.script import ( - CScript, - OP_ADD, - OP_TRUE, -) +from test_framework.p2p import P2PDataStore +from test_framework.script import OP_ADD, OP_TRUE, CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx from test_framework.util import assert_raises_rpc_error diff --git a/test/functional/abc-parkedchain.py b/test/functional/abc-parkedchain.py --- a/test/functional/abc-parkedchain.py +++ b/test/functional/abc-parkedchain.py @@ -5,11 +5,7 @@ """Test the parckblock and unparkblock RPC calls.""" from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - connect_nodes, - wait_until -) +from test_framework.util import assert_equal, connect_nodes, wait_until class ParkedChainTest(BitcoinTestFramework): diff --git a/test/functional/abc-replay-protection.py b/test/functional/abc-replay-protection.py --- a/test/functional/abc-replay-protection.py +++ b/test/functional/abc-replay-protection.py @@ -28,11 +28,11 @@ ) from test_framework.p2p import P2PDataStore from test_framework.script import ( - CScript, OP_CHECKSIG, OP_TRUE, SIGHASH_ALL, SIGHASH_FORKID, + CScript, SignatureHashForkId, ) from test_framework.test_framework import BitcoinTestFramework diff --git a/test/functional/abc-schnorr.py b/test/functional/abc-schnorr.py --- a/test/functional/abc-schnorr.py +++ b/test/functional/abc-schnorr.py @@ -26,17 +26,15 @@ FromHex, ToHex, ) -from test_framework.p2p import ( - P2PDataStore, -) +from test_framework.p2p import P2PDataStore from test_framework.script import ( - CScript, OP_1, OP_CHECKMULTISIG, OP_CHECKSIG, OP_TRUE, SIGHASH_ALL, SIGHASH_FORKID, + CScript, SignatureHashForkId, ) from test_framework.test_framework import BitcoinTestFramework diff --git a/test/functional/abc-schnorrmultisig.py b/test/functional/abc-schnorrmultisig.py --- a/test/functional/abc-schnorrmultisig.py +++ b/test/functional/abc-schnorrmultisig.py @@ -29,23 +29,20 @@ FromHex, ToHex, ) -from test_framework.p2p import ( - P2PDataStore, -) +from test_framework.p2p import P2PDataStore from test_framework.script import ( - CScript, OP_0, OP_1, OP_CHECKMULTISIG, OP_TRUE, SIGHASH_ALL, SIGHASH_FORKID, + CScript, SignatureHashForkId, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error - # ECDSA checkmultisig with non-null dummy are invalid since the new mode # refuses ECDSA. ECDSA_NULLDUMMY_ERROR = 'mandatory-script-verify-flag-failed (Only Schnorr signatures allowed in this operation)' diff --git a/test/functional/abc-segwit-recovery.py b/test/functional/abc-segwit-recovery.py --- a/test/functional/abc-segwit-recovery.py +++ b/test/functional/abc-segwit-recovery.py @@ -23,20 +23,16 @@ CTxOut, ToHex, ) -from test_framework.p2p import ( - P2PDataStore, -) +from test_framework.p2p import P2PDataStore from test_framework.script import ( - CScript, - hash160, OP_EQUAL, OP_HASH160, OP_TRUE, + CScript, + hash160, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_raises_rpc_error, -) +from test_framework.util import assert_raises_rpc_error TEST_TIME = int(time.time()) diff --git a/test/functional/abc-sync-chain.py b/test/functional/abc-sync-chain.py --- a/test/functional/abc-sync-chain.py +++ b/test/functional/abc-sync-chain.py @@ -17,7 +17,6 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import wait_until - NUM_IBD_BLOCKS = 50 diff --git a/test/functional/abc-transaction-ordering.py b/test/functional/abc-transaction-ordering.py --- a/test/functional/abc-transaction-ordering.py +++ b/test/functional/abc-transaction-ordering.py @@ -7,27 +7,18 @@ non topological order once the feature is activated. """ -from collections import deque import random import time +from collections import deque from test_framework.blocktools import ( create_block, create_coinbase, make_conform_to_ctor, ) -from test_framework.messages import ( - COutPoint, - CTransaction, - CTxIn, - CTxOut, -) +from test_framework.messages import COutPoint, CTransaction, CTxIn, CTxOut from test_framework.p2p import P2PDataStore -from test_framework.script import ( - CScript, - OP_RETURN, - OP_TRUE, -) +from test_framework.script import OP_RETURN, OP_TRUE, CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/abc_feature_minerfund.py b/test/functional/abc_feature_minerfund.py --- a/test/functional/abc_feature_minerfund.py +++ b/test/functional/abc_feature_minerfund.py @@ -3,18 +3,12 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -from test_framework.blocktools import ( - create_block, - create_coinbase, -) +from decimal import Decimal + +from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ToHex from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_greater_than_or_equal, -) - -from decimal import Decimal +from test_framework.util import assert_equal, assert_greater_than_or_equal AXION_ACTIVATION_TIME = 2000000600 diff --git a/test/functional/abc_mining_basic.py b/test/functional/abc_mining_basic.py --- a/test/functional/abc_mining_basic.py +++ b/test/functional/abc_mining_basic.py @@ -6,13 +6,13 @@ Tests for Bitcoin ABC mining RPCs """ +from decimal import Decimal + from test_framework.cdefs import ( BLOCK_MAXBYTES_MAXSIGCHECKS_RATIO, DEFAULT_MAX_BLOCK_SIZE, ) -from test_framework.messages import ( - XEC, -) +from test_framework.messages import XEC from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -20,8 +20,6 @@ connect_nodes, ) -from decimal import Decimal - AXION_ACTIVATION_TIME = 2000000600 MINER_FUND_ADDR = 'ecregtest:pqnqv9lt7e5vjyp0w88zf2af0l92l8rxdgz0wv9ltl' MINER_FUND_LEGACY_ADDR = '2MviGxxFciGeWTgkUgYgjqehWt18c4ZsShd' diff --git a/test/functional/abc_p2p_avalanche_peer_discovery.py b/test/functional/abc_p2p_avalanche_peer_discovery.py --- a/test/functional/abc_p2p_avalanche_peer_discovery.py +++ b/test/functional/abc_p2p_avalanche_peer_discovery.py @@ -12,29 +12,23 @@ from test_framework.address import ADDRESS_ECREG_UNSPENDABLE from test_framework.avatools import ( - get_ava_p2p_interface, create_coinbase_stakes, + get_ava_p2p_interface, get_proof_ids, ) -from test_framework.key import ( - ECKey, - ECPubKey, -) -from test_framework.p2p import p2p_lock +from test_framework.key import ECKey, ECPubKey from test_framework.messages import ( + MSG_AVA_PROOF, + NODE_AVALANCHE, + NODE_NETWORK, AvalancheProof, CInv, FromHex, - MSG_AVA_PROOF, msg_getdata, - NODE_AVALANCHE, - NODE_NETWORK, ) +from test_framework.p2p import p2p_lock from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - wait_until, -) +from test_framework.util import assert_equal, wait_until from test_framework.wallet_util import bytes_to_wif UNCONDITIONAL_RELAY_DELAY = 2 * 60 diff --git a/test/functional/abc_p2p_avalanche_voting.py b/test/functional/abc_p2p_avalanche_voting.py --- a/test/functional/abc_p2p_avalanche_voting.py +++ b/test/functional/abc_p2p_avalanche_voting.py @@ -6,19 +6,13 @@ import random from test_framework.avatools import ( - get_ava_p2p_interface, create_coinbase_stakes, + get_ava_p2p_interface, ) -from test_framework.key import ( - ECKey, - ECPubKey, -) +from test_framework.key import ECKey, ECPubKey from test_framework.messages import AvalancheVote from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - wait_until, -) +from test_framework.util import assert_equal, wait_until from test_framework.wallet_util import bytes_to_wif BLOCK_ACCEPTED = 0 diff --git a/test/functional/abc_p2p_compactblocks.py b/test/functional/abc_p2p_compactblocks.py --- a/test/functional/abc_p2p_compactblocks.py +++ b/test/functional/abc_p2p_compactblocks.py @@ -11,9 +11,9 @@ (e.g. sigops limits). """ -from collections import deque import random import time +from collections import deque from test_framework.blocktools import ( create_block, @@ -32,18 +32,11 @@ msg_sendcmpct, ser_compact_size, ) -from test_framework.p2p import ( - p2p_lock, - P2PDataStore, - P2PInterface, -) -from test_framework.script import CScript, OP_RETURN, OP_TRUE +from test_framework.p2p import P2PDataStore, P2PInterface, p2p_lock +from test_framework.script import OP_RETURN, OP_TRUE, CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx -from test_framework.util import ( - assert_equal, - wait_until -) +from test_framework.util import assert_equal, wait_until class PreviousSpendableOutput(): diff --git a/test/functional/abc_p2p_fullblocktest.py b/test/functional/abc_p2p_fullblocktest.py --- a/test/functional/abc_p2p_fullblocktest.py +++ b/test/functional/abc_p2p_fullblocktest.py @@ -11,9 +11,9 @@ (e.g. sigops limits). """ -from collections import deque import random import time +from collections import deque from test_framework.blocktools import ( create_block, @@ -21,23 +21,17 @@ create_tx_with_script, make_conform_to_ctor, ) -from test_framework.cdefs import ( - ONE_MEGABYTE, -) +from test_framework.cdefs import ONE_MEGABYTE from test_framework.messages import ( COutPoint, CTransaction, CTxIn, CTxOut, - ser_compact_size, ToHex, + ser_compact_size, ) from test_framework.p2p import P2PDataStore -from test_framework.script import ( - CScript, - OP_RETURN, - OP_TRUE, -) +from test_framework.script import OP_RETURN, OP_TRUE, CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/abc_p2p_proof_inventory.py b/test/functional/abc_p2p_proof_inventory.py --- a/test/functional/abc_p2p_proof_inventory.py +++ b/test/functional/abc_p2p_proof_inventory.py @@ -6,26 +6,21 @@ Test proof inventory relaying """ -from test_framework.avatools import ( - gen_proof, - get_proof_ids, - wait_for_proof, -) +import time + from test_framework.address import ADDRESS_ECREG_UNSPENDABLE +from test_framework.avatools import gen_proof, get_proof_ids, wait_for_proof from test_framework.key import ECKey from test_framework.messages import ( + MSG_AVA_PROOF, + MSG_TYPE_MASK, AvalancheProof, CInv, FromHex, - MSG_AVA_PROOF, - MSG_TYPE_MASK, msg_avaproof, msg_getdata, ) -from test_framework.p2p import ( - P2PInterface, - p2p_lock, -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -35,8 +30,6 @@ ) from test_framework.wallet_util import bytes_to_wif -import time - # Broadcast reattempt occurs every 10 to 15 minutes MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # Delay to allow the node to respond to getdata requests diff --git a/test/functional/abc_rpc_addavalanchenode.py b/test/functional/abc_rpc_addavalanchenode.py --- a/test/functional/abc_rpc_addavalanchenode.py +++ b/test/functional/abc_rpc_addavalanchenode.py @@ -16,9 +16,7 @@ ) from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_raises_rpc_error, -) +from test_framework.util import assert_raises_rpc_error from test_framework.wallet_util import bytes_to_wif diff --git a/test/functional/abc_rpc_avalancheproof.py b/test/functional/abc_rpc_avalancheproof.py --- a/test/functional/abc_rpc_avalancheproof.py +++ b/test/functional/abc_rpc_avalancheproof.py @@ -26,9 +26,9 @@ from test_framework.util import ( append_config, assert_equal, + assert_raises_rpc_error, connect_nodes, wait_until, - assert_raises_rpc_error, ) from test_framework.wallet_util import bytes_to_wif diff --git a/test/functional/abc_rpc_buildavalancheproof.py b/test/functional/abc_rpc_buildavalancheproof.py --- a/test/functional/abc_rpc_buildavalancheproof.py +++ b/test/functional/abc_rpc_buildavalancheproof.py @@ -7,9 +7,7 @@ from test_framework.avatools import create_coinbase_stakes from test_framework.key import ECKey from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_raises_rpc_error, -) +from test_framework.util import assert_raises_rpc_error from test_framework.wallet_util import bytes_to_wif diff --git a/test/functional/abc_rpc_getavalanchepeerinfo.py b/test/functional/abc_rpc_getavalanchepeerinfo.py --- a/test/functional/abc_rpc_getavalanchepeerinfo.py +++ b/test/functional/abc_rpc_getavalanchepeerinfo.py @@ -4,8 +4,8 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the getavalanchepeerinfo RPC.""" from test_framework.avatools import ( - get_ava_p2p_interface, create_coinbase_stakes, + get_ava_p2p_interface, ) from test_framework.key import ECKey from test_framework.test_framework import BitcoinTestFramework diff --git a/test/functional/abc_wallet_dumpcoins.py b/test/functional/abc_wallet_dumpcoins.py --- a/test/functional/abc_wallet_dumpcoins.py +++ b/test/functional/abc_wallet_dumpcoins.py @@ -6,11 +6,11 @@ Test the dumpcoins RPCs call. """ +from decimal import Decimal + from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal -from decimal import Decimal - class DumpCoinsTest(BitcoinTestFramework): def set_test_params(self): diff --git a/test/functional/abc_wallet_standardness.py b/test/functional/abc_wallet_standardness.py --- a/test/functional/abc_wallet_standardness.py +++ b/test/functional/abc_wallet_standardness.py @@ -6,29 +6,22 @@ that it might try to spend.""" from decimal import Decimal -from test_framework.messages import ( - CTransaction, - CTxOut, - FromHex, - ToHex, -) + +from test_framework.messages import CTransaction, CTxOut, FromHex, ToHex from test_framework.script import ( - CScript, OP_1, OP_5, - OP_CHECKSIG, OP_CHECKMULTISIG, + OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, OP_PUSHDATA1, + CScript, hash160, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_raises_rpc_error, - assert_equal, -) +from test_framework.util import assert_equal, assert_raises_rpc_error SATOSHI = Decimal('0.01') 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,23 +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, - wait_until, -) +from test_framework.util import assert_equal, connect_nodes, wait_until # 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/feature_abortnode.py b/test/functional/feature_abortnode.py --- a/test/functional/feature_abortnode.py +++ b/test/functional/feature_abortnode.py @@ -10,10 +10,11 @@ - Verify that bitcoind AbortNode's. """ -from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import wait_until, get_datadir_path, connect_nodes import os +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import connect_nodes, get_datadir_path, wait_until + class AbortNodeTest(BitcoinTestFramework): diff --git a/test/functional/feature_assumevalid.py b/test/functional/feature_assumevalid.py --- a/test/functional/feature_assumevalid.py +++ b/test/functional/feature_assumevalid.py @@ -31,7 +31,7 @@ """ import time -from test_framework.blocktools import (create_block, create_coinbase) +from test_framework.blocktools import create_block, create_coinbase from test_framework.key import ECKey from test_framework.messages import ( CBlockHeader, @@ -43,7 +43,7 @@ msg_headers, ) from test_framework.p2p import P2PInterface -from test_framework.script import (CScript, OP_TRUE) +from test_framework.script import OP_TRUE, CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx from test_framework.util import assert_equal diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py --- a/test/functional/feature_bip68_sequence.py +++ b/test/functional/feature_bip68_sequence.py @@ -6,10 +6,7 @@ import time -from test_framework.blocktools import ( - create_block, - create_coinbase, -) +from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ( XEC, COutPoint, diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -8,6 +8,7 @@ import struct import time +from data import invalid_txs from test_framework.blocktools import ( create_block, create_coinbase, @@ -17,8 +18,8 @@ from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE from test_framework.key import ECKey from test_framework.messages import ( - CBlock, COIN, + CBlock, COutPoint, CTransaction, CTxIn, @@ -28,7 +29,6 @@ ) from test_framework.p2p import P2PDataStore from test_framework.script import ( - CScript, OP_ELSE, OP_ENDIF, OP_FALSE, @@ -38,14 +38,13 @@ OP_TRUE, SIGHASH_ALL, SIGHASH_FORKID, + CScript, SignatureHashForkId, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx from test_framework.util import assert_equal -from data import invalid_txs - # Use this class for tests that require behavior other than normal p2p behavior. # For now, it is used to serialize a bloated varint (b64). diff --git a/test/functional/feature_blocksdir.py b/test/functional/feature_blocksdir.py --- a/test/functional/feature_blocksdir.py +++ b/test/functional/feature_blocksdir.py @@ -8,7 +8,10 @@ import os import shutil -from test_framework.test_framework import BitcoinTestFramework, initialize_datadir +from test_framework.test_framework import ( + BitcoinTestFramework, + initialize_datadir, +) class BlocksdirTest(BitcoinTestFramework): diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -8,24 +8,27 @@ 1351. """ -from test_framework.blocktools import create_block, create_coinbase, create_transaction, make_conform_to_ctor +from test_framework.blocktools import ( + create_block, + create_coinbase, + create_transaction, + make_conform_to_ctor, +) from test_framework.messages import ( CTransaction, FromHex, + ToHex, msg_block, msg_tx, - ToHex, -) -from test_framework.p2p import ( - P2PInterface, ) +from test_framework.p2p import P2PInterface from test_framework.script import ( - CScript, - CScriptNum, OP_1NEGATE, OP_CHECKLOCKTIMEVERIFY, OP_DROP, OP_TRUE, + CScript, + CScriptNum, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx diff --git a/test/functional/feature_csv_activation.py b/test/functional/feature_csv_activation.py --- a/test/functional/feature_csv_activation.py +++ b/test/functional/feature_csv_activation.py @@ -40,9 +40,9 @@ bip112tx_special - test negative argument to OP_CSV """ +import time from decimal import Decimal from itertools import product -import time from test_framework.blocktools import ( create_block, @@ -52,10 +52,10 @@ from test_framework.messages import XEC, CTransaction, FromHex, ToHex from test_framework.p2p import P2PDataStore from test_framework.script import ( - CScript, OP_CHECKSEQUENCEVERIFY, OP_DROP, OP_TRUE, + CScript, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx diff --git a/test/functional/feature_dbcrash.py b/test/functional/feature_dbcrash.py --- a/test/functional/feature_dbcrash.py +++ b/test/functional/feature_dbcrash.py @@ -41,10 +41,7 @@ ToHex, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - hex_str_to_bytes, -) +from test_framework.util import assert_equal, hex_str_to_bytes class ChainstateWriteCrashTest(BitcoinTestFramework): diff --git a/test/functional/feature_dersig.py b/test/functional/feature_dersig.py --- a/test/functional/feature_dersig.py +++ b/test/functional/feature_dersig.py @@ -7,7 +7,11 @@ Test that the DERSIG soft-fork activates at (regtest) height 1251. """ -from test_framework.blocktools import create_block, create_coinbase, create_transaction +from test_framework.blocktools import ( + create_block, + create_coinbase, + create_transaction, +) from test_framework.messages import msg_block from test_framework.p2p import P2PInterface from test_framework.script import CScript diff --git a/test/functional/feature_maxuploadtarget.py b/test/functional/feature_maxuploadtarget.py --- a/test/functional/feature_maxuploadtarget.py +++ b/test/functional/feature_maxuploadtarget.py @@ -11,12 +11,12 @@ * Verify that the upload counters are reset after 24 hours. """ -from collections import defaultdict import time +from collections import defaultdict -from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE from test_framework.blocktools import mine_big_block -from test_framework.messages import CInv, MSG_BLOCK, msg_getdata +from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE +from test_framework.messages import MSG_BLOCK, CInv, msg_getdata from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/feature_proxy.py b/test/functional/feature_proxy.py --- a/test/functional/feature_proxy.py +++ b/test/functional/feature_proxy.py @@ -38,11 +38,7 @@ Socks5Server, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - PORT_MIN, - PORT_RANGE, -) +from test_framework.util import PORT_MIN, PORT_RANGE, assert_equal RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -13,7 +13,7 @@ from test_framework.blocktools import create_coinbase from test_framework.messages import CBlock, ToHex -from test_framework.script import CScript, OP_RETURN, OP_NOP +from test_framework.script import OP_NOP, OP_RETURN, CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py --- a/test/functional/feature_settings.py +++ b/test/functional/feature_settings.py @@ -5,7 +5,6 @@ """Test various command line arguments and configuration file parameters.""" import json - from pathlib import Path from test_framework.test_framework import BitcoinTestFramework diff --git a/test/functional/feature_shutdown.py b/test/functional/feature_shutdown.py --- a/test/functional/feature_shutdown.py +++ b/test/functional/feature_shutdown.py @@ -4,9 +4,10 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test bitcoind shutdown.""" +from threading import Thread + from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, get_rpc_proxy, wait_until -from threading import Thread def test_long_call(node): diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py --- a/test/functional/interface_bitcoin_cli.py +++ b/test/functional/interface_bitcoin_cli.py @@ -5,6 +5,7 @@ """Test bitcoin-cli""" from decimal import Decimal + from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -5,14 +5,15 @@ """Test the REST API.""" import binascii +import http.client +import json +import urllib.parse from decimal import Decimal from enum import Enum -import http.client from io import BytesIO -import json from struct import pack, unpack -import urllib.parse +from test_framework.messages import BLOCK_HEADER_SIZE from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -21,8 +22,6 @@ hex_str_to_bytes, ) -from test_framework.messages import BLOCK_HEADER_SIZE - class ReqType(Enum): JSON = 1 diff --git a/test/functional/interface_rpc.py b/test/functional/interface_rpc.py --- a/test/functional/interface_rpc.py +++ b/test/functional/interface_rpc.py @@ -5,6 +5,7 @@ """Tests some generic aspects of the RPC interface.""" import os + from test_framework.authproxy import JSONRPCException from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_greater_than_or_equal diff --git a/test/functional/interface_zmq.py b/test/functional/interface_zmq.py --- a/test/functional/interface_zmq.py +++ b/test/functional/interface_zmq.py @@ -5,15 +5,12 @@ """Test the ZMQ notification interface.""" import struct from io import BytesIO +from time import sleep from test_framework.address import ADDRESS_ECREG_UNSPENDABLE -from test_framework.test_framework import BitcoinTestFramework from test_framework.messages import CTransaction, hash256 -from test_framework.util import ( - assert_equal, - connect_nodes, -) -from time import sleep +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, connect_nodes def hash256_reversed(byte_str): diff --git a/test/functional/mempool_accept.py b/test/functional/mempool_accept.py --- a/test/functional/mempool_accept.py +++ b/test/functional/mempool_accept.py @@ -4,21 +4,18 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test mempool acceptance of raw transactions.""" -from test_framework.test_framework import BitcoinTestFramework from test_framework.key import ECKey from test_framework.messages import ( + MAX_BLOCK_BASE_SIZE, + MAX_MONEY, XEC, COutPoint, CTransaction, CTxOut, FromHex, - MAX_BLOCK_BASE_SIZE, ToHex, - MAX_MONEY, ) from test_framework.script import ( - hash160, - CScript, OP_0, OP_2, OP_3, @@ -26,11 +23,11 @@ OP_EQUAL, OP_HASH160, OP_RETURN, + CScript, + hash160, ) -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, assert_raises_rpc_error class MempoolAcceptanceTest(BitcoinTestFramework): diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py --- a/test/functional/mempool_persist.py +++ b/test/functional/mempool_persist.py @@ -35,9 +35,9 @@ node1 can't write to disk. """ -from decimal import Decimal import os import time +from decimal import Decimal from test_framework.p2p import P2PTxInvStore from test_framework.test_framework import BitcoinTestFramework diff --git a/test/functional/mempool_reorg.py b/test/functional/mempool_reorg.py --- a/test/functional/mempool_reorg.py +++ b/test/functional/mempool_reorg.py @@ -8,8 +8,8 @@ that spend (directly or indirectly) coinbase transactions. """ -from test_framework.test_framework import BitcoinTestFramework from test_framework.blocktools import create_raw_transaction +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error diff --git a/test/functional/mempool_resurrect.py b/test/functional/mempool_resurrect.py --- a/test/functional/mempool_resurrect.py +++ b/test/functional/mempool_resurrect.py @@ -4,8 +4,8 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test resurrection of mined transactions when the blockchain is re-organized.""" -from test_framework.test_framework import BitcoinTestFramework from test_framework.blocktools import create_raw_transaction +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/mempool_spend_coinbase.py b/test/functional/mempool_spend_coinbase.py --- a/test/functional/mempool_spend_coinbase.py +++ b/test/functional/mempool_spend_coinbase.py @@ -12,8 +12,8 @@ but less mature coinbase spends are NOT. """ -from test_framework.test_framework import BitcoinTestFramework from test_framework.blocktools import create_raw_transaction +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error diff --git a/test/functional/mempool_unbroadcast.py b/test/functional/mempool_unbroadcast.py --- a/test/functional/mempool_unbroadcast.py +++ b/test/functional/mempool_unbroadcast.py @@ -10,11 +10,7 @@ from test_framework.blocktools import create_confirmed_utxos from test_framework.p2p import P2PTxInvStore from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - connect_nodes, - disconnect_nodes, -) +from test_framework.util import assert_equal, connect_nodes, disconnect_nodes # 15 minutes in seconds MAX_INITIAL_BROADCAST_DELAY = 15 * 60 diff --git a/test/functional/mempool_updatefromblock.py b/test/functional/mempool_updatefromblock.py --- a/test/functional/mempool_updatefromblock.py +++ b/test/functional/mempool_updatefromblock.py @@ -8,8 +8,8 @@ when transactions have been re-added from a disconnected block to the mempool. """ import time - from decimal import Decimal + from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -11,18 +11,9 @@ import copy from decimal import Decimal -from test_framework.blocktools import ( - create_coinbase, - TIME_GENESIS_BLOCK, -) -from test_framework.messages import ( - CBlock, - CBlockHeader, - BLOCK_HEADER_SIZE, -) -from test_framework.p2p import ( - P2PDataStore, -) +from test_framework.blocktools import TIME_GENESIS_BLOCK, create_coinbase +from test_framework.messages import BLOCK_HEADER_SIZE, CBlock, CBlockHeader +from test_framework.p2p import P2PDataStore from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, diff --git a/test/functional/mining_getblocktemplate_longpoll.py b/test/functional/mining_getblocktemplate_longpoll.py --- a/test/functional/mining_getblocktemplate_longpoll.py +++ b/test/functional/mining_getblocktemplate_longpoll.py @@ -4,8 +4,8 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test longpolling with getblocktemplate.""" -from decimal import Decimal import threading +from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework from test_framework.util import get_rpc_proxy, random_transaction diff --git a/test/functional/mining_prioritisetransaction.py b/test/functional/mining_prioritisetransaction.py --- a/test/functional/mining_prioritisetransaction.py +++ b/test/functional/mining_prioritisetransaction.py @@ -10,6 +10,7 @@ create_confirmed_utxos, send_big_transactions, ) + # FIXME: review how this test needs to be adapted w.r.t _LEGACY_MAX_BLOCK_SIZE from test_framework.cdefs import LEGACY_MAX_BLOCK_SIZE from test_framework.messages import COIN diff --git a/test/functional/p2p_addr_relay.py b/test/functional/p2p_addr_relay.py --- a/test/functional/p2p_addr_relay.py +++ b/test/functional/p2p_addr_relay.py @@ -6,17 +6,12 @@ Test addr relay """ -from test_framework.messages import ( - CAddress, - NODE_NETWORK, - msg_addr, -) +import time + +from test_framework.messages import NODE_NETWORK, CAddress, msg_addr from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, -) -import time +from test_framework.util import assert_equal ADDRS = [] for i in range(10): diff --git a/test/functional/p2p_addrv2_relay.py b/test/functional/p2p_addrv2_relay.py --- a/test/functional/p2p_addrv2_relay.py +++ b/test/functional/p2p_addrv2_relay.py @@ -8,11 +8,7 @@ import time -from test_framework.messages import ( - CAddress, - msg_addrv2, - NODE_NETWORK, -) +from test_framework.messages import NODE_NETWORK, CAddress, msg_addrv2 from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/p2p_blocksonly.py b/test/functional/p2p_blocksonly.py --- a/test/functional/p2p_blocksonly.py +++ b/test/functional/p2p_blocksonly.py @@ -4,7 +4,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test p2p blocksonly""" -from test_framework.messages import msg_tx, CTransaction, FromHex +from test_framework.messages import CTransaction, FromHex, msg_tx from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -12,9 +12,11 @@ from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ( + MSG_BLOCK, + MSG_CMPCT_BLOCK, + NODE_NETWORK, BlockTransactions, BlockTransactionsRequest, - calculate_shortid, CBlock, CBlockHeader, CInv, @@ -24,8 +26,10 @@ CTxOut, FromHex, HeaderAndShortIDs, - MSG_BLOCK, - MSG_CMPCT_BLOCK, + P2PHeaderAndShortIDs, + PrefilledTransaction, + ToHex, + calculate_shortid, msg_block, msg_blocktxn, msg_cmpctblock, @@ -37,22 +41,12 @@ msg_sendcmpct, msg_sendheaders, msg_tx, - NODE_NETWORK, - P2PHeaderAndShortIDs, - PrefilledTransaction, - ToHex, ) -from test_framework.p2p import ( - p2p_lock, - P2PInterface, -) -from test_framework.script import CScript, OP_TRUE +from test_framework.p2p import P2PInterface, p2p_lock +from test_framework.script import OP_TRUE, CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_tx -from test_framework.util import ( - assert_equal, - wait_until, -) +from test_framework.util import assert_equal, wait_until # TestP2PConn: A peer we use to send messages to bitcoind, and store responses. diff --git a/test/functional/p2p_dos_header_tree.py b/test/functional/p2p_dos_header_tree.py --- a/test/functional/p2p_dos_header_tree.py +++ b/test/functional/p2p_dos_header_tree.py @@ -4,18 +4,12 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test that we reject low difficulty headers to prevent our block tree from filling up with useless bloat""" -from test_framework.messages import ( - CBlockHeader, - FromHex, -) -from test_framework.p2p import ( - P2PInterface, - msg_headers, -) -from test_framework.test_framework import BitcoinTestFramework - import os +from test_framework.messages import CBlockHeader, FromHex +from test_framework.p2p import P2PInterface, msg_headers +from test_framework.test_framework import BitcoinTestFramework + class RejectLowDifficultyHeadersTest(BitcoinTestFramework): def set_test_params(self): diff --git a/test/functional/p2p_feefilter.py b/test/functional/p2p_feefilter.py --- a/test/functional/p2p_feefilter.py +++ b/test/functional/p2p_feefilter.py @@ -7,10 +7,7 @@ from decimal import Decimal from test_framework.messages import MSG_TX, msg_feefilter -from test_framework.p2p import ( - P2PInterface, - p2p_lock, -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/p2p_filter.py b/test/functional/p2p_filter.py --- a/test/functional/p2p_filter.py +++ b/test/functional/p2p_filter.py @@ -7,11 +7,11 @@ """ from test_framework.messages import ( - CInv, MAX_BLOOM_FILTER_SIZE, MAX_BLOOM_HASH_FUNCS, MSG_BLOCK, MSG_FILTERED_BLOCK, + CInv, msg_filteradd, msg_filterclear, msg_filterload, diff --git a/test/functional/p2p_fingerprint.py b/test/functional/p2p_fingerprint.py --- a/test/functional/p2p_fingerprint.py +++ b/test/functional/p2p_fingerprint.py @@ -10,10 +10,10 @@ import time -from test_framework.blocktools import (create_block, create_coinbase) +from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ( - CInv, MSG_BLOCK, + CInv, msg_block, msg_getdata, msg_getheaders, diff --git a/test/functional/p2p_getaddr_caching.py b/test/functional/p2p_getaddr_caching.py --- a/test/functional/p2p_getaddr_caching.py +++ b/test/functional/p2p_getaddr_caching.py @@ -5,20 +5,16 @@ """Test addr response caching""" import time + from test_framework.messages import ( - CAddress, NODE_NETWORK, + CAddress, msg_addr, msg_getaddr, ) -from test_framework.p2p import ( - P2PInterface, - p2p_lock -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, -) +from test_framework.util import assert_equal MAX_ADDR_TO_SEND = 1000 diff --git a/test/functional/p2p_getdata.py b/test/functional/p2p_getdata.py --- a/test/functional/p2p_getdata.py +++ b/test/functional/p2p_getdata.py @@ -5,10 +5,7 @@ """Test GETDATA processing behavior""" from collections import defaultdict -from test_framework.messages import ( - CInv, - msg_getdata, -) +from test_framework.messages import CInv, msg_getdata from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework diff --git a/test/functional/p2p_inv_download.py b/test/functional/p2p_inv_download.py --- a/test/functional/p2p_inv_download.py +++ b/test/functional/p2p_inv_download.py @@ -6,25 +6,25 @@ Test inventory download behavior """ +import functools +import time + from test_framework.address import ADDRESS_ECREG_UNSPENDABLE from test_framework.avatools import wait_for_proof from test_framework.key import ECKey from test_framework.messages import ( + MSG_AVA_PROOF, + MSG_TX, + MSG_TYPE_MASK, AvalancheProof, CInv, CTransaction, FromHex, - MSG_AVA_PROOF, - MSG_TX, - MSG_TYPE_MASK, msg_avaproof, msg_inv, msg_notfound, ) -from test_framework.p2p import ( - P2PInterface, - p2p_lock, -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -33,9 +33,6 @@ ) from test_framework.wallet_util import bytes_to_wif -import functools -import time - class TestP2PConn(P2PInterface): def __init__(self, inv_type): diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -7,11 +7,12 @@ import time from test_framework.messages import ( - CBlockHeader, - CInv, MAX_HEADERS_RESULTS, MAX_INV_SIZE, MAX_PROTOCOL_MESSAGE_LENGTH, + MSG_TX, + CBlockHeader, + CInv, msg_avahello, msg_avapoll, msg_avaresponse, @@ -19,19 +20,11 @@ msg_headers, msg_inv, msg_ping, - MSG_TX, ser_string, ) -from test_framework.p2p import ( - P2PDataStore, - P2PInterface, -) +from test_framework.p2p import P2PDataStore, P2PInterface from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - hex_str_to_bytes, - assert_equal, - wait_until, -) +from test_framework.util import assert_equal, hex_str_to_bytes, wait_until # Account for the 5-byte length prefix VALID_DATA_LIMIT = MAX_PROTOCOL_MESSAGE_LENGTH - 5 diff --git a/test/functional/p2p_invalid_tx.py b/test/functional/p2p_invalid_tx.py --- a/test/functional/p2p_invalid_tx.py +++ b/test/functional/p2p_invalid_tx.py @@ -7,11 +7,8 @@ In this test we connect to one node over p2p, and test tx requests. """ -from test_framework.blocktools import ( - create_block, - create_coinbase, -) -from test_framework.txtools import pad_tx +from data import invalid_txs +from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ( COIN, COutPoint, @@ -20,16 +17,10 @@ CTxOut, ) from test_framework.p2p import P2PDataStore -from test_framework.script import ( - CScript, - OP_TRUE, -) +from test_framework.script import OP_TRUE, CScript from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - wait_until, -) -from data import invalid_txs +from test_framework.txtools import pad_tx +from test_framework.util import assert_equal, wait_until class InvalidTxRequestTest(BitcoinTestFramework): diff --git a/test/functional/p2p_leak.py b/test/functional/p2p_leak.py --- a/test/functional/p2p_leak.py +++ b/test/functional/p2p_leak.py @@ -19,10 +19,7 @@ msg_verack, msg_version, ) -from test_framework.p2p import ( - p2p_lock, - P2PInterface, -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, diff --git a/test/functional/p2p_leak_tx.py b/test/functional/p2p_leak_tx.py --- a/test/functional/p2p_leak_tx.py +++ b/test/functional/p2p_leak_tx.py @@ -4,12 +4,10 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test that we don't leak txs to inbound peers that we haven't yet announced to""" -from test_framework.messages import msg_getdata, CInv, MSG_TX +from test_framework.messages import MSG_TX, CInv, msg_getdata from test_framework.p2p import P2PDataStore from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, -) +from test_framework.util import assert_equal class P2PNode(P2PDataStore): diff --git a/test/functional/p2p_nobloomfilter_messages.py b/test/functional/p2p_nobloomfilter_messages.py --- a/test/functional/p2p_nobloomfilter_messages.py +++ b/test/functional/p2p_nobloomfilter_messages.py @@ -11,7 +11,12 @@ 4. They send a p2p filterclear message """ -from test_framework.messages import msg_mempool, msg_filteradd, msg_filterload, msg_filterclear +from test_framework.messages import ( + msg_filteradd, + msg_filterclear, + msg_filterload, + msg_mempool, +) from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal diff --git a/test/functional/p2p_node_network_limited.py b/test/functional/p2p_node_network_limited.py --- a/test/functional/p2p_node_network_limited.py +++ b/test/functional/p2p_node_network_limited.py @@ -9,17 +9,14 @@ - send a block within 288 + 2 of the tip - disconnect peers who request blocks older than that.""" from test_framework.messages import ( - CInv, MSG_BLOCK, - msg_getdata, - msg_verack, NODE_BLOOM, NODE_NETWORK_LIMITED, + CInv, + msg_getdata, + msg_verack, ) -from test_framework.p2p import ( - p2p_lock, - P2PInterface, -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, diff --git a/test/functional/p2p_permissions.py b/test/functional/p2p_permissions.py --- a/test/functional/p2p_permissions.py +++ b/test/functional/p2p_permissions.py @@ -7,13 +7,10 @@ Test that permissions are correctly calculated and applied """ -from test_framework.messages import ( - CTransaction, - FromHex, -) +from test_framework.messages import CTransaction, FromHex from test_framework.p2p import P2PDataStore -from test_framework.test_node import ErrorMatch from test_framework.test_framework import BitcoinTestFramework +from test_framework.test_node import ErrorMatch from test_framework.txtools import pad_tx from test_framework.util import ( assert_equal, diff --git a/test/functional/p2p_sendheaders.py b/test/functional/p2p_sendheaders.py --- a/test/functional/p2p_sendheaders.py +++ b/test/functional/p2p_sendheaders.py @@ -87,9 +87,9 @@ """ from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ( + MSG_BLOCK, CBlockHeader, CInv, - MSG_BLOCK, msg_block, msg_getblocks, msg_getdata, @@ -98,16 +98,9 @@ msg_inv, msg_sendheaders, ) -from test_framework.p2p import ( - p2p_lock, - P2PInterface, -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - wait_until, -) - +from test_framework.util import assert_equal, wait_until DIRECT_FETCH_RESPONSE_TIME = 0.05 diff --git a/test/functional/p2p_unrequested_blocks.py b/test/functional/p2p_unrequested_blocks.py --- a/test/functional/p2p_unrequested_blocks.py +++ b/test/functional/p2p_unrequested_blocks.py @@ -59,17 +59,14 @@ create_tx_with_script, ) from test_framework.messages import ( + MSG_BLOCK, CBlockHeader, CInv, - MSG_BLOCK, msg_block, msg_headers, msg_inv, ) -from test_framework.p2p import ( - p2p_lock, - P2PInterface, -) +from test_framework.p2p import P2PInterface, p2p_lock from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, diff --git a/test/functional/rpc_bind.py b/test/functional/rpc_bind.py --- a/test/functional/rpc_bind.py +++ b/test/functional/rpc_bind.py @@ -4,10 +4,15 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test running bitcoind with the -rpcbind and -rpcallowip options.""" -from platform import uname import sys +from platform import uname -from test_framework.netutil import addr_to_hex, all_interfaces, get_bind_addrs, test_ipv6_local +from test_framework.netutil import ( + addr_to_hex, + all_interfaces, + get_bind_addrs, + test_ipv6_local, +) from test_framework.test_framework import BitcoinTestFramework, SkipTest from test_framework.util import ( assert_equal, diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -19,28 +19,26 @@ Tests correspond to code in rpc/blockchain.cpp. """ -from decimal import Decimal import http.client import subprocess +from decimal import Decimal from test_framework.blocktools import ( + TIME_GENESIS_BLOCK, create_block, create_coinbase, - TIME_GENESIS_BLOCK, -) -from test_framework.messages import ( - msg_block, ) +from test_framework.messages import msg_block from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, assert_greater_than, assert_greater_than_or_equal, + assert_is_hash_string, + assert_is_hex_string, assert_raises, assert_raises_rpc_error, - assert_is_hex_string, - assert_is_hash_string, ) diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -12,10 +12,7 @@ from test_framework.descriptors import descsum_create, drop_origins from test_framework.key import ECPubKey from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_raises_rpc_error, - assert_equal, -) +from test_framework.util import assert_equal, assert_raises_rpc_error class RpcCreateMultiSigTest(BitcoinTestFramework): diff --git a/test/functional/rpc_deriveaddresses.py b/test/functional/rpc_deriveaddresses.py --- a/test/functional/rpc_deriveaddresses.py +++ b/test/functional/rpc_deriveaddresses.py @@ -3,8 +3,8 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the deriveaddresses rpc call.""" -from test_framework.test_framework import BitcoinTestFramework from test_framework.descriptors import descsum_create +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py --- a/test/functional/rpc_dumptxoutset.py +++ b/test/functional/rpc_dumptxoutset.py @@ -4,12 +4,12 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the generation of UTXO snapshots using `dumptxoutset`. """ -from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error - import hashlib from pathlib import Path +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, assert_raises_rpc_error + class DumptxoutsetTest(BitcoinTestFramework): def set_test_params(self): diff --git a/test/functional/rpc_generate.py b/test/functional/rpc_generate.py --- a/test/functional/rpc_generate.py +++ b/test/functional/rpc_generate.py @@ -5,10 +5,7 @@ """Test generate RPC.""" from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) +from test_framework.util import assert_equal, assert_raises_rpc_error class RPCGenerateTest(BitcoinTestFramework): diff --git a/test/functional/rpc_generateblock.py b/test/functional/rpc_generateblock.py --- a/test/functional/rpc_generateblock.py +++ b/test/functional/rpc_generateblock.py @@ -6,10 +6,7 @@ ''' from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) +from test_framework.util import assert_equal, assert_raises_rpc_error class GenerateBlockTest(BitcoinTestFramework): diff --git a/test/functional/rpc_getblockfilter.py b/test/functional/rpc_getblockfilter.py --- a/test/functional/rpc_getblockfilter.py +++ b/test/functional/rpc_getblockfilter.py @@ -6,8 +6,11 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( - assert_equal, assert_is_hex_string, assert_raises_rpc_error, - connect_nodes, disconnect_nodes + assert_equal, + assert_is_hex_string, + assert_raises_rpc_error, + connect_nodes, + disconnect_nodes, ) FILTER_TYPES = ["basic"] diff --git a/test/functional/rpc_getblockstats.py b/test/functional/rpc_getblockstats.py --- a/test/functional/rpc_getblockstats.py +++ b/test/functional/rpc_getblockstats.py @@ -11,10 +11,7 @@ import os from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) +from test_framework.util import assert_equal, assert_raises_rpc_error TESTSDIR = os.path.dirname(os.path.realpath(__file__)) diff --git a/test/functional/rpc_getdescriptorinfo.py b/test/functional/rpc_getdescriptorinfo.py --- a/test/functional/rpc_getdescriptorinfo.py +++ b/test/functional/rpc_getdescriptorinfo.py @@ -5,12 +5,9 @@ """Test getdescriptorinfo RPC. """ -from test_framework.test_framework import BitcoinTestFramework from test_framework.descriptors import descsum_create -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, assert_raises_rpc_error class DescriptorTest(BitcoinTestFramework): diff --git a/test/functional/rpc_help.py b/test/functional/rpc_help.py --- a/test/functional/rpc_help.py +++ b/test/functional/rpc_help.py @@ -4,11 +4,11 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test RPC help output.""" +import os + from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error -import os - class HelpRpcTest(BitcoinTestFramework): def set_test_params(self): diff --git a/test/functional/rpc_invalidateblock.py b/test/functional/rpc_invalidateblock.py --- a/test/functional/rpc_invalidateblock.py +++ b/test/functional/rpc_invalidateblock.py @@ -6,11 +6,7 @@ from test_framework.address import ADDRESS_ECREG_UNSPENDABLE_DESCRIPTOR from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - connect_nodes, - wait_until, -) +from test_framework.util import assert_equal, connect_nodes, wait_until class InvalidateTest(BitcoinTestFramework): diff --git a/test/functional/rpc_misc.py b/test/functional/rpc_misc.py --- a/test/functional/rpc_misc.py +++ b/test/functional/rpc_misc.py @@ -5,16 +5,15 @@ """Test RPC misc output.""" import xml.etree.ElementTree as ET +from test_framework.authproxy import JSONRPCException from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( - assert_raises_rpc_error, assert_equal, assert_greater_than, assert_greater_than_or_equal, + assert_raises_rpc_error, ) -from test_framework.authproxy import JSONRPCException - class RpcMiscTest(BitcoinTestFramework): def set_test_params(self): diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -7,21 +7,21 @@ Tests correspond to code in rpc/net.cpp. """ +import time from decimal import Decimal from itertools import product -import time +import test_framework.messages from test_framework.avatools import create_coinbase_stakes from test_framework.key import ECKey -from test_framework.p2p import P2PInterface -import test_framework.messages from test_framework.messages import NODE_NETWORK +from test_framework.p2p import P2PInterface from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_approx, assert_equal, - assert_greater_than_or_equal, assert_greater_than, + assert_greater_than_or_equal, assert_raises_rpc_error, connect_nodes, p2p_port, diff --git a/test/functional/rpc_preciousblock.py b/test/functional/rpc_preciousblock.py --- a/test/functional/rpc_preciousblock.py +++ b/test/functional/rpc_preciousblock.py @@ -5,10 +5,7 @@ """Test the preciousblock RPC.""" 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 def unidirectional_node_sync_via_rpc(node_src, node_dest): diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -7,8 +7,8 @@ import json import os - from decimal import Decimal + from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_approx, diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -12,10 +12,10 @@ - getrawtransaction """ -from decimal import Decimal - from collections import OrderedDict +from decimal import Decimal from io import BytesIO + from test_framework.messages import ( COutPoint, CTransaction, diff --git a/test/functional/rpc_setban.py b/test/functional/rpc_setban.py --- a/test/functional/rpc_setban.py +++ b/test/functional/rpc_setban.py @@ -5,10 +5,7 @@ """Test the setban rpc call.""" from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - connect_nodes, - p2p_port -) +from test_framework.util import connect_nodes, p2p_port class SetBanTests(BitcoinTestFramework): diff --git a/test/functional/rpc_txoutproof.py b/test/functional/rpc_txoutproof.py --- a/test/functional/rpc_txoutproof.py +++ b/test/functional/rpc_txoutproof.py @@ -4,13 +4,13 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test gettxoutproof and verifytxoutproof RPCs.""" +from test_framework.messages import CMerkleBlock, FromHex, ToHex from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, assert_raises_rpc_error, connect_nodes, ) -from test_framework.messages import CMerkleBlock, FromHex, ToHex class MerkleBlockTest(BitcoinTestFramework): diff --git a/test/functional/rpc_users.py b/test/functional/rpc_users.py --- a/test/functional/rpc_users.py +++ b/test/functional/rpc_users.py @@ -7,18 +7,14 @@ import configparser import http.client import os -from random import SystemRandom import string import subprocess import sys import urllib.parse +from random import SystemRandom from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - get_datadir_path, - str_to_b64str, -) +from test_framework.util import assert_equal, get_datadir_path, str_to_b64str def call_with_auth(node, user, password): diff --git a/test/functional/rpc_whitelist.py b/test/functional/rpc_whitelist.py --- a/test/functional/rpc_whitelist.py +++ b/test/functional/rpc_whitelist.py @@ -5,16 +5,13 @@ """ A test for RPC users with restricted permissions """ -from test_framework.test_framework import BitcoinTestFramework -import os -from test_framework.util import ( - get_datadir_path, - assert_equal, - str_to_b64str -) import http.client +import os import urllib.parse +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_equal, get_datadir_path, str_to_b64str + def rpccall(node, user, method): url = urllib.parse.urlparse(node.url) 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, -) +from .util import assert_equal, satoshi_round, wait_until 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 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, ) 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, - 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 @@ -16,6 +11,11 @@ import random import re import time +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/functional/wallet_address_types.py b/test/functional/wallet_address_types.py --- a/test/functional/wallet_address_types.py +++ b/test/functional/wallet_address_types.py @@ -32,14 +32,11 @@ this also verifies that spending coins sent to all these address types works. """ -from decimal import Decimal import itertools +from decimal import Decimal +from test_framework.descriptors import descsum_check, descsum_create from test_framework.test_framework import BitcoinTestFramework -from test_framework.descriptors import ( - descsum_create, - descsum_check, -) from test_framework.util import ( assert_equal, assert_greater_than, diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -30,10 +30,10 @@ Shutdown again, restore using importwallet, and confirm again balances are correct. """ -from decimal import Decimal import os -from random import randint import shutil +from decimal import Decimal +from random import randint from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -3,10 +3,12 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test the wallet balance RPC methods.""" -from decimal import Decimal import struct +from decimal import Decimal -from test_framework.address import ADDRESS_ECREG_UNSPENDABLE as ADDRESS_WATCHONLY +from test_framework.address import ( + ADDRESS_ECREG_UNSPENDABLE as ADDRESS_WATCHONLY, +) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -5,7 +5,7 @@ """Test the wallet.""" from decimal import Decimal -from test_framework.messages import FromHex, CTransaction +from test_framework.messages import CTransaction, FromHex from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_array_result, diff --git a/test/functional/wallet_coinbase_category.py b/test/functional/wallet_coinbase_category.py --- a/test/functional/wallet_coinbase_category.py +++ b/test/functional/wallet_coinbase_category.py @@ -8,9 +8,7 @@ """ from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_array_result -) +from test_framework.util import assert_array_result class CoinbaseCategoryTest(BitcoinTestFramework): diff --git a/test/functional/wallet_create_tx.py b/test/functional/wallet_create_tx.py --- a/test/functional/wallet_create_tx.py +++ b/test/functional/wallet_create_tx.py @@ -3,14 +3,9 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. +from test_framework.blocktools import TIME_GENESIS_BLOCK from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) -from test_framework.blocktools import ( - TIME_GENESIS_BLOCK, -) +from test_framework.util import assert_equal, assert_raises_rpc_error class CreateTxWalletTest(BitcoinTestFramework): diff --git a/test/functional/wallet_createwallet.py b/test/functional/wallet_createwallet.py --- a/test/functional/wallet_createwallet.py +++ b/test/functional/wallet_createwallet.py @@ -6,10 +6,7 @@ """ from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) +from test_framework.util import assert_equal, assert_raises_rpc_error class CreateWalletTest(BitcoinTestFramework): diff --git a/test/functional/wallet_descriptor.py b/test/functional/wallet_descriptor.py --- a/test/functional/wallet_descriptor.py +++ b/test/functional/wallet_descriptor.py @@ -5,10 +5,7 @@ """Test descriptor wallet function.""" from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error -) +from test_framework.util import assert_equal, assert_raises_rpc_error class WalletDescriptorTest(BitcoinTestFramework): diff --git a/test/functional/wallet_dump.py b/test/functional/wallet_dump.py --- a/test/functional/wallet_dump.py +++ b/test/functional/wallet_dump.py @@ -9,10 +9,7 @@ import time from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error, -) +from test_framework.util import assert_equal, assert_raises_rpc_error def read_dump(file_name, addrs, script_addrs, hd_master_addr_old): diff --git a/test/functional/wallet_encryption.py b/test/functional/wallet_encryption.py --- a/test/functional/wallet_encryption.py +++ b/test/functional/wallet_encryption.py @@ -9,9 +9,9 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, - assert_raises_rpc_error, assert_greater_than, assert_greater_than_or_equal, + assert_raises_rpc_error, ) diff --git a/test/functional/wallet_groups.py b/test/functional/wallet_groups.py --- a/test/functional/wallet_groups.py +++ b/test/functional/wallet_groups.py @@ -4,12 +4,9 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test wallet group functionality.""" -from test_framework.test_framework import BitcoinTestFramework from test_framework.messages import CTransaction, FromHex, ToHex -from test_framework.util import ( - assert_approx, - assert_equal, -) +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_approx, assert_equal class WalletGroupTest(BitcoinTestFramework): diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py --- a/test/functional/wallet_hd.py +++ b/test/functional/wallet_hd.py @@ -10,8 +10,8 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, + assert_raises_rpc_error, connect_nodes, - assert_raises_rpc_error ) diff --git a/test/functional/wallet_import_rescan.py b/test/functional/wallet_import_rescan.py --- a/test/functional/wallet_import_rescan.py +++ b/test/functional/wallet_import_rescan.py @@ -19,19 +19,14 @@ happened previously. """ -from decimal import Decimal import collections import enum import itertools import random +from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - connect_nodes, - set_node_times, -) - +from test_framework.util import assert_equal, connect_nodes, set_node_times Call = enum.Enum("Call", "single multiaddress multiscript") Data = enum.Enum("Data", "address pub priv") diff --git a/test/functional/wallet_import_with_label.py b/test/functional/wallet_import_with_label.py --- a/test/functional/wallet_import_with_label.py +++ b/test/functional/wallet_import_with_label.py @@ -12,14 +12,13 @@ from test_framework.address import script_to_p2sh from test_framework.script import ( - CScript, OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, + CScript, hash160, ) - from test_framework.test_framework import BitcoinTestFramework from test_framework.util import hex_str_to_bytes from test_framework.wallet_util import test_address diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py --- a/test/functional/wallet_importdescriptors.py +++ b/test/functional/wallet_importdescriptors.py @@ -15,17 +15,14 @@ - `test_address()` is called to call getaddressinfo for an address on node1 and test the values returned.""" -from test_framework.test_framework import BitcoinTestFramework from test_framework.descriptors import descsum_create +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, assert_raises_rpc_error, find_vout_for_address, ) -from test_framework.wallet_util import ( - get_generate_key, - test_address, -) +from test_framework.wallet_util import get_generate_key, test_address class ImportDescriptorsTest(BitcoinTestFramework): diff --git a/test/functional/wallet_importmulti.py b/test/functional/wallet_importmulti.py --- a/test/functional/wallet_importmulti.py +++ b/test/functional/wallet_importmulti.py @@ -15,22 +15,15 @@ - `test_address()` is called to call getaddressinfo for an address on node1 and test the values returned.""" -from test_framework.script import ( - CScript, - OP_NOP, -) -from test_framework.test_framework import BitcoinTestFramework from test_framework.descriptors import descsum_create +from test_framework.script import OP_NOP, CScript +from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, assert_greater_than, assert_raises_rpc_error, ) -from test_framework.wallet_util import ( - get_key, - get_multisig, - test_address, -) +from test_framework.wallet_util import get_key, get_multisig, test_address class ImportMultiTest(BitcoinTestFramework): diff --git a/test/functional/wallet_keypool_topup.py b/test/functional/wallet_keypool_topup.py --- a/test/functional/wallet_keypool_topup.py +++ b/test/functional/wallet_keypool_topup.py @@ -14,10 +14,7 @@ import shutil 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 class KeypoolRestoreTest(BitcoinTestFramework): diff --git a/test/functional/wallet_listtransactions.py b/test/functional/wallet_listtransactions.py --- a/test/functional/wallet_listtransactions.py +++ b/test/functional/wallet_listtransactions.py @@ -7,10 +7,7 @@ from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_array_result, - assert_equal, -) +from test_framework.util import assert_array_result, assert_equal class ListTransactionsTest(BitcoinTestFramework): diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -6,11 +6,11 @@ Verify that a bitcoind node can load multiple wallet files """ -from decimal import Decimal -from threading import Thread import os import shutil import time +from decimal import Decimal +from threading import Thread from test_framework.authproxy import JSONRPCException from test_framework.test_framework import BitcoinTestFramework diff --git a/test/functional/wallet_reorgsrestore.py b/test/functional/wallet_reorgsrestore.py --- a/test/functional/wallet_reorgsrestore.py +++ b/test/functional/wallet_reorgsrestore.py @@ -13,16 +13,12 @@ disconnected. """ -from decimal import Decimal import os import shutil +from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - connect_nodes, - disconnect_nodes, -) +from test_framework.util import assert_equal, connect_nodes, disconnect_nodes class ReorgsRestoreTest(BitcoinTestFramework): diff --git a/test/functional/wallet_txn_clone.py b/test/functional/wallet_txn_clone.py --- a/test/functional/wallet_txn_clone.py +++ b/test/functional/wallet_txn_clone.py @@ -5,13 +5,10 @@ """Test the wallet accounts properly when there are cloned transactions with malleated scriptsigs.""" import io + +from test_framework.messages import XEC, CTransaction from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - connect_nodes, - disconnect_nodes, -) -from test_framework.messages import CTransaction, XEC +from test_framework.util import assert_equal, connect_nodes, disconnect_nodes class TxnMallTest(BitcoinTestFramework): diff --git a/test/functional/wallet_watchonly.py b/test/functional/wallet_watchonly.py --- a/test/functional/wallet_watchonly.py +++ b/test/functional/wallet_watchonly.py @@ -6,10 +6,7 @@ """ from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_raises_rpc_error -) +from test_framework.util import assert_equal, assert_raises_rpc_error class CreateWalletWatchonlyTest(BitcoinTestFramework): 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 = [