From 78a5f6e3665d9fdecfca7c787731af91abc352ad Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Mon, 2 May 2022 11:29:24 +0200 Subject: [PATCH 1/3] integration tests: reproduce 0 amt invoice bug --- integration_tests/incoming_payment_test.go | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/integration_tests/incoming_payment_test.go b/integration_tests/incoming_payment_test.go index 91e9b2e9..51a45e12 100644 --- a/integration_tests/incoming_payment_test.go +++ b/integration_tests/incoming_payment_test.go @@ -110,6 +110,45 @@ func (suite *IncomingPaymentTestSuite) TestIncomingPayment() { assert.Equal(suite.T(), int64(fundingSatAmt), balance.BTC.AvailableBalance) } +func (suite *IncomingPaymentTestSuite) TestIncomingPaymentZeroAmt() { + var buf bytes.Buffer + req := httptest.NewRequest(http.MethodGet, "/balance", &buf) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.userToken)) + rec := httptest.NewRecorder() + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret))) + suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance) + suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice) + suite.echo.ServeHTTP(rec, req) + //lookup balance before + balance := &ExpectedBalanceResponse{} + assert.Equal(suite.T(), http.StatusOK, rec.Code) + assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&balance)) + initialBalance := balance.BTC.AvailableBalance + fundingSatAmt := 0 + sendSatAmt := 10 + invoiceResponse := suite.createAddInvoiceReq(fundingSatAmt, "integration test IncomingPaymentTestSuite", suite.userToken) + //try to pay invoice with external node + // Prepare the LNRPC call + sendPaymentRequest := lnrpc.SendRequest{ + PaymentRequest: invoiceResponse.PayReq, + Amt: int64(sendSatAmt), + FeeLimit: nil, + } + _, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) + assert.NoError(suite.T(), err) + + //wait a bit for the callback event to hit + time.Sleep(100 * time.Millisecond) + //check balance again + req = httptest.NewRequest(http.MethodGet, "/balance", &buf) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.userToken)) + suite.echo.ServeHTTP(rec, req) + balance = &ExpectedBalanceResponse{} + assert.Equal(suite.T(), http.StatusOK, rec.Code) + assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&balance)) + //assert the payment value was added to the user's account + assert.Equal(suite.T(), initialBalance+int64(sendSatAmt), balance.BTC.AvailableBalance) +} func TestIncomingPaymentTestSuite(t *testing.T) { suite.Run(t, new(IncomingPaymentTestSuite)) From f99409d14536f249eac9608ef11266e2b510ce93 Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Mon, 2 May 2022 11:30:17 +0200 Subject: [PATCH 2/3] invoice: use rawinvoice amt paid --- lib/service/invoicesubscription.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/service/invoicesubscription.go b/lib/service/invoicesubscription.go index 580f9004..f17b7a67 100644 --- a/lib/service/invoicesubscription.go +++ b/lib/service/invoicesubscription.go @@ -81,7 +81,11 @@ func (svc *LndhubService) ProcessInvoiceUpdate(ctx context.Context, rawInvoice * InvoiceID: invoice.ID, CreditAccountID: creditAccount.ID, DebitAccountID: debitAccount.ID, - Amount: invoice.Amount, + Amount: rawInvoice.AmtPaidSat, + } + + if rawInvoice.AmtPaidSat != invoice.Amount { + svc.Logger.Infof("Incoming invoice amount mismatch. Invoice id:%v, amt: %d, amt_paid: %d.", invoice.ID, invoice.Amount, rawInvoice.AmtPaidSat) } // Save the transaction entry From cd72e81b246811addfeaccb047964ae60254e089 Mon Sep 17 00:00:00 2001 From: kiwiidb <33457577+kiwiidb@users.noreply.github.com> Date: Mon, 2 May 2022 12:39:42 +0200 Subject: [PATCH 3/3] Update lib/service/invoicesubscription.go Add user ID Co-authored-by: Michael Bumann --- lib/service/invoicesubscription.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/service/invoicesubscription.go b/lib/service/invoicesubscription.go index f17b7a67..378d7460 100644 --- a/lib/service/invoicesubscription.go +++ b/lib/service/invoicesubscription.go @@ -85,7 +85,7 @@ func (svc *LndhubService) ProcessInvoiceUpdate(ctx context.Context, rawInvoice * } if rawInvoice.AmtPaidSat != invoice.Amount { - svc.Logger.Infof("Incoming invoice amount mismatch. Invoice id:%v, amt: %d, amt_paid: %d.", invoice.ID, invoice.Amount, rawInvoice.AmtPaidSat) + svc.Logger.Infof("Incoming invoice amount mismatch. user_id:%v invoice_id:%v, amt:%d, amt_paid:%d.", invoice.UserID, invoice.ID, invoice.Amount, rawInvoice.AmtPaidSat) } // Save the transaction entry