diff --git a/integration_tests/internal_payment_test.go b/integration_tests/internal_payment_test.go index c155bef..a37798e 100644 --- a/integration_tests/internal_payment_test.go +++ b/integration_tests/internal_payment_test.go @@ -131,6 +131,27 @@ func (suite *PaymentTestSuite) TestInternalPayment() { assert.Equal(suite.T(), 1, len(transactionEntriesBob)) assert.Equal(suite.T(), int64(bobSatRequested), transactionEntriesBob[0].Amount) assert.Equal(suite.T(), int64(bobSatRequested), bobBalance) + + //generate 0 amount invoice + zeroAmt := suite.createAddInvoiceReq(0, "integration test internal payment bob 0 amount", suite.bobToken) + toPayForZeroAmt := 10 + rec := httptest.NewRecorder() + var buf bytes.Buffer + assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedPayInvoiceRequestBody{ + Invoice: zeroAmt.PayReq, + Amount: toPayForZeroAmt, + })) + req := httptest.NewRequest(http.MethodPost, "/payinvoice", &buf) + req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) + req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.aliceToken)) + suite.echo.ServeHTTP(rec, req) + + payInvoiceResponse := &ExpectedPayInvoiceResponseBody{} + assert.Equal(suite.T(), http.StatusOK, rec.Code) + assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(payInvoiceResponse)) + //assert bob was credited the correct amount + bobBalance, _ = suite.service.CurrentUserBalance(context.Background(), bobId) + assert.Equal(suite.T(), int64(bobSatRequested+toPayForZeroAmt), bobBalance) } func (suite *PaymentTestSuite) TestInternalPaymentFail() { diff --git a/lib/service/invoices.go b/lib/service/invoices.go index 601fd23..01603e6 100644 --- a/lib/service/invoices.go +++ b/lib/service/invoices.go @@ -80,7 +80,7 @@ func (svc *LndhubService) SendInternalPayment(ctx context.Context, invoice *mode InvoiceID: incomingInvoice.ID, CreditAccountID: recipientCreditAccount.ID, DebitAccountID: recipientDebitAccount.ID, - Amount: incomingInvoice.Amount, + Amount: invoice.Amount, } _, err = svc.DB.NewInsert().Model(&recipientEntry).Exec(ctx) if err != nil { @@ -101,6 +101,7 @@ func (svc *LndhubService) SendInternalPayment(ctx context.Context, invoice *mode incomingInvoice.Internal = true // mark incoming invoice as internal, just for documentation/debugging incomingInvoice.State = common.InvoiceStateSettled incomingInvoice.SettledAt = schema.NullTime{Time: time.Now()} + incomingInvoice.Amount = invoice.Amount // set just in case of 0 amount invoice _, err = svc.DB.NewUpdate().Model(&incomingInvoice).WherePK().Exec(ctx) if err != nil { // could not save the invoice of the recipient