Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Helpful routines for regression testing.""" | """Helpful routines for regression testing.""" | ||||
from base64 import b64encode | from base64 import b64encode | ||||
from binascii import unhexlify | from binascii import unhexlify | ||||
from decimal import Decimal, ROUND_DOWN | from decimal import Decimal, ROUND_DOWN | ||||
from subprocess import CalledProcessError | from subprocess import CalledProcessError | ||||
import hashlib | |||||
import inspect | import inspect | ||||
import json | import json | ||||
import logging | import logging | ||||
import os | import os | ||||
import random | import random | ||||
import re | import re | ||||
import time | import time | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | def check_json_precision(): | ||||
if satoshis != 2000000000000003: | if satoshis != 2000000000000003: | ||||
raise RuntimeError("JSON encode/decode loses precision") | raise RuntimeError("JSON encode/decode loses precision") | ||||
def count_bytes(hex_string): | def count_bytes(hex_string): | ||||
return len(bytearray.fromhex(hex_string)) | return len(bytearray.fromhex(hex_string)) | ||||
def hash256(byte_str): | |||||
sha256 = hashlib.sha256() | |||||
sha256.update(byte_str) | |||||
sha256d = hashlib.sha256() | |||||
sha256d.update(sha256.digest()) | |||||
return sha256d.digest()[::-1] | |||||
def hex_str_to_bytes(hex_str): | def hex_str_to_bytes(hex_str): | ||||
return unhexlify(hex_str.encode('ascii')) | return unhexlify(hex_str.encode('ascii')) | ||||
def str_to_b64str(string): | def str_to_b64str(string): | ||||
return b64encode(string.encode('utf-8')).decode('ascii') | return b64encode(string.encode('utf-8')).decode('ascii') | ||||
▲ Show 20 Lines • Show All 371 Lines • Show Last 20 Lines |