Skip to content

Commit

Permalink
test: the amount of the fee invoice is taken into account when testing
Browse files Browse the repository at this point in the history
Claim coop testing of swap out time is dominating.
The reason seems to be that the channel taker balance check is stuck in an infinite loop until time out.

In the case of swap out, it seems that the amount of the fee invoice needs to be taken into account.
  • Loading branch information
YusukeShimizu committed Sep 12, 2023
1 parent 8802cf2 commit 56ad784
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/testcases.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func coopClaimTest(t *testing.T, params *testParams) {
//
// Move local balance from taker to maker so that the taker does not
// have enough balance to pay the invoice and cancels the swap coop.
feeInvoiceAmt, err := params.makerNode.GetFeeInvoiceAmtSat()
require.NoError(err)

moveAmt := (params.origTakerBalance - params.swapAmt) + 100
inv, err := params.makerNode.AddInvoice(moveAmt, "shift balance", "")
require.NoError(err)
Expand All @@ -56,8 +59,10 @@ func coopClaimTest(t *testing.T, params *testParams) {
err = testframework.WaitFor(func() bool {
setTakerFunds, err = params.takerNode.GetChannelBalanceSat(params.scid)
require.NoError(err)
return params.origTakerBalance-moveAmt-10 < setTakerFunds && setTakerFunds < params.origTakerBalance-moveAmt+10
return params.origTakerBalance-moveAmt-10-feeInvoiceAmt < setTakerFunds &&
setTakerFunds < params.origTakerBalance-moveAmt+10-feeInvoiceAmt
}, testframework.TIMEOUT)
require.NoError(err)

//
// STEP 3: Confirm opening tx
Expand Down
15 changes: 15 additions & 0 deletions testframework/clightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"regexp"
"strings"
"time"

"github.com/elementsproject/glightning/glightning"
Expand Down Expand Up @@ -504,3 +505,17 @@ func (n *CLightningNode) GetMemoFromPayreq(bolt11 string) (string, error) {

return r.Description, nil
}

func (n *CLightningNode) GetFeeInvoiceAmtSat() (sat uint64, err error) {
var feeInvoiceAmt uint64
r, err := n.Rpc.ListInvoices()
if err != nil {
return 0, err
}
for _, i := range r {
if strings.Contains(i.Description, "fee") {
feeInvoiceAmt += i.AmountMilliSatoshi.MSat() / 1000
}
}
return feeInvoiceAmt, nil
}
1 change: 1 addition & 0 deletions testframework/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type LightningNode interface {
// invoices.
GetLatestInvoice() (payreq string, err error)
GetMemoFromPayreq(payreq string) (memo string, err error)
GetFeeInvoiceAmtSat() (sat uint64, err error)

Run(waitForReady, swaitForBitcoinSynced bool) error
Stop() error
Expand Down
16 changes: 16 additions & 0 deletions testframework/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"os"
"path/filepath"
"strings"

"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire"
Expand Down Expand Up @@ -516,3 +517,18 @@ func ScidFromLndChanId(id uint64) string {
lndScid := lnwire.NewShortChanIDFromInt(id)
return fmt.Sprintf("%dx%dx%d", lndScid.BlockHeight, lndScid.TxIndex, lndScid.TxPosition)
}

func (n *LndNode) GetFeeInvoiceAmtSat() (sat uint64, err error) {
var feeInvoiceAmt uint64
r, err := n.Rpc.ListInvoices(context.Background(), &lnrpc.ListInvoiceRequest{})
if err != nil {
return 0, err
}

for _, i := range r.Invoices {
if strings.Contains(i.GetMemo(), "fee") {
feeInvoiceAmt += uint64(i.GetValue())
}
}
return feeInvoiceAmt, nil
}

0 comments on commit 56ad784

Please sign in to comment.