Files
lndhub.go/integration_tests/outgoing_payment_test.go
Stefan Kostic 09aee50ec0 Cleanup
2022-02-17 20:17:29 +01:00

53 lines
1.7 KiB
Go

package integration_tests
import (
"context"
"fmt"
"time"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/stretchr/testify/assert"
)
func (suite *PaymentTestSuite) TestOutGoingPayment() {
aliceFundingSats := 1000
externalSatRequested := 500
//fund alice account
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
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 alice",
Value: int64(externalSatRequested),
}
invoice, err := suite.fundingClient.AddInvoice(context.Background(), &externalInvoice)
assert.NoError(suite.T(), err)
//pay external from alice
payResponse := suite.createPayInvoiceReq(invoice.PaymentRequest, suite.aliceToken)
assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
// check that balance was reduced
userId := getUserIdFromToken(suite.aliceToken)
aliceBalance, err := suite.service.CurrentUserBalance(context.Background(), userId)
if err != nil {
fmt.Printf("Error when getting balance %v\n", err.Error())
}
assert.Equal(suite.T(), int64(500), aliceBalance)
// check that no additional transaction entry was created
transactonEntries, err := suite.service.TransactionEntriesFor(context.Background(), userId)
if err != nil {
fmt.Printf("Error when getting transaction entries %v\n", err.Error())
}
assert.Equal(suite.T(), 2, len(transactonEntries))
}