mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-20 06:05:08 +01:00
improve integration tests
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
|||||||
type RabbitMQTestSuite struct {
|
type RabbitMQTestSuite struct {
|
||||||
TestSuite
|
TestSuite
|
||||||
mlnd *MockLND
|
mlnd *MockLND
|
||||||
|
externalLnd *MockLND
|
||||||
invoiceUpdateSubCancelFn context.CancelFunc
|
invoiceUpdateSubCancelFn context.CancelFunc
|
||||||
userToken string
|
userToken string
|
||||||
svc *service.LndhubService
|
svc *service.LndhubService
|
||||||
@@ -33,12 +34,17 @@ type RabbitMQTestSuite struct {
|
|||||||
|
|
||||||
func (suite *RabbitMQTestSuite) SetupSuite() {
|
func (suite *RabbitMQTestSuite) SetupSuite() {
|
||||||
mlnd := newDefaultMockLND()
|
mlnd := newDefaultMockLND()
|
||||||
|
//needs different pubkey
|
||||||
|
//to allow for "external" payments
|
||||||
|
externalLnd, err := NewMockLND("1234567890abcdef1234", 0, make(chan (*lnrpc.Invoice)))
|
||||||
|
assert.NoError(suite.T(), err)
|
||||||
svc, err := LndHubTestServiceInit(mlnd)
|
svc, err := LndHubTestServiceInit(mlnd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("could not initialize test service: %v", err)
|
log.Fatalf("could not initialize test service: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.mlnd = mlnd
|
suite.mlnd = mlnd
|
||||||
|
suite.externalLnd = externalLnd
|
||||||
suite.testQueueName = "test_invoice"
|
suite.testQueueName = "test_invoice"
|
||||||
|
|
||||||
_, userTokens, err := createUsers(svc, 1)
|
_, userTokens, err := createUsers(svc, 1)
|
||||||
@@ -60,7 +66,10 @@ func (suite *RabbitMQTestSuite) SetupSuite() {
|
|||||||
suite.echo.Use(tokens.Middleware(suite.svc.Config.JWTSecret))
|
suite.echo.Use(tokens.Middleware(suite.svc.Config.JWTSecret))
|
||||||
suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.svc).AddInvoice)
|
suite.echo.POST("/addinvoice", controllers.NewAddInvoiceController(suite.svc).AddInvoice)
|
||||||
suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.svc).PayInvoice)
|
suite.echo.POST("/payinvoice", controllers.NewPayInvoiceController(suite.svc).PayInvoice)
|
||||||
go svc.StartRabbitMqPublisher(ctx)
|
go func() {
|
||||||
|
err = svc.StartRabbitMqPublisher(ctx)
|
||||||
|
assert.NoError(suite.T(), err)
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RabbitMQTestSuite) TestPublishInvoice() {
|
func (suite *RabbitMQTestSuite) TestPublishInvoice() {
|
||||||
@@ -91,7 +100,7 @@ func (suite *RabbitMQTestSuite) TestPublishInvoice() {
|
|||||||
|
|
||||||
m, err := ch.Consume(
|
m, err := ch.Consume(
|
||||||
q.Name,
|
q.Name,
|
||||||
"#.#.invoice",
|
"invoice.*.*",
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
@@ -113,7 +122,9 @@ func (suite *RabbitMQTestSuite) TestPublishInvoice() {
|
|||||||
//check if outgoing invoices also get published
|
//check if outgoing invoices also get published
|
||||||
outgoingInvoiceValue := 500
|
outgoingInvoiceValue := 500
|
||||||
outgoingInvoiceDescription := "test rabbit outgoing invoice"
|
outgoingInvoiceDescription := "test rabbit outgoing invoice"
|
||||||
outgoingInv, err := suite.mlnd.AddInvoice(context.Background(), &lnrpc.Invoice{Value: int64(outgoingInvoiceValue), Memo: outgoingInvoiceDescription})
|
preimage, err := makePreimageHex()
|
||||||
|
assert.NoError(suite.T(), err)
|
||||||
|
outgoingInv, err := suite.externalLnd.AddInvoice(context.Background(), &lnrpc.Invoice{Value: int64(outgoingInvoiceValue), Memo: outgoingInvoiceDescription, RPreimage: preimage})
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
//pay invoice
|
//pay invoice
|
||||||
suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||||
@@ -126,9 +137,8 @@ func (suite *RabbitMQTestSuite) TestPublishInvoice() {
|
|||||||
err = json.NewDecoder(r).Decode(&receivedPayment)
|
err = json.NewDecoder(r).Decode(&receivedPayment)
|
||||||
assert.NoError(suite.T(), err)
|
assert.NoError(suite.T(), err)
|
||||||
|
|
||||||
assert.Equal(suite.T(), outgoingInv.RHash, receivedPayment.RHash)
|
|
||||||
assert.Equal(suite.T(), common.InvoiceTypeOutgoing, receivedPayment.Type)
|
assert.Equal(suite.T(), common.InvoiceTypeOutgoing, receivedPayment.Type)
|
||||||
assert.Equal(suite.T(), outgoingInvoiceValue, receivedPayment.Amount)
|
assert.Equal(suite.T(), int64(outgoingInvoiceValue), receivedPayment.Amount)
|
||||||
assert.Equal(suite.T(), outgoingInvoiceDescription, receivedPayment.Memo)
|
assert.Equal(suite.T(), outgoingInvoiceDescription, receivedPayment.Memo)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user