aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-06-12 18:28:22 -0400
committerAndrew Chow <github@achow101.com>2023-06-12 18:34:42 -0400
commitd80348ccb65601d19b4b408d442e0999b5a6cf98 (patch)
treef7d80ed4a93090c6563414b94ea55a99195f78b8
parentc92fd638860c5b4477851fb3790bc8068f808d3e (diff)
parent7d452d826a7056411077b870efc3872bb2fa45e4 (diff)
downloadbitcoin-d80348ccb65601d19b4b408d442e0999b5a6cf98.tar.xz
Merge bitcoin/bitcoin#27853: rest: bugfix, fix crash error when calling `/deploymentinfo`
7d452d826a7056411077b870efc3872bb2fa45e4 test: add coverage for `/deploymentinfo` passing a blockhash (brunoerg) ce887eaf4917c337b21aa2e7811804ce003d36be rest: bugfix, fix crash error when calling `/deploymentinfo` (brunoerg) Pull request description: Calling `/deploymentinfo` passing a valid blockhash makes bitcoind to crash. It happens because we're pushing a JSON value of type array when it expects type object. See: ```cpp jsonRequest.params = UniValue(UniValue::VARR); ``` ```cpp jsonRequest.params.pushKV("blockhash", hash_str); ``` This PR fixes it by changing `pushKV` to `push_back` and adds more test coverage. ACKs for top commit: achow101: ACK 7d452d826a7056411077b870efc3872bb2fa45e4 stickies-v: ACK 7d452d826a7056411077b870efc3872bb2fa45e4 Tree-SHA512: f01551e556aba2380c3eaed0bc59057304302c202d317d7c1eec5f7ef839851f672aed80819a8719cb1cbbad2aad735d6d44314ac7d6d98bff8217f5a16c312b
-rw-r--r--src/rest.cpp2
-rwxr-xr-xtest/functional/interface_rest.py4
2 files changed, 5 insertions, 1 deletions
diff --git a/src/rest.cpp b/src/rest.cpp
index c9e61d70bd..ba149c1a9e 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -627,7 +627,7 @@ static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const
return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
}
- jsonRequest.params.pushKV("blockhash", hash_str);
+ jsonRequest.params.push_back(hash_str);
}
req->WriteHeader("Content-Type", "application/json");
diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py
index 315d717986..1ba8f60d99 100755
--- a/test/functional/interface_rest.py
+++ b/test/functional/interface_rest.py
@@ -421,6 +421,10 @@ class RESTTest (BitcoinTestFramework):
deployment_info = self.nodes[0].getdeploymentinfo()
assert_equal(deployment_info, self.test_rest_request('/deploymentinfo'))
+ previous_bb_hash = self.nodes[0].getblockhash(self.nodes[0].getblockcount() - 1)
+ deployment_info = self.nodes[0].getdeploymentinfo(previous_bb_hash)
+ assert_equal(deployment_info, self.test_rest_request(f"/deploymentinfo/{previous_bb_hash}"))
+
non_existing_blockhash = '42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4'
resp = self.test_rest_request(f'/deploymentinfo/{non_existing_blockhash}', ret_type=RetType.OBJ, status=400)
assert_equal(resp.read().decode('utf-8').rstrip(), "Block not found")