Skip to content

Commit

Permalink
Merge pull request #167 from getAlby/fix/0-amount-incoming-invoice
Browse files Browse the repository at this point in the history
Fix: 0 amount incoming invoice
  • Loading branch information
kiwiidb authored May 2, 2022
2 parents 820a993 + cd72e81 commit cfec721
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
39 changes: 39 additions & 0 deletions integration_tests/incoming_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion lib/service/invoicesubscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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. user_id:%v invoice_id:%v, amt:%d, amt_paid:%d.", invoice.UserID, invoice.ID, invoice.Amount, rawInvoice.AmtPaidSat)
}

// Save the transaction entry
Expand Down

0 comments on commit cfec721

Please sign in to comment.