aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/test_framework/util.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-01-18 12:21:18 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2016-01-18 12:24:01 +0100
commite4e77ee55d8a041ab9922879522856f5f7903c58 (patch)
tree4b42369f98813f2dc7d0d2739cb577ff555d93ae /qa/rpc-tests/test_framework/util.py
parentae20172941ff83791a8ae9a858d4f4e70bf9aadb (diff)
parent135d6ec8cedc83ad800da45080c16d49e9182e80 (diff)
downloadbitcoin-e4e77ee55d8a041ab9922879522856f5f7903c58.tar.xz
Merge pull request #7194
135d6ec Add RPC tests for getblockheader. (James O'Beirne) 4745636 Add RPC documentation for getblockheader[chainwork]. (James O'Beirne) 16d4fce Add assert_is_hex_string and assert_is_hash_string to RPC test utils. (James O'Beirne)
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 15fd50363e..d8bb63dbbb 100644
--- a/qa/rpc-tests/test_framework/util.py
+++ b/qa/rpc-tests/test_framework/util.py
@@ -407,6 +407,23 @@ 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)