@@ -1269,3 +1269,76 @@ func testFundingManagerFundingTimeout(ht *lntest.HarnessTest) {
12691269 // Cleanup the mempool by mining blocks.
12701270 ht .MineBlocksAndAssertNumTxes (6 , 1 )
12711271}
1272+
1273+ // testOpenChannelWithShutdownAddr verifies that if the funder or fundee
1274+ // specifies an upfront shutdown address in the config, the funds are correctly
1275+ // transferred to the specified address during channel closure.
1276+ func testOpenChannelWithShutdownAddr (ht * lntest.HarnessTest ) {
1277+ const (
1278+ // Channel funding amount in sat.
1279+ channelAmount int64 = 100000
1280+
1281+ // Payment amount in sat.
1282+ paymentAmount int64 = 50000
1283+ )
1284+
1285+ // Create nodes for testing, ensuring Alice has sufficient initial
1286+ // funds.
1287+ alice := ht .NewNodeWithCoins ("Alice" , nil )
1288+ bob := ht .NewNode ("Bob" , nil )
1289+
1290+ // Generate upfront shutdown addresses for both nodes.
1291+ aliceShutdownAddr := alice .RPC .NewAddress (& lnrpc.NewAddressRequest {
1292+ Type : lnrpc .AddressType_UNUSED_WITNESS_PUBKEY_HASH ,
1293+ })
1294+ bobShutdownAddr := bob .RPC .NewAddress (& lnrpc.NewAddressRequest {
1295+ Type : lnrpc .AddressType_UNUSED_WITNESS_PUBKEY_HASH ,
1296+ })
1297+
1298+ // Update nodes with upfront shutdown addresses and restart them.
1299+ aliceNodeArgs := []string {
1300+ fmt .Sprintf (
1301+ "--upfront-shutdown-address=%s" ,
1302+ aliceShutdownAddr .Address ,
1303+ ),
1304+ }
1305+ ht .RestartNodeWithExtraArgs (alice , aliceNodeArgs )
1306+
1307+ bobNodeArgs := []string {
1308+ fmt .Sprintf (
1309+ "--upfront-shutdown-address=%s" ,
1310+ bobShutdownAddr .Address ,
1311+ ),
1312+ }
1313+ ht .RestartNodeWithExtraArgs (bob , bobNodeArgs )
1314+
1315+ // Connect Alice and Bob.
1316+ ht .ConnectNodes (alice , bob )
1317+
1318+ // Open a channel between Alice and Bob.
1319+ openChannelParams := lntest.OpenChannelParams {
1320+ Amt : btcutil .Amount (channelAmount ),
1321+ PushAmt : btcutil .Amount (paymentAmount ),
1322+ }
1323+ channelPoint := ht .OpenChannel (alice , bob , openChannelParams )
1324+
1325+ // Now close out the channel and obtain the raw closing TX.
1326+ closingTxid := ht .CloseChannel (alice , channelPoint )
1327+ closingTx := ht .GetRawTransaction (closingTxid ).MsgTx ()
1328+
1329+ // Calculate Alice's updated balance.
1330+ aliceFee := ht .CalculateTxFee (closingTx )
1331+ aliceExpectedBalance := channelAmount - paymentAmount - int64 (aliceFee )
1332+
1333+ // Ensure Alice sees the change output in the list of unspent outputs.
1334+ // We expect 6 confirmed UTXOs, as 5 UTXOs of 1 BTC each were sent to
1335+ // the node during NewNodeWithCoins.
1336+ aliceUTXOConfirmed := ht .AssertNumUTXOsConfirmed (alice , 6 )[0 ]
1337+ require .Equal (ht , aliceShutdownAddr .Address , aliceUTXOConfirmed .Address )
1338+ require .Equal (ht , aliceExpectedBalance , aliceUTXOConfirmed .AmountSat )
1339+
1340+ // Ensure Bob see the change output in the list of unspent outputs.
1341+ bobUTXOConfirmed := ht .AssertNumUTXOsConfirmed (bob , 1 )[0 ]
1342+ require .Equal (ht , bobShutdownAddr .Address , bobUTXOConfirmed .Address )
1343+ require .Equal (ht , paymentAmount , bobUTXOConfirmed .AmountSat )
1344+ }
0 commit comments