From 661c0d43e09ea2a0fa90de7d547ae5275bdf8878 Mon Sep 17 00:00:00 2001 From: Max Kurapov Date: Thu, 4 Apr 2024 10:12:19 +0200 Subject: [PATCH] chore(test): adding test for checking completion of incoming payment --- test/integration/integration.test.ts | 32 +++++++++++++++++---- test/integration/lib/admin-client.ts | 33 ++++++++++++++++++++++ test/integration/lib/test-actions/admin.ts | 21 +++++++++++++- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/test/integration/integration.test.ts b/test/integration/integration.test.ts index f1e17a3d2a..a5d073ada3 100644 --- a/test/integration/integration.test.ts +++ b/test/integration/integration.test.ts @@ -4,6 +4,7 @@ import { MockASE } from './lib/mock-ase' import { Fee, WebhookEventType } from 'mock-account-service-lib' import { poll } from './lib/utils' import { TestActions, createTestActions } from './lib/test-actions' +import { IncomingPaymentState } from './lib/generated/graphql' jest.setTimeout(20_000) @@ -215,7 +216,8 @@ describe('Integration tests', (): void => { createReceiver, createQuote, createOutgoingPayment, - getOutgoingPayment + getOutgoingPayment, + getIncomingPayment } = testActions.admin const senderWalletAddress = await c9.accounts.getByWalletAddressUrl( @@ -248,13 +250,19 @@ describe('Integration tests', (): void => { value ) expect(outgoingPayment_.sentAmount.value).toBe(BigInt(value)) + + const incomingPaymentId = receiver.id.split('/').slice(-1)[0] + const incomingPayment = await getIncomingPayment(incomingPaymentId) + expect(incomingPayment.receivedAmount.value).toBe(BigInt(value)) + expect(incomingPayment.state).toBe(IncomingPaymentState.Completed) }) test('Peer to Peer - Cross Currency', async (): Promise => { const { createReceiver, createQuote, createOutgoingPayment, - getOutgoingPayment + getOutgoingPayment, + getIncomingPayment } = testActions.admin const senderWalletAddress = await c9.accounts.getByWalletAddressUrl( @@ -285,7 +293,10 @@ describe('Integration tests', (): void => { senderWalletAddressId, quote ) - const payment = await getOutgoingPayment(outgoingPayment.id, value) + const completedOutgoingPayment = await getOutgoingPayment( + outgoingPayment.id, + value + ) const receiverAssetCode = receiver.incomingAmount.assetCode const exchangeRate = @@ -305,21 +316,30 @@ describe('Integration tests', (): void => { assert(fee.basisPoints === 200) assert(fee.asset === 'USD') assert(fee.scale === 2) - expect(payment.receiveAmount).toMatchObject({ + expect(completedOutgoingPayment.receiveAmount).toMatchObject({ assetCode: 'EUR', assetScale: 2, value: 500n }) - expect(payment.debitAmount).toMatchObject({ + expect(completedOutgoingPayment.debitAmount).toMatchObject({ assetCode: 'USD', assetScale: 2, value: 668n }) - expect(payment.sentAmount).toMatchObject({ + expect(completedOutgoingPayment.sentAmount).toMatchObject({ assetCode: 'USD', assetScale: 2, value: 550n }) + + const incomingPaymentId = receiver.id.split('/').slice(-1)[0] + const incomingPayment = await getIncomingPayment(incomingPaymentId) + expect(incomingPayment.receivedAmount).toMatchObject({ + assetCode: 'EUR', + assetScale: 2, + value: 501n + }) + expect(incomingPayment.state).toBe(IncomingPaymentState.Completed) }) }) }) diff --git a/test/integration/lib/admin-client.ts b/test/integration/lib/admin-client.ts index 6f848d2fcc..42e2314e96 100644 --- a/test/integration/lib/admin-client.ts +++ b/test/integration/lib/admin-client.ts @@ -8,6 +8,7 @@ import { CreateWalletAddressInput, CreateWalletAddressMutationResponse, DepositOutgoingPaymentLiquidityInput, + IncomingPayment, LiquidityMutationResponse, OutgoingPayment, OutgoingPaymentResponse, @@ -146,6 +147,38 @@ export class AdminClient { }) } + async getIncomingPayment(id: string): Promise { + return await this.apolloClient + .query({ + query: gql` + query GetIncomingPayment($id: String!) { + incomingPayment(id: $id) { + id + walletAddressId + state + expiresAt + incomingAmount { + value + assetCode + assetScale + } + receivedAmount { + value + assetCode + assetScale + } + metadata + createdAt + } + } + `, + variables: { id } + }) + .then((response): IncomingPayment => { + return response.data.incomingPayment + }) + } + async getOutgoingPayment(id: string): Promise { return await this.apolloClient .query({ diff --git a/test/integration/lib/test-actions/admin.ts b/test/integration/lib/test-actions/admin.ts index aa03bf063c..88b48518cd 100644 --- a/test/integration/lib/test-actions/admin.ts +++ b/test/integration/lib/test-actions/admin.ts @@ -4,7 +4,8 @@ import { Quote, OutgoingPayment, OutgoingPaymentState, - CreateReceiverInput + CreateReceiverInput, + IncomingPayment } from '../generated/graphql' import { MockASE } from '../mock-ase' import { pollCondition } from '../utils' @@ -22,6 +23,7 @@ export interface AdminActions { senderWalletAddressId: string, quote: Quote ): Promise + getIncomingPayment(incomingPaymentId: string): Promise getOutgoingPayment( outgoingPaymentId: string, amountValueToSend: string @@ -36,6 +38,8 @@ export function createAdminActions(deps: AdminActionsDeps): AdminActions { createQuote(deps, senderWalletAddressId, receiver), createOutgoingPayment: (senderWalletAddressId, quote) => createOutgoingPayment(deps, senderWalletAddressId, quote), + getIncomingPayment: (incomingPaymentId) => + getIncomingPayment(deps, incomingPaymentId), getOutgoingPayment: (outgoingPaymentId, amountValueToSend) => getOutgoingPayment(deps, outgoingPaymentId, amountValueToSend) } @@ -155,3 +159,18 @@ async function getOutgoingPayment( expect(payment.receiveAmount.value).toBe(BigInt(amountValueToSend)) return payment } +async function getIncomingPayment( + deps: AdminActionsDeps, + incomingPaymentId: string +): Promise { + const { receivingASE } = deps + const payment = + await receivingASE.adminClient.getIncomingPayment(incomingPaymentId) + + if (payment.incomingAmount?.value) { + payment.incomingAmount.value = BigInt(payment.incomingAmount.value) + } + payment.receivedAmount.value = BigInt(payment.receivedAmount.value) + + return payment +}