Skip to content

Commit

Permalink
mod+itest: add test case for initiator having zero balance
Browse files Browse the repository at this point in the history
This commit adds a test case for the edge case that previously lead to a
panic in the sender of an HTLC if the initiator of a channel didn't have
any asset balance in the channel anymore.
  • Loading branch information
guggero committed Jul 16, 2024
1 parent d3bdd03 commit 3da641a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/lightninglabs/loop/swapserverrpc v1.0.8
github.com/lightninglabs/pool v0.6.5-beta.0.20240604070222-e121aadb3289
github.com/lightninglabs/pool/auctioneerrpc v1.1.2
github.com/lightninglabs/taproot-assets v0.4.0-rc4
github.com/lightninglabs/taproot-assets v0.4.0-rc4.0.20240716183814-7647ba8f48d5
github.com/lightningnetwork/lnd v0.18.0-beta.rc4.0.20240712025014-90f997c908d0
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/fn v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,8 @@ github.com/lightninglabs/pool/auctioneerrpc v1.1.2 h1:Dbg+9Z9jXnhimR27EN37foc4aB
github.com/lightninglabs/pool/auctioneerrpc v1.1.2/go.mod h1:1wKDzN2zEP8srOi0B9iySlEsPdoPhw6oo3Vbm1v4Mhw=
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display h1:pRdza2wleRN1L2fJXd6ZoQ9ZegVFTAb2bOQfruJPKcY=
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
github.com/lightninglabs/taproot-assets v0.4.0-rc4 h1:tl8gClGZBmLlkMxfDRVAdIhx+LyhThZCEjYBpuM37pc=
github.com/lightninglabs/taproot-assets v0.4.0-rc4/go.mod h1:oAiEnRj2sCbPHAURot+tmKbyDhIoxnvkmag0JqlF1bs=
github.com/lightninglabs/taproot-assets v0.4.0-rc4.0.20240716183814-7647ba8f48d5 h1:+d5HMOuBUWMsUVx6tAzy7+g8m4A76tec5/FOb1w5iVs=
github.com/lightninglabs/taproot-assets v0.4.0-rc4.0.20240716183814-7647ba8f48d5/go.mod h1:oAiEnRj2sCbPHAURot+tmKbyDhIoxnvkmag0JqlF1bs=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f h1:Pua7+5TcFEJXIIZ1I2YAUapmbcttmLj4TTi786bIi3s=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
github.com/lightningnetwork/lnd v0.18.0-beta.rc4.0.20240712025014-90f997c908d0 h1:V+PoltFSxN5oijkErYe+QbnVz5WJjBsAzaMNRrhmz3Q=
Expand Down
34 changes: 26 additions & 8 deletions itest/litd_custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,32 +369,50 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
logBalance(t.t, nodes, assetID, "initial")

// ------------
// Test case 1: Send a direct keysend payment from Charlie to Dave.
// Test case 1: Send a direct keysend payment from Charlie to Dave,
// sending the whole balance.
// ------------
const keySendAmount = 1000
keySendAmount := charlieFundingAmount
sendAssetKeySendPayment(
t.t, charlie, dave, keySendAmount, assetID, fn.None[int64](),
t.t, charlie, dave, charlieFundingAmount, assetID,
fn.None[int64](),
)
logBalance(t.t, nodes, assetID, "after keysend")

charlieAssetBalance -= keySendAmount
daveAssetBalance += keySendAmount

// We should be able to send the 1000 assets back immediately, because
// We should be able to send 1000 assets back immediately, because
// there is enough on-chain balance on Dave's side to be able to create
// an HTLC. We use an invoice to execute another code path.
const charlieInvoiceAmount = 1_000
invoiceResp := createAssetInvoice(
t.t, dave, charlie, keySendAmount, assetID,
t.t, dave, charlie, charlieInvoiceAmount, assetID,
)
payInvoiceWithAssets(t.t, dave, charlie, invoiceResp, assetID, true)
logBalance(t.t, nodes, assetID, "after invoice back")

charlieAssetBalance += keySendAmount
daveAssetBalance -= keySendAmount
charlieAssetBalance += charlieInvoiceAmount
daveAssetBalance -= charlieInvoiceAmount

// We should also be able to do a non-asset (BTC only) keysend payment.
// We should also be able to do a non-asset (BTC only) keysend payment
// from Charlie to Dave. This'll also replenish the BTC balance of
// Dave, making it possible to send another asset HTLC below, sending
// all assets back to Charlie (so we have enough balance for further
// tests).
sendKeySendPayment(t.t, charlie, dave, 2000, nil)
logBalance(t.t, nodes, assetID, "after BTC only keysend")

// Let's keysend the rest of the balance back to Charlie.
sendAssetKeySendPayment(
t.t, dave, charlie, charlieFundingAmount-charlieInvoiceAmount,
assetID, fn.None[int64](),
)
logBalance(t.t, nodes, assetID, "after keysend back")

charlieAssetBalance += charlieFundingAmount - charlieInvoiceAmount
daveAssetBalance -= charlieFundingAmount - charlieInvoiceAmount

// ------------
// Test case 2: Pay a normal invoice from Dave by Charlie, making it
// a direct channel invoice payment with no RFQ SCID present in the
Expand Down

0 comments on commit 3da641a

Please sign in to comment.