Skip to content

Commit

Permalink
fix: legacy integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Nov 30, 2023
1 parent 1e4278b commit e479db3
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 20 deletions.
162 changes: 144 additions & 18 deletions core/api/test/legacy-integration/02-user-wallet/02-tx-display.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ describe("Display properties on transactions", () => {
memo,
})
if (invoice instanceof Error) throw invoice
const { paymentRequest: uncheckedPaymentRequest, paymentHash } = invoice.lnInvoice
const {
paymentRequest: uncheckedPaymentRequest,
paymentHash,
destination,
} = invoice.lnInvoice

const paymentResult = await Payments.payNoAmountInvoiceByWalletIdForBtcWallet({
uncheckedPaymentRequest,
Expand All @@ -362,7 +366,23 @@ describe("Display properties on transactions", () => {
amount: amountInvoice,
})
if (paymentResult instanceof Error) throw paymentResult
expect(paymentResult).toBe(PaymentSendStatus.Success)
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: senderWalletId,
status: "success",
settlementAmount: amountInvoice * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "lightning",
paymentHash,
pubkey: destination,
}),
settlementVia: expect.objectContaining({
type: "intraledger",
}),
}),
})

// Check entries
const txns = await getAllTransactionsByHash(paymentHash)
Expand Down Expand Up @@ -437,7 +457,22 @@ describe("Display properties on transactions", () => {
senderAccount: accountB,
})
if (paymentResult instanceof Error) throw paymentResult
expect(paymentResult).toBe(PaymentSendStatus.Success)
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: walletIdB,
status: "success",
settlementAmount: amountInvoice * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "lightning",
paymentHash,
}),
settlementVia: expect.objectContaining({
type: "lightning",
}),
}),
})

// Check entries
const txns = await getAllTransactionsByHash(paymentHash)
Expand Down Expand Up @@ -503,7 +538,23 @@ describe("Display properties on transactions", () => {
senderAccount: accountB,
})
if (paymentResult instanceof Error) throw paymentResult
expect(paymentResult).toBe(PaymentSendStatus.Success)
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: walletIdB,
status: "success",
settlementAmount:
(amountInvoice + paymentResult.transaction.settlementFee) * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "lightning",
paymentHash,
}),
settlementVia: expect.objectContaining({
type: "lightning",
}),
}),
})

// Check entries
const txns = await getAllTransactionsByHash(paymentHash)
Expand Down Expand Up @@ -848,16 +899,31 @@ describe("Display properties on transactions", () => {
})
if (address instanceof Error) throw address

const paid = await Payments.payOnChainByWalletIdForBtcWallet({
const paymentResult = await Payments.payOnChainByWalletIdForBtcWallet({
senderAccount,
senderWalletId,
address,
amount: amountSats,
speed: PayoutSpeed.Fast,
memo,
})
if (paid instanceof Error) throw paid
expect(paid.status).toBe(PaymentSendStatus.Success)
if (paymentResult instanceof Error) throw paymentResult
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: senderWalletId,
status: "success",
settlementAmount: amountSats * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "onchain",
address,
}),
settlementVia: expect.objectContaining({
type: "intraledger",
}),
}),
})

// Check entries
const memoTxns = await getAllTransactionsByMemo(memo)
Expand Down Expand Up @@ -921,16 +987,31 @@ describe("Display properties on transactions", () => {
})
if (address instanceof Error) throw address

const paid = await Payments.payOnChainByWalletIdForBtcWallet({
const paymentResult = await Payments.payOnChainByWalletIdForBtcWallet({
senderAccount,
senderWalletId,
address,
amount: amountSats,
speed: PayoutSpeed.Fast,
memo,
})
if (paid instanceof Error) throw paid
expect(paid.status).toBe(PaymentSendStatus.Success)
if (paymentResult instanceof Error) throw paymentResult
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: senderWalletId,
status: "success",
settlementAmount: amountSats * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "onchain",
address,
}),
settlementVia: expect.objectContaining({
type: "intraledger",
}),
}),
})

// Check entries
const memoTxns = await getAllTransactionsByMemo(memo)
Expand Down Expand Up @@ -1013,16 +1094,33 @@ describe("Display properties on transactions", () => {
lnd: lndOutside1,
})

