mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-07 06:56:11 +01:00
one more file to refactor
This commit is contained in:
@@ -9,35 +9,35 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/getAlby/lndhub.go/common"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
aliceFundingSats := 1000
|
||||
//todo
|
||||
externalSatRequested := 500
|
||||
// 1 sat + 1 ppm
|
||||
fee := 1
|
||||
suite.mlnd.fee = 1
|
||||
//fund alice account
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
err := suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
//wait a bit for the callback event to hit
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
time.Sleep(10 * 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(&ExpectedPayInvoiceRequestBody{
|
||||
// Invoice: invoice.PaymentRequest,
|
||||
//}, suite.aliceToken)
|
||||
//assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
externalInvoice := lnrpc.Invoice{
|
||||
Memo: "integration tests: external pay from alice",
|
||||
Value: int64(externalSatRequested),
|
||||
}
|
||||
invoice, err := suite.externalLND.AddInvoice(context.Background(), &externalInvoice)
|
||||
assert.NoError(suite.T(), err)
|
||||
//pay external from alice
|
||||
payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
Invoice: invoice.PaymentRequest,
|
||||
}, suite.aliceToken)
|
||||
assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
|
||||
// check that balance was reduced
|
||||
userId := getUserIdFromToken(suite.aliceToken)
|
||||
@@ -45,7 +45,7 @@ func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
if err != nil {
|
||||
fmt.Printf("Error when getting balance %v\n", err.Error())
|
||||
}
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+fee), aliceBalance)
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+int(suite.mlnd.fee)), aliceBalance)
|
||||
|
||||
// check that no additional transaction entry was created
|
||||
transactonEntries, err := suite.service.TransactionEntriesFor(context.Background(), userId)
|
||||
@@ -77,7 +77,7 @@ func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
assert.Equal(suite.T(), int64(0), transactonEntries[1].ParentID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[1].InvoiceID)
|
||||
|
||||
assert.Equal(suite.T(), int64(fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), int64(suite.mlnd.fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), feeAccount.ID, transactonEntries[2].CreditAccountID)
|
||||
assert.Equal(suite.T(), currentAccount.ID, transactonEntries[2].DebitAccountID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[2].InvoiceID)
|
||||
@@ -94,7 +94,7 @@ func (suite *PaymentTestSuite) TestOutGoingPayment() {
|
||||
responseBody := &[]ExpectedOutgoingInvoice{}
|
||||
assert.Equal(suite.T(), http.StatusOK, rec.Code)
|
||||
assert.NoError(suite.T(), json.NewDecoder(rec.Body).Decode(&responseBody))
|
||||
assert.Equal(suite.T(), int64(fee), (*responseBody)[0].Fee)
|
||||
assert.Equal(suite.T(), int64(suite.mlnd.fee), (*responseBody)[0].Fee)
|
||||
}
|
||||
|
||||
func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
@@ -102,27 +102,26 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
aliceFundingSats := 1000
|
||||
externalSatRequested := 1000
|
||||
// 1 sat + 1 ppm
|
||||
fee := 1
|
||||
suite.mlnd.fee = 1
|
||||
//fund alice account
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test external payment alice", suite.aliceToken)
|
||||
err := suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
//wait a bit for the callback event to hit
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
time.Sleep(10 * 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(&ExpectedPayInvoiceRequestBody{
|
||||
// Invoice: invoice.PaymentRequest,
|
||||
//}, suite.aliceToken)
|
||||
//assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
externalInvoice := lnrpc.Invoice{
|
||||
Memo: "integration tests: external pay from alice",
|
||||
Value: int64(externalSatRequested),
|
||||
}
|
||||
invoice, err := suite.externalLND.AddInvoice(context.Background(), &externalInvoice)
|
||||
assert.NoError(suite.T(), err)
|
||||
//pay external from alice
|
||||
payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
Invoice: invoice.PaymentRequest,
|
||||
}, suite.aliceToken)
|
||||
assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
|
||||
// check that balance was reduced
|
||||
userId := getUserIdFromToken(suite.aliceToken)
|
||||
@@ -131,7 +130,7 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
if err != nil {
|
||||
fmt.Printf("Error when getting balance %v\n", err.Error())
|
||||
}
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+fee), aliceBalance)
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested)+suite.mlnd.fee, aliceBalance)
|
||||
assert.Equal(suite.T(), int64(-1), aliceBalance)
|
||||
|
||||
// check that no additional transaction entry was created
|
||||
@@ -164,7 +163,7 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
assert.Equal(suite.T(), int64(0), transactonEntries[1].ParentID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[1].InvoiceID)
|
||||
|
||||
assert.Equal(suite.T(), int64(fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), int64(suite.mlnd.fee), transactonEntries[2].Amount)
|
||||
assert.Equal(suite.T(), feeAccount.ID, transactonEntries[2].CreditAccountID)
|
||||
assert.Equal(suite.T(), currentAccount.ID, transactonEntries[2].DebitAccountID)
|
||||
assert.Equal(suite.T(), outgoingInvoices[0].ID, transactonEntries[2].InvoiceID)
|
||||
@@ -175,27 +174,27 @@ func (suite *PaymentTestSuite) TestOutGoingPaymentWithNegativeBalance() {
|
||||
|
||||
func (suite *PaymentTestSuite) TestZeroAmountInvoice() {
|
||||
aliceFundingSats := 1000
|
||||
//amtToPay := 1000
|
||||
amtToPay := 1000
|
||||
//fund alice account
|
||||
invoiceResponse := suite.createAddInvoiceReq(aliceFundingSats, "integration test zero amount payment alice", suite.aliceToken)
|
||||
err := suite.mlnd.mockPaidInvoice(invoiceResponse, 0, false, nil)
|
||||
assert.NoError(suite.T(), err)
|
||||
|
||||
//wait a bit for the callback event to hit
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
//create external invoice
|
||||
//externalInvoice := lnrpc.Invoice{
|
||||
// Memo: "integration tests: zero amount pay from alice",
|
||||
// Value: 0,
|
||||
//}
|
||||
//invoice, err := suite.fundingClient.AddInvoice(context.Background(), &externalInvoice)
|
||||
//assert.NoError(suite.T(), err)
|
||||
externalInvoice := lnrpc.Invoice{
|
||||
Memo: "integration tests: zero amount pay from alice",
|
||||
Value: 0,
|
||||
}
|
||||
invoice, err := suite.externalLND.AddInvoice(context.Background(), &externalInvoice)
|
||||
assert.NoError(suite.T(), err)
|
||||
////pay external from alice
|
||||
//payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
// Invoice: invoice.PaymentRequest,
|
||||
// Amount: amtToPay,
|
||||
//}, suite.aliceToken)
|
||||
//assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
//assert.Equal(suite.T(), int64(amtToPay), payResponse.Amount)
|
||||
payResponse := suite.createPayInvoiceReq(&ExpectedPayInvoiceRequestBody{
|
||||
Invoice: invoice.PaymentRequest,
|
||||
Amount: amtToPay,
|
||||
}, suite.aliceToken)
|
||||
assert.NotEmpty(suite.T(), payResponse.PaymentPreimage)
|
||||
assert.Equal(suite.T(), int64(amtToPay), payResponse.Amount)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user