mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 02:31:07 +00:00
contrib: Remove confusing and redundant encoding from IO
The encoding arg is confusing, because it is not applied consistently for all IO. Also, it is useless, as the majority of files are ASCII encoded, which are fine to encode and decode with any mode. Moreover, UTF-8 is already required for most scripts to work properly, so setting the encoding twice is redundant. So remove the encoding from most IO. It would be fine to remove from all IO, however I kept it for two files: * contrib/asmap/asmap-tool.py: This specifically looks for utf-8 encoding errors, so it makes sense to sepecify the utf-8 encoding explicitly. * test/functional/test_framework/test_node.py: Reading the debug log in text mode specifically counts the utf-8 characters (not bytes), so it makes sense to specify the utf-8 encoding explicitly.
This commit is contained in:
parent
fa7d72bd1b
commit
fae612424b
@ -26,7 +26,6 @@ def main():
|
||||
["bash", "-c", "grep export ./ci/test/00_setup_env*.sh"],
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
encoding="utf8",
|
||||
).stdout.splitlines()
|
||||
settings = set(l.split("=")[0].split("export ")[1] for l in settings)
|
||||
# Add "hidden" settings, which are never exported, manually. Otherwise,
|
||||
@ -42,7 +41,7 @@ def main():
|
||||
u=os.environ["USER"],
|
||||
c=os.environ["CONTAINER_NAME"],
|
||||
)
|
||||
with open(env_file, "w", encoding="utf8") as file:
|
||||
with open(env_file, "w") as file:
|
||||
for k, v in os.environ.items():
|
||||
if k in settings:
|
||||
file.write(f"{k}={v}\n")
|
||||
|
||||
@ -49,7 +49,7 @@ for arg in sys.argv[1:]:
|
||||
# TODO: implement support for multiple include directories
|
||||
for arg in sorted(files.keys()):
|
||||
module = files[arg]
|
||||
with open(arg, 'r', encoding="utf8") as f:
|
||||
with open(arg, 'r') as f:
|
||||
for line in f:
|
||||
match = RE.match(line)
|
||||
if match:
|
||||
|
||||
@ -169,7 +169,7 @@ def main():
|
||||
sys.exit(p.returncode)
|
||||
|
||||
if not args.i:
|
||||
with open(filename, encoding="utf8") as f:
|
||||
with open(filename) as f:
|
||||
code = f.readlines()
|
||||
formatted_code = StringIO(stdout).readlines()
|
||||
diff = difflib.unified_diff(
|
||||
|
||||
@ -140,7 +140,7 @@ def file_has_without_c_style_copyright_for_holder(contents, holder_name):
|
||||
################################################################################
|
||||
|
||||
def read_file(filename):
|
||||
return open(filename, 'r', encoding="utf8").read()
|
||||
return open(filename, 'r').read()
|
||||
|
||||
def gather_file_info(filename):
|
||||
info = {}
|
||||
@ -316,12 +316,12 @@ def get_most_recent_git_change_year(filename):
|
||||
################################################################################
|
||||
|
||||
def read_file_lines(filename):
|
||||
with open(filename, 'r', encoding="utf8") as f:
|
||||
with open(filename, 'r') as f:
|
||||
file_lines = f.readlines()
|
||||
return file_lines
|
||||
|
||||
def write_file_lines(filename, file_lines):
|
||||
with open(filename, 'w', encoding="utf8") as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.write(''.join(file_lines))
|
||||
|
||||
################################################################################
|
||||
|
||||
@ -16,8 +16,8 @@ pattern = args.pattern
|
||||
outfile = args.outfile
|
||||
|
||||
in_remove = False
|
||||
with open(tracefile, 'r', encoding="utf8") as f:
|
||||
with open(outfile, 'w', encoding="utf8") as wf:
|
||||
with open(tracefile, 'r') as f:
|
||||
with open(outfile, 'w') as wf:
|
||||
for line in f:
|
||||
for p in pattern:
|
||||
if line.startswith("SF:") and p in line:
|
||||
|
||||
@ -34,7 +34,7 @@ def get_blk_dt(blk_hdr):
|
||||
# When getting the list of block hashes, undo any byte reversals.
|
||||
def get_block_hashes(settings):
|
||||
blkindex = []
|
||||
with open(settings['hashlist'], "r", encoding="utf8") as f:
|
||||
with open(settings['hashlist'], "r") as f:
|
||||
for line in f:
|
||||
line = line.rstrip()
|
||||
if settings['rev_hash_bytes'] == 'true':
|
||||
@ -267,7 +267,7 @@ if __name__ == '__main__':
|
||||
print("Usage: linearize-data.py CONFIG-FILE")
|
||||
sys.exit(1)
|
||||
|
||||
with open(sys.argv[1], encoding="utf8") as f:
|
||||
with open(sys.argv[1]) as f:
|
||||
for line in f:
|
||||
# skip comment lines
|
||||
m = re.search(r'^\s*#', line)
|
||||
|
||||
@ -87,7 +87,7 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
|
||||
|
||||
def get_rpc_cookie():
|
||||
# Open the cookie file
|
||||
with open(os.path.join(os.path.expanduser(settings['datadir']), '.cookie'), 'r', encoding="ascii") as f:
|
||||
with open(os.path.join(os.path.expanduser(settings['datadir']), '.cookie'), 'r') as f:
|
||||
combined = f.readline()
|
||||
combined_split = combined.split(":")
|
||||
settings['rpcuser'] = combined_split[0]
|
||||
@ -98,7 +98,7 @@ if __name__ == '__main__':
|
||||
print("Usage: linearize-hashes.py CONFIG-FILE")
|
||||
sys.exit(1)
|
||||
|
||||
with open(sys.argv[1], encoding="utf8") as f:
|
||||
with open(sys.argv[1]) as f:
|
||||
for line in f:
|
||||
# skip comment lines
|
||||
m = re.search(r'^\s*#', line)
|
||||
|
||||
@ -205,7 +205,7 @@ def main():
|
||||
|
||||
jsonrep = json.dumps(messages)
|
||||
if output:
|
||||
with open(str(output), 'w+', encoding="utf8") as f_out:
|
||||
with open(str(output), 'w+') as f_out:
|
||||
f_out.write(jsonrep)
|
||||
else:
|
||||
print(jsonrep)
|
||||
|
||||
@ -168,16 +168,16 @@ def main():
|
||||
g.write(' *\n')
|
||||
g.write(' * Each line contains a BIP155 serialized (networkID, addr, port) tuple.\n')
|
||||
g.write(' */\n')
|
||||
with open(os.path.join(indir,'nodes_main.txt'), 'r', encoding="utf8") as f:
|
||||
with open(os.path.join(indir,'nodes_main.txt'), 'r') as f:
|
||||
process_nodes(g, f, 'chainparams_seed_main')
|
||||
g.write('\n')
|
||||
with open(os.path.join(indir,'nodes_signet.txt'), 'r', encoding="utf8") as f:
|
||||
with open(os.path.join(indir,'nodes_signet.txt'), 'r') as f:
|
||||
process_nodes(g, f, 'chainparams_seed_signet')
|
||||
g.write('\n')
|
||||
with open(os.path.join(indir,'nodes_test.txt'), 'r', encoding="utf8") as f:
|
||||
with open(os.path.join(indir,'nodes_test.txt'), 'r') as f:
|
||||
process_nodes(g, f, 'chainparams_seed_test')
|
||||
g.write('\n')
|
||||
with open(os.path.join(indir,'nodes_testnet4.txt'), 'r', encoding="utf8") as f:
|
||||
with open(os.path.join(indir,'nodes_testnet4.txt'), 'r') as f:
|
||||
process_nodes(g, f, 'chainparams_seed_testnet4')
|
||||
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n')
|
||||
|
||||
|
||||
@ -211,7 +211,7 @@ def main():
|
||||
print('Done.', file=sys.stderr)
|
||||
|
||||
print('Loading and parsing DNS seeds…', end='', file=sys.stderr, flush=True)
|
||||
with open(args.seeds, 'r', encoding='utf8') as f:
|
||||
with open(args.seeds, 'r') as f:
|
||||
lines = f.readlines()
|
||||
ips = [parseline(line) for line in lines]
|
||||
random.shuffle(ips)
|
||||
|
||||
@ -246,8 +246,8 @@ def files_are_equal(filename1, filename2):
|
||||
eq = contents1 == contents2
|
||||
|
||||
if not eq:
|
||||
with open(filename1, 'r', encoding='utf-8') as f1, \
|
||||
open(filename2, 'r', encoding='utf-8') as f2:
|
||||
with open(filename1, 'r') as f1, \
|
||||
open(filename2, 'r') as f2:
|
||||
f1lines = f1.readlines()
|
||||
f2lines = f2.readlines()
|
||||
|
||||
@ -426,7 +426,7 @@ def verify_shasums_signature(
|
||||
def parse_sums_file(sums_file_path: str, filename_filter: list[str]) -> list[list[str]]:
|
||||
# extract hashes/filenames of binaries to verify from hash file;
|
||||
# each line has the following format: "<hash> <binary_filename>"
|
||||
with open(sums_file_path, 'r', encoding='utf8') as hash_file:
|
||||
with open(sums_file_path, 'r') as hash_file:
|
||||
return [line.split()[:2] for line in hash_file if len(filename_filter) == 0 or any(f in line for f in filename_filter)]
|
||||
|
||||
|
||||
|
||||
@ -82,17 +82,17 @@ def main():
|
||||
# get directory of this program and read data files
|
||||
dirname = os.path.dirname(os.path.abspath(__file__))
|
||||
print("Using verify-commits data from " + dirname)
|
||||
with open(dirname + "/trusted-git-root", "r", encoding="utf8") as f:
|
||||
with open(dirname + "/trusted-git-root", "r") as f:
|
||||
verified_root = f.read().splitlines()[0]
|
||||
with open(dirname + "/trusted-sha512-root-commit", "r", encoding="utf8") as f:
|
||||
with open(dirname + "/trusted-sha512-root-commit", "r") as f:
|
||||
verified_sha512_root = f.read().splitlines()[0]
|
||||
with open(dirname + "/allow-revsig-commits", "r", encoding="utf8") as f:
|
||||
with open(dirname + "/allow-revsig-commits", "r") as f:
|
||||
revsig_allowed = f.read().splitlines()
|
||||
with open(dirname + "/allow-unclean-merge-commits", "r", encoding="utf8") as f:
|
||||
with open(dirname + "/allow-unclean-merge-commits", "r") as f:
|
||||
unclean_merge_allowed = f.read().splitlines()
|
||||
with open(dirname + "/allow-incorrect-sha512-commits", "r", encoding="utf8") as f:
|
||||
with open(dirname + "/allow-incorrect-sha512-commits", "r") as f:
|
||||
incorrect_sha512_allowed = f.read().splitlines()
|
||||
with open(dirname + "/trusted-keys", "r", encoding="utf8") as f:
|
||||
with open(dirname + "/trusted-keys", "r") as f:
|
||||
trusted_keys = f.read().splitlines()
|
||||
|
||||
# Set commit and variables
|
||||
|
||||
@ -148,7 +148,7 @@ def get_log_events(source, logfile):
|
||||
Log events may be split over multiple lines. We use the timestamp
|
||||
regex match as the marker for a new log event."""
|
||||
try:
|
||||
with open(logfile, 'r', encoding='utf-8') as infile:
|
||||
with open(logfile, 'r') as infile:
|
||||
event = ''
|
||||
timestamp = ''
|
||||
for line in infile:
|
||||
|
||||
@ -97,7 +97,7 @@ class AsmapTest(BitcoinTestFramework):
|
||||
self.log.info('Test bitcoind -asmap with empty map file')
|
||||
self.stop_node(0)
|
||||
empty_asmap = os.path.join(self.datadir, "ip_asn.map")
|
||||
with open(empty_asmap, "w", encoding="utf-8") as f:
|
||||
with open(empty_asmap, "w") as f:
|
||||
f.write("")
|
||||
msg = f"Error: Could not parse asmap file \"{empty_asmap}\""
|
||||
self.node.assert_start_raises_init_error(extra_args=[f'-asmap={empty_asmap}'], expected_msg=msg)
|
||||
|
||||
@ -55,7 +55,7 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||
os.rename(conf_path.with_suffix('.confbkp'), conf_path)
|
||||
|
||||
self.log.debug('Verifying includeconf directive pointing to directory is caught')
|
||||
with open(conf_path, 'a', encoding='utf-8') as conf:
|
||||
with open(conf_path, 'a') as conf:
|
||||
conf.write(f'includeconf={self.nodes[0].datadir_path}\n')
|
||||
self.nodes[0].assert_start_raises_init_error(
|
||||
extra_args=['-regtest'],
|
||||
@ -68,12 +68,12 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||
self.log.info('Disabling configuration via -noconf')
|
||||
|
||||
conf_path = self.nodes[0].datadir_path / 'bitcoin.conf'
|
||||
with open(conf_path, encoding='utf-8') as conf:
|
||||
with open(conf_path) as conf:
|
||||
settings = [f'-{line.rstrip()}' for line in conf if len(line) > 1 and line[0] != '[']
|
||||
os.rename(conf_path, conf_path.with_suffix('.confbkp'))
|
||||
|
||||
self.log.debug('Verifying garbage in config can be detected')
|
||||
with open(conf_path, 'a', encoding='utf-8') as conf:
|
||||
with open(conf_path, 'a') as conf:
|
||||
conf.write('garbage\n')
|
||||
self.nodes[0].assert_start_raises_init_error(
|
||||
extra_args=['-regtest'],
|
||||
@ -107,9 +107,9 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||
expected_msg=conf_in_config_file_err,
|
||||
)
|
||||
inc_conf_file_path = self.nodes[0].datadir_path / 'include.conf'
|
||||
with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a', encoding='utf-8') as conf:
|
||||
with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a') as conf:
|
||||
conf.write(f'includeconf={inc_conf_file_path}\n')
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('conf=some.conf\n')
|
||||
self.nodes[0].assert_start_raises_init_error(
|
||||
expected_msg=conf_in_config_file_err,
|
||||
@ -119,65 +119,65 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||
expected_msg='Error: Error parsing command line arguments: Invalid parameter -dash_cli=1',
|
||||
extra_args=['-dash_cli=1'],
|
||||
)
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('dash_conf=1\n')
|
||||
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=['Ignoring unknown configuration value dash_conf']):
|
||||
self.start_node(0)
|
||||
self.stop_node(0)
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('reindex=1\n')
|
||||
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=['Warning: reindex=1 is set in the configuration file, which will significantly slow down startup. Consider removing or commenting out this option for better performance, unless there is currently a condition which makes rebuilding the indexes necessary']):
|
||||
self.start_node(0)
|
||||
self.stop_node(0)
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('-dash=1\n')
|
||||
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 1: -dash=1, options in configuration file must be specified without leading -')
|
||||
|
||||
if self.is_wallet_compiled():
|
||||
with open(inc_conf_file_path, 'w', encoding='utf8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write("wallet=foo\n")
|
||||
self.nodes[0].assert_start_raises_init_error(expected_msg=f'Error: Config setting for -wallet only applied on {self.chain} network when in [{self.chain}] section.')
|
||||
|
||||
main_conf_file_path = self.nodes[0].datadir_path / "bitcoin_main.conf"
|
||||
util.write_config(main_conf_file_path, n=0, chain='', extra_config=f'includeconf={inc_conf_file_path}\n')
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('acceptnonstdtxn=1\n')
|
||||
self.nodes[0].assert_start_raises_init_error(extra_args=[f"-conf={main_conf_file_path}", "-allowignoredconf"], expected_msg='Error: acceptnonstdtxn is not currently supported for main chain')
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('nono\n')
|
||||
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 1: nono, if you intended to specify a negated option, use nono=1 instead')
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass')
|
||||
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided')
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('server=1\nrpcuser=someuser\nmain.rpcpassword=some#pass')
|
||||
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided')
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('server=1\nrpcuser=someuser\n[main]\nrpcpassword=some#pass')
|
||||
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Error reading configuration file: parse error on line 4, using # in rpcpassword can be ambiguous and should be avoided')
|
||||
|
||||
inc_conf_file2_path = self.nodes[0].datadir_path / 'include2.conf'
|
||||
with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a', encoding='utf-8') as conf:
|
||||
with open(self.nodes[0].datadir_path / 'bitcoin.conf', 'a') as conf:
|
||||
conf.write(f'includeconf={inc_conf_file2_path}\n')
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('testnot.datadir=1\n')
|
||||
with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file2_path, 'w') as conf:
|
||||
conf.write('[testnet]\n')
|
||||
self.restart_node(0)
|
||||
self.nodes[0].stop_node(expected_stderr=f'Warning: {inc_conf_file_path}:1 Section [testnot] is not recognized.{os.linesep}{inc_conf_file2_path}:1 Section [testnet] is not recognized.')
|
||||
|
||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file_path, 'w') as conf:
|
||||
conf.write('') # clear
|
||||
with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
|
||||
with open(inc_conf_file2_path, 'w') as conf:
|
||||
conf.write('') # clear
|
||||
|
||||
def test_config_file_log(self):
|
||||
@ -522,9 +522,9 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||
conf_file = default_data_dir / "bitcoin.conf"
|
||||
|
||||
# datadir needs to be set before [chain] section
|
||||
with open(conf_file, encoding='utf8') as f:
|
||||
with open(conf_file) as f:
|
||||
conf_file_contents = f.read()
|
||||
with open(conf_file, 'w', encoding='utf8') as f:
|
||||
with open(conf_file, 'w') as f:
|
||||
f.write(f"datadir={new_data_dir}\n")
|
||||
f.write(conf_file_contents)
|
||||
|
||||
|
||||
@ -24,12 +24,12 @@ class IncludeConfTest(BitcoinTestFramework):
|
||||
def run_test(self):
|
||||
# Create additional config files
|
||||
# - tmpdir/node0/relative.conf
|
||||
with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:
|
||||
f.write("uacomment=relative\n")
|
||||
# - tmpdir/node0/relative2.conf
|
||||
with open(self.nodes[0].datadir_path / "relative2.conf", "w", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "relative2.conf", "w") as f:
|
||||
f.write("uacomment=relative2\n")
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
|
||||
f.write("uacomment=main\nincludeconf=relative.conf\n")
|
||||
self.restart_node(0)
|
||||
|
||||
@ -50,7 +50,7 @@ class IncludeConfTest(BitcoinTestFramework):
|
||||
)
|
||||
|
||||
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
|
||||
with open(self.nodes[0].datadir_path / "relative.conf", "a", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "relative.conf", "a") as f:
|
||||
f.write("includeconf=relative2.conf\n")
|
||||
self.start_node(0)
|
||||
|
||||
@ -61,7 +61,7 @@ class IncludeConfTest(BitcoinTestFramework):
|
||||
self.log.info("-includeconf cannot contain invalid arg")
|
||||
|
||||
# Commented out as long as we ignore invalid arguments in configuration files
|
||||
#with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
|
||||
#with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:
|
||||
# f.write("foo=bar\n")
|
||||
#self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Invalid configuration value foo")
|
||||
|
||||
@ -70,11 +70,11 @@ class IncludeConfTest(BitcoinTestFramework):
|
||||
self.nodes[0].assert_start_raises_init_error(expected_msg="Error: Error reading configuration file: Failed to include configuration file relative.conf")
|
||||
|
||||
self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'")
|
||||
with open(self.nodes[0].datadir_path / "relative.conf", "w", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "relative.conf", "w") as f:
|
||||
# Restore initial file contents
|
||||
f.write("uacomment=relative\n")
|
||||
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
|
||||
f.write("includeconf=relative2.conf\n")
|
||||
|
||||
self.start_node(0)
|
||||
|
||||
@ -41,10 +41,10 @@ class LoadblockTest(BitcoinTestFramework):
|
||||
hash_list = tempfile.NamedTemporaryFile(dir=data_dir,
|
||||
mode='w',
|
||||
delete=False,
|
||||
encoding="utf-8")
|
||||
)
|
||||
|
||||
self.log.info("Create linearization config file")
|
||||
with open(cfg_file, "a", encoding="utf-8") as cfg:
|
||||
with open(cfg_file, "a") as cfg:
|
||||
cfg.write(f"datadir={data_dir}\n")
|
||||
cfg.write(f"rpcuser={node_url.username}\n")
|
||||
cfg.write(f"rpcpassword={node_url.password}\n")
|
||||
|
||||
@ -200,7 +200,7 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
self.wait_until(lambda: os.path.isfile(self.shutdownnotify_file), timeout=10)
|
||||
|
||||
def large_work_invalid_chain_warning_in_alert_file(self):
|
||||
with open(self.alertnotify_file, 'r', encoding='utf8') as f:
|
||||
with open(self.alertnotify_file, 'r') as f:
|
||||
alert_text = f.read()
|
||||
return LARGE_WORK_INVALID_CHAIN_WARNING in alert_text
|
||||
|
||||
@ -213,7 +213,7 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
fname = os.path.join(self.walletnotify_dir, notify_outputname(self.wallet, tx_id))
|
||||
# Wait for the cached writes to hit storage
|
||||
self.wait_until(lambda: os.path.getsize(fname) > 0, timeout=10)
|
||||
with open(fname, 'rt', encoding='utf-8') as f:
|
||||
with open(fname, 'rt') as f:
|
||||
text = f.read()
|
||||
# Universal newline ensures '\n' on 'nt'
|
||||
assert_equal(text[-1], '\n')
|
||||
|
||||
@ -27,7 +27,7 @@ class StartupNotifyTest(BitcoinTestFramework):
|
||||
self.log.info("Test -startupnotify is executed once")
|
||||
|
||||
def get_count():
|
||||
with open(tmpdir_file, "r", encoding="utf8") as f:
|
||||
with open(tmpdir_file, "r") as f:
|
||||
file_content = f.read()
|
||||
return file_content.count(FILE_NAME)
|
||||
|
||||
|
||||
@ -1396,7 +1396,7 @@ def dump_json_test(tx, input_utxos, idx, success, failure):
|
||||
sha1 = hashlib.sha1(dump.encode("utf-8")).hexdigest()
|
||||
dirname = os.environ.get("TEST_DUMP_DIR", ".") + ("/%s" % sha1[0])
|
||||
os.makedirs(dirname, exist_ok=True)
|
||||
with open(dirname + ("/%s" % sha1), 'w', encoding="utf8") as f:
|
||||
with open(dirname + ("/%s" % sha1), 'w') as f:
|
||||
f.write(dump)
|
||||
|
||||
# Data type to keep track of UTXOs, where they were created, and how to spend them.
|
||||
|
||||
@ -32,7 +32,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||
def setup_network(self):
|
||||
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
|
||||
# Open and close to create zero-length file
|
||||
with open(self.alert_filename, 'w', encoding='utf8'):
|
||||
with open(self.alert_filename, 'w'):
|
||||
pass
|
||||
self.extra_args = [[f"-alertnotify=echo %s >> \"{self.alert_filename}\""]]
|
||||
self.setup_nodes()
|
||||
@ -55,7 +55,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
|
||||
|
||||
def versionbits_in_alert_file(self):
|
||||
"""Test that the versionbits warning has been written to the alert file."""
|
||||
with open(self.alert_filename, 'r', encoding='utf8') as f:
|
||||
with open(self.alert_filename, 'r') as f:
|
||||
alert_text = f.read()
|
||||
return VB_PATTERN.search(alert_text) is not None
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ class MiningMainnetTest(BitcoinTestFramework):
|
||||
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), self.options.datafile)
|
||||
prev_hash = node.getbestblockhash()
|
||||
blocks = None
|
||||
with open(path, encoding='utf-8') as f:
|
||||
with open(path) as f:
|
||||
blocks = json.load(f)
|
||||
n_blocks = len(blocks['timestamps'])
|
||||
assert_equal(n_blocks, 2016)
|
||||
|
||||
@ -11,7 +11,7 @@ import json
|
||||
def perform_pre_checks():
|
||||
mock_result_path = os.path.join(os.getcwd(), "mock_result")
|
||||
if os.path.isfile(mock_result_path):
|
||||
with open(mock_result_path, "r", encoding="utf8") as f:
|
||||
with open(mock_result_path, "r") as f:
|
||||
mock_result = f.read()
|
||||
if mock_result[0]:
|
||||
sys.stdout.write(mock_result[2:])
|
||||
|
||||
@ -11,7 +11,7 @@ import json
|
||||
def perform_pre_checks():
|
||||
mock_result_path = os.path.join(os.getcwd(), "mock_result")
|
||||
if os.path.isfile(mock_result_path):
|
||||
with open(mock_result_path, "r", encoding="utf8") as f:
|
||||
with open(mock_result_path, "r") as f:
|
||||
mock_result = f.read()
|
||||
if mock_result[0]:
|
||||
sys.stdout.write(mock_result[2:])
|
||||
@ -60,7 +60,7 @@ def signtx(args):
|
||||
if args.fingerprint != "00000001":
|
||||
return sys.stdout.write(json.dumps({"error": "Unexpected fingerprint", "fingerprint": args.fingerprint}))
|
||||
|
||||
with open(os.path.join(os.getcwd(), "mock_psbt"), "r", encoding="utf8") as f:
|
||||
with open(os.path.join(os.getcwd(), "mock_psbt"), "r") as f:
|
||||
mock_psbt = f.read()
|
||||
|
||||
if args.fingerprint == "00000001" :
|
||||
|
||||
@ -184,7 +184,7 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
|
||||
|
||||
def test_sortedmulti_descriptors_bip67(self):
|
||||
self.log.info('Testing sortedmulti descriptors with BIP 67 test vectors')
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json'), encoding='utf-8') as f:
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json')) as f:
|
||||
vectors = json.load(f)
|
||||
|
||||
for t in vectors:
|
||||
|
||||
@ -266,7 +266,7 @@ class DecodeScriptTest(BitcoinTestFramework):
|
||||
assert_equal('OP_RETURN 3011020701010101010101020601010101010101', rpc_result['vin'][0]['scriptSig']['asm'])
|
||||
|
||||
def decodescript_datadriven_tests(self):
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_decodescript.json'), encoding='utf-8') as f:
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_decodescript.json')) as f:
|
||||
dd_tests = json.load(f)
|
||||
|
||||
for script, result in dd_tests:
|
||||
|
||||
@ -78,11 +78,11 @@ class GetblockstatsTest(BitcoinTestFramework):
|
||||
'mocktime': int(mocktime),
|
||||
'stats': self.expected_stats,
|
||||
}
|
||||
with open(filename, 'w', encoding="utf8") as f:
|
||||
with open(filename, 'w') as f:
|
||||
json.dump(to_dump, f, sort_keys=True, indent=2)
|
||||
|
||||
def load_test_data(self, filename):
|
||||
with open(filename, 'r', encoding="utf8") as f:
|
||||
with open(filename, 'r') as f:
|
||||
d = json.load(f)
|
||||
blocks = d['blocks']
|
||||
mocktime = d['mocktime']
|
||||
|
||||
@ -22,7 +22,7 @@ def process_mapping(fname):
|
||||
cmds = []
|
||||
string_params = []
|
||||
in_rpcs = False
|
||||
with open(fname, "r", encoding="utf8") as f:
|
||||
with open(fname, "r") as f:
|
||||
for line in f:
|
||||
line = line.rstrip()
|
||||
if not in_rpcs:
|
||||
@ -153,7 +153,7 @@ class HelpRpcTest(BitcoinTestFramework):
|
||||
os.mkdir(dump_dir)
|
||||
calls = [line.split(' ', 1)[0] for line in self.nodes[0].help().splitlines() if line and not line.startswith('==')]
|
||||
for call in calls:
|
||||
with open(os.path.join(dump_dir, call), 'w', encoding='utf-8') as f:
|
||||
with open(os.path.join(dump_dir, call), 'w') as f:
|
||||
# Make sure the node can generate the help at runtime without crashing
|
||||
f.write(self.nodes[0].help(call))
|
||||
|
||||
|
||||
@ -799,7 +799,7 @@ class PSBTTest(BitcoinTestFramework):
|
||||
assert_equal(unknown_psbt, unknown_out)
|
||||
|
||||
# Open the data file
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_psbt.json'), encoding='utf-8') as f:
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_psbt.json')) as f:
|
||||
d = json.load(f)
|
||||
invalids = d['invalid']
|
||||
invalid_with_msgs = d["invalid_with_msg"]
|
||||
|
||||
@ -37,7 +37,7 @@ class RPCSignerTest(BitcoinTestFramework):
|
||||
self.skip_if_no_external_signer()
|
||||
|
||||
def set_mock_result(self, node, res):
|
||||
with open(os.path.join(node.cwd, "mock_result"), "w", encoding="utf8") as f:
|
||||
with open(os.path.join(node.cwd, "mock_result"), "w") as f:
|
||||
f.write(res)
|
||||
|
||||
def clear_mock_result(self, node):
|
||||
|
||||
@ -61,11 +61,11 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||
rpcauth3 = lines[1]
|
||||
self.password = lines[3]
|
||||
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
|
||||
f.write(rpcauth + "\n")
|
||||
f.write(rpcauth2 + "\n")
|
||||
f.write(rpcauth3 + "\n")
|
||||
with open(self.nodes[1].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
|
||||
with open(self.nodes[1].datadir_path / "bitcoin.conf", "a") as f:
|
||||
f.write("rpcuser={}\n".format(self.rpcuser))
|
||||
f.write("rpcpassword={}\n".format(self.rpcpassword))
|
||||
self.restart_node(0)
|
||||
|
||||
@ -61,7 +61,7 @@ class RPCWhitelistTest(BitcoinTestFramework):
|
||||
]
|
||||
# These commands shouldn't be allowed for any user to test failures
|
||||
self.never_allowed = ["getnetworkinfo"]
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a", encoding="utf8") as f:
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", "a") as f:
|
||||
f.write("\nrpcwhitelistdefault=0\n")
|
||||
for user in self.users:
|
||||
f.write("rpcauth=" + user[0] + ":" + user[1] + "\n")
|
||||
@ -96,7 +96,7 @@ class RPCWhitelistTest(BitcoinTestFramework):
|
||||
|
||||
# Replace file configurations
|
||||
self.nodes[0].replace_in_config([("rpcwhitelistdefault=0", "rpcwhitelistdefault=1")])
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", 'a', encoding='utf8') as f:
|
||||
with open(self.nodes[0].datadir_path / "bitcoin.conf", 'a') as f:
|
||||
f.write("rpcwhitelist=__cookie__:getblockcount,getblockchaininfo,getmempoolinfo,stop\n")
|
||||
self.restart_node(0)
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ class AuthServiceProxyWrapper():
|
||||
rpc_method = self.auth_service_proxy_instance._service_name
|
||||
|
||||
if self.coverage_logfile:
|
||||
with open(self.coverage_logfile, 'a+', encoding='utf8') as f:
|
||||
with open(self.coverage_logfile, 'a+') as f:
|
||||
f.write("%s\n" % rpc_method)
|
||||
|
||||
def __truediv__(self, relative_uri):
|
||||
@ -107,7 +107,7 @@ def write_all_rpc_commands(dirname: str, node: AuthServiceProxy) -> bool:
|
||||
if line and not line.startswith('='):
|
||||
commands.add("%s\n" % line.split()[0])
|
||||
|
||||
with open(filename, 'w', encoding='utf8') as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.writelines(list(commands))
|
||||
|
||||
return True
|
||||
|
||||
@ -134,7 +134,7 @@ class TestFrameworkEllSwift(unittest.TestCase):
|
||||
def test_elligator_encode_testvectors(self):
|
||||
"""Implement the BIP324 test vectors for ellswift encoding (read from xswiftec_inv_test_vectors.csv)."""
|
||||
vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'xswiftec_inv_test_vectors.csv')
|
||||
with open(vectors_file, newline='', encoding='utf8') as csvfile:
|
||||
with open(vectors_file, newline='') as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
u = FE.from_bytes(bytes.fromhex(row['u']))
|
||||
@ -150,7 +150,7 @@ class TestFrameworkEllSwift(unittest.TestCase):
|
||||
def test_elligator_decode_testvectors(self):
|
||||
"""Implement the BIP324 test vectors for ellswift decoding (read from ellswift_decode_test_vectors.csv)."""
|
||||
vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ellswift_decode_test_vectors.csv')
|
||||
with open(vectors_file, newline='', encoding='utf8') as csvfile:
|
||||
with open(vectors_file, newline='') as csvfile:
|
||||
reader = csv.DictReader(csvfile)
|
||||
for row in reader:
|
||||
encoding = bytes.fromhex(row['ellswift'])
|
||||
|
||||
@ -316,7 +316,7 @@ class TestFrameworkKey(unittest.TestCase):
|
||||
"""Implement the BIP340 test vectors (read from bip340_test_vectors.csv)."""
|
||||
num_tests = 0
|
||||
vectors_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'bip340_test_vectors.csv')
|
||||
with open(vectors_file, newline='', encoding='utf8') as csvfile:
|
||||
with open(vectors_file, newline='') as csvfile:
|
||||
reader = csv.reader(csvfile)
|
||||
next(reader)
|
||||
for row in reader:
|
||||
|
||||
@ -69,7 +69,7 @@ def netstat(typ='tcp'):
|
||||
To get pid of all network process running on system, you must run this script
|
||||
as superuser
|
||||
'''
|
||||
with open('/proc/net/'+typ,'r',encoding='utf8') as f:
|
||||
with open('/proc/net/'+typ,'r') as f:
|
||||
content = f.readlines()
|
||||
content.pop(0)
|
||||
result = []
|
||||
|
||||
@ -751,7 +751,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
self.log = logging.getLogger('TestFramework')
|
||||
self.log.setLevel(logging.DEBUG)
|
||||
# Create file handler to log all messages
|
||||
fh = logging.FileHandler(self.options.tmpdir + '/test_framework.log', encoding='utf-8')
|
||||
fh = logging.FileHandler(self.options.tmpdir + '/test_framework.log')
|
||||
fh.setLevel(logging.DEBUG)
|
||||
# Create console handler to log messages to stderr. By default this logs only error messages, but can be configured with --loglevel.
|
||||
ch = logging.StreamHandler(sys.stdout)
|
||||
|
||||
@ -506,13 +506,13 @@ class TestNode():
|
||||
The substitutions are passed as a list of search-replace-tuples, e.g.
|
||||
[("old", "new"), ("foo", "bar"), ...]
|
||||
"""
|
||||
with open(self.bitcoinconf, 'r', encoding='utf8') as conf:
|
||||
with open(self.bitcoinconf, 'r') as conf:
|
||||
conf_data = conf.read()
|
||||
for replacement in replacements:
|
||||
assert_equal(len(replacement), 2)
|
||||
old, new = replacement[0], replacement[1]
|
||||
conf_data = conf_data.replace(old, new)
|
||||
with open(self.bitcoinconf, 'w', encoding='utf8') as conf:
|
||||
with open(self.bitcoinconf, 'w') as conf:
|
||||
conf.write(conf_data)
|
||||
|
||||
@property
|
||||
|
||||
@ -528,7 +528,7 @@ def write_config(config_path, *, n, chain, extra_config="", disable_autoconnect=
|
||||
else:
|
||||
chain_name_conf_arg = chain
|
||||
chain_name_conf_section = chain
|
||||
with open(config_path, 'w', encoding='utf8') as f:
|
||||
with open(config_path, 'w') as f:
|
||||
if chain_name_conf_arg:
|
||||
f.write("{}=1\n".format(chain_name_conf_arg))
|
||||
if chain_name_conf_section:
|
||||
@ -594,7 +594,7 @@ def get_temp_default_datadir(temp_dir: pathlib.Path) -> tuple[dict, pathlib.Path
|
||||
|
||||
|
||||
def append_config(datadir, options):
|
||||
with open(os.path.join(datadir, "bitcoin.conf"), 'a', encoding='utf8') as f:
|
||||
with open(os.path.join(datadir, "bitcoin.conf"), 'a') as f:
|
||||
for option in options:
|
||||
f.write(option + "\n")
|
||||
|
||||
@ -603,7 +603,7 @@ def get_auth_cookie(datadir, chain):
|
||||
user = None
|
||||
password = None
|
||||
if os.path.isfile(os.path.join(datadir, "bitcoin.conf")):
|
||||
with open(os.path.join(datadir, "bitcoin.conf"), 'r', encoding='utf8') as f:
|
||||
with open(os.path.join(datadir, "bitcoin.conf"), 'r') as f:
|
||||
for line in f:
|
||||
if line.startswith("rpcuser="):
|
||||
assert user is None # Ensure that there is only one rpcuser line
|
||||
@ -612,7 +612,7 @@ def get_auth_cookie(datadir, chain):
|
||||
assert password is None # Ensure that there is only one rpcpassword line
|
||||
password = line.split("=")[1].strip("\n")
|
||||
try:
|
||||
with open(os.path.join(datadir, chain, ".cookie"), 'r', encoding="ascii") as f:
|
||||
with open(os.path.join(datadir, chain, ".cookie"), 'r') as f:
|
||||
userpass = f.read()
|
||||
split_userpass = userpass.split(':')
|
||||
user = split_userpass[0]
|
||||
|
||||
@ -428,7 +428,7 @@ def main():
|
||||
# Read config generated by configure.
|
||||
config = configparser.ConfigParser()
|
||||
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini"
|
||||
config.read_file(open(configfile, encoding="utf8"))
|
||||
config.read_file(open(configfile))
|
||||
|
||||
passon_args.append("--configfile=%s" % configfile)
|
||||
|
||||
@ -699,7 +699,7 @@ def print_results(test_results, max_len_name, runtime):
|
||||
|
||||
|
||||
def write_results(test_results, filepath, total_runtime):
|
||||
with open(filepath, mode="w", encoding="utf8") as results_file:
|
||||
with open(filepath, mode="w") as results_file:
|
||||
results_writer = csv.writer(results_file)
|
||||
results_writer.writerow(['test', 'status', 'duration(seconds)'])
|
||||
all_passed = True
|
||||
@ -911,7 +911,7 @@ class RPCCoverage():
|
||||
if not os.path.isfile(coverage_ref_filename):
|
||||
raise RuntimeError("No coverage reference found")
|
||||
|
||||
with open(coverage_ref_filename, 'r', encoding="utf8") as coverage_ref_file:
|
||||
with open(coverage_ref_filename, 'r') as coverage_ref_file:
|
||||
all_cmds.update([line.strip() for line in coverage_ref_file.readlines()])
|
||||
|
||||
for root, _, files in os.walk(self.dir):
|
||||
@ -920,7 +920,7 @@ class RPCCoverage():
|
||||
coverage_filenames.add(os.path.join(root, filename))
|
||||
|
||||
for filename in coverage_filenames:
|
||||
with open(filename, 'r', encoding="utf8") as coverage_file:
|
||||
with open(filename, 'r') as coverage_file:
|
||||
covered_cmds.update([line.strip() for line in coverage_file.readlines()])
|
||||
|
||||
return all_cmds - covered_cmds
|
||||
|
||||
@ -28,7 +28,7 @@ class ToolUtils(BitcoinTestFramework):
|
||||
def run_test(self):
|
||||
self.testcase_dir = Path(self.config["environment"]["SRCDIR"]) / "test" / "functional" / "data" / "util"
|
||||
self.bins = self.get_binaries()
|
||||
with open(self.testcase_dir / "bitcoin-util-test.json", encoding="utf8") as f:
|
||||
with open(self.testcase_dir / "bitcoin-util-test.json") as f:
|
||||
input_data = json.loads(f.read())
|
||||
|
||||
for i, test_obj in enumerate(input_data):
|
||||
@ -50,7 +50,7 @@ class ToolUtils(BitcoinTestFramework):
|
||||
# Read the input data (if there is any)
|
||||
inputData = None
|
||||
if "input" in testObj:
|
||||
with open(self.testcase_dir / testObj["input"], encoding="utf8") as f:
|
||||
with open(self.testcase_dir / testObj["input"]) as f:
|
||||
inputData = f.read()
|
||||
|
||||
# Read the expected output data (if there is any)
|
||||
@ -60,7 +60,7 @@ class ToolUtils(BitcoinTestFramework):
|
||||
if "output_cmp" in testObj:
|
||||
outputFn = testObj['output_cmp']
|
||||
outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
|
||||
with open(self.testcase_dir / outputFn, encoding="utf8") as f:
|
||||
with open(self.testcase_dir / outputFn) as f:
|
||||
outputData = f.read()
|
||||
if not outputData:
|
||||
raise Exception(f"Output data missing for {outputFn}")
|
||||
|
||||
@ -83,7 +83,7 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||
|
||||
def read_dump(self, filename):
|
||||
dump = OrderedDict()
|
||||
with open(filename, "r", encoding="utf8") as f:
|
||||
with open(filename, "r") as f:
|
||||
for row in f:
|
||||
row = row.strip()
|
||||
key, value = row.split(',')
|
||||
@ -98,7 +98,7 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||
def write_dump(self, dump, filename, magic=None, skip_checksum=False):
|
||||
if magic is None:
|
||||
magic = "BITCOIN_CORE_WALLET_DUMP"
|
||||
with open(filename, "w", encoding="utf8") as f:
|
||||
with open(filename, "w") as f:
|
||||
row = ",".join([magic, dump[magic]]) + "\n"
|
||||
f.write(row)
|
||||
for k, v in dump.items():
|
||||
|
||||
@ -112,7 +112,7 @@ class WalletBackupTest(BitcoinTestFramework):
|
||||
def restore_invalid_wallet(self):
|
||||
node = self.nodes[3]
|
||||
invalid_wallet_file = self.nodes[0].datadir_path / 'invalid_wallet_file.bak'
|
||||
open(invalid_wallet_file, 'a', encoding="utf8").write('invald wallet')
|
||||
open(invalid_wallet_file, 'a').write('invald wallet')
|
||||
wallet_name = "res0"
|
||||
not_created_wallet_file = node.wallets_path / wallet_name
|
||||
error_message = "Wallet file verification failed. Failed to load database path '{}'. Data is not in recognized format.".format(not_created_wallet_file)
|
||||
|
||||
@ -100,7 +100,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||
bad_deriv_wallet.dumpwallet(dump_path)
|
||||
addr = None
|
||||
seed = None
|
||||
with open(dump_path, encoding="utf8") as f:
|
||||
with open(dump_path) as f:
|
||||
for line in f:
|
||||
if f"hdkeypath=m/0'/0'/{LAST_KEYPOOL_INDEX}'" in line:
|
||||
addr = line.split(" ")[4].split("=")[1]
|
||||
@ -123,7 +123,7 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||
os.unlink(dump_path)
|
||||
bad_deriv_wallet.dumpwallet(dump_path)
|
||||
bad_path_addr = None
|
||||
with open(dump_path, encoding="utf8") as f:
|
||||
with open(dump_path) as f:
|
||||
for line in f:
|
||||
if f"hdkeypath={bad_deriv_path}" in line:
|
||||
bad_path_addr = line.split(" ")[4].split("=")[1]
|
||||
|
||||
@ -134,13 +134,13 @@ class WalletEncryptionTest(BitcoinTestFramework):
|
||||
do_wallet_tool("-wallet=noprivs", f"-dumpfile={dumpfile_path}", "dump")
|
||||
|
||||
# Modify the dump
|
||||
with open(dumpfile_path, "r", encoding="utf-8") as f:
|
||||
with open(dumpfile_path, "r") as f:
|
||||
dump_content = f.readlines()
|
||||
# Drop the checksum line
|
||||
dump_content = dump_content[:-1]
|
||||
# Insert a valid mkey line. This corresponds to a passphrase of "pass".
|
||||
dump_content.append("046d6b657901000000,300dc926f3b3887aad3d5d5f5a0fc1b1a4a1722f9284bd5c6ff93b64a83902765953939c58fe144013c8b819f42cf698b208e9911e5f0c544fa300000000cc52050000\n")
|
||||
with open(dumpfile_path, "w", encoding="utf-8") as f:
|
||||
with open(dumpfile_path, "w") as f:
|
||||
contents = "".join(dump_content)
|
||||
f.write(contents)
|
||||
checksum = hash256(contents.encode())
|
||||
@ -158,7 +158,7 @@ class WalletEncryptionTest(BitcoinTestFramework):
|
||||
# Make a new dump and check that there are no mkeys
|
||||
dumpfile_path = self.nodes[0].datadir_path / "noprivs_enc.dump"
|
||||
do_wallet_tool("-wallet=noprivs_enc", f"-dumpfile={dumpfile_path}", "dump")
|
||||
with open(dumpfile_path, "r", encoding="utf-8") as f:
|
||||
with open(dumpfile_path, "r") as f:
|
||||
# Check there's nothing with an 'mkey' prefix
|
||||
assert_equal(all([not line.startswith("046d6b6579") for line in f]), True)
|
||||
|
||||
|
||||
@ -180,7 +180,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
self.nodes[0].assert_start_raises_init_error(['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist')
|
||||
# should not initialize if the specified walletdir is not a directory
|
||||
not_a_dir = wallet_dir('notadir')
|
||||
open(not_a_dir, 'a', encoding="utf8").close()
|
||||
open(not_a_dir, 'a').close()
|
||||
self.nodes[0].assert_start_raises_init_error(['-walletdir=' + not_a_dir], 'Error: Specified -walletdir "' + not_a_dir + '" is not a directory')
|
||||
|
||||
# if wallets/ doesn't exist, datadir should be the default wallet dir
|
||||
|
||||
@ -48,7 +48,7 @@ class WalletSignerTest(BitcoinTestFramework):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def set_mock_result(self, node, res):
|
||||
with open(os.path.join(node.cwd, "mock_result"), "w", encoding="utf8") as f:
|
||||
with open(os.path.join(node.cwd, "mock_result"), "w") as f:
|
||||
f.write(res)
|
||||
|
||||
def clear_mock_result(self, node):
|
||||
@ -170,7 +170,7 @@ class WalletSignerTest(BitcoinTestFramework):
|
||||
|
||||
assert hww.testmempoolaccept([mock_tx])[0]["allowed"]
|
||||
|
||||
with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w", encoding="utf8") as f:
|
||||
with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w") as f:
|
||||
f.write(mock_psbt_signed["psbt"])
|
||||
|
||||
self.log.info('Test send using hww1')
|
||||
@ -195,7 +195,7 @@ class WalletSignerTest(BitcoinTestFramework):
|
||||
mock_psbt_bumped = mock_wallet.psbtbumpfee(orig_tx_id)["psbt"]
|
||||
mock_psbt_bumped_signed = mock_wallet.walletprocesspsbt(psbt=mock_psbt_bumped, sign=True, sighashtype="ALL", bip32derivs=True)
|
||||
|
||||
with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w", encoding="utf8") as f:
|
||||
with open(os.path.join(self.nodes[1].cwd, "mock_psbt"), "w") as f:
|
||||
f.write(mock_psbt_bumped_signed["psbt"])
|
||||
|
||||
self.log.info('Test bumpfee using hww1')
|
||||
|
||||
@ -99,7 +99,7 @@ def main():
|
||||
# Read config generated by configure.
|
||||
config = configparser.ConfigParser()
|
||||
configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini"
|
||||
config.read_file(open(configfile, encoding="utf8"))
|
||||
config.read_file(open(configfile))
|
||||
|
||||
if not config["components"].getboolean("ENABLE_FUZZ_BINARY"):
|
||||
logging.error("Must have fuzz executable built")
|
||||
|
||||
@ -185,7 +185,7 @@ def check_shebang_file_permissions(files_meta) -> int:
|
||||
|
||||
# *.py files which don't contain an `if __name__ == '__main__'` are not expected to be executed directly
|
||||
if file_meta.extension == "py":
|
||||
with open(filename, "r", encoding="utf8") as f:
|
||||
with open(filename, "r") as f:
|
||||
file_data = f.read()
|
||||
if not re.search("""if __name__ == ['"]__main__['"]:""", file_data):
|
||||
continue
|
||||
|
||||
@ -71,7 +71,7 @@ def main():
|
||||
|
||||
regex_pattern = f'^#(ifndef|define|endif //) {header_id}'
|
||||
|
||||
with open(header_file, 'r', encoding='utf-8') as f:
|
||||
with open(header_file, 'r') as f:
|
||||
header_file_contents = f.readlines()
|
||||
|
||||
count = 0
|
||||
|
||||
@ -40,13 +40,13 @@ EXPECTED_BOOST_INCLUDES = [
|
||||
|
||||
|
||||
def get_toplevel():
|
||||
return check_output(["git", "rev-parse", "--show-toplevel"], text=True, encoding="utf8").rstrip("\n")
|
||||
return check_output(["git", "rev-parse", "--show-toplevel"], text=True).rstrip("\n")
|
||||
|
||||
|
||||
def list_files_by_suffix(suffixes):
|
||||
exclude_args = [":(exclude)" + dir for dir in EXCLUDED_DIRS]
|
||||
|
||||
files_list = check_output(["git", "ls-files", "src"] + exclude_args, text=True, encoding="utf8").splitlines()
|
||||
files_list = check_output(["git", "ls-files", "src"] + exclude_args, text=True).splitlines()
|
||||
|
||||
return [file for file in files_list if file.endswith(suffixes)]
|
||||
|
||||
@ -68,7 +68,7 @@ def find_included_cpps():
|
||||
included_cpps = list()
|
||||
|
||||
try:
|
||||
included_cpps = check_output(["git", "grep", "-E", r"^#include [<\"][^>\"]+\.cpp[>\"]", "--", "*.cpp", "*.h"], text=True, encoding="utf8").splitlines()
|
||||
included_cpps = check_output(["git", "grep", "-E", r"^#include [<\"][^>\"]+\.cpp[>\"]", "--", "*.cpp", "*.h"], text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
@ -82,7 +82,7 @@ def find_extra_boosts():
|
||||
exclusion_set = set()
|
||||
|
||||
try:
|
||||
included_boosts = check_output(["git", "grep", "-E", r"^#include <boost/", "--", "*.cpp", "*.h"], text=True, encoding="utf8").splitlines()
|
||||
included_boosts = check_output(["git", "grep", "-E", r"^#include <boost/", "--", "*.cpp", "*.h"], text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
@ -105,7 +105,7 @@ def find_quote_syntax_inclusions():
|
||||
quote_syntax_inclusions = list()
|
||||
|
||||
try:
|
||||
quote_syntax_inclusions = check_output(["git", "grep", r"^#include \"", "--", "*.cpp", "*.h"] + exclude_args, text=True, encoding="utf8").splitlines()
|
||||
quote_syntax_inclusions = check_output(["git", "grep", r"^#include \"", "--", "*.cpp", "*.h"] + exclude_args, text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
@ -120,7 +120,7 @@ def main():
|
||||
|
||||
# Check for duplicate includes
|
||||
for filename in list_files_by_suffix((".cpp", ".h")):
|
||||
with open(filename, "r", encoding="utf8") as file:
|
||||
with open(filename, "r") as file:
|
||||
include_list = [line.rstrip("\n") for line in file if re.match(r"^#include", line)]
|
||||
|
||||
duplicates = find_duplicate_includes(include_list)
|
||||
@ -148,13 +148,13 @@ def main():
|
||||
if extra_boosts:
|
||||
for boost in extra_boosts:
|
||||
print(f"A new Boost dependency in the form of \"{boost}\" appears to have been introduced:")
|
||||
print(check_output(["git", "grep", boost, "--", "*.cpp", "*.h"], text=True, encoding="utf8"))
|
||||
print(check_output(["git", "grep", boost, "--", "*.cpp", "*.h"], text=True))
|
||||
exit_code = 1
|
||||
|
||||
# Check if Boost dependencies are no longer used
|
||||
for expected_boost in EXPECTED_BOOST_INCLUDES:
|
||||
try:
|
||||
check_output(["git", "grep", "-q", r"^#include <%s>" % expected_boost, "--", "*.cpp", "*.h"], text=True, encoding="utf8")
|
||||
check_output(["git", "grep", "-q", r"^#include <%s>" % expected_boost, "--", "*.cpp", "*.h"], text=True)
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
|
||||
@ -219,7 +219,7 @@ def find_locale_dependent_function_uses():
|
||||
git_grep_output = list()
|
||||
|
||||
try:
|
||||
git_grep_output = check_output(git_grep_command, text=True, encoding="utf8").splitlines()
|
||||
git_grep_output = check_output(git_grep_command, text=True).splitlines()
|
||||
except CalledProcessError as e:
|
||||
if e.returncode > 1:
|
||||
raise e
|
||||
|
||||
@ -41,7 +41,7 @@ def main():
|
||||
if re.search('src/(secp256k1|minisketch)/', file_path):
|
||||
continue
|
||||
|
||||
with open(file_path, 'r', encoding='utf-8') as file_obj:
|
||||
with open(file_path, 'r') as file_obj:
|
||||
contents = file_obj.read()
|
||||
|
||||
non_comment_pattern = re.compile(r'^\s*((?!#).+)$', re.MULTILINE)
|
||||
|
||||
@ -23,7 +23,7 @@ def grep_boost_fixture_test_suite():
|
||||
"src/test/**.cpp",
|
||||
"src/wallet/test/**.cpp",
|
||||
]
|
||||
return subprocess.check_output(command, text=True, encoding="utf8")
|
||||
return subprocess.check_output(command, text=True)
|
||||
|
||||
|
||||
def check_matching_test_names(test_suite_list):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user