From 7ead9ba80431060e5ba4953587c7bde8ed9db3a3 Mon Sep 17 00:00:00 2001 From: Leonardo Comandini Date: Mon, 17 Mar 2025 18:53:27 +0100 Subject: [PATCH 1/2] elip101: add test for abf serialization roundtrip --- src/pset/elip101.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/pset/elip101.rs b/src/pset/elip101.rs index 859cbcb5..bd30d739 100644 --- a/src/pset/elip101.rs +++ b/src/pset/elip101.rs @@ -67,6 +67,7 @@ impl Output { #[cfg(test)] mod test { use super::*; + use crate::AssetId; use crate::encode::{serialize_hex, Encodable}; use crate::hex::{FromHex, ToHex}; @@ -110,4 +111,31 @@ mod test { assert!(output_hex.contains(ELIP0101_IDENTIFIER)); assert!(output_hex.contains(abf_hex)); } + + #[test] + fn abf_roundtrip() { + use crate::pset::PartiallySignedTransaction; + + // Set abf on an input and on an output + let abf = AssetBlindingFactor::from_slice(&[3; 32]).unwrap(); + let mut pset = PartiallySignedTransaction::new_v2(); + let mut input = Input::default(); + input.set_abf(abf); + pset.add_input(input); + let mut output = Output { + amount: Some(1), + asset: Some(AssetId::from_slice(&[9; 32]).unwrap()), + ..Default::default() + }; + output.set_abf(abf); + pset.add_output(output); + + // Serialize and deserialize + let bytes = encode::serialize(&pset); + let pset_back = encode::deserialize::(&bytes).unwrap(); + // Check the abf + // FIXME: input abf should be there + assert!(pset_back.inputs()[0].get_abf().is_none()); + assert_eq!(pset_back.outputs()[0].get_abf().unwrap().unwrap(), abf); + } } From 45267c90e0694a2b97ba11b8c297e75178042528 Mon Sep 17 00:00:00 2001 From: Leonardo Comandini Date: Mon, 17 Mar 2025 18:59:03 +0100 Subject: [PATCH 2/2] pset: input: insert non-pset proprietary keys As it is done for pset outputs. --- src/pset/elip101.rs | 3 +-- src/pset/map/input.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pset/elip101.rs b/src/pset/elip101.rs index bd30d739..05886c8b 100644 --- a/src/pset/elip101.rs +++ b/src/pset/elip101.rs @@ -134,8 +134,7 @@ mod test { let bytes = encode::serialize(&pset); let pset_back = encode::deserialize::(&bytes).unwrap(); // Check the abf - // FIXME: input abf should be there - assert!(pset_back.inputs()[0].get_abf().is_none()); + assert_eq!(pset_back.inputs()[0].get_abf().unwrap().unwrap(), abf); assert_eq!(pset_back.outputs()[0].get_abf().unwrap().unwrap(), abf); } } diff --git a/src/pset/map/input.rs b/src/pset/map/input.rs index 39801d6e..0ab407b6 100644 --- a/src/pset/map/input.rs +++ b/src/pset/map/input.rs @@ -759,8 +759,18 @@ impl Map for Input { Entry::Occupied(_) => return Err(Error::DuplicateKey(raw_key).into()), }, } + } else { + match self.proprietary.entry(prop_key) { + Entry::Vacant(empty_key) => { + empty_key.insert(raw_value); + } + Entry::Occupied(_) => { + return Err(Error::DuplicateKey(raw_key).into()) + } + } } } + _ => match self.unknown.entry(raw_key) { Entry::Vacant(empty_key) => { empty_key.insert(raw_value);