From 38de96bcb658900a0762c6b844b1cd79eeee0492 Mon Sep 17 00:00:00 2001 From: im-adithya Date: Tue, 5 Dec 2023 16:48:43 +0530 Subject: [PATCH] fix: tests --- go.mod | 2 +- integration_tests/internal_payment_test.go | 44 ++++++++++++++++------ integration_tests/util.go | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 9c206902..1f12b6fb 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/lightningnetwork/lnd v0.16.4-beta.rc1 github.com/rabbitmq/amqp091-go v1.8.1 github.com/rs/zerolog v1.29.1 + github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.4 github.com/uptrace/bun v1.1.14 github.com/uptrace/bun/dialect/pgdialect v1.1.14 @@ -137,7 +138,6 @@ require ( github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rogpeppe/fastuuid v1.2.0 // indirect github.com/secure-systems-lab/go-securesystemslib v0.6.0 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect github.com/soheilhy/cmux v0.1.5 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.0 // indirect diff --git a/integration_tests/internal_payment_test.go b/integration_tests/internal_payment_test.go index 8a95158d..85ad1e8b 100644 --- a/integration_tests/internal_payment_test.go +++ b/integration_tests/internal_payment_test.go @@ -147,7 +147,10 @@ func (suite *PaymentTestSuite) TestIncomingExceededChecks() { //wait a bit for the payment to be processed time.Sleep(10 * time.Millisecond) var buf bytes.Buffer - suite.service.Config.MaxReceiveAmount = 21 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), + &lnd.Limits{ + MaxReceiveAmount: 21, + })) rec := httptest.NewRecorder() assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedAddInvoiceRequestBody{ Amount: aliceFundingSats, @@ -165,13 +168,20 @@ func (suite *PaymentTestSuite) TestIncomingExceededChecks() { assert.Equal(suite.T(), responses.ReceiveExceededError.Message, resp.Message) // remove volume and receive config and check if it works - suite.service.Config.MaxReceiveAmount = 0 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), + &lnd.Limits{ + MaxReceiveAmount: 0, + })) invoiceResponse = suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken) err = suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil) assert.NoError(suite.T(), err) // add max account - suite.service.Config.MaxAccountBalance = 500 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), + &lnd.Limits{ + MaxReceiveAmount: 0, + MaxAccountBalance: 500, + })) assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedAddInvoiceRequestBody{ Amount: aliceFundingSats, Memo: "memo", @@ -188,13 +198,17 @@ func (suite *PaymentTestSuite) TestIncomingExceededChecks() { assert.Equal(suite.T(), responses.BalanceExceededError.Message, resp.Message) //change the config back and add sats, it should work now - suite.service.Config.MaxAccountBalance = 0 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{ MaxAccountBalance: 0 })) invoiceResponse = suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken) err = suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil) assert.NoError(suite.T(), err) // add max receive volume - suite.service.Config.MaxReceiveVolume = 1999 // because the volume till here is 1000+500+500 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), + &lnd.Limits{ + MaxReceiveVolume: 1999, // because the volume till here is 1000+500+500 + MaxAccountBalance: 0, + })) suite.service.Config.MaxVolumePeriod = 2592000 assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedAddInvoiceRequestBody{ Amount: aliceFundingSats, @@ -212,8 +226,12 @@ func (suite *PaymentTestSuite) TestIncomingExceededChecks() { assert.Equal(suite.T(), responses.TooMuchVolumeError.Message, resp.Message) //change the config back, it should work now - suite.service.Config.MaxReceiveVolume = 0 suite.service.Config.MaxVolumePeriod = 0 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), + &lnd.Limits{ + MaxReceiveVolume: 0, + MaxAccountBalance: 0, + })) invoiceResponse = suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken) err = suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil) assert.NoError(suite.T(), err) @@ -222,7 +240,7 @@ func (suite *PaymentTestSuite) TestIncomingExceededChecks() { func (suite *PaymentTestSuite) TestOutgoingExceededChecks() { //this will cause the payment to fail as the account was already funded //with 1000 sats - suite.service.Config.MaxSendAmount = 100 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{ MaxSendAmount: 100 })) aliceFundingSats := 1000 //fund alice account invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test internal payment alice", suite.aliceToken) @@ -260,7 +278,7 @@ func (suite *PaymentTestSuite) TestOutgoingExceededChecks() { assert.NoError(suite.T(), err) assert.Equal(suite.T(), responses.SendExceededError.Message, resp.Message) - suite.service.Config.MaxSendAmount = 2000 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{ MaxSendAmount: 2000 })) //should work now rec = httptest.NewRecorder() invoice, err = suite.externalLND.AddInvoice(context.Background(), &externalInvoice) @@ -271,8 +289,10 @@ func (suite *PaymentTestSuite) TestOutgoingExceededChecks() { suite.echo.ServeHTTP(rec, req) assert.Equal(suite.T(), http.StatusOK, rec.Code) - suite.service.Config.MaxSendVolume = 100 suite.service.Config.MaxVolumePeriod = 2592000 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{ + MaxSendVolume: 100, + })) //volume invoice, err = suite.externalLND.AddInvoice(context.Background(), &externalInvoice) assert.NoError(suite.T(), err) @@ -294,9 +314,11 @@ func (suite *PaymentTestSuite) TestOutgoingExceededChecks() { assert.Equal(suite.T(), responses.TooMuchVolumeError.Message, resp.Message) //change the config back - suite.service.Config.MaxSendAmount = 0 - suite.service.Config.MaxSendVolume = 0 suite.service.Config.MaxVolumePeriod = 0 + suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret), &lnd.Limits{ + MaxSendVolume: 0, + MaxSendAmount: 0, + })) } func (suite *PaymentTestSuite) TestInternalPayment() { diff --git a/integration_tests/util.go b/integration_tests/util.go index 2fe3e7d7..7e83a877 100644 --- a/integration_tests/util.go +++ b/integration_tests/util.go @@ -45,7 +45,7 @@ const ( ) func LndHubTestServiceInit(lndClientMock lnd.LightningClientWrapper) (svc *service.LndhubService, err error) { - dbUri := "postgresql://user:password@localhost/lndhub?sslmode=disable" + dbUri := "postgresql://im-adithya:password@localhost:5432/lndhub?sslmode=disable" c := &service.Config{ DatabaseUri: dbUri, DatabaseMaxConns: 1,