Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Dec 5, 2023
1 parent e681e69 commit a9e046f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 33 additions & 11 deletions integration_tests/internal_payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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() {
Expand Down

0 comments on commit a9e046f

Please sign in to comment.