From 2df32e0ee0045caba533cc62026b0f9579719f4c Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 14 Oct 2024 10:13:11 -0600 Subject: [PATCH] zcash_keys: Add a test for parsing a problematic mainnet address. --- Cargo.lock | 1 + zcash_keys/Cargo.toml | 1 + zcash_keys/src/encoding.rs | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d81ef639d..dc20e975e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5985,6 +5985,7 @@ dependencies = [ name = "zcash_keys" version = "0.4.0" dependencies = [ + "assert_matches", "bech32", "bip32", "blake2b_simd", diff --git a/zcash_keys/Cargo.toml b/zcash_keys/Cargo.toml index 5f1f5382a9..45f7e9e040 100644 --- a/zcash_keys/Cargo.toml +++ b/zcash_keys/Cargo.toml @@ -67,6 +67,7 @@ byteorder = { workspace = true, optional = true } blake2b_simd = { workspace = true } [dev-dependencies] +assert_matches.workspace = true hex.workspace = true jubjub.workspace = true proptest.workspace = true diff --git a/zcash_keys/src/encoding.rs b/zcash_keys/src/encoding.rs index cb31b625a8..6f61b0938b 100644 --- a/zcash_keys/src/encoding.rs +++ b/zcash_keys/src/encoding.rs @@ -517,13 +517,16 @@ pub fn decode_transparent_address( #[cfg(test)] #[cfg(feature = "sapling")] mod tests_sapling { + use assert_matches::assert_matches; + use zcash_protocol::consensus::Network; + use super::{ decode_extended_full_viewing_key, decode_extended_spending_key, decode_payment_address, encode_extended_full_viewing_key, encode_extended_spending_key, encode_payment_address, - Bech32DecodeError, + AddressCodec, Bech32DecodeError, }; use sapling::{zip32::ExtendedSpendingKey, PaymentAddress}; - use zcash_primitives::constants; + use zcash_primitives::{constants, legacy::TransparentAddress}; #[test] fn extended_spending_key() { @@ -689,4 +692,14 @@ mod tests_sapling { Err(Bech32DecodeError::ReadError) ); } + + #[test] + fn linear_pro_278() { + let encoded = "t1gDxhpMTfKJCyTgUHppnEkUonrcqMVL8J8"; + + assert_matches!( + TransparentAddress::decode(&Network::MainNetwork, encoded), + Ok(_) + ); + } }