mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-19 13:44:53 +01:00
one more file to refactor
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
type PaymentTestSuite struct {
|
||||
TestSuite
|
||||
mlnd *MockLND
|
||||
externalLND *MockLND
|
||||
service *service.LndhubService
|
||||
aliceLogin ExpectedCreateUserResponseBody
|
||||
aliceToken string
|
||||
@@ -41,6 +42,11 @@ func (suite *PaymentTestSuite) SetupSuite() {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
suite.mlnd = mlnd
|
||||
externalLND, err := NewMockLND("1234567890abcdefabcd", 0, make(chan (*lnrpc.Invoice)))
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
suite.externalLND = externalLND
|
||||
svc, err := LndHubTestServiceInit(mlnd)
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/getAlby/lndhub.go/lib/service"
|
||||
"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"
|
||||
)
|
||||
@@ -23,7 +24,11 @@ type InvoiceTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *InvoiceTestSuite) SetupSuite() {
|
||||
svc, err := LndHubTestServiceInit(nil)
|
||||
mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice)))
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
svc, err := LndHubTestServiceInit(mlnd)
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/getAlby/lndhub.go/lib/tokens"
|
||||
"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"
|
||||
)
|
||||
@@ -21,14 +22,20 @@ import (
|
||||
type KeySendTestSuite struct {
|
||||
TestSuite
|
||||
service *service.LndhubService
|
||||
mlnd *MockLND
|
||||
aliceLogin ExpectedCreateUserResponseBody
|
||||
aliceToken string
|
||||
invoiceUpdateSubCancelFn context.CancelFunc
|
||||
}
|
||||
|
||||
func (suite *KeySendTestSuite) SetupSuite() {
|
||||
|
||||
svc, err := LndHubTestServiceInit(nil)
|
||||
fee := int64(1)
|
||||
mlnd, err := NewMockLND("1234567890abcdef", fee, make(chan (*lnrpc.Invoice)))
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
suite.mlnd = mlnd
|
||||
svc, err := LndHubTestServiceInit(mlnd)
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
@@ -70,23 +77,15 @@ func (suite *KeySendTestSuite) TearDownSuite() {
|
||||
func (suite *KeySendTestSuite) TestKeysendPayment() {
|
||||
aliceFundingSats := 1000
|
||||
externalSatRequested := 500
|
||||
// 1 sat + 1 ppm
|
||||
fee := 1
|
||||
//fund alice account
|
||||
//todo
|
||||
// invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
// sendPaymentRequest := lnrpc.SendRequest{
|
||||
// PaymentRequest: invoiceResponse.PayReq,
|
||||
// FeeLimit: nil,
|
||||
// }
|
||||
// _, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest)
|
||||
// assert.NoError(suite.T(), err)
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
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)
|
||||
|
||||
//todo
|
||||
//suite.createKeySendReq(int64(externalSatRequested), "key send test", simnetLnd3PubKey, suite.aliceToken)
|
||||
suite.createKeySendReq(int64(externalSatRequested), "key send test", "03abcdef123456789a", suite.aliceToken)
|
||||
|
||||
// check that balance was reduced
|
||||
userId := getUserIdFromToken(suite.aliceToken)
|
||||
@@ -94,21 +93,16 @@ func (suite *KeySendTestSuite) TestKeysendPayment() {
|
||||
if err != nil {
|
||||
fmt.Printf("Error when getting balance %v\n", err.Error())
|
||||
}
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+fee), aliceBalance)
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+int(suite.mlnd.fee)), aliceBalance)
|
||||
}
|
||||
|
||||
func (suite *KeySendTestSuite) TestKeysendPaymentNonExistentDestination() {
|
||||
//aliceFundingSats := 1000
|
||||
aliceFundingSats := 1000
|
||||
externalSatRequested := 500
|
||||
//fund alice account
|
||||
//todo
|
||||
//invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
//sendPaymentRequest := lnrpc.SendRequest{
|
||||
// PaymentRequest: invoiceResponse.PayReq,
|
||||
// FeeLimit: nil,
|
||||
//}
|
||||
//_, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest)
|
||||
//assert.NoError(suite.T(), err)
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
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)
|
||||
|
||||
@@ -12,17 +12,12 @@ import (
|
||||
const SendPaymentMockError = "mocked send payment error"
|
||||
|
||||
type LNDMockWrapper struct {
|
||||
*lnd.LNDWrapper
|
||||
lnd.LightningClientWrapper
|
||||
}
|
||||
|
||||
func NewLNDMockWrapper(lndOptions lnd.LNDoptions) (result *LNDMockWrapper, err error) {
|
||||
lnd, err := lnd.NewLNDclient(lndOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func NewLNDMockWrapper(lnd lnd.LightningClientWrapper) (result *LNDMockWrapper, err error) {
|
||||
return &LNDMockWrapper{
|
||||
LNDWrapper: lnd,
|
||||
lnd,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -35,17 +30,12 @@ func (wrapper *LNDMockWrapper) SendPaymentSync(ctx context.Context, req *lnrpc.S
|
||||
var errorMessageChannel = make(chan string, 1)
|
||||
|
||||
type LNDMockWrapperAsync struct {
|
||||
*lnd.LNDWrapper
|
||||
lnd.LightningClientWrapper
|
||||
}
|
||||
|
||||
func NewLNDMockWrapperAsync(lndOptions lnd.LNDoptions) (result *LNDMockWrapperAsync, err error) {
|
||||
lnd, err := lnd.NewLNDclient(lndOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func NewLNDMockWrapperAsync(lnd lnd.LightningClientWrapper) (result *LNDMockWrapperAsync, err error) {
|
||||
return &LNDMockWrapperAsync{
|
||||
LNDWrapper: lnd,
|
||||
lnd,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,35 +9,35 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/getAlby/lndhub.go/common"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
aliceFundingSats := 1000
|
||||
//todo
|
||||
externalSatRequested := 500
|
||||
// 1 sat + 1 ppm
|
||||
fee := 1
|
||||
suite.mlnd.fee = 1
|
||||
//fund alice account
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
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 alice",
|
||||
// Value: int64(externalSatRequested),
|
||||
//}
|
||||
//invoice, err := suite.fundingClient.AddInvoice(context.Background(), &externalInvoice)
|
||||
//assert.NoError(suite.T(), err)
|
||||
////pay external from alice
|
||||
//payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
// Invoice: invoice.PaymentRequest,
|
||||
//}, suite.aliceToken)
|
||||
//assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
externalInvoice := lnrpc.Invoice{
|
||||
Memo: "integration tests: external pay from alice",
|
||||
Value: int64(externalSatRequested),
|
||||
}
|
||||
invoice, err := suite.externalLND.AddInvoice(context.Background(), &externalInvoice)
|
||||
assert.NoError(suite.T(), err)
|
||||
//pay external from alice
|
||||
payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
Invoice: invoice.PaymentRequest,
|
||||
}, suite.aliceToken)
|
||||
assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
|
||||
// check that balance was reduced
|
||||
userId := getUserIdFromToken(suite.aliceToken)
|
||||
@@ -45,7 +45,7 @@ func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
if err != nil {
|
||||
fmt.Printf("Error when getting balance %v\n", err.Error())
|
||||
}
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+fee), aliceBalance)
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+int(suite.mlnd.fee)), aliceBalance)
|
||||
|
||||
// check that no additional transaction entry was created
|
||||
transactonEntries, err := suite.service.TransactionEntriesFor(context.Background(), userId)
|
||||
@@ -77,7 +77,7 @@ func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
assert.Equal(suite.T(), int64(0), transactonEntries[1].ParentID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[1].InvoiceID)
|
||||
|
||||
assert.Equal(suite.T(), int64(fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), int64(suite.mlnd.fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), feeAccount.ID, transactonEntries[2].CreditAccountID)
|
||||
assert.Equal(suite.T(), currentAccount.ID, transactonEntries[2].DebitAccountID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[2].InvoiceID)
|
||||
@@ -94,7 +94,7 @@ func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
responseBody := &[]ExpectedOutgoingInvoice{}
|
||||
assert.Equal(suite.T(), http.StatusOK, rec.Code)
|
||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&responseBody))
|
||||
assert.Equal(suite.T(), int64(fee), (*responseBody)[0].Fee)
|
||||
assert.Equal(suite.T(), int64(suite.mlnd.fee), (*responseBody)[0].Fee)
|
||||
}
|
||||
|
||||
func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
@@ -102,27 +102,26 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
aliceFundingSats := 1000
|
||||
externalSatRequested := 1000
|
||||
// 1 sat + 1 ppm
|
||||
fee := 1
|
||||
suite.mlnd.fee = 1
|
||||
//fund alice account
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
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 alice",
|
||||
// Value: int64(externalSatRequested),
|
||||
//}
|
||||
//invoice, err := suite.fundingClient.AddInvoice(context.Background(), &externalInvoice)
|
||||
//assert.NoError(suite.T(), err)
|
||||
////pay external from alice
|
||||
//payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
// Invoice: invoice.PaymentRequest,
|
||||
//}, suite.aliceToken)
|
||||
//assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
externalInvoice := lnrpc.Invoice{
|
||||
Memo: "integration tests: external pay from alice",
|
||||
Value: int64(externalSatRequested),
|
||||
}
|
||||
invoice, err := suite.externalLND.AddInvoice(context.Background(), &externalInvoice)
|
||||
assert.NoError(suite.T(), err)
|
||||
//pay external from alice
|
||||
payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
Invoice: invoice.PaymentRequest,
|
||||
}, suite.aliceToken)
|
||||
assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
|
||||
// check that balance was reduced
|
||||
userId := getUserIdFromToken(suite.aliceToken)
|
||||
@@ -131,7 +130,7 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
if err != nil {
|
||||
fmt.Printf("Error when getting balance %v\n", err.Error())
|
||||
}
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+fee), aliceBalance)
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested)+suite.mlnd.fee, aliceBalance)
|
||||
assert.Equal(suite.T(), int64(-1), aliceBalance)
|
||||
|
||||
// check that no additional transaction entry was created
|
||||
@@ -164,7 +163,7 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
assert.Equal(suite.T(), int64(0), transactonEntries[1].ParentID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[1].InvoiceID)
|
||||
|
||||
assert.Equal(suite.T(), int64(fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), int64(suite.mlnd.fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), feeAccount.ID, transactonEntries[2].CreditAccountID)
|
||||
assert.Equal(suite.T(), currentAccount.ID, transactonEntries[2].DebitAccountID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[2].InvoiceID)
|
||||
@@ -175,27 +174,27 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
|
||||
func (suite *PaymentTestSuite) TestZeroAmountInvoice() {
|
||||
aliceFundingSats := 1000
|
||||
//amtToPay := 1000
|
||||
amtToPay := 1000
|
||||
//fund alice account
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test zero amount payment alice", suite.aliceToken)
|
||||
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: zero amount pay from alice",
|
||||
// Value: 0,
|
||||
//}
|
||||
//invoice, err := suite.fundingClient.AddInvoice(context.Background(), &externalInvoice)
|
||||
//assert.NoError(suite.T(), err)
|
||||
externalInvoice := lnrpc.Invoice{
|
||||
Memo: "integration tests: zero amount pay from alice",
|
||||
Value: 0,
|
||||
}
|
||||
invoice, err := suite.externalLND.AddInvoice(context.Background(), &externalInvoice)
|
||||
assert.NoError(suite.T(), err)
|
||||
////pay external from alice
|
||||
//payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
// Invoice: invoice.PaymentRequest,
|
||||
// Amount: amtToPay,
|
||||
//}, suite.aliceToken)
|
||||
//assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
//assert.Equal(suite.T(), int64(amtToPay), payResponse.Amount)
|
||||
payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
Invoice: invoice.PaymentRequest,
|
||||
Amount: amtToPay,
|
||||
}, suite.aliceToken)
|
||||
assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
assert.Equal(suite.T(), int64(amtToPay), payResponse.Amount)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -13,9 +13,9 @@ 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"
|
||||
)
|
||||
@@ -23,17 +23,26 @@ import (
|
||||
type PaymentTestErrorsSuite struct {
|
||||
TestSuite
|
||||
service *service.LndhubService
|
||||
mlnd *MockLND
|
||||
externalLND *MockLND
|
||||
userLogin ExpectedCreateUserResponseBody
|
||||
userToken string
|
||||
invoiceUpdateSubCancelFn context.CancelFunc
|
||||
}
|
||||
|
||||
func (suite *PaymentTestErrorsSuite) 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)
|
||||
}
|
||||
// inject fake lnd client with failing send payment sync into service
|
||||
lndClient, err := NewLNDMockWrapper(lnd.LNDoptions{
|
||||
Address: mockLNDAddress,
|
||||
MacaroonHex: mockLNDMacaroonHex,
|
||||
})
|
||||
lndClient, err := NewLNDMockWrapper(mlnd)
|
||||
suite.mlnd = mlnd
|
||||
suite.externalLND = externalLND
|
||||
if err != nil {
|
||||
log.Fatalf("Error setting up test client: %v", err)
|
||||
}
|
||||
@@ -71,26 +80,22 @@ func (suite *PaymentTestErrorsSuite) TestExternalFailingInvoice() {
|
||||
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, mock will fail immediately
|
||||
//_ = suite.createPayInvoiceReqError(invoice.PaymentRequest, suite.userToken)
|
||||
_ = suite.createPayInvoiceReqError(invoice.PaymentRequest, suite.userToken)
|
||||
|
||||
userId := getUserIdFromToken(suite.userToken)
|
||||
|
||||
|
||||
@@ -39,7 +39,11 @@ func TestSubscriptionStartTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(SubscriptionStartTestSuite))
|
||||
}
|
||||
func (suite *SubscriptionStartTestSuite) SetupSuite() {
|
||||
svc, err := LndHubTestServiceInit(nil)
|
||||
mockLND, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice)))
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
svc, err := LndHubTestServiceInit(mockLND)
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ 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"
|
||||
@@ -25,8 +24,8 @@ import (
|
||||
|
||||
type WebHookTestSuite struct {
|
||||
TestSuite
|
||||
fundingClient *lnd.LNDWrapper
|
||||
service *service.LndhubService
|
||||
mlnd *MockLND
|
||||
userLogin ExpectedCreateUserResponseBody
|
||||
userToken string
|
||||
webHookServer *httptest.Server
|
||||
@@ -47,7 +46,12 @@ func (suite *WebHookTestSuite) SetupSuite() {
|
||||
suite.invoiceChan <- invoice
|
||||
}))
|
||||
suite.webHookServer = webhookServer
|
||||
svc, err := LndHubTestServiceInit(nil)
|
||||
mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice)))
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
svc, err := LndHubTestServiceInit(mlnd)
|
||||
suite.mlnd = mlnd
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
@@ -79,11 +83,7 @@ func (suite *WebHookTestSuite) SetupSuite() {
|
||||
func (suite *WebHookTestSuite) TestWebHook() {
|
||||
// create incoming invoice and fund account
|
||||
invoice := suite.createAddInvoiceReq(1000, "integration test webhook", suite.userToken)
|
||||
sendPaymentRequest := lnrpc.SendRequest{
|
||||
PaymentRequest: invoice.PayReq,
|
||||
FeeLimit: nil,
|
||||
}
|
||||
_, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest)
|
||||
err := suite.mlnd.mockPaidInvoice(invoice, 0, false, nil)
|
||||
assert.NoError(suite.T(), err)
|
||||
invoiceFromWebhook := <-suite.invoiceChan
|
||||
assert.Equal(suite.T(), "integration test webhook", invoiceFromWebhook.Memo)
|
||||
|
||||
Reference in New Issue
Block a user