Skip to content

Commit

Permalink
Add assert_is_hex_string and assert_is_hash_string to RPC test utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesob committed Dec 14, 2015
1 parent 9ee02cf commit 16d4fce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions qa/rpc-tests/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,22 @@ def assert_raises(exc, fun, *args, **kwds):
else:
raise AssertionError("No exception raised")

def assert_is_hex_string(string):
try:
int(string, 16)
except Exception as e:
raise AssertionError(
"Couldn't interpret %r as hexadecimal; raised: %s" % (string, e))

def assert_is_hash_string(string, length=64):
if not isinstance(string, basestring):
raise AssertionError("Expected a string, got type %r" % type(string))
elif length and len(string) != length:
raise AssertionError(
"String of length %d expected; got %d" % (length, len(string)))
elif not re.match('[abcdef0-9]+$', string):
raise AssertionError(
"String %r contains invalid characters for a hash." % string)

def satoshi_round(amount):
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)

0 comments on commit 16d4fce

Please sign in to comment.