aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/test_framework/util.py
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@gmail.com>2015-12-09 09:01:34 -0800
committerJames O'Beirne <james.obeirne@gmail.com>2015-12-14 10:40:11 -0800
commit16d4fce0b203bdaa679ad5b3f1e6b6f46880d5d2 (patch)
tree2640e393f7dfd7da38e704cf7d115dbf25e93e09 /qa/rpc-tests/test_framework/util.py
parent9ee02cf564d1ce79d2981899cb4d38c914210dc7 (diff)
downloadbitcoin-16d4fce0b203bdaa679ad5b3f1e6b6f46880d5d2.tar.xz
Add assert_is_hex_string and assert_is_hash_string to RPC test utils.
Diffstat (limited to 'qa/rpc-tests/test_framework/util.py')
-rw-r--r--qa/rpc-tests/test_framework/util.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py
index 72df3ae685..a0f5b1afde 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -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)