test: rest /tx with an invalid/unknown txid #24054

pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2022-01-rest-functional changing 1 files +14 −4
  1. brunoerg commented at 11:00 am on January 13, 2022: member
    This PR adds test coverage to the endpoint /tx (rest) passing an invalid and an unknown txid to test its return. Invalid -> should return status code 400 (bad request) Unknown -> should return status code 404 (not found)
  2. fanquake added the label Tests on Jan 13, 2022
  3. brunoerg force-pushed on Jan 13, 2022
  4. jonatack commented at 6:49 pm on January 13, 2022: member

    ACK a6376a823d9862342d9f3542349e81912c4bdb69

    A couple of (more self-documenting?) ideas for fun, feel free to ignore.

    0        invalid_txid = "abc"
    1        resp = self.test_rest_request(uri=f"/tx/{invalid_txid}", ret_type=RetType.OBJ, status=400)
    2        assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {invalid_txid}")
    3
    4        unknown_txid ="0000000000000000000000000000000000000000000000000000000000000000"
    5        resp = self.test_rest_request(uri=f"/tx/{unknown_txid}", ret_type=RetType.OBJ, status=404)
    6        assert_equal(resp.read().decode('utf-8').rstrip(), f"{unknown_txid} not found")
    
    0        invalid_txid = "abc"
    1        unknown_txid = "0000000000000000000000000000000000000000000000000000000000000000"
    2        for tx in [{'id': invalid_txid, 'status': 400, 'error': f"Invalid hash: {invalid_txid}"},
    3                   {'id': unknown_txid, 'status': 404, 'error': f"{unknown_txid} not found"}]:
    4            resp = self.test_rest_request(uri=f"/tx/{tx['id']}", status=tx['status'], ret_type=RetType.OBJ)
    5            assert_equal(resp.read().decode('utf-8').rstrip(), tx['error'])
    
  5. brunoerg force-pushed on Jan 13, 2022
  6. brunoerg commented at 7:40 pm on January 13, 2022: member
    force-pushed addressing @jonatack’s comment. Instead of creating invalid_txid and unknown_txid I used invalid_param and unknown_param to use them in other scenarios (e.g invalid blocks) that use the same values.
  7. test: rest /tx with an invalid/unknown txid bd52684508
  8. in test/functional/interface_rest.py:108 in 6e3caa9a53 outdated
    102@@ -103,6 +103,14 @@ def run_test(self):
    103         n, = filter_output_indices_by_value(json_obj['vout'], Decimal('0.1'))
    104         spending = (txid, n)
    105 
    106+        # Test /tx with an invalid and an unknown txid
    107+        invalid_param = "abc"
    108+        unknown_param = "0000000000000000000000000000000000000000000000000000000000000000"
    


    jonatack commented at 7:50 pm on January 13, 2022:
    Ah, nice that these can be reused. Since the reuses are much further down, maybe hoist these to constants at the top.

    brunoerg commented at 8:02 pm on January 13, 2022:
    Cool! Done!
  9. brunoerg force-pushed on Jan 13, 2022
  10. DrahtBot commented at 2:32 am on January 14, 2022: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24098 (rest: Use query parameters to control resource loading by stickies-v)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  11. kallewoof commented at 7:34 am on January 19, 2022: member
    ACK bd52684508ca2964e6a3af503d21ff99675380c7
  12. MarcoFalke merged this on Jan 19, 2022
  13. MarcoFalke closed this on Jan 19, 2022

  14. jonatack commented at 5:07 pm on January 19, 2022: member
    Posthumous ACK
  15. sidhujag referenced this in commit ef54306288 on Jan 20, 2022
  16. DrahtBot locked this on Jan 19, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-23 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me