mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-22 15:14:51 +01:00
Add missing test
This commit is contained in:
@@ -25,10 +25,8 @@ type PaymentTestErrorsSuite struct {
|
||||
TestSuite
|
||||
fundingClient *lnd.LNDWrapper
|
||||
service *service.LndhubService
|
||||
aliceLogin controllers.CreateUserResponseBody
|
||||
aliceToken string
|
||||
bobLogin controllers.CreateUserResponseBody
|
||||
bobToken string
|
||||
userLogin controllers.CreateUserResponseBody
|
||||
userToken string
|
||||
invoiceUpdateSubCancelFn context.CancelFunc
|
||||
}
|
||||
|
||||
@@ -56,7 +54,7 @@ func (suite *PaymentTestErrorsSuite) SetupSuite() {
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing test service: %v", err)
|
||||
}
|
||||
users, userTokens, err := createUsers(svc, 2)
|
||||
users, userTokens, err := createUsers(svc, 1)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating test users: %v", err)
|
||||
}
|
||||
@@ -71,12 +69,10 @@ func (suite *PaymentTestErrorsSuite) SetupSuite() {
|
||||
e.HTTPErrorHandler = responses.HTTPErrorHandler
|
||||
e.Validator = &lib.CustomValidator{Validator: validator.New()}
|
||||
suite.echo = e
|
||||
assert.Equal(suite.T(), 2, len(users))
|
||||
assert.Equal(suite.T(), 2, len(userTokens))
|
||||
suite.aliceLogin = users[0]
|
||||
suite.aliceToken = userTokens[0]
|
||||
suite.bobLogin = users[1]
|
||||
suite.bobToken = userTokens[1]
|
||||
assert.Equal(suite.T(), 1, len(users))
|
||||
assert.Equal(suite.T(), 1, len(userTokens))
|
||||
suite.userLogin = users[0]
|
||||
suite.userToken = userTokens[0]
|
||||
suite.echo.Use(tokens.Middleware([]byte(suite.service.Config.JWTSecret)))
|
||||
suite.echo.GET("/balance", controllers.NewBalanceController(suite.service).Balance)
|
||||
suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.service).AddInvoice)
|
||||
@@ -84,10 +80,10 @@ func (suite *PaymentTestErrorsSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
func (suite *PaymentTestErrorsSuite) TestExternalFailingInvoice() {
|
||||
aliceFundingSats := 1000
|
||||
userFundingSats := 1000
|
||||
externalSatRequested := 500
|
||||
//fund alice account
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
//fund user account
|
||||
invoiceResponse := suite.createAddInvoiceReq(userFundingSats, "integration test external payment user", suite.userToken)
|
||||
sendPaymentRequest := lnrpc.SendRequest{
|
||||
PaymentRequest: invoiceResponse.PayReq,
|
||||
FeeLimit: nil,
|
||||
@@ -100,15 +96,15 @@ func (suite *PaymentTestErrorsSuite) TestExternalFailingInvoice() {
|
||||
|
||||
//create external invoice
|
||||
externalInvoice := lnrpc.Invoice{
|
||||
Memo: "integration tests: external pay from alice",
|
||||
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 alice, mock will fail
|
||||
_ = suite.createPayInvoiceReqError(invoice.PaymentRequest, suite.aliceToken)
|
||||
//pay external from user, mock will fail immediately
|
||||
_ = suite.createPayInvoiceReqError(invoice.PaymentRequest, suite.userToken)
|
||||
|
||||
userId := getUserIdFromToken(suite.aliceToken)
|
||||
userId := getUserIdFromToken(suite.userToken)
|
||||
|
||||
invoices, err := suite.service.InvoicesFor(context.Background(), userId, common.InvoiceTypeOutgoing)
|
||||
if err != nil {
|
||||
@@ -123,7 +119,7 @@ func (suite *PaymentTestErrorsSuite) TestExternalFailingInvoice() {
|
||||
fmt.Printf("Error when getting transaction entries %v\n", err.Error())
|
||||
}
|
||||
|
||||
aliceBalance, err := suite.service.CurrentUserBalance(context.Background(), userId)
|
||||
userBalance, err := suite.service.CurrentUserBalance(context.Background(), userId)
|
||||
if err != nil {
|
||||
fmt.Printf("Error when getting balance %v\n", err.Error())
|
||||
}
|
||||
@@ -135,7 +131,7 @@ func (suite *PaymentTestErrorsSuite) TestExternalFailingInvoice() {
|
||||
assert.Equal(suite.T(), transactonEntries[1].Amount, int64(externalSatRequested))
|
||||
assert.Equal(suite.T(), transactonEntries[2].Amount, int64(externalSatRequested))
|
||||
// assert that balance is the same
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats), aliceBalance)
|
||||
assert.Equal(suite.T(), int64(userFundingSats), userBalance)
|
||||
}
|
||||
|
||||
func (suite *PaymentTestErrorsSuite) TearDownSuite() {
|
||||
|
||||
Reference in New Issue
Block a user