Skip to content

Commit

Permalink
chore(test): adding test for checking completion of incoming payment
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurapov committed Apr 4, 2024
1 parent bda7179 commit 661c0d4
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 7 deletions.
32 changes: 26 additions & 6 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -215,7 +216,8 @@ describe('Integration tests', (): void => {
createReceiver,
createQuote,
createOutgoingPayment,
getOutgoingPayment
getOutgoingPayment,
getIncomingPayment
} = testActions.admin

const senderWalletAddress = await c9.accounts.getByWalletAddressUrl(
Expand Down Expand Up @@ -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<void> => {
const {
createReceiver,
createQuote,
createOutgoingPayment,
getOutgoingPayment
getOutgoingPayment,
getIncomingPayment
} = testActions.admin

const senderWalletAddress = await c9.accounts.getByWalletAddressUrl(
Expand Down Expand Up @@ -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 =
Expand All @@ -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)
})
})
})
33 changes: 33 additions & 0 deletions test/integration/lib/admin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CreateWalletAddressInput,
CreateWalletAddressMutationResponse,
DepositOutgoingPaymentLiquidityInput,
IncomingPayment,
LiquidityMutationResponse,
OutgoingPayment,
OutgoingPaymentResponse,
Expand Down Expand Up @@ -146,6 +147,38 @@ export class AdminClient {
})
}

async getIncomingPayment(id: string): Promise<IncomingPayment> {
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<OutgoingPayment> {
return await this.apolloClient
.query({
Expand Down
21 changes: 20 additions & 1 deletion test/integration/lib/test-actions/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
Quote,
OutgoingPayment,
OutgoingPaymentState,
CreateReceiverInput
CreateReceiverInput,
IncomingPayment
} from '../generated/graphql'
import { MockASE } from '../mock-ase'
import { pollCondition } from '../utils'
Expand All @@ -22,6 +23,7 @@ export interface AdminActions {
senderWalletAddressId: string,
quote: Quote
): Promise<OutgoingPayment>
getIncomingPayment(incomingPaymentId: string): Promise<IncomingPayment>
getOutgoingPayment(
outgoingPaymentId: string,
amountValueToSend: string
Expand All @@ -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)
}
Expand Down Expand Up @@ -155,3 +159,18 @@ async function getOutgoingPayment(
expect(payment.receiveAmount.value).toBe(BigInt(amountValueToSend))
return payment
}
async function getIncomingPayment(
deps: AdminActionsDeps,
incomingPaymentId: string
): Promise<IncomingPayment> {
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
}

0 comments on commit 661c0d4

Please sign in to comment.