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-2016 The Bitcoin Core developers | # Copyright (c) 2014-2016 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 hexlify, unhexlify | from binascii import unhexlify | ||||
from decimal import Decimal, ROUND_DOWN | from decimal import Decimal, ROUND_DOWN | ||||
import hashlib | 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 | ||||
▲ Show 20 Lines • Show All 193 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 bytes_to_hex_str(byte_str): | def b_2_x(byte_str): | ||||
return hexlify(byte_str).decode('ascii') | return byte_str.hex() | ||||
def hash256(byte_str): | def hash256(byte_str): | ||||
sha256 = hashlib.sha256() | sha256 = hashlib.sha256() | ||||
sha256.update(byte_str) | sha256.update(byte_str) | ||||
sha256d = hashlib.sha256() | sha256d = hashlib.sha256() | ||||
sha256d.update(sha256.digest()) | sha256d.update(sha256.digest()) | ||||
return sha256d.digest()[::-1] | return sha256d.digest()[::-1] | ||||
▲ Show 20 Lines • Show All 421 Lines • Show Last 20 Lines |