test: add p2pkh transparent-output decode test
What changed, and why it matters
This commit only adds a new automated test for Zcash transparent output parsing. It builds a sample pay-to-public-key-hash (p2pkh) output at runtime and checks that the parser correctly extracts the recipient address, value, and 'not change' classification. There is no change to production code, no bug fix, and no security-relevant behavior change.
No action required. This is a test-only addition with no security implications.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds one helper function and one unit test in rust/apps/zcash/src/pczt/parse.rs. The helper constructs a transparent p2pkh output script (OP_DUP OP_HASH160 <20-byte hash> OP_EQUALVERIFY OP_CHECKSIG), wraps it in a pczt::Output, and the test verifies parse_transparent_output returns the expected address prefix, formatted value, and is_change=false. It mirrors an existing p2sh output test. No production parsing logic is modified.
Changed components
rust/apps/zcash/src/pczt/parse.rs (test module only)Inspect captured patch +37 / −0
diff --git a/rust/apps/zcash/src/pczt/parse.rs b/rust/apps/zcash/src/pczt/parse.rs
index d49be3b..6a06ab0 100644
--- a/rust/apps/zcash/src/pczt/parse.rs
+++ b/rust/apps/zcash/src/pczt/parse.rs
@@ -924,6 +924,43 @@ mod tests {
assert!(!parsed.get_is_change());
}
+ fn p2pkh_output_to_external_recipient(value: u64) -> transparent::pczt::Output {
+ let hash = [0x11; 20];
+ let script_pubkey = {
+ // OP_DUP OP_HASH160 <20-byte push> OP_EQUALVERIFY OP_CHECKSIG
+ let mut script = vec![0x76, 0xa9, 0x14];
+ script.extend_from_slice(&hash);
+ script.push(0x88);
+ script.push(0xac);
+ script
+ };
+ let user_address =
+ ZcashAddress::from_transparent_p2pkh(MAIN_NETWORK.network_type(), hash).encode();
+ // No bip32_derivation: this output goes to an address we don't control.
+ pczt::Output::parse(
+ value,
+ script_pubkey,
+ None,
+ BTreeMap::new(),
+ Some(user_address),
+ BTreeMap::new(),
+ )
+ .unwrap()
+ }
+
+ #[test]
+ fn test_parse_p2pkh_output_decodes_recipient_address_and_value() {
+ let seed_fingerprint = [0x22; 32];
+ let output = p2pkh_output_to_external_recipient(100_000);
+
+ let parsed = parse_transparent_output(&MAIN_NETWORK, &seed_fingerprint, &output).unwrap();
+
+ assert!(parsed.get_address().starts_with("t1"));
+ assert_eq!(parsed.get_value(), "0.001 ZEC");
+ // A p2pkh output to an address we don't control is a recipient, not change.
+ assert!(!parsed.get_is_change());
+ }
+
#[test]
fn test_decode_memo_with_hex_content() {
{
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.