@@ -3,6 +3,7 @@ package itest
33import  (
44	"bytes" 
55	"context" 
6+ 	"encoding/hex" 
67	"fmt" 
78	"math" 
89	"math/big" 
@@ -12,6 +13,7 @@ import (
1213	"github.com/btcsuite/btcd/btcec/v2/schnorr" 
1314	"github.com/btcsuite/btcd/btcutil" 
1415	"github.com/btcsuite/btcd/chaincfg/chainhash" 
16+ 	"github.com/btcsuite/btcd/wire" 
1517	"github.com/lightninglabs/taproot-assets/asset" 
1618	"github.com/lightninglabs/taproot-assets/itest" 
1719	"github.com/lightninglabs/taproot-assets/proof" 
@@ -3261,8 +3263,8 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
32613263	// At this point, both sides should have 4 (or +4 with MPP) HTLCs 
32623264	// active. 
32633265	numHtlcs  :=  4 
3266+ 	numAdditionalShards  :=  assetInvoiceAmt  /  assetsPerMPPShard 
32643267	if  mpp  {
3265- 		numAdditionalShards  :=  assetInvoiceAmt  /  assetsPerMPPShard 
32663268		numHtlcs  +=  numAdditionalShards  *  2 
32673269	}
32683270	t .Logf ("Asserting both Alice and Bob have %d HTLCs..." , numHtlcs )
@@ -3521,6 +3523,10 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
35213523
35223524	// We'll wait for both Alice and Bob to present their respective sweeps 
35233525	// to the sweeper. 
3526+ 	numTimeoutHTLCs  :=  1 
3527+ 	if  mpp  {
3528+ 		numTimeoutHTLCs  +=  numAdditionalShards 
3529+ 	}
35243530	assertSweepExists (
35253531		t .t , alice ,
35263532		walletrpc .WitnessType_TAPROOT_HTLC_LOCAL_OFFERED_TIMEOUT ,
@@ -3542,6 +3548,59 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
35423548	// Finally, we'll mine a single block to confirm them. 
35433549	mineBlocks (t , net , 1 , 2 )
35443550
3551+ 	// Make sure Bob swept all his HTLCs. 
3552+ 	bobSweeps , err  :=  bob .WalletKitClient .ListSweeps (
3553+ 		ctx , & walletrpc.ListSweepsRequest {
3554+ 			Verbose : true ,
3555+ 		},
3556+ 	)
3557+ 	require .NoError (t .t , err )
3558+ 
3559+ 	var  bobSweepTx  * wire.MsgTx 
3560+ 	for  _ , sweep  :=  range  bobSweeps .GetTransactionDetails ().Transactions  {
3561+ 		for  _ , tx  :=  range  timeoutSweeps  {
3562+ 			if  sweep .TxHash  ==  tx .String () {
3563+ 
3564+ 				txBytes , err  :=  hex .DecodeString (sweep .RawTxHex )
3565+ 				require .NoError (t .t , err )
3566+ 
3567+ 				bobSweepTx  =  & wire.MsgTx {}
3568+ 				err  =  bobSweepTx .Deserialize (
3569+ 					bytes .NewReader (txBytes ),
3570+ 				)
3571+ 				require .NoError (t .t , err )
3572+ 			}
3573+ 		}
3574+ 	}
3575+ 	require .NotNil (t .t , bobSweepTx , "Bob's sweep transaction not found" )
3576+ 
3577+ 	// There's always an extra input that pays for the fees. So we can only 
3578+ 	// count the remainder as HTLC inputs. 
3579+ 	numSweptHTLCs  :=  len (bobSweepTx .TxIn ) -  1 
3580+ 
3581+ 	// If we didn't yet sweep all HTLCs, then we need to wait for another 
3582+ 	// sweep. 
3583+ 	if  numSweptHTLCs  <  numTimeoutHTLCs  {
3584+ 		assertSweepExists (
3585+ 			t .t , bob ,
3586+ 			// nolint: lll 
3587+ 			walletrpc .WitnessType_TAPROOT_HTLC_OFFERED_REMOTE_TIMEOUT ,
3588+ 		)
3589+ 
3590+ 		t .Logf ("Confirming additional HTLC timeout sweep txns" )
3591+ 
3592+ 		additionalTimeoutSweeps , err  :=  waitForNTxsInMempool (
3593+ 			net .Miner .Client , 1 , shortTimeout ,
3594+ 		)
3595+ 		require .NoError (t .t , err )
3596+ 
3597+ 		t .Logf ("Asserting balance on additional timeout sweeps: %v" ,
3598+ 			additionalTimeoutSweeps )
3599+ 
3600+ 		// Finally, we'll mine a single block to confirm them. 
3601+ 		mineBlocks (t , net , 1 , 1 )
3602+ 	}
3603+ 
35453604	// At this point, Bob's balance should be incremented by an additional 
35463605	// HTLC value. 
35473606	bobExpectedBalance  +=  uint64 (assetInvoiceAmt  -  1 )
0 commit comments