one more file to refactor

This commit is contained in:
kiwiidb
2022-06-15 17:54:15 +02:00
parent 8952227bee
commit c9d7ddd9c7
9 changed files with 146 additions and 138 deletions

View File

@@ -13,15 +13,17 @@ import (
"github.com/getAlby/lndhub.go/lib/responses"
"github.com/getAlby/lndhub.go/lib/service"
"github.com/getAlby/lndhub.go/lib/tokens"
"github.com/getAlby/lndhub.go/lnd"
"github.com/go-playground/validator/v10"
"github.com/labstack/echo/v4"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type PaymentTestAsyncErrorsSuite struct {
TestSuite
mlnd *MockLND
externalLND *MockLND
service *service.LndhubService
userLogin ExpectedCreateUserResponseBody
userToken string
@@ -30,11 +32,18 @@ type PaymentTestAsyncErrorsSuite struct {
}
func (suite *PaymentTestAsyncErrorsSuite) SetupSuite() {
mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice)))
if err != nil {
log.Fatalf("Error initializing test service: %v", err)
}
externalLND, err := NewMockLND("1234567890abcdefabcd", 0, make(chan (*lnrpc.Invoice)))
if err != nil {
log.Fatalf("Error initializing test service: %v", err)
}
suite.externalLND = externalLND
suite.mlnd = mlnd
// inject fake lnd client with failing send payment sync into service
lndClient, err := NewLNDMockWrapperAsync(lnd.LNDoptions{
Address: mockLNDAddress,
MacaroonHex: mockLNDMacaroonHex,
})
lndClient, err := NewLNDMockWrapperAsync(mlnd)
suite.serviceClient = lndClient
if err != nil {
log.Fatalf("Error setting up test client: %v", err)
@@ -73,26 +82,22 @@ func (suite *PaymentTestAsyncErrorsSuite) TestExternalAsyncFailingInvoice() {
userFundingSats := 1000
externalSatRequested := 500
// fund user account
//invoiceResponse := suite.createAddInvoiceReq(userFundingSats, "integration test external payment user", suite.userToken)
//sendPaymentRequest := lnrpc.SendRequest{
// PaymentRequest: invoiceResponse.PayReq,
// FeeLimit: nil,
//}
//_, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest)
//assert.NoError(suite.T(), err)
invoiceResponse := suite.createAddInvoiceReq(userFundingSats, "integration test external payment user", suite.userToken)
err := suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil)
assert.NoError(suite.T(), err)
// wait a bit for the callback event to hit
time.Sleep(100 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
// create external invoice
//externalInvoice := lnrpc.Invoice{
// Memo: "integration tests: external pay from user",
// Value: int64(externalSatRequested),
//}
//invoice, err := suite.fundingClient.AddInvoice(context.Background(), &externalInvoice)
//assert.NoError(suite.T(), err)
externalInvoice := lnrpc.Invoice{
Memo: "integration tests: external pay from user",
Value: int64(externalSatRequested),
}
invoice, err := suite.externalLND.AddInvoice(context.Background(), &externalInvoice)
assert.NoError(suite.T(), err)
// pay external from user, req will be canceled after 2 sec
//go suite.createPayInvoiceReqWithCancel(invoice.PaymentRequest, suite.userToken)
go suite.createPayInvoiceReqWithCancel(invoice.PaymentRequest, suite.userToken)
// wait for request to fail
time.Sleep(5 * time.Second)