working on test refactoring

This commit is contained in:
kiwiidb
2022-06-15 11:39:54 +02:00
parent 9e9fc4fbf0
commit 9574b41a08
12 changed files with 299 additions and 324 deletions

View File

@@ -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)