aboutsummaryrefslogtreecommitdiff
path: root/test/functional/tool_wallet.py
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-05-04 14:08:09 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-05-04 14:18:13 +0200
commit2c0c6f44770403899bd8514ad7343356853bf38c (patch)
tree7b25556404f24897b8b172948dbeee99c89792e0 /test/functional/tool_wallet.py
parentaebcd18c654a1706954a9e2c9cbfe97dfe531357 (diff)
downloadbitcoin-2c0c6f44770403899bd8514ad7343356853bf38c.tar.xz
test: dedup file hashing using `sha256sum_file` helper
Rather than doing the open/read/hash-steps manually in the affected functional tests, we can just use the `sha256sum_file` helper from the utils module instead. Note that for the tool_wallet.py test, the used hash is changed from sha1 to sha256, but as the only purpose is to detect file content changes, this doesn't matter. Also, the optimization using `memoryview` is overkill here, as the opened file has only a size of 24KiB and determining the hash doesn't take longer than a few hundred micro-seconds on my machine.
Diffstat (limited to 'test/functional/tool_wallet.py')
-rwxr-xr-xtest/functional/tool_wallet.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/test/functional/tool_wallet.py b/test/functional/tool_wallet.py
index a888f93b03..4dfb4ac4b3 100755
--- a/test/functional/tool_wallet.py
+++ b/test/functional/tool_wallet.py
@@ -4,7 +4,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test bitcoin-wallet."""
-import hashlib
import os
import stat
import subprocess
@@ -13,9 +12,10 @@ import textwrap
from collections import OrderedDict
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_equal
-
-BUFFER_SIZE = 16 * 1024
+from test_framework.util import (
+ assert_equal,
+ sha256sum_file,
+)
class ToolWalletTest(BitcoinTestFramework):
@@ -54,12 +54,7 @@ class ToolWalletTest(BitcoinTestFramework):
assert_equal(p.poll(), 0)
def wallet_shasum(self):
- h = hashlib.sha1()
- mv = memoryview(bytearray(BUFFER_SIZE))
- with open(self.wallet_path, 'rb', buffering=0) as f:
- for n in iter(lambda: f.readinto(mv), 0):
- h.update(mv[:n])
- return h.hexdigest()
+ return sha256sum_file(self.wallet_path).hex()
def wallet_timestamp(self):
return os.path.getmtime(self.wallet_path)