Merge bitcoin/bitcoin#27853: rest: bugfix, fix crash error when calling /deploymentinfo

7d452d826a test: add coverage for `/deploymentinfo` passing a blockhash (brunoerg)
ce887eaf49 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 7d452d826a
  stickies-v:
    ACK 7d452d826a

Tree-SHA512: f01551e556aba2380c3eaed0bc59057304302c202d317d7c1eec5f7ef839851f672aed80819a8719cb1cbbad2aad735d6d44314ac7d6d98bff8217f5a16c312b
This commit is contained in:
Andrew Chow 2023-06-12 18:28:22 -04:00
commit d80348ccb6
No known key found for this signature in database
GPG Key ID: 17565732E08E5E41
2 changed files with 5 additions and 1 deletions

View File

@ -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");

View File

@ -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")