From 4919b68e7a603053bb4fa725bb477bab28a33215 Mon Sep 17 00:00:00 2001 From: Oleksandr Fedorenko Date: Fri, 6 Mar 2026 20:42:43 +0200 Subject: [PATCH 1/2] add tests for GET /block/:hash/txid/:index --- tests/rest.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/rest.rs b/tests/rest.rs index 002798941..8686a7327 100644 --- a/tests/rest.rs +++ b/tests/rest.rs @@ -342,6 +342,26 @@ fn test_rest_block() -> Result<()> { let res = get_plain(rest_addr, &format!("/block/{}/txid/1", blockhash))?; assert_eq!(res, txid.to_string()); + // Test GET /block/:hash/txid/:index + // Should fail with 400 code when block hash is invalid + let invalid_hash_resp = ureq::get(&format!("http://{}/block/{}/txs/1", rest_addr, "invalid_hash")) + .config() + .http_status_as_error(false) + .build() + .call()?; + assert_eq!(invalid_hash_resp.status(), 400); + assert_eq!(invalid_hash_resp.into_body().read_to_string()?, "Invalid hex string"); + + // Test GET /block/:hash/txid/:index + // Should fail with 404 code when block isn't found + let invalid_hash_resp = ureq::get(&format!("http://{}/block/{}/txs/0", rest_addr, "0000000000000000000000000000000000000000000000000000000000000000")) + .config() + .http_status_as_error(false) + .build() + .call()?; + assert_eq!(invalid_hash_resp.status(), 404); + assert_eq!(invalid_hash_resp.into_body().read_to_string()?, "Block not found"); + rest_handle.stop(); Ok(()) } From f32a9b9fc3d5b37ce00f6cf88c9a39fc2c1d3bb2 Mon Sep 17 00:00:00 2001 From: Oleksandr Fedorenko Date: Fri, 6 Mar 2026 20:52:40 +0200 Subject: [PATCH 2/2] fix error handling fot GET /block/:hash/txid/:index --- src/rest.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rest.rs b/src/rest.rs index 4cde8d887..5a42fee0d 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -795,7 +795,14 @@ fn handle_request( let txs = query .chain() - .get_block_txs(&hash, start_index, CHAIN_TXS_PER_PAGE)? + .get_block_txs(&hash, start_index, CHAIN_TXS_PER_PAGE) + .map_err(|e| { + if e.description().contains("block not found") { + HttpError::not_found("Block not found".to_string()) + } else { + HttpError::from(e) + } + })? .into_iter() .map(|tx| (tx, blockid)) .collect();