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 PaymentTestAsyncErrorsSuite struct {
TestSuite
fundingClient *lnd.LNDWrapper
service *service.LndhubService
userLogin ExpectedCreateUserResponseBody
userToken string
@@ -32,25 +30,15 @@ type PaymentTestAsyncErrorsSuite struct {
}
func (suite *PaymentTestAsyncErrorsSuite) 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 := NewLNDMockWrapperAsync(lnd.LNDoptions{
Address: lnd1RegtestAddress,
MacaroonHex: lnd1RegtestMacaroonHex,
Address: mockLNDAddress,
MacaroonHex: mockLNDMacaroonHex,
})
suite.serviceClient = lndClient
if err != nil {
log.Fatalf("Error setting up test client: %v", err)
}
suite.fundingClient = fundingClient
svc, err := LndHubTestServiceInit(lndClient)
if err != nil {
@@ -85,26 +73,26 @@ func (suite *PaymentTestAsyncErrorsSuite) TestExternalAsyncFailingInvoice() {
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, req will be canceled after 2 sec
go suite.createPayInvoiceReqWithCancel(invoice.PaymentRequest, suite.userToken)
//go suite.createPayInvoiceReqWithCancel(invoice.PaymentRequest, suite.userToken)
// wait for request to fail
time.Sleep(5 * time.Second)