Continuing to chip away at the untested RPC interface. This PR:
- adds tests for
getblockheader
(previously uncovered) - adds missing documentation to the
getblockheader
RPC help - adds two assertion utilities to the RPC testing framework
Continuing to chip away at the untested RPC interface. This PR:
getblockheader
(previously uncovered)getblockheader
RPC help406@@ -407,5 +407,22 @@ def assert_raises(exc, fun, *args, **kwds):
407 else:
408 raise AssertionError("No exception raised")
409
410+def assert_is_hex_string(string):
411+ try:
412+ int(string, 16)
413+ except Exception as e:
414+ raise AssertionError(
415+ "Couldn't interpret %r as hexidecimal; raised: %s" % (string, e))
322@@ -323,7 +323,8 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
323 " \"bits\" : \"1d00ffff\", (string) The bits\n"
324 " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
325 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
326- " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
327+ " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
328+ " \"chainwork\" : \"0000...1f3\" (string) Number of hashes expected to produce the current chain (in hex)\n"
What about “Expected number of hashes required to produce the current chain”?
Current wording could be read as “do that work, will get the current chain”, which is a bit unlikely. :)
418+ if not isinstance(string, basestring):
419+ raise AssertionError("Expected a string, got type %r" % type(string))
420+ elif length and len(string) != length:
421+ raise AssertionError(
422+ "String of length %d expected; got %d" % (length, len(string)))
423+ elif not re.match('[abcdef0-9]+', string):
I think you want:
0 elif not re.match('[abcdef0-9]+$', string):
322@@ -323,7 +323,8 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
323 " \"bits\" : \"1d00ffff\", (string) The bits\n"
324 " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
325 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
326- " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
327+ " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
328+ " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n"
Ok, I disagree that it’s clear, but if everyone else is fine with it I can conform as well.
Regardless, my pull is not covered here, so not sure why would I close it?
edit: My title wasn’t clear, so I added the specific rpc.
Perhaps my newer suggestion is equitable?
https://github.com/bitcoin/bitcoin/pull/7232/files#r48769375