diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index a1b90860f6..f1794f505c 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -197,6 +197,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)) # zeros in 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 ###################