From 092fc434854f881330771a93a1280ac67b1d3549 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Thu, 30 Apr 2020 01:05:55 -0400 Subject: tests: Add a sha256sum_file function to util --- test/functional/test_framework/util.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional') diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 7688febae7..0f4713d50e 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -8,6 +8,7 @@ from base64 import b64encode from binascii import unhexlify from decimal import Decimal, ROUND_DOWN from subprocess import CalledProcessError +import hashlib import inspect import json import logging @@ -260,6 +261,14 @@ def wait_until_helper(predicate, *, attempts=float('inf'), timeout=float('inf'), raise AssertionError("Predicate {} not true after {} seconds".format(predicate_source, timeout)) raise RuntimeError('Unreachable') +def sha256sum_file(filename): + h = hashlib.sha256() + with open(filename, 'rb') as f: + d = f.read(4096) + while len(d) > 0: + h.update(d) + d = f.read(4096) + return h.digest() # RPC/P2P connection constants and functions ############################################ -- cgit v1.2.3