Skip to content

Commit

Permalink
feat(integration): cross currency assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCurrey committed Apr 2, 2024
1 parent 18203a5 commit 0dda0e4
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions test/integration/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'assert'
import { C9_CONFIG, HLB_CONFIG } from './lib/config'
import { MockASE } from './lib/mock-ase'
import { WebhookEventType } from 'mock-account-service-lib'
import { Fee, WebhookEventType } from 'mock-account-service-lib'
import { poll } from './lib/utils'
import { TestActions, createTestActions } from './lib/test-actions'

Expand Down Expand Up @@ -279,28 +279,46 @@ describe('Integration tests', (): void => {

const receiver = await createReceiver(createReceiverInput)
assert(receiver.incomingAmount)
assert(
receiver.incomingAmount.assetScale === senderWalletAddress.assetScale
)
const receiverAssetCode = receiver.incomingAmount.assetCode

const quote = await createQuote(senderWalletAddressId, receiver)
const outgoingPayment = await createOutgoingPayment(
senderWalletAddressId,
quote
)
const payment = await getOutgoingPayment(outgoingPayment.id, value)

const receiverAssetCode = receiver.incomingAmount.assetCode
const exchangeRate =
c9.config.seed.rates[receiverAssetCode][senderAssetCode]
const { sentAmount, receiveAmount } = payment
hlb.config.seed.rates[senderAssetCode][receiverAssetCode]
const fee = c9.config.seed.fees.find((fee: Fee) => fee.asset === 'USD')

if (exchangeRate > 1) {
expect(sentAmount.value).toBeGreaterThan(receiveAmount.value)
} else if (exchangeRate < 1) {
expect(sentAmount.value).toBeLessThan(receiveAmount.value)
} else {
expect(sentAmount.value).toBe(receiveAmount.value)
}
// Expected amounts depend on the configuration of asset codes, scale, exchange rate, and fees.
assert(receiverAssetCode === 'EUR')
assert(senderAssetCode === 'USD')
assert(
receiver.incomingAmount.assetScale === senderWalletAddress.assetScale
)
assert(senderWalletAddress.assetScale === 2)
assert(exchangeRate === 0.91)
assert(fee.fixed === 100)
assert(fee.basisPoints === 200)
assert(fee.asset === 'USD')
assert(fee.scale === 2)
expect(payment.receiveAmount).toMatchObject({
assetCode: 'EUR',
assetScale: 2,
value: 500n
})
expect(payment.debitAmount).toMatchObject({
assetCode: 'USD',
assetScale: 2,
value: 668n
})
expect(payment.sentAmount).toMatchObject({
assetCode: 'USD',
assetScale: 2,
value: 550n
})
})
})
})

0 comments on commit 0dda0e4

Please sign in to comment.