Skip to content

Commit

Permalink
test: add assert_scale assertion to test framework
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#19089
Rebased-From: 067e5dc
  • Loading branch information
jonatack authored and luke-jr committed Jun 13, 2020
1 parent 4012891 commit 4b5091f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ def assert_array_result(object_array, to_match, expected, should_not_find=False)
if num_matched > 0 and should_not_find:
raise AssertionError("Objects were found %s" % (str(to_match)))

def assert_scale(number, expected_scale=8):
"""Assert number has expected scale, e.g. fractional digits; number of
digits after the decimal. The default of 8 corresponds to a Bitcoin amount."""
number = str(number)
mantissa = number.split('.')[-1].upper()
if mantissa[:3] == '0E-':
assert_equal(mantissa, '0E-{}'.format(expected_scale)) # exponent notation
elif mantissa == number:
assert_equal(0, expected_scale) # no mantissa, ergo, expected scale must be 0
else:
assert_equal(len(mantissa), expected_scale)

# Utility functions
###################

Expand Down

0 comments on commit 4b5091f

Please sign in to comment.