From 7db6ff6bb2501e9a5df4ec50c957c4b8ca8a83db Mon Sep 17 00:00:00 2001 From: Marek Date: Thu, 12 Dec 2024 14:19:47 +0100 Subject: [PATCH] Reintroduce snapshots for invalid TXIDs --- zebra-rpc/src/methods/tests/snapshot.rs | 7 +++++++ .../getrawtransaction_invalid_txid@mainnet_10.snap | 11 +++++++++++ .../getrawtransaction_invalid_txid@testnet_10.snap | 11 +++++++++++ zebra-rpc/src/methods/tests/vectors.rs | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@mainnet_10.snap create mode 100644 zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@testnet_10.snap diff --git a/zebra-rpc/src/methods/tests/snapshot.rs b/zebra-rpc/src/methods/tests/snapshot.rs index eff36b3f991..2bdec5d7497 100644 --- a/zebra-rpc/src/methods/tests/snapshot.rs +++ b/zebra-rpc/src/methods/tests/snapshot.rs @@ -451,6 +451,13 @@ async fn test_rpc_response_data_for_network(network: &Network) { settings.bind(|| insta::assert_json_snapshot!(format!("getrawtransaction_unknown_txid"), rsp)); mempool.expect_no_requests().await; + // `getrawtransaction` with an invalid TXID + let rsp = rpc + .get_raw_transaction("aBadC0de".to_owned(), Some(1)) + .await; + settings.bind(|| insta::assert_json_snapshot!(format!("getrawtransaction_invalid_txid"), rsp)); + mempool.expect_no_requests().await; + // `getaddresstxids` let get_address_tx_ids = rpc .get_address_tx_ids(GetAddressTxIdsRequest { diff --git a/zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@mainnet_10.snap b/zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@mainnet_10.snap new file mode 100644 index 00000000000..e048f7ad516 --- /dev/null +++ b/zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@mainnet_10.snap @@ -0,0 +1,11 @@ +--- +source: zebra-rpc/src/methods/tests/snapshot.rs +expression: rsp +snapshot_kind: text +--- +{ + "Err": { + "code": -5, + "message": "Invalid string length" + } +} diff --git a/zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@testnet_10.snap b/zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@testnet_10.snap new file mode 100644 index 00000000000..e048f7ad516 --- /dev/null +++ b/zebra-rpc/src/methods/tests/snapshots/getrawtransaction_invalid_txid@testnet_10.snap @@ -0,0 +1,11 @@ +--- +source: zebra-rpc/src/methods/tests/snapshot.rs +expression: rsp +snapshot_kind: text +--- +{ + "Err": { + "code": -5, + "message": "Invalid string length" + } +} diff --git a/zebra-rpc/src/methods/tests/vectors.rs b/zebra-rpc/src/methods/tests/vectors.rs index f4ae6257be8..998cdc155ee 100644 --- a/zebra-rpc/src/methods/tests/vectors.rs +++ b/zebra-rpc/src/methods/tests/vectors.rs @@ -728,7 +728,7 @@ async fn rpc_getrawtransaction() { let rpc_req = rpc.get_raw_transaction(tx.hash().encode_hex(), Some(0u8)); let (rsp, _) = futures::join!(rpc_req, mempool_req); - let get_tx = rsp.expect("We should have a "); + let get_tx = rsp.expect("we should have a `GetRawTransaction` struct"); if let GetRawTransaction::Raw(raw_tx) = get_tx { assert_eq!(raw_tx.as_ref(), tx.zcash_serialize_to_vec().unwrap());