Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def assert_fee_amount(fee, tx_size, fee_per_kB, wiggleroom=2): | ||||
wiggleroom defines an amount that the test expects the wallet to be off by | wiggleroom defines an amount that the test expects the wallet to be off by | ||||
when estimating fees. This can be due to the dummy signature that is added | when estimating fees. This can be due to the dummy signature that is added | ||||
during fee calculation, or due to the wallet funding transactions using the | during fee calculation, or due to the wallet funding transactions using the | ||||
ceiling of the calculated fee. | ceiling of the calculated fee. | ||||
""" | """ | ||||
target_fee = round(tx_size * fee_per_kB / 1000, 8) | target_fee = round(tx_size * fee_per_kB / 1000, 8) | ||||
if fee < (tx_size - wiggleroom) * fee_per_kB / 1000: | if fee < (tx_size - wiggleroom) * fee_per_kB / 1000: | ||||
raise AssertionError( | raise AssertionError( | ||||
"Fee of {} BCH too low! (Should be {} BCH)".format(str(fee), str(target_fee))) | "Fee of {} XEC too low! (Should be {} XEC)".format(str(fee), str(target_fee))) | ||||
if fee > (tx_size + wiggleroom) * fee_per_kB / 1000: | if fee > (tx_size + wiggleroom) * fee_per_kB / 1000: | ||||
raise AssertionError( | raise AssertionError( | ||||
"Fee of {} BCH too high! (Should be {} BCH)".format(str(fee), str(target_fee))) | "Fee of {} XEC too high! (Should be {} XEC)".format(str(fee), str(target_fee))) | ||||
def assert_equal(thing1, thing2, *args): | def assert_equal(thing1, thing2, *args): | ||||
if thing1 != thing2 or any(thing1 != arg for arg in args): | if thing1 != thing2 or any(thing1 != arg for arg in args): | ||||
raise AssertionError("not({})".format(" == ".join(str(arg) | raise AssertionError("not({})".format(" == ".join(str(arg) | ||||
for arg in (thing1, thing2) + args))) | for arg in (thing1, thing2) + args))) | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | def assert_array_result(object_array, to_match, expected, | ||||
if num_matched > 0 and should_not_find: | if num_matched > 0 and should_not_find: | ||||
raise AssertionError("Objects were found {}".format(str(to_match))) | raise AssertionError("Objects were found {}".format(str(to_match))) | ||||
# Utility functions | # Utility functions | ||||
################### | ################### | ||||
def check_json_precision(): | def check_json_precision(): | ||||
"""Make sure json library being used does not lose precision converting BCH values""" | """Make sure json library being used does not lose precision converting XEC | ||||
values""" | |||||
n = Decimal("20000000.00000003") | n = Decimal("20000000.00000003") | ||||
satoshis = int(json.loads(json.dumps(float(n))) * 1.0e8) | satoshis = int(json.loads(json.dumps(float(n))) * 1.0e8) | ||||
if satoshis != 2000000000000003: | if satoshis != 2000000000000003: | ||||
raise RuntimeError("JSON encode/decode loses precision") | raise RuntimeError("JSON encode/decode loses precision") | ||||
def EncodeDecimal(o): | def EncodeDecimal(o): | ||||
if isinstance(o, Decimal): | if isinstance(o, Decimal): | ||||
▲ Show 20 Lines • Show All 375 Lines • Show Last 20 Lines |