mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-07 13:18:43 +02: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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user