tests should be working?

This commit is contained in:
kiwiidb
2022-12-02 14:52:15 +01:00
parent 1edfe2b3bf
commit bccd73312a
5 changed files with 25 additions and 16 deletions

View File

@@ -114,22 +114,27 @@ func (suite *HodlInvoiceSuite) TestHodlInvoiceSuccess() {
Value: externalInvoice.Value,
CreationDate: 0,
Fee: 0,
PaymentPreimage: "",
ValueSat: 0,
PaymentPreimage: "123preimage",
ValueSat: externalInvoice.Value,
ValueMsat: 0,
PaymentRequest: invoice.PaymentRequest,
Status: lnrpc.Payment_SUCCEEDED,
FailureReason: 0,
})
//wait a bit for db update to happen
time.Sleep(time.Second)
if err != nil {
fmt.Printf("Error when getting balance %v\n", err.Error())
}
//fetch user balance again
userBalance, err = suite.service.CurrentUserBalance(context.Background(), userId)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), int64(userFundingSats-externalSatRequested), userBalance)
// check payment is updated as succesful
inv, err = suite.service.FindInvoiceByPaymentHash(context.Background(), userId, hex.EncodeToString(invoice.RHash))
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), common.InvoiceStateInitialized, inv.State)
assert.Equal(suite.T(), common.InvoiceStateSettled, inv.State)
}
func (suite *HodlInvoiceSuite) TestHodlInvoiceFailure() {
@@ -178,13 +183,15 @@ func (suite *HodlInvoiceSuite) TestHodlInvoiceFailure() {
Value: externalInvoice.Value,
CreationDate: 0,
Fee: 0,
PaymentPreimage: "",
ValueSat: 0,
PaymentPreimage: "123preimage",
ValueSat: externalInvoice.Value,
ValueMsat: 0,
PaymentRequest: invoice.PaymentRequest,
Status: lnrpc.Payment_FAILED,
FailureReason: lnrpc.PaymentFailureReason_FAILURE_REASON_INCORRECT_PAYMENT_DETAILS,
})
//wait a bit for db update to happen
time.Sleep(time.Second)
// check that balance was reverted and invoice is in error state
userBalance, err = suite.service.CurrentUserBalance(context.Background(), userId)
@@ -199,7 +206,8 @@ func (suite *HodlInvoiceSuite) TestHodlInvoiceFailure() {
}
assert.Equal(suite.T(), 1, len(invoices))
assert.Equal(suite.T(), common.InvoiceStateError, invoices[0].State)
assert.Equal(suite.T(), SendPaymentMockError, invoices[0].ErrorMessage)
errorString := "FAILURE_REASON_INCORRECT_PAYMENT_DETAILS"
assert.Equal(suite.T(), errorString, invoices[0].ErrorMessage)
transactonEntries, err := suite.service.TransactionEntriesFor(context.Background(), userId)
if err != nil {

View File

@@ -231,7 +231,7 @@ func (mlnd *MockLND) DecodeBolt11(ctx context.Context, bolt11 string, options ..
}
result := &lnrpc.PayReq{
Destination: hex.EncodeToString(inv.Destination.SerializeCompressed()),
PaymentHash: string(inv.PaymentHash[:]),
PaymentHash: hex.EncodeToString(inv.PaymentHash[:]),
NumSatoshis: int64(*inv.MilliSat) / 1000,
Timestamp: inv.Timestamp.Unix(),
Expiry: int64(inv.Expiry()),

View File

@@ -25,8 +25,9 @@ type HodlPaymentSubscriber struct {
}
// wait for channel, then return
func (hps *HodlPaymentSubscriber) Recv() (lnrpc.Payment, error) {
return <-hps.ch, nil
func (hps *HodlPaymentSubscriber) Recv() (*lnrpc.Payment, error) {
result := <-hps.ch
return &result, nil
}
func NewLNDMockHodlWrapperAsync(lnd lnd.LightningClientWrapper) (result *LNDMockHodlWrapperAsync, err error) {
@@ -39,7 +40,7 @@ func NewLNDMockHodlWrapperAsync(lnd lnd.LightningClientWrapper) (result *LNDMock
}
func (wrapper *LNDMockHodlWrapperAsync) SubscribePayment(ctx context.Context, req *routerrpc.TrackPaymentRequest, options ...grpc.CallOption) (lnd.SubscribePaymentWrapper, error) {
return nil, nil
return wrapper.hps, nil
}
func (wrapper *LNDMockHodlWrapperAsync) SendPaymentSync(ctx context.Context, req *lnrpc.SendRequest, options ...grpc.CallOption) (*lnrpc.SendResponse, error) {

View File

@@ -24,6 +24,7 @@ func (svc *LndhubService) CheckAllPendingOutgoingPayments(ctx context.Context) (
//spawn goroutines
//https://go.dev/doc/faq#closures_and_goroutines
inv := inv
svc.Logger.Infof("Spawning tracker for payment with hash %s", inv.RHash)
go svc.TrackOutgoingPaymentstatus(ctx, &inv)
}
return nil
@@ -31,7 +32,6 @@ func (svc *LndhubService) CheckAllPendingOutgoingPayments(ctx context.Context) (
// Should be called in a goroutine as the tracking can potentially take a long time
func (svc *LndhubService) TrackOutgoingPaymentstatus(ctx context.Context, invoice *models.Invoice) {
fmt.Println(invoice.RHash)
//ask lnd using TrackPaymentV2 by hash of payment
rawHash, err := hex.DecodeString(invoice.RHash)
if err != nil {

View File

@@ -251,7 +251,7 @@ func (svc *LndhubService) HandleFailedPayment(ctx context.Context, invoice *mode
_, err := svc.DB.NewInsert().Model(&entry).Exec(ctx)
if err != nil {
sentry.CaptureException(err)
svc.Logger.Errorf("Could not insert transaction entry user_id:%v invoice_id:%v", invoice.UserID, invoice.ID)
svc.Logger.Errorf("Could not insert transaction entry user_id:%v invoice_id:%v error %s", invoice.UserID, invoice.ID, err.Error())
return err
}
@@ -263,7 +263,7 @@ func (svc *LndhubService) HandleFailedPayment(ctx context.Context, invoice *mode
_, err = svc.DB.NewUpdate().Model(invoice).WherePK().Exec(ctx)
if err != nil {
sentry.CaptureException(err)
svc.Logger.Errorf("Could not update failed payment invoice user_id:%v invoice_id:%v", invoice.UserID, invoice.ID)
svc.Logger.Errorf("Could not update failed payment invoice user_id:%v invoice_id:%v error %s", invoice.UserID, invoice.ID, err.Error())
}
return err
}
@@ -275,7 +275,7 @@ func (svc *LndhubService) HandleSuccessfulPayment(ctx context.Context, invoice *
_, err := svc.DB.NewUpdate().Model(invoice).WherePK().Exec(ctx)
if err != nil {
sentry.CaptureException(err)
svc.Logger.Errorf("Could not update sucessful payment invoice user_id:%v invoice_id:%v", invoice.UserID, invoice.ID)
svc.Logger.Errorf("Could not update sucessful payment invoice user_id:%v invoice_id:%v, error %s", invoice.UserID, invoice.ID, err.Error())
}
// Get the user's fee account for the transaction entry, current account is already there in parent entry
@@ -297,14 +297,14 @@ func (svc *LndhubService) HandleSuccessfulPayment(ctx context.Context, invoice *
_, err = svc.DB.NewInsert().Model(&entry).Exec(ctx)
if err != nil {
sentry.CaptureException(err)
svc.Logger.Errorf("Could not insert fee transaction entry user_id:%v invoice_id:%v", invoice.UserID, invoice.ID)
svc.Logger.Errorf("Could not insert fee transaction entry user_id:%v invoice_id:%v error %s", invoice.UserID, invoice.ID, err.Error())
return err
}
userBalance, err := svc.CurrentUserBalance(ctx, entry.UserID)
if err != nil {
sentry.CaptureException(err)
svc.Logger.Errorf("Could not fetch user balance user_id:%v invoice_id:%v", invoice.UserID, invoice.ID)
svc.Logger.Errorf("Could not fetch user balance user_id:%v invoice_id:%v error %s", invoice.UserID, invoice.ID, err.Error())
return err
}