Skip to content

Commit 092fc43

Browse files
committed
tests: Add a sha256sum_file function to util
1 parent 0bd995a commit 092fc43

File tree

1 file changed

+9
-0
lines changed
  • test/functional/test_framework

1 file changed

+9
-0
lines changed

test/functional/test_framework/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from binascii import unhexlify
99
from decimal import Decimal, ROUND_DOWN
1010
from subprocess import CalledProcessError
11+
import hashlib
1112
import inspect
1213
import json
1314
import logging
@@ -260,6 +261,14 @@ def wait_until_helper(predicate, *, attempts=float('inf'), timeout=float('inf'),
260261
raise AssertionError("Predicate {} not true after {} seconds".format(predicate_source, timeout))
261262
raise RuntimeError('Unreachable')
262263

264+
def sha256sum_file(filename):
265+
h = hashlib.sha256()
266+
with open(filename, 'rb') as f:
267+
d = f.read(4096)
268+
while len(d) > 0:
269+
h.update(d)
270+
d = f.read(4096)
271+
return h.digest()
263272

264273
# RPC/P2P connection constants and functions
265274
############################################

0 commit comments

Comments
 (0)