@@ -37,9 +37,13 @@ pub mod types;
3737mod tests {
3838 use crate :: types;
3939 use crate :: HWIClient ;
40+ use std:: collections:: BTreeMap ;
4041 use std:: str:: FromStr ;
4142
42- use bitcoin:: util:: bip32:: DerivationPath ;
43+ use bitcoin:: psbt:: { Input , Output } ;
44+ use bitcoin:: util:: bip32:: { DerivationPath , KeySource } ;
45+ use bitcoin:: { secp256k1, Transaction } ;
46+ use bitcoin:: { TxIn , TxOut } ;
4347
4448 #[ test]
4549 #[ serial]
@@ -145,10 +149,62 @@ mod tests {
145149 // #[serial]
146150 // fn test_display_address_with_path_taproot() {}
147151
148- // TODO: Create PSBT with scratch using given Hardware Wallet
149- // #[test]
150- // #[serial]
151- // fn test_sign_tx() {}
152+ #[ test]
153+ #[ serial]
154+ fn test_sign_tx ( ) {
155+ let devices = HWIClient :: enumerate ( ) . unwrap ( ) ;
156+ let device = devices. first ( ) . unwrap ( ) ;
157+ let client = HWIClient :: get_client ( device, true , types:: HWIChain :: Test ) . unwrap ( ) ;
158+ let derivation_path = DerivationPath :: from_str ( "m/44'/1'/0'/0/0" ) . unwrap ( ) ;
159+
160+ let address = client
161+ . display_address_with_path ( & derivation_path, types:: HWIAddressType :: Legacy )
162+ . unwrap ( ) ;
163+
164+ let pk = client. get_xpub ( & derivation_path, true ) . unwrap ( ) ;
165+ let mut hd_keypaths: BTreeMap < secp256k1:: PublicKey , KeySource > = Default :: default ( ) ;
166+ hd_keypaths. insert ( pk. public_key , ( device. fingerprint , derivation_path) ) ;
167+
168+ let tx = Transaction {
169+ version : 1 ,
170+ lock_time : 0 ,
171+ input : vec ! [ TxIn :: default ( ) ] ,
172+ output : vec ! [ TxOut {
173+ value: 100 ,
174+ script_pubkey: address. address. script_pubkey( ) ,
175+ } ] ,
176+ } ;
177+
178+ let txin = TxIn {
179+ previous_output : bitcoin:: OutPoint {
180+ txid : tx. txid ( ) ,
181+ vout : Default :: default ( ) ,
182+ } ,
183+ ..Default :: default ( )
184+ } ;
185+ let psbt = bitcoin:: psbt:: PartiallySignedTransaction {
186+ unsigned_tx : Transaction {
187+ version : 1 ,
188+ lock_time : 0 ,
189+ input : vec ! [ txin] ,
190+ output : vec ! [ ] ,
191+ } ,
192+ xpub : Default :: default ( ) ,
193+ version : 0 ,
194+ proprietary : BTreeMap :: new ( ) ,
195+ unknown : BTreeMap :: new ( ) ,
196+
197+ inputs : vec ! [ Input {
198+ non_witness_utxo: Some ( tx) ,
199+ witness_utxo: None ,
200+ bip32_derivation: hd_keypaths,
201+ ..Default :: default ( )
202+ } ] ,
203+ outputs : vec ! [ Output :: default ( ) , Output :: default ( ) ] ,
204+ } ;
205+ let client = get_first_device ( ) ;
206+ client. sign_tx ( & psbt) . unwrap ( ) ;
207+ }
152208
153209 #[ test]
154210 #[ serial]
0 commit comments