const paid = await Payments.payOnChainByWalletIdForBtcWallet({
const paymentResult = await Payments.payOnChainByWalletIdForBtcWallet({
senderAccount,
senderWalletId,
address,
amount: amountSats,
speed: PayoutSpeed.Fast,
memo,
})
if (paid instanceof Error) throw paid
expect(paid.status).toBe(PaymentSendStatus.Success)
if (paymentResult instanceof Error) throw paymentResult
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: senderWalletId,
status: "pending",
settlementAmount: (amountSats + paymentResult.transaction.settlementFee) * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "onchain",
address,
}),
settlementVia: expect.objectContaining({
type: "onchain",
transactionHash: undefined,
vout: undefined,
}),
}),
})

// Check entries
const txns = await getAllTransactionsByMemo(memo)
Expand Down Expand Up @@ -1081,14 +1179,28 @@ describe("Display properties on transactions", () => {
// Send payment
const memo = "invoiceMemo #" + (Math.random() * 1_000_000).toFixed()

const paid = await Payments.intraledgerPaymentSendWalletIdForBtcWallet({
const paymentResult = await Payments.intraledgerPaymentSendWalletIdForBtcWallet({
senderWalletId,
senderAccount,
memo,
recipientWalletId,
amount: amountSats,
})
expect(paid).toBe(PaymentSendStatus.Success)
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: senderWalletId,
status: "success",
settlementAmount: amountSats * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "intraledger",
}),
settlementVia: expect.objectContaining({
type: "intraledger",
}),
}),
})

// Check entries
const txns = await getAllTransactionsByMemo(memo)
Expand Down Expand Up @@ -1131,7 +1243,7 @@ describe("Display properties on transactions", () => {
// TxMetadata:
// - WalletIdTradeIntraAccountLedgerMetadata

const amountSats = 20_000
const amountSats = 10_000

const senderWalletId = walletIdB
const senderAccount = accountB
Expand All @@ -1140,14 +1252,28 @@ describe("Display properties on transactions", () => {
// Send payment
const memo = "invoiceMemo #" + (Math.random() * 1_000_000).toFixed()

const paid = await Payments.intraledgerPaymentSendWalletIdForBtcWallet({
const paymentResult = await Payments.intraledgerPaymentSendWalletIdForBtcWallet({
senderWalletId,
senderAccount,
memo,
recipientWalletId,
amount: amountSats,
})
expect(paid).toBe(PaymentSendStatus.Success)
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: senderWalletId,
status: "success",
settlementAmount: amountSats * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "intraledger",
}),
settlementVia: expect.objectContaining({
type: "intraledger",
}),
}),
})

// Check entries
const txns = await getAllTransactionsByMemo(memo)
Expand Down
20 changes: 18 additions & 2 deletions core/api/test/legacy-integration/app/cron/delete-payments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,32 @@ describe("Delete payments from Lnd - Lightning Pay", () => {
const { request, secret, id } = await createInvoice({ lnd: lndOutside1 })
const paymentHash = id as PaymentHash
const revealedPreImage = secret as RevealedPreImage
const amount = toSats(1000)

const paymentResult = await Payments.payNoAmountInvoiceByWalletIdForBtcWallet({
uncheckedPaymentRequest: request,
memo: null,
amount: toSats(1000),
amount,
senderWalletId: walletIdB,
senderAccount: accountB,
})
if (paymentResult instanceof Error) throw paymentResult
expect(paymentResult).toBe(PaymentSendStatus.Success)
expect(paymentResult).toEqual({
status: PaymentSendStatus.Success,
transaction: expect.objectContaining({
walletId: walletIdB,
status: "success",
settlementAmount: (amount + paymentResult.transaction.settlementFee) * -1,
settlementCurrency: "BTC",
initiationVia: expect.objectContaining({
type: "lightning",
paymentHash,
}),
settlementVia: expect.objectContaining({
type: "lightning",
}),
}),
})

const lndService = LndService()
if (lndService instanceof Error) return lndService
Expand Down

0 comments on commit e479db3

Please sign in to comment.