@@ -139,6 +139,26 @@ describe(`Esplora client (${network})`, () => {
139139 expect ( wallet . latest_checkpoint . height ) . toBeGreaterThan ( 0 ) ;
140140 } , 30000 ) ;
141141
142+ it ( "lists scanned outputs and resolves known UTXOs" , ( ) => {
143+ const utxos = wallet . list_unspent ( ) ;
144+
145+ expect ( utxos . length ) . toBeGreaterThan ( 0 ) ;
146+
147+ const firstUtxo = utxos [ 0 ] ;
148+ const resolved = wallet . get_utxo ( firstUtxo . outpoint ) ;
149+
150+ expect ( resolved ) . toBeDefined ( ) ;
151+ expect ( resolved ! . outpoint . toString ( ) ) . toBe ( firstUtxo . outpoint . toString ( ) ) ;
152+ expect ( resolved ! . derivation_index ) . toBe ( firstUtxo . derivation_index ) ;
153+ expect ( resolved ! . txout . value . to_sat ( ) ) . toBe ( firstUtxo . txout . value . to_sat ( ) ) ;
154+ expect ( wallet . is_mine ( firstUtxo . txout . script_pubkey ) ) . toBe ( true ) ;
155+ expect (
156+ wallet
157+ . list_output ( )
158+ . some ( ( output ) => output . outpoint . toString ( ) === firstUtxo . outpoint . toString ( ) )
159+ ) . toBe ( true ) ;
160+ } ) ;
161+
142162 it ( "fetches fee estimates" , async ( ) => {
143163 const confirmationTarget = 2 ;
144164 const feeEstimates = await esploraClient . get_fee_estimates ( ) ;
@@ -232,6 +252,35 @@ describe(`Esplora client (${network})`, () => {
232252 ) ;
233253 } ) ;
234254
255+ it ( "calculates fee and fee rate for signed wallet transactions" , ( ) => {
256+ const recipientAddress = wallet . peek_address ( "external" , 15 ) ;
257+ const sendAmount = Amount . from_sat ( BigInt ( 800 ) ) ;
258+
259+ const psbt = wallet
260+ . build_tx ( )
261+ . fee_rate ( new FeeRate ( BigInt ( 1 ) ) )
262+ . add_recipient (
263+ new Recipient ( recipientAddress . address . script_pubkey , sendAmount )
264+ )
265+ . finish ( ) ;
266+
267+ const expectedFee = psbt . fee ( ) . to_sat ( ) ;
268+
269+ expect ( wallet . sign ( psbt , new SignOptions ( ) ) ) . toBe ( true ) ;
270+
271+ const expectedFeeRate = psbt . fee_rate ( ) ;
272+ expect ( expectedFeeRate ) . toBeDefined ( ) ;
273+
274+ const tx = psbt . extract_tx ( ) ;
275+ const calculatedFee = wallet . calculate_fee ( tx ) ;
276+ const calculatedFeeRate = wallet . calculate_fee_rate ( tx ) ;
277+
278+ expect ( calculatedFee . to_sat ( ) ) . toBe ( expectedFee ) ;
279+ expect ( calculatedFeeRate . to_sat_per_vb_ceil ( ) ) . toBe (
280+ expectedFeeRate ! . to_sat_per_vb_ceil ( )
281+ ) ;
282+ } ) ;
283+
235284 describe ( "TxBuilder advanced options (funded wallet)" , ( ) => {
236285 // Note: FeeRate is consumed by wasm-bindgen when passed to a builder method,
237286 // so we create fresh instances for each test instead of using the shared feeRate.
0 commit comments