diff --git a/integration_tests/checkpayment_test.go b/integration_tests/checkpayment_test.go index a0d8051..5a52f3b 100644 --- a/integration_tests/checkpayment_test.go +++ b/integration_tests/checkpayment_test.go @@ -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,7 +24,6 @@ import ( type CheckPaymentTestSuite struct { TestSuite - fundingClient *lnd.LNDWrapper service *service.LndhubService userLogin ExpectedCreateUserResponseBody userToken string @@ -33,15 +31,6 @@ type CheckPaymentTestSuite struct { } func (suite *CheckPaymentTestSuite) SetupSuite() { - lndClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - suite.fundingClient = lndClient - svc, err := LndHubTestServiceInit(nil) if err != nil { log.Fatalf("Error initializing test service: %v", err) @@ -85,12 +74,11 @@ func (suite *CheckPaymentTestSuite) TestCheckPaymentNotFound() { func (suite *CheckPaymentTestSuite) TestCheckPaymentProperIsPaidResponse() { // create incoming invoice and fund account invoice := suite.createAddInvoiceReq(1000, "integration test check payments for user", suite.userToken) - sendPaymentRequest := lnrpc.SendRequest{ + //TODO fund + _ = lnrpc.SendRequest{ PaymentRequest: invoice.PayReq, 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) diff --git a/integration_tests/gettxs_test.go b/integration_tests/gettxs_test.go index ead6a8b..a1ac771 100644 --- a/integration_tests/gettxs_test.go +++ b/integration_tests/gettxs_test.go @@ -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" @@ -26,23 +25,21 @@ import ( type GetTxTestSuite struct { TestSuite Service *service.LndhubService - fundingClient *lnd.LNDWrapper userLogin ExpectedCreateUserResponseBody userToken string + mockLND *MockLND invoiceUpdateSubCancelFn context.CancelFunc } func (suite *GetTxTestSuite) SetupSuite() { - lndClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) + mockLND := &MockLND{ + Sub: &MockSubscribeInvoices{ + invoiceChan: make(chan (*lnrpc.Invoice)), + }, + fee: 0, + addIndexCounter: 0, } - suite.fundingClient = lndClient - - svc, err := LndHubTestServiceInit(nil) + svc, err := LndHubTestServiceInit(mockLND) if err != nil { log.Fatalf("Error initializing test service: %v", err) } @@ -56,6 +53,7 @@ func (suite *GetTxTestSuite) SetupSuite() { suite.invoiceUpdateSubCancelFn = cancel go svc.InvoiceUpdateSubscription(ctx) suite.Service = svc + suite.mockLND = mockLND e := echo.New() e.HTTPErrorHandler = responses.HTTPErrorHandler @@ -88,17 +86,14 @@ func (suite *GetTxTestSuite) TestGetOutgoingInvoices() { assert.Equal(suite.T(), http.StatusOK, rec.Code) assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&responseBody)) assert.Empty(suite.T(), responseBody) - // create incoming invoice and fund account + // fund account invoice := suite.createAddInvoiceReq(1000, "integration test internal payment alice", suite.userToken) - sendPaymentRequest := lnrpc.SendRequest{ - PaymentRequest: invoice.PayReq, - FeeLimit: nil, - } - _, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) + err := suite.mockLND.mockPaidInvoice(invoice) assert.NoError(suite.T(), err) - //wait a bit for the callback event to hit - time.Sleep(100 * time.Millisecond) + //wait for a short time to allow the payment to be processed asynchronously + time.Sleep(10 * time.Millisecond) + // create invoice invoice = suite.createAddInvoiceReq(500, "integration test internal payment alice", suite.userToken) // pay invoice, this will create outgoing invoice and settle it diff --git a/integration_tests/incoming_payment_test.go b/integration_tests/incoming_payment_test.go index 66e0727..3b4496a 100644 --- a/integration_tests/incoming_payment_test.go +++ b/integration_tests/incoming_payment_test.go @@ -5,7 +5,6 @@ import ( "context" "crypto/rand" "crypto/sha256" - "encoding/hex" "encoding/json" "fmt" "log" @@ -20,18 +19,15 @@ 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/labstack/gommon/random" - "github.com/lightningnetwork/lnd/lnrpc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" ) type IncomingPaymentTestSuite struct { TestSuite - fundingClient *lnd.LNDWrapper service *service.LndhubService userLogin ExpectedCreateUserResponseBody userToken string @@ -39,15 +35,6 @@ type IncomingPaymentTestSuite struct { } func (suite *IncomingPaymentTestSuite) SetupSuite() { - lndClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - suite.fundingClient = lndClient - svc, err := LndHubTestServiceInit(nil) if err != nil { log.Fatalf("Error initializing test service: %v", err) @@ -92,15 +79,16 @@ func (suite *IncomingPaymentTestSuite) TestIncomingPayment() { //assert the user has no balance to start with assert.Equal(suite.T(), int64(0), balance.BTC.AvailableBalance) fundingSatAmt := 10 - invoiceResponse := suite.createAddInvoiceReq(fundingSatAmt, "integration test IncomingPaymentTestSuite", suite.userToken) + //TODO fund + //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, - FeeLimit: nil, - } - _, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) - assert.NoError(suite.T(), err) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoiceResponse.PayReq, + // 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) @@ -129,18 +117,19 @@ func (suite *IncomingPaymentTestSuite) TestIncomingPaymentZeroAmt() { assert.Equal(suite.T(), http.StatusOK, rec.Code) assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&balance)) initialBalance := balance.BTC.AvailableBalance - fundingSatAmt := 0 + //fundingSatAmt := 0 sendSatAmt := 10 - invoiceResponse := suite.createAddInvoiceReq(fundingSatAmt, "integration test IncomingPaymentTestSuite", suite.userToken) + //todo fund + //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) + //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) @@ -175,21 +164,20 @@ func (suite *IncomingPaymentTestSuite) TestIncomingPaymentKeysend() { preImage, err := randBytesFromStr(32, random.Hex) assert.NoError(suite.T(), err) pHash.Write(preImage) - destBytes, err := hex.DecodeString(suite.service.IdentityPubkey) - assert.NoError(suite.T(), err) - sendPaymentRequest := lnrpc.SendRequest{ - Dest: destBytes, - Amt: int64(keysendSatAmt), - PaymentHash: pHash.Sum(nil), - DestFeatures: []lnrpc.FeatureBit{lnrpc.FeatureBit_TLV_ONION_REQ}, - DestCustomRecords: map[uint64][]byte{ - service.TLV_WALLET_ID: []byte(suite.userLogin.Login), - service.KEYSEND_CUSTOM_RECORD: preImage, - }, - FeeLimit: nil, - } - _, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) - assert.NoError(suite.T(), err) + //todo fund + //jsendPaymentRequest := lnrpc.SendRequest{ + //j Dest: destBytes, + //j Amt: int64(keysendSatAmt), + //j PaymentHash: pHash.Sum(nil), + //j DestFeatures: []lnrpc.FeatureBit{lnrpc.FeatureBit_TLV_ONION_REQ}, + //j DestCustomRecords: map[uint64][]byte{ + //j service.TLV_WALLET_ID: []byte(suite.userLogin.Login), + //j service.KEYSEND_CUSTOM_RECORD: preImage, + //j }, + //j FeeLimit: nil, + //j} + //_, 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) diff --git a/integration_tests/internal_payment_test.go b/integration_tests/internal_payment_test.go index c0fe93e..303de33 100644 --- a/integration_tests/internal_payment_test.go +++ b/integration_tests/internal_payment_test.go @@ -20,7 +20,6 @@ import ( "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" ) @@ -37,15 +36,6 @@ type PaymentTestSuite struct { } func (suite *PaymentTestSuite) SetupSuite() { - lndClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd3RegtestAddress, - MacaroonHex: lnd3RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - suite.fundingClient = lndClient - svc, err := LndHubTestServiceInit(nil) if err != nil { log.Fatalf("Error initializing test service: %v", err) @@ -93,14 +83,15 @@ func (suite *PaymentTestSuite) TestInternalPayment() { bobSatRequested := 500 // currently fee is 0 for internal payments fee := 0 + //todo fund //fund alice account - invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test internal 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 internal payment alice", suite.aliceToken) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoiceResponse.PayReq, + // 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) @@ -145,13 +136,14 @@ func (suite *PaymentTestSuite) TestInternalPaymentFail() { // currently fee is 0 for internal payments fee := 0 //fund alice account - invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken) - sendPaymentRequest := lnrpc.SendRequest{ - PaymentRequest: invoiceResponse.PayReq, - FeeLimit: nil, - } - _, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) - assert.NoError(suite.T(), err) + //todo + //invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoiceResponse.PayReq, + // 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) @@ -199,17 +191,18 @@ func (suite *PaymentTestSuite) TestInternalPaymentFail() { assert.Equal(suite.T(), int64(aliceFundingSats)-int64(bobSatRequested+fee), int64(aliceBalance)) } func (suite *PaymentTestSuite) TestInternalPaymentKeysend() { - aliceFundingSats := 1000 + //aliceFundingSats := 1000 bobAmt := 100 memo := "integration test internal keysend from alice" + //todo //fund alice account - invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test internal keysend 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 internal keysend alice", suite.aliceToken) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoiceResponse.PayReq, + // 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) diff --git a/integration_tests/keysend_test.go b/integration_tests/keysend_test.go index 150dad0..5f60d46 100644 --- a/integration_tests/keysend_test.go +++ b/integration_tests/keysend_test.go @@ -12,17 +12,14 @@ 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 KeySendTestSuite struct { TestSuite - fundingClient *lnd.LNDWrapper service *service.LndhubService aliceLogin ExpectedCreateUserResponseBody aliceToken string @@ -30,14 +27,6 @@ type KeySendTestSuite struct { } func (suite *KeySendTestSuite) SetupSuite() { - lndClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - suite.fundingClient = lndClient svc, err := LndHubTestServiceInit(nil) if err != nil { @@ -84,18 +73,20 @@ func (suite *KeySendTestSuite) TestKeysendPayment() { // 1 sat + 1 ppm fee := 1 //fund alice account - 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) + //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) //wait a bit for the callback event to hit time.Sleep(100 * time.Millisecond) - suite.createKeySendReq(int64(externalSatRequested), "key send test", simnetLnd3PubKey, suite.aliceToken) + //todo + //suite.createKeySendReq(int64(externalSatRequested), "key send test", simnetLnd3PubKey, suite.aliceToken) // check that balance was reduced userId := getUserIdFromToken(suite.aliceToken) @@ -107,16 +98,17 @@ func (suite *KeySendTestSuite) TestKeysendPayment() { } func (suite *KeySendTestSuite) TestKeysendPaymentNonExistentDestination() { - aliceFundingSats := 1000 + //aliceFundingSats := 1000 externalSatRequested := 500 //fund alice account - 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) + //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) //wait a bit for the callback event to hit time.Sleep(100 * time.Millisecond) diff --git a/integration_tests/lnd_mock.go b/integration_tests/lnd_mock.go index 079934a..448c199 100644 --- a/integration_tests/lnd_mock.go +++ b/integration_tests/lnd_mock.go @@ -2,6 +2,10 @@ package integration_tests import ( "context" + "crypto/ecdsa" + "crypto/sha256" + "encoding/hex" + "math/big" "time" "github.com/btcsuite/btcd/btcec" @@ -23,6 +27,31 @@ type MockSubscribeInvoices struct { invoiceChan chan (*lnrpc.Invoice) } +const privkey = "0123456789abcdef" + +func getPubkey() ecdsa.PublicKey { + privKeyBytes, _ := hex.DecodeString(privkey) + x, y := btcec.S256().ScalarBaseMult(privKeyBytes) + return ecdsa.PublicKey{ + Curve: btcec.S256(), + X: x, + Y: y, + } +} + +func signMsg(msg []byte) ([]byte, error) { + privKeyBytes, err := hex.DecodeString(privkey) + if err != nil { + return nil, err + } + ecdsaPrivKey := &ecdsa.PrivateKey{ + PublicKey: getPubkey(), + D: new(big.Int).SetBytes(privKeyBytes), + } + return btcec.SignCompact(btcec.S256(), (*btcec.PrivateKey)(ecdsaPrivKey), + msg, true) +} + func (mockSub *MockSubscribeInvoices) Recv() (*lnrpc.Invoice, error) { inv := <-mockSub.invoiceChan return inv, nil @@ -51,38 +80,76 @@ func (mlnd *MockLND) SendPaymentSync(ctx context.Context, req *lnrpc.SendRequest } func (mlnd *MockLND) AddInvoice(ctx context.Context, req *lnrpc.Invoice, options ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error) { - msat := lnwire.MilliSatoshi(req.ValueMsat) + pHash := sha256.New() + pHash.Write(req.RPreimage) + pHash.Sum(nil) + msat := lnwire.MilliSatoshi(1000 * req.Value) invoice := &zpay32.Invoice{ - Net: &chaincfg.Params{}, - MilliSat: &msat, - Timestamp: time.Now(), - PaymentHash: &[32]byte{}, - PaymentAddr: &[32]byte{}, - Destination: &btcec.PublicKey{}, - Description: new(string), - DescriptionHash: &[32]byte{}, - FallbackAddr: nil, - } - copy(req.RHash, invoice.PaymentHash[:]) - copy(req.PaymentAddr, invoice.PaymentAddr[:]) - copy(req.DescriptionHash, invoice.DescriptionHash[:]) - pr, err := invoice.Encode(zpay32.MessageSigner{ - SignCompact: func(msg []byte) ([]byte, error) { - return []byte{}, nil + Net: &chaincfg.RegressionNetParams, + MilliSat: &msat, + Timestamp: time.Now(), + PaymentHash: &[32]byte{}, + PaymentAddr: &[32]byte{}, + Features: &lnwire.FeatureVector{ + RawFeatureVector: &lnwire.RawFeatureVector{}, }, + FallbackAddr: nil, + } + copy(invoice.PaymentHash[:], pHash.Sum(nil)) + copy(invoice.PaymentAddr[:], req.PaymentAddr) + if len(req.DescriptionHash) != 0 { + invoice.DescriptionHash = &[32]byte{} + copy(req.DescriptionHash, invoice.DescriptionHash[:]) + } + if req.Memo != "" { + invoice.Description = &req.Memo + } + pr, err := invoice.Encode(zpay32.MessageSigner{ + SignCompact: signMsg, }) if err != nil { return nil, err } mlnd.addIndexCounter += 1 return &lnrpc.AddInvoiceResponse{ - RHash: req.RHash, + RHash: invoice.PaymentHash[:], PaymentRequest: pr, AddIndex: mlnd.addIndexCounter, - PaymentAddr: []byte{}, }, nil } +func (mlnd *MockLND) mockPaidInvoice(added *ExpectedAddInvoiceResponseBody) error { + inv, err := mlnd.DecodeBolt11(context.Background(), added.PayReq) + if err != nil { + return err + } + rhash, err := hex.DecodeString(added.RHash) + if err != nil { + return err + } + mlnd.Sub.invoiceChan <- &lnrpc.Invoice{ + Memo: inv.Description, + RPreimage: []byte("123preimage"), + RHash: rhash, + Value: inv.NumSatoshis, + ValueMsat: inv.NumMsat, + Settled: true, + CreationDate: time.Now().Unix(), + SettleDate: time.Now().Unix(), + PaymentRequest: added.PayReq, + DescriptionHash: []byte(inv.DescriptionHash), + FallbackAddr: inv.FallbackAddr, + CltvExpiry: uint64(inv.CltvExpiry), + AmtPaid: inv.NumSatoshis, + AmtPaidSat: inv.NumSatoshis, + AmtPaidMsat: inv.NumMsat, + State: lnrpc.Invoice_SETTLED, + Htlcs: []*lnrpc.InvoiceHTLC{}, + IsKeysend: false, + } + return nil +} + func (mlnd *MockLND) SubscribeInvoices(ctx context.Context, req *lnrpc.InvoiceSubscription, options ...grpc.CallOption) (lnd.SubscribeInvoicesWrapper, error) { return mlnd.Sub, nil } @@ -106,7 +173,7 @@ func (mlnd *MockLND) GetInfo(ctx context.Context, req *lnrpc.GetInfoRequest, opt Testnet: false, Chains: []*lnrpc.Chain{{ Chain: "BTC", - Network: "mainnet", + Network: "regtest", }}, Uris: []string{"https://mocky.mcmockface.com"}, Features: map[uint32]*lnrpc.Feature{}, @@ -114,23 +181,25 @@ func (mlnd *MockLND) GetInfo(ctx context.Context, req *lnrpc.GetInfoRequest, opt } func (mlnd *MockLND) DecodeBolt11(ctx context.Context, bolt11 string, options ...grpc.CallOption) (*lnrpc.PayReq, error) { - inv, err := zpay32.Decode(bolt11, &chaincfg.MainNetParams) + inv, err := zpay32.Decode(bolt11, &chaincfg.RegressionNetParams) if err != nil { return nil, err } - return &lnrpc.PayReq{ - Destination: string(inv.Destination.SerializeCompressed()), - PaymentHash: string(inv.PaymentHash[:]), - NumSatoshis: int64(*inv.MilliSat) / 1000, - Timestamp: inv.Timestamp.Unix(), - Expiry: int64(inv.Expiry()), - Description: *inv.Description, - DescriptionHash: string(inv.DescriptionHash[:]), - FallbackAddr: inv.FallbackAddr.EncodeAddress(), - CltvExpiry: int64(inv.MinFinalCLTVExpiry()), - RouteHints: []*lnrpc.RouteHint{}, - PaymentAddr: []byte{}, - NumMsat: int64(*inv.MilliSat), - Features: map[uint32]*lnrpc.Feature{}, - }, nil + result := &lnrpc.PayReq{ + Destination: string(inv.Destination.SerializeCompressed()), + PaymentHash: string(inv.PaymentHash[:]), + NumSatoshis: int64(*inv.MilliSat) / 1000, + Timestamp: inv.Timestamp.Unix(), + Expiry: int64(inv.Expiry()), + Description: *inv.Description, + CltvExpiry: int64(inv.MinFinalCLTVExpiry()), + RouteHints: []*lnrpc.RouteHint{}, + PaymentAddr: []byte{}, + NumMsat: int64(*inv.MilliSat), + Features: map[uint32]*lnrpc.Feature{}, + } + if inv.DescriptionHash != nil { + result.DescriptionHash = string(inv.DescriptionHash[:]) + } + return result, nil } diff --git a/integration_tests/outgoing_payment_test.go b/integration_tests/outgoing_payment_test.go index bbc98c8..73810d3 100644 --- a/integration_tests/outgoing_payment_test.go +++ b/integration_tests/outgoing_payment_test.go @@ -15,6 +15,7 @@ import ( func (suite *PaymentTestSuite) TestOutGoingPayment() { aliceFundingSats := 1000 + //todo externalSatRequested := 500 // 1 sat + 1 ppm fee := 1 diff --git a/integration_tests/payment_failure_async_test.go b/integration_tests/payment_failure_async_test.go index d88a825..d684e7f 100644 --- a/integration_tests/payment_failure_async_test.go +++ b/integration_tests/payment_failure_async_test.go @@ -16,14 +16,12 @@ import ( "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 - fundingClient *lnd.LNDWrapper service *service.LndhubService userLogin ExpectedCreateUserResponseBody userToken string @@ -32,25 +30,15 @@ type PaymentTestAsyncErrorsSuite struct { } func (suite *PaymentTestAsyncErrorsSuite) SetupSuite() { - // use real client for funding only - fundingClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - // inject fake lnd client with failing send payment sync into service lndClient, err := NewLNDMockWrapperAsync(lnd.LNDoptions{ - Address: lnd1RegtestAddress, - MacaroonHex: lnd1RegtestMacaroonHex, + Address: mockLNDAddress, + MacaroonHex: mockLNDMacaroonHex, }) suite.serviceClient = lndClient if err != nil { log.Fatalf("Error setting up test client: %v", err) } - suite.fundingClient = fundingClient svc, err := LndHubTestServiceInit(lndClient) if err != nil { @@ -85,26 +73,26 @@ 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) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoiceResponse.PayReq, + // 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) // 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.fundingClient.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) diff --git a/integration_tests/payment_failure_test.go b/integration_tests/payment_failure_test.go index c66734c..f599149 100644 --- a/integration_tests/payment_failure_test.go +++ b/integration_tests/payment_failure_test.go @@ -16,14 +16,12 @@ import ( "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 PaymentTestErrorsSuite struct { TestSuite - fundingClient *lnd.LNDWrapper service *service.LndhubService userLogin ExpectedCreateUserResponseBody userToken string @@ -31,24 +29,14 @@ type PaymentTestErrorsSuite struct { } func (suite *PaymentTestErrorsSuite) SetupSuite() { - // use real client for funding only - fundingClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - // inject fake lnd client with failing send payment sync into service lndClient, err := NewLNDMockWrapper(lnd.LNDoptions{ - Address: lnd1RegtestAddress, - MacaroonHex: lnd1RegtestMacaroonHex, + Address: mockLNDAddress, + MacaroonHex: mockLNDMacaroonHex, }) if err != nil { log.Fatalf("Error setting up test client: %v", err) } - suite.fundingClient = fundingClient svc, err := LndHubTestServiceInit(lndClient) if err != nil { @@ -83,26 +71,26 @@ 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) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoiceResponse.PayReq, + // 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) //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.fundingClient.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) diff --git a/integration_tests/util.go b/integration_tests/util.go index b28b835..096fe1a 100644 --- a/integration_tests/util.go +++ b/integration_tests/util.go @@ -23,18 +23,24 @@ import ( "github.com/uptrace/bun/migrate" ) +//not used anymore +// const ( +// lnd1RegtestAddress = "rpc.lnd1.regtest.getalby.com:443" +// lnd1RegtestMacaroonHex = "0201036c6e6402f801030a10e2133a1cac2c5b4d56e44e32dc64c8551201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620c4f9783e0873fa50a2091806f5ebb919c5dc432e33800b401463ada6485df0ed" +// lnd2RegtestAddress = "rpc.lnd2.regtest.getalby.com:443" +// lnd2RegtestMacaroonHex = "0201036C6E6402F801030A101782922F4358E80655920FC7A7C3E9291201301A160A0761646472657373120472656164120577726974651A130A04696E666F120472656164120577726974651A170A08696E766F69636573120472656164120577726974651A210A086D616361726F6F6E120867656E6572617465120472656164120577726974651A160A076D657373616765120472656164120577726974651A170A086F6666636861696E120472656164120577726974651A160A076F6E636861696E120472656164120577726974651A140A057065657273120472656164120577726974651A180A067369676E6572120867656E657261746512047265616400000620628FFB2938C8540DD3AA5E578D9B43456835FAA176E175FFD4F9FBAE540E3BE9" +// // Use lnd3 for a funding client when testing out fee handling for payments done by lnd-1, since lnd3 doesn't have a direct channel to lnd1. +// // This will cause payment to be routed through lnd2, which will charge a fee (lnd default fee 1 sat base + 1 ppm). +// lnd3RegtestAddress = "rpc.lnd3.regtest.getalby.com:443" +// lnd3RegtestMacaroonHex = "0201036c6e6402f801030a102a5aa69a5efdf4b4a55a5304b164641f1201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620defbb5a809262297fd661a9ab6d3deb4b7acca4f1309c79addb952f0dc2d8c82" +// simnetLnd1PubKey = "0242898f86064c2fd72de22059c947a83ba23e9d97aedeae7b6dba647123f1d71b" +// simnetLnd2PubKey = "025c1d5d1b4c983cc6350fc2d756fbb59b4dc365e45e87f8e3afe07e24013e8220" +// simnetLnd3PubKey = "03c7092d076f799ab18806743634b4c9bb34e351bdebc91d5b35963f3dc63ec5aa" +// ) + const ( - lnd1RegtestAddress = "rpc.lnd1.regtest.getalby.com:443" - lnd1RegtestMacaroonHex = "0201036c6e6402f801030a10e2133a1cac2c5b4d56e44e32dc64c8551201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620c4f9783e0873fa50a2091806f5ebb919c5dc432e33800b401463ada6485df0ed" - lnd2RegtestAddress = "rpc.lnd2.regtest.getalby.com:443" - lnd2RegtestMacaroonHex = "0201036C6E6402F801030A101782922F4358E80655920FC7A7C3E9291201301A160A0761646472657373120472656164120577726974651A130A04696E666F120472656164120577726974651A170A08696E766F69636573120472656164120577726974651A210A086D616361726F6F6E120867656E6572617465120472656164120577726974651A160A076D657373616765120472656164120577726974651A170A086F6666636861696E120472656164120577726974651A160A076F6E636861696E120472656164120577726974651A140A057065657273120472656164120577726974651A180A067369676E6572120867656E657261746512047265616400000620628FFB2938C8540DD3AA5E578D9B43456835FAA176E175FFD4F9FBAE540E3BE9" - // Use lnd3 for a funding client when testing out fee handling for payments done by lnd-1, since lnd3 doesn't have a direct channel to lnd1. - // This will cause payment to be routed through lnd2, which will charge a fee (lnd default fee 1 sat base + 1 ppm). - lnd3RegtestAddress = "rpc.lnd3.regtest.getalby.com:443" - lnd3RegtestMacaroonHex = "0201036c6e6402f801030a102a5aa69a5efdf4b4a55a5304b164641f1201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620defbb5a809262297fd661a9ab6d3deb4b7acca4f1309c79addb952f0dc2d8c82" - simnetLnd1PubKey = "0242898f86064c2fd72de22059c947a83ba23e9d97aedeae7b6dba647123f1d71b" - simnetLnd2PubKey = "025c1d5d1b4c983cc6350fc2d756fbb59b4dc365e45e87f8e3afe07e24013e8220" - simnetLnd3PubKey = "03c7092d076f799ab18806743634b4c9bb34e351bdebc91d5b35963f3dc63ec5aa" + mockLNDAddress = "mock.lnd.local" + mockLNDMacaroonHex = "omnomnom" ) func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *service.LndhubService, err error) { @@ -47,8 +53,8 @@ func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *servi JWTSecret: []byte("SECRET"), JWTAccessTokenExpiry: 3600, JWTRefreshTokenExpiry: 3600, - LNDAddress: lnd1RegtestAddress, - LNDMacaroonHex: lnd1RegtestMacaroonHex, + LNDAddress: mockLNDAddress, + LNDMacaroonHex: mockLNDMacaroonHex, } dbConn, err := db.Open(c.DatabaseUri) if err != nil { @@ -66,27 +72,14 @@ func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *servi return nil, fmt.Errorf("failed to migrate: %w", err) } - var lndClient lnd.LightningClientWrapper - if lndClientMock == nil { - lndClient, err = lnd.NewLNDclient(lnd.LNDoptions{ - Address: c.LNDAddress, - MacaroonHex: c.LNDMacaroonHex, - }) - if err != nil { - return nil, fmt.Errorf("failed to initialize lnd service client: %w", err) - } - } else { - lndClient = lndClientMock - } - logger := lib.Logger(c.LogFilePath) svc = &service.LndhubService{ Config: c, DB: dbConn, - LndClient: lndClient, + LndClient: lndClientMock, Logger: logger, } - getInfo, err := lndClient.GetInfo(ctx, &lnrpc.GetInfoRequest{}) + getInfo, err := lndClientMock.GetInfo(ctx, &lnrpc.GetInfoRequest{}) if err != nil { logger.Fatalf("Error getting node info: %v", err) } diff --git a/integration_tests/webhook_test.go b/integration_tests/webhook_test.go index b1c21df..237d513 100644 --- a/integration_tests/webhook_test.go +++ b/integration_tests/webhook_test.go @@ -35,19 +35,10 @@ type WebHookTestSuite struct { } func (suite *WebHookTestSuite) SetupSuite() { - lndClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - suite.fundingClient = lndClient - suite.invoiceChan = make(chan models.Invoice) webhookServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { invoice := models.Invoice{} - err = json.NewDecoder(r.Body).Decode(&invoice) + err := json.NewDecoder(r.Body).Decode(&invoice) if err != nil { suite.echo.Logger.Error(err) close(suite.invoiceChan) diff --git a/integration_tests/websocket_test.go b/integration_tests/websocket_test.go index 910a264..f34c782 100644 --- a/integration_tests/websocket_test.go +++ b/integration_tests/websocket_test.go @@ -15,11 +15,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/gorilla/websocket" "github.com/labstack/echo/v4" - "github.com/lightningnetwork/lnd/lnrpc" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" ) @@ -30,7 +28,6 @@ type KeepAlive struct { type WebSocketTestSuite struct { TestSuite - fundingClient *lnd.LNDWrapper service *service.LndhubService userLogin ExpectedCreateUserResponseBody userToken string @@ -55,14 +52,6 @@ func (h *WsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (suite *WebSocketTestSuite) SetupSuite() { - lndClient, err := lnd.NewLNDclient(lnd.LNDoptions{ - Address: lnd2RegtestAddress, - MacaroonHex: lnd2RegtestMacaroonHex, - }) - if err != nil { - log.Fatalf("Error setting up funding client: %v", err) - } - suite.fundingClient = lndClient svc, err := LndHubTestServiceInit(nil) if err != nil { @@ -111,13 +100,13 @@ func (suite *WebSocketTestSuite) TestWebSocket() { assert.Equal(suite.T(), "keepalive", keepAlive.Type) // create incoming invoice and fund account - invoice := suite.createAddInvoiceReq(1000, "integration test websocket 1", suite.userToken) - sendPaymentRequest := lnrpc.SendRequest{ - PaymentRequest: invoice.PayReq, - FeeLimit: nil, - } - _, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) - assert.NoError(suite.T(), err) + //invoice := suite.createAddInvoiceReq(1000, "integration test websocket 1", suite.userToken) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoice.PayReq, + // FeeLimit: nil, + //} + //_, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) + //assert.NoError(suite.T(), err) _, msg, err = ws.ReadMessage() assert.NoError(suite.T(), err) @@ -142,12 +131,12 @@ func (suite *WebSocketTestSuite) TestWebSocketDoubeSubscription() { //read keepalive msg _, _, err = ws2.ReadMessage() assert.NoError(suite.T(), err) - invoice := suite.createAddInvoiceReq(1000, "integration test websocket 2", suite.userToken) - sendPaymentRequest := lnrpc.SendRequest{ - PaymentRequest: invoice.PayReq, - FeeLimit: nil, - } - _, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) + //invoice := suite.createAddInvoiceReq(1000, "integration test websocket 2", suite.userToken) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoice.PayReq, + // FeeLimit: nil, + //} + //_, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) assert.NoError(suite.T(), err) _, msg1, err := ws1.ReadMessage() assert.NoError(suite.T(), err) @@ -164,12 +153,12 @@ func (suite *WebSocketTestSuite) TestWebSocketDoubeSubscription() { assert.Equal(suite.T(), "integration test websocket 2", event2.Invoice.Description) //close 1 subscription, assert that the existing sub still receives their invoices ws1.Close() - invoice = suite.createAddInvoiceReq(1000, "integration test websocket 3", suite.userToken) - sendPaymentRequest = lnrpc.SendRequest{ - PaymentRequest: invoice.PayReq, - FeeLimit: nil, - } - _, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) + //invoice = suite.createAddInvoiceReq(1000, "integration test websocket 3", suite.userToken) + //sendPaymentRequest = lnrpc.SendRequest{ + // PaymentRequest: invoice.PayReq, + // FeeLimit: nil, + //} + //_, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) assert.NoError(suite.T(), err) _, msg3, err := ws2.ReadMessage() assert.NoError(suite.T(), err) @@ -194,21 +183,21 @@ func (suite *WebSocketTestSuite) TestWebSocketDoubleUser() { _, _, err = user2Ws.ReadMessage() assert.NoError(suite.T(), err) // add invoice for user 1 - user1Invoice := suite.createAddInvoiceReq(1000, "integration test websocket user 1", suite.userToken) - sendPaymentRequestUser1 := lnrpc.SendRequest{ - PaymentRequest: user1Invoice.PayReq, - FeeLimit: nil, - } - // add invoice for user 2 - user2Invoice := suite.createAddInvoiceReq(1000, "integration test websocket user 2", suite.userToken2) - sendPaymentRequestUser2 := lnrpc.SendRequest{ - PaymentRequest: user2Invoice.PayReq, - FeeLimit: nil, - } + //user1Invoice := suite.createAddInvoiceReq(1000, "integration test websocket user 1", suite.userToken) + //sendPaymentRequestUser1 := lnrpc.SendRequest{ + // PaymentRequest: user1Invoice.PayReq, + // FeeLimit: nil, + //} + //// add invoice for user 2 + //user2Invoice := suite.createAddInvoiceReq(1000, "integration test websocket user 2", suite.userToken2) + //sendPaymentRequestUser2 := lnrpc.SendRequest{ + // PaymentRequest: user2Invoice.PayReq, + // FeeLimit: nil, + //} //pay invoices - _, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequestUser1) - assert.NoError(suite.T(), err) - _, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequestUser2) + //_, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequestUser1) + //assert.NoError(suite.T(), err) + //_, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequestUser2) assert.NoError(suite.T(), err) //read user 1 received msg _, user1Msg, err := user1Ws.ReadMessage() @@ -231,21 +220,21 @@ func (suite *WebSocketTestSuite) TestWebSocketDoubleUser() { func (suite *WebSocketTestSuite) TestWebSocketMissingInvoice() { // create incoming invoice and fund account invoice1 := suite.createAddInvoiceReq(1000, "integration test websocket missing invoices", suite.userToken) - sendPaymentRequest := lnrpc.SendRequest{ - PaymentRequest: invoice1.PayReq, - FeeLimit: nil, - } - _, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) - assert.NoError(suite.T(), err) + //sendPaymentRequest := lnrpc.SendRequest{ + // PaymentRequest: invoice1.PayReq, + // FeeLimit: nil, + //} + //_, err := suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) + //assert.NoError(suite.T(), err) - // create 2nd invoice and pay it as well - invoice2 := suite.createAddInvoiceReq(1000, "integration test websocket missing invoices 2nd", suite.userToken) - sendPaymentRequest = lnrpc.SendRequest{ - PaymentRequest: invoice2.PayReq, - FeeLimit: nil, - } - _, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) - assert.NoError(suite.T(), err) + //// create 2nd invoice and pay it as well + //invoice2 := suite.createAddInvoiceReq(1000, "integration test websocket missing invoices 2nd", suite.userToken) + //sendPaymentRequest = lnrpc.SendRequest{ + // PaymentRequest: invoice2.PayReq, + // FeeLimit: nil, + //} + //_, err = suite.fundingClient.SendPaymentSync(context.Background(), &sendPaymentRequest) + //assert.NoError(suite.T(), err) //start listening to websocket after 2nd invoice has been paid //we should get an event for the 2nd invoice if we specify the hash as the query parameter