@@ -480,6 +480,106 @@ pub struct PsbtFixture {
480480 pub extracted_transaction : Option < String > ,
481481}
482482
483+ // Test helper types for multi-stage PSBT testing
484+
485+ pub struct PsbtStages {
486+ pub network : Network ,
487+ pub tx_format : TxFormat ,
488+ pub wallet_keys : crate :: fixed_script_wallet:: RootWalletKeys ,
489+ pub unsigned : PsbtFixture ,
490+ pub halfsigned : PsbtFixture ,
491+ pub fullsigned : PsbtFixture ,
492+ }
493+
494+ impl PsbtStages {
495+ pub fn load ( network : Network , tx_format : TxFormat ) -> Result < Self , String > {
496+ let unsigned = load_psbt_fixture_with_format (
497+ network. to_utxolib_name ( ) ,
498+ SignatureState :: Unsigned ,
499+ tx_format,
500+ )
501+ . expect ( "Failed to load unsigned fixture" ) ;
502+ let halfsigned = load_psbt_fixture_with_format (
503+ network. to_utxolib_name ( ) ,
504+ SignatureState :: Halfsigned ,
505+ tx_format,
506+ )
507+ . expect ( "Failed to load halfsigned fixture" ) ;
508+ let fullsigned = load_psbt_fixture_with_format (
509+ network. to_utxolib_name ( ) ,
510+ SignatureState :: Fullsigned ,
511+ tx_format,
512+ )
513+ . expect ( "Failed to load fullsigned fixture" ) ;
514+ let wallet_keys_unsigned =
515+ parse_wallet_keys ( & unsigned) . expect ( "Failed to parse wallet keys" ) ;
516+ let wallet_keys_halfsigned =
517+ parse_wallet_keys ( & halfsigned) . expect ( "Failed to parse wallet keys" ) ;
518+ let wallet_keys_fullsigned =
519+ parse_wallet_keys ( & fullsigned) . expect ( "Failed to parse wallet keys" ) ;
520+ assert_eq ! ( wallet_keys_unsigned, wallet_keys_halfsigned) ;
521+ assert_eq ! ( wallet_keys_unsigned, wallet_keys_fullsigned) ;
522+ let secp = crate :: bitcoin:: secp256k1:: Secp256k1 :: new ( ) ;
523+ let wallet_keys = crate :: fixed_script_wallet:: RootWalletKeys :: new (
524+ wallet_keys_unsigned
525+ . iter ( )
526+ . map ( |x| crate :: bitcoin:: bip32:: Xpub :: from_priv ( & secp, x) )
527+ . collect :: < Vec < _ > > ( )
528+ . try_into ( )
529+ . expect ( "Failed to convert to XpubTriple" ) ,
530+ ) ;
531+
532+ Ok ( Self {
533+ network,
534+ tx_format,
535+ wallet_keys,
536+ unsigned,
537+ halfsigned,
538+ fullsigned,
539+ } )
540+ }
541+ }
542+
543+ pub struct PsbtInputStages {
544+ pub network : Network ,
545+ pub tx_format : TxFormat ,
546+ pub wallet_keys : crate :: fixed_script_wallet:: RootWalletKeys ,
547+ pub wallet_script_type : ScriptType ,
548+ pub input_index : usize ,
549+ pub input_fixture_unsigned : PsbtInputFixture ,
550+ pub input_fixture_halfsigned : PsbtInputFixture ,
551+ pub input_fixture_fullsigned : PsbtInputFixture ,
552+ }
553+
554+ impl PsbtInputStages {
555+ pub fn from_psbt_stages (
556+ psbt_stages : & PsbtStages ,
557+ wallet_script_type : ScriptType ,
558+ ) -> Result < Self , String > {
559+ let input_fixture_unsigned = psbt_stages
560+ . unsigned
561+ . find_input_with_script_type ( wallet_script_type) ?;
562+ let input_fixture_halfsigned = psbt_stages
563+ . halfsigned
564+ . find_input_with_script_type ( wallet_script_type) ?;
565+ let input_fixture_fullsigned = psbt_stages
566+ . fullsigned
567+ . find_input_with_script_type ( wallet_script_type) ?;
568+ assert_eq ! ( input_fixture_unsigned. 0 , input_fixture_halfsigned. 0 ) ;
569+ assert_eq ! ( input_fixture_unsigned. 0 , input_fixture_fullsigned. 0 ) ;
570+ Ok ( Self {
571+ network : psbt_stages. network ,
572+ tx_format : psbt_stages. tx_format ,
573+ wallet_keys : psbt_stages. wallet_keys . clone ( ) ,
574+ wallet_script_type,
575+ input_index : input_fixture_unsigned. 0 ,
576+ input_fixture_unsigned : input_fixture_unsigned. 1 . clone ( ) ,
577+ input_fixture_halfsigned : input_fixture_halfsigned. 1 . clone ( ) ,
578+ input_fixture_fullsigned : input_fixture_fullsigned. 1 . clone ( ) ,
579+ } )
580+ }
581+ }
582+
483583/// Helper function to find a unique input matching a predicate
484584fn find_unique_input < ' a , T , I , F > (
485585 iter : I ,
0 commit comments