mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-02-23 13:54:25 +01:00
Merge pull request #227 from getAlby/fix/0-amount-internal-invoices
Fix/0 amount internal invoices
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user