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(aliceFundingSats)-int64(externalSatRequested), 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(), 3, len(transactonEntries)) }