From 40e34086d7cb24ce053fb81e67fef47a5d855ebd Mon Sep 17 00:00:00 2001 From: kiwiidb Date: Wed, 15 Jun 2022 18:27:03 +0200 Subject: [PATCH] all tests passing --- integration_tests/auth_test.go | 2 +- integration_tests/checkpayment_test.go | 16 +++++++--------- integration_tests/create_test.go | 2 +- integration_tests/getinfo_test.go | 4 ++-- integration_tests/gettxs_test.go | 6 +----- integration_tests/incoming_payment_test.go | 5 +---- integration_tests/internal_payment_test.go | 5 +---- integration_tests/invoice_test.go | 7 +------ integration_tests/keysend_test.go | 7 ++----- integration_tests/lnd_mock.go | 9 +++++++++ integration_tests/outgoing_payment_test.go | 2 +- integration_tests/payment_failure_async_test.go | 5 +---- integration_tests/payment_failure_test.go | 5 +---- integration_tests/subscription_start_test.go | 13 ++++--------- integration_tests/webhook_test.go | 6 +----- integration_tests/websocket_test.go | 6 +----- 16 files changed, 35 insertions(+), 65 deletions(-) diff --git a/integration_tests/auth_test.go b/integration_tests/auth_test.go index ac19437..14af729 100644 --- a/integration_tests/auth_test.go +++ b/integration_tests/auth_test.go @@ -30,7 +30,7 @@ type UserAuthTestSuite struct { } func (suite *UserAuthTestSuite) SetupSuite() { - svc, err := LndHubTestServiceInit(nil) + svc, err := LndHubTestServiceInit(newDefaultMockLND()) if err != nil { log.Fatalf("Error initializing test service: %v", err) } diff --git a/integration_tests/checkpayment_test.go b/integration_tests/checkpayment_test.go index 5a52f3b..86b9da9 100644 --- a/integration_tests/checkpayment_test.go +++ b/integration_tests/checkpayment_test.go @@ -17,7 +17,6 @@ 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" ) @@ -25,16 +24,19 @@ import ( type CheckPaymentTestSuite struct { TestSuite service *service.LndhubService + mlnd *MockLND userLogin ExpectedCreateUserResponseBody userToken string invoiceUpdateSubCancelFn context.CancelFunc } func (suite *CheckPaymentTestSuite) SetupSuite() { - svc, err := LndHubTestServiceInit(nil) + mockLND := newDefaultMockLND() + svc, err := LndHubTestServiceInit(mockLND) if err != nil { log.Fatalf("Error initializing test service: %v", err) } + suite.mlnd = mockLND users, userTokens, err := createUsers(svc, 1) if err != nil { log.Fatalf("Error creating test users: %v", err) @@ -74,14 +76,10 @@ 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) - //TODO fund - _ = lnrpc.SendRequest{ - PaymentRequest: invoice.PayReq, - FeeLimit: nil, - } - + err := suite.mlnd.mockPaidInvoice(invoice, 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 invoice invoice = suite.createAddInvoiceReq(500, "integration test check payments for user", suite.userToken) // pay invoice, this will create outgoing invoice and settle it diff --git a/integration_tests/create_test.go b/integration_tests/create_test.go index 42202fe..ed214e0 100644 --- a/integration_tests/create_test.go +++ b/integration_tests/create_test.go @@ -25,7 +25,7 @@ type CreateUserTestSuite struct { } func (suite *CreateUserTestSuite) SetupSuite() { - svc, err := LndHubTestServiceInit(nil) + svc, err := LndHubTestServiceInit(newDefaultMockLND()) if err != nil { log.Fatalf("Error initializing test service: %v", err) } diff --git a/integration_tests/getinfo_test.go b/integration_tests/getinfo_test.go index 8df60a7..b6d0719 100644 --- a/integration_tests/getinfo_test.go +++ b/integration_tests/getinfo_test.go @@ -28,7 +28,7 @@ type GetInfoTestSuite struct { } func (suite *GetInfoTestSuite) SetupSuite() { - svc, err := LndHubTestServiceInit(nil) + svc, err := LndHubTestServiceInit(newDefaultMockLND()) if err != nil { log.Fatalf("Error initializing test service: %v", err) } @@ -60,7 +60,7 @@ func (suite *GetInfoTestSuite) TestGetInfoWithDefaultAlias() { assert.Equal(suite.T(), http.StatusOK, rec.Code) assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(getInfoResponse)) assert.NotNil(suite.T(), getInfoResponse) - assert.Equal(suite.T(), "alby-simnet-lnd1", getInfoResponse.Alias) + assert.Equal(suite.T(), "Mocky McMockface", getInfoResponse.Alias) } func (suite *GetInfoTestSuite) TestGetInfoWithGivenAlias() { diff --git a/integration_tests/gettxs_test.go b/integration_tests/gettxs_test.go index 563d561..a1a6f05 100644 --- a/integration_tests/gettxs_test.go +++ b/integration_tests/gettxs_test.go @@ -17,7 +17,6 @@ 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" ) @@ -32,10 +31,7 @@ type GetTxTestSuite struct { } func (suite *GetTxTestSuite) SetupSuite() { - mockLND, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } + mockLND := newDefaultMockLND() svc, err := LndHubTestServiceInit(mockLND) if err != nil { log.Fatalf("Error initializing test service: %v", err) diff --git a/integration_tests/incoming_payment_test.go b/integration_tests/incoming_payment_test.go index e11bbe7..5cb9588 100644 --- a/integration_tests/incoming_payment_test.go +++ b/integration_tests/incoming_payment_test.go @@ -35,10 +35,7 @@ type IncomingPaymentTestSuite struct { } func (suite *IncomingPaymentTestSuite) SetupSuite() { - mockLND, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } + mockLND := newDefaultMockLND() suite.mockLND = mockLND svc, err := LndHubTestServiceInit(mockLND) if err != nil { diff --git a/integration_tests/internal_payment_test.go b/integration_tests/internal_payment_test.go index 27c26e5..c155bef 100644 --- a/integration_tests/internal_payment_test.go +++ b/integration_tests/internal_payment_test.go @@ -37,10 +37,7 @@ type PaymentTestSuite struct { } func (suite *PaymentTestSuite) SetupSuite() { - mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } + mlnd := newDefaultMockLND() suite.mlnd = mlnd externalLND, err := NewMockLND("1234567890abcdefabcd", 0, make(chan (*lnrpc.Invoice))) if err != nil { diff --git a/integration_tests/invoice_test.go b/integration_tests/invoice_test.go index aafaa51..55c0369 100644 --- a/integration_tests/invoice_test.go +++ b/integration_tests/invoice_test.go @@ -12,7 +12,6 @@ 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" ) @@ -24,11 +23,7 @@ type InvoiceTestSuite struct { } func (suite *InvoiceTestSuite) SetupSuite() { - mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } - svc, err := LndHubTestServiceInit(mlnd) + svc, err := LndHubTestServiceInit(newDefaultMockLND()) if err != nil { log.Fatalf("Error initializing test service: %v", err) } diff --git a/integration_tests/keysend_test.go b/integration_tests/keysend_test.go index a996afe..b93a08a 100644 --- a/integration_tests/keysend_test.go +++ b/integration_tests/keysend_test.go @@ -14,7 +14,6 @@ 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" ) @@ -30,10 +29,8 @@ type KeySendTestSuite struct { func (suite *KeySendTestSuite) SetupSuite() { fee := int64(1) - mlnd, err := NewMockLND("1234567890abcdef", fee, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } + mlnd := newDefaultMockLND() + mlnd.fee = fee suite.mlnd = mlnd svc, err := LndHubTestServiceInit(mlnd) if err != nil { diff --git a/integration_tests/lnd_mock.go b/integration_tests/lnd_mock.go index 0e6de8f..77327ac 100644 --- a/integration_tests/lnd_mock.go +++ b/integration_tests/lnd_mock.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "crypto/sha256" "encoding/hex" + "log" "math/big" "time" @@ -253,3 +254,11 @@ func randBytesFromStr(length int, from string) ([]byte, error) { } return b, nil } + +func newDefaultMockLND() *MockLND { + mockLND, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) + if err != nil { + log.Fatalf("Error initializing test service: %v", err) + } + return mockLND +} diff --git a/integration_tests/outgoing_payment_test.go b/integration_tests/outgoing_payment_test.go index 5ec4ccb..affea15 100644 --- a/integration_tests/outgoing_payment_test.go +++ b/integration_tests/outgoing_payment_test.go @@ -130,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)+suite.mlnd.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 diff --git a/integration_tests/payment_failure_async_test.go b/integration_tests/payment_failure_async_test.go index c518058..7f29ae8 100644 --- a/integration_tests/payment_failure_async_test.go +++ b/integration_tests/payment_failure_async_test.go @@ -32,10 +32,7 @@ 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) - } + mlnd := newDefaultMockLND() externalLND, err := NewMockLND("1234567890abcdefabcd", 0, make(chan (*lnrpc.Invoice))) if err != nil { log.Fatalf("Error initializing test service: %v", err) diff --git a/integration_tests/payment_failure_test.go b/integration_tests/payment_failure_test.go index b8e84f3..4ead195 100644 --- a/integration_tests/payment_failure_test.go +++ b/integration_tests/payment_failure_test.go @@ -31,10 +31,7 @@ type PaymentTestErrorsSuite struct { } func (suite *PaymentTestErrorsSuite) SetupSuite() { - mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } + mlnd := newDefaultMockLND() externalLND, err := NewMockLND("1234567890abcdefabcd", 0, make(chan (*lnrpc.Invoice))) if err != nil { log.Fatalf("Error initializing test service: %v", err) diff --git a/integration_tests/subscription_start_test.go b/integration_tests/subscription_start_test.go index 2f99459..2cde79f 100644 --- a/integration_tests/subscription_start_test.go +++ b/integration_tests/subscription_start_test.go @@ -25,10 +25,9 @@ import ( type SubscriptionStartTestSuite struct { TestSuite - service *service.LndhubService - userLogin ExpectedCreateUserResponseBody - userToken string - invoiceUpdateSubCancelFn context.CancelFunc + service *service.LndhubService + userLogin ExpectedCreateUserResponseBody + userToken string } func (suite *SubscriptionStartTestSuite) TearDownSuite() { @@ -39,11 +38,7 @@ func TestSubscriptionStartTestSuite(t *testing.T) { suite.Run(t, new(SubscriptionStartTestSuite)) } func (suite *SubscriptionStartTestSuite) SetupSuite() { - mockLND, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } - svc, err := LndHubTestServiceInit(mockLND) + svc, err := LndHubTestServiceInit(newDefaultMockLND()) if err != nil { log.Fatalf("Error initializing test service: %v", err) } diff --git a/integration_tests/webhook_test.go b/integration_tests/webhook_test.go index 7fcc634..85605e3 100644 --- a/integration_tests/webhook_test.go +++ b/integration_tests/webhook_test.go @@ -17,7 +17,6 @@ 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" ) @@ -46,10 +45,7 @@ func (suite *WebHookTestSuite) SetupSuite() { suite.invoiceChan <- invoice })) suite.webHookServer = webhookServer - mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } + mlnd := newDefaultMockLND() svc, err := LndHubTestServiceInit(mlnd) suite.mlnd = mlnd if err != nil { diff --git a/integration_tests/websocket_test.go b/integration_tests/websocket_test.go index 8c5ca98..dd5989f 100644 --- a/integration_tests/websocket_test.go +++ b/integration_tests/websocket_test.go @@ -18,7 +18,6 @@ import ( "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" ) @@ -54,10 +53,7 @@ func (h *WsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (suite *WebSocketTestSuite) SetupSuite() { - mlnd, err := NewMockLND("1234567890abcdef", 0, make(chan (*lnrpc.Invoice))) - if err != nil { - log.Fatalf("Error initializing test service: %v", err) - } + mlnd := newDefaultMockLND() svc, err := LndHubTestServiceInit(mlnd) if err != nil { log.Fatalf("Error initializing test service: %v", err)