@@ -556,12 +556,12 @@ uniffi::deps::static_assertions::assert_impl_all!(Wallet: Sync, Send);
556556// crate.
557557#[ cfg( test) ]
558558mod test {
559- use crate :: { TxBuilder , Wallet } ;
560- use bdk:: bitcoin:: Address ;
559+ use crate :: { DerivationPath , ExtendedPrivKey , TxBuilder , Wallet } ;
561560 use bdk:: bitcoin:: Network :: Testnet ;
561+ use bdk:: bitcoin:: { Address , Network } ;
562562 use bdk:: wallet:: get_funded_wallet;
563563 use std:: str:: FromStr ;
564- use std:: sync:: Mutex ;
564+ use std:: sync:: { Arc , Mutex } ;
565565
566566 #[ test]
567567 fn test_drain_wallet ( ) {
@@ -616,4 +616,38 @@ mod test {
616616 let output_value = psbt. unsigned_tx . output . get ( 0 ) . cloned ( ) . unwrap ( ) . value ;
617617 assert_eq ! ( output_value, 49_890 as u64 ) ; // input - fee
618618 }
619+
620+ #[ test]
621+ fn test_generate_extended_priv_key ( ) {
622+ let mnemonic =
623+ "option hub fatigue fork harbor cement fatal couple kit cloth life toilet" . to_string ( ) ;
624+ let extended_priv_key = ExtendedPrivKey :: new ( Network :: Testnet , mnemonic, None ) . unwrap ( ) ;
625+ assert_eq ! ( extended_priv_key. to_string( ) , "tprv8ZgxMBicQKsPf1bXwktHW7GQDBgYBXnpUu5LdYckxpcQcqUEh2YFEad9jYB1TVo41vGRoUSjoQ5MwWonJYqXNMUbXrGPX96yKB8zdzjXKCK" . to_string( ) )
626+ }
627+
628+ #[ test]
629+ fn test_derive_extended_priv_key ( ) {
630+ let mnemonic =
631+ "option hub fatigue fork harbor cement fatal couple kit cloth life toilet" . to_string ( ) ;
632+ let extended_priv_key = ExtendedPrivKey :: new ( Network :: Testnet , mnemonic, None ) . unwrap ( ) ;
633+ let derivation_path = DerivationPath :: new ( "m/84'/1'/0'/0" . to_string ( ) ) . unwrap ( ) ;
634+ let derived_extended_priv_key =
635+ extended_priv_key. derive_xprv ( Some ( Arc :: new ( derivation_path) ) ) ;
636+ assert_eq ! ( derived_extended_priv_key. to_string( ) , "tprv8hstRa2WtkiWegA8t9VMah1C7BZhG2KkENt7Fr4GT4SpTPKCfX7WWbeihv2ZDkzWoLx2wouKXYsj2eRo54UNGCbVog8QS2kLNvj2b3TmMEx" . to_string( ) ) ;
637+ let derived_extended_priv_key_no_path = extended_priv_key. derive_xprv ( None ) ;
638+ assert_eq ! ( derived_extended_priv_key_no_path. to_string( ) , "tprv8ZgxMBicQKsPf1bXwktHW7GQDBgYBXnpUu5LdYckxpcQcqUEh2YFEad9jYB1TVo41vGRoUSjoQ5MwWonJYqXNMUbXrGPX96yKB8zdzjXKCK" . to_string( ) ) ;
639+ }
640+
641+ #[ test]
642+ fn test_derive_extended_pub_key ( ) {
643+ let mnemonic =
644+ "option hub fatigue fork harbor cement fatal couple kit cloth life toilet" . to_string ( ) ;
645+ let extended_priv_key = ExtendedPrivKey :: new ( Network :: Testnet , mnemonic, None ) . unwrap ( ) ;
646+ let derivation_path = DerivationPath :: new ( "m/84'/1'/0'/0" . to_string ( ) ) . unwrap ( ) ;
647+ let derived_extended_pub_key =
648+ extended_priv_key. derive_xpub ( Some ( Arc :: new ( derivation_path) ) ) ;
649+ assert_eq ! ( derived_extended_pub_key. to_string( ) , "tpubDEZvZz4m38QBY9Bvmo9wz6fJgD5dRMWeogUtYN6ZsLFDHsZyHuw6h6Gat43Ltiq1wbeoJLzb3dQpWEnr5uf2gBDjduqsn1ikTCqye3vYcy5" ) ;
650+ let derived_extended_pub_key_no_path = extended_priv_key. derive_xpub ( None ) ;
651+ assert_eq ! ( derived_extended_pub_key_no_path. to_string( ) , "tpubD6NzVbkrYhZ4YUdKqQYsuWvWnDCULryj4Cg7v4f4P6QoTKj1KRMqR5F1ugxoXDcdaTMGqvsK61dQe8npmn85fmaJ4uEHACGpWsMuEv2upVi" . to_string( ) ) ;
652+ }
619653}
0 commit comments