1
1
import assert from 'assert'
2
2
import { MockASE , C9_CONFIG , HLB_CONFIG } from 'test-lib'
3
- import { Fee , WebhookEventType } from 'mock-account-service-lib'
3
+ import { WebhookEventType } from 'mock-account-service-lib'
4
4
import { poll } from './lib/utils'
5
5
import { TestActions , createTestActions } from './lib/test-actions'
6
6
import { IncomingPaymentState } from 'test-lib/dist/generated/graphql'
@@ -126,7 +126,6 @@ describe('Integration tests', (): void => {
126
126
const outgoingPaymentGrant = await grantRequestOutgoingPayment (
127
127
senderWalletAddress ,
128
128
{
129
- debitAmount : quote . debitAmount ,
130
129
receiveAmount : quote . receiveAmount
131
130
}
132
131
)
@@ -202,10 +201,7 @@ describe('Integration tests', (): void => {
202
201
)
203
202
const outgoingPaymentGrant = await grantRequestOutgoingPayment (
204
203
senderWalletAddress ,
205
- {
206
- debitAmount : quote . debitAmount ,
207
- receiveAmount : quote . receiveAmount
208
- } ,
204
+ { receiveAmount : quote . receiveAmount } ,
209
205
{
210
206
method : 'redirect' ,
211
207
uri : 'https://example.com' ,
@@ -238,14 +234,15 @@ describe('Integration tests', (): void => {
238
234
239
235
await getPublicIncomingPayment ( incomingPayment . id , amountValueToSend )
240
236
} )
241
- test ( 'Open Payments without Quote ' , async ( ) : Promise < void > => {
237
+ test ( 'Open Payments Multiple Outgoing Payments into Incoming Payment ' , async ( ) : Promise < void > => {
242
238
const {
243
239
grantRequestIncomingPayment,
244
240
createIncomingPayment,
245
241
grantRequestOutgoingPayment,
246
242
pollGrantContinue,
247
243
createOutgoingPayment,
248
- getOutgoingPayment
244
+ getOutgoingPayment,
245
+ getPublicIncomingPayment
249
246
} = testActions . openPayments
250
247
const { consentInteraction } = testActions
251
248
@@ -264,11 +261,7 @@ describe('Integration tests', (): void => {
264
261
} )
265
262
expect ( senderWalletAddress . id ) . toBe ( senderWalletAddressUrl )
266
263
267
- const debitAmount = {
268
- assetCode : senderWalletAddress . assetCode ,
269
- assetScale : senderWalletAddress . assetScale ,
270
- value : '500'
271
- }
264
+ const grantValue = 100n
272
265
273
266
const incomingPaymentGrant = await grantRequestIncomingPayment (
274
267
receiverWalletAddress
@@ -281,13 +274,23 @@ describe('Integration tests', (): void => {
281
274
const outgoingPaymentGrant = await grantRequestOutgoingPayment (
282
275
senderWalletAddress ,
283
276
{
284
- debitAmount,
285
- receiveAmount : debitAmount
277
+ debitAmount : {
278
+ assetCode : senderWalletAddress . assetCode ,
279
+ assetScale : senderWalletAddress . assetScale ,
280
+ value : String ( grantValue )
281
+ }
286
282
}
287
283
)
288
284
await consentInteraction ( outgoingPaymentGrant , senderWalletAddress )
289
285
const grantContinue = await pollGrantContinue ( outgoingPaymentGrant )
290
- const outgoingPayment = await createOutgoingPayment (
286
+
287
+ const debitAmount = {
288
+ assetCode : senderWalletAddress . assetCode ,
289
+ assetScale : senderWalletAddress . assetScale ,
290
+ value : '50'
291
+ }
292
+
293
+ const outgoingPayment1 = await createOutgoingPayment (
291
294
senderWalletAddress ,
292
295
grantContinue ,
293
296
{
@@ -296,12 +299,32 @@ describe('Integration tests', (): void => {
296
299
}
297
300
)
298
301
299
- const outgoingPayment_ = await getOutgoingPayment (
300
- outgoingPayment . id ,
301
- grantContinue
302
+ await poll (
303
+ async ( ) => getOutgoingPayment ( outgoingPayment1 . id , grantContinue ) ,
304
+ ( responseData ) => BigInt ( responseData . sentAmount . value ) > 0n ,
305
+ 5 ,
306
+ 0.5
307
+ )
308
+
309
+ expect ( outgoingPayment1 . debitAmount ) . toMatchObject ( debitAmount )
310
+
311
+ const outgoingPayment2 = await createOutgoingPayment (
312
+ senderWalletAddress ,
313
+ grantContinue ,
314
+ {
315
+ incomingPayment : incomingPayment . id ,
316
+ debitAmount
317
+ }
318
+ )
319
+
320
+ await poll (
321
+ async ( ) => getOutgoingPayment ( outgoingPayment2 . id , grantContinue ) ,
322
+ ( responseData ) => BigInt ( responseData . sentAmount . value ) > 0n ,
323
+ 5 ,
324
+ 0.5
302
325
)
303
326
304
- expect ( outgoingPayment_ . debitAmount ) . toMatchObject ( debitAmount )
327
+ await getPublicIncomingPayment ( incomingPayment . id , '98' ) // adjusted for ILP slippage
305
328
} )
306
329
test ( 'Peer to Peer' , async ( ) : Promise < void > => {
307
330
const {
@@ -399,7 +422,6 @@ describe('Integration tests', (): void => {
399
422
const receiverAssetCode = receiver . incomingAmount . assetCode
400
423
const exchangeRate =
401
424
hlb . config . seed . rates [ senderAssetCode ] [ receiverAssetCode ]
402
- const fee = c9 . config . seed . fees . find ( ( fee : Fee ) => fee . asset === 'USD' )
403
425
404
426
// Expected amounts depend on the configuration of asset codes, scale, exchange rate, and fees.
405
427
assert ( receiverAssetCode === 'EUR' )
@@ -409,11 +431,6 @@ describe('Integration tests', (): void => {
409
431
)
410
432
assert ( senderWalletAddress . assetScale === 2 )
411
433
assert ( exchangeRate === 0.91 )
412
- assert ( fee )
413
- assert ( fee . fixed === 100 )
414
- assert ( fee . basisPoints === 200 )
415
- assert ( fee . asset === 'USD' )
416
- assert ( fee . scale === 2 )
417
434
expect ( completedOutgoingPayment . receiveAmount ) . toMatchObject ( {
418
435
assetCode : 'EUR' ,
419
436
assetScale : 2 ,
@@ -422,7 +439,7 @@ describe('Integration tests', (): void => {
422
439
expect ( completedOutgoingPayment . debitAmount ) . toMatchObject ( {
423
440
assetCode : 'USD' ,
424
441
assetScale : 2 ,
425
- value : 668n
442
+ value : 556n // with ILP slippage
426
443
} )
427
444
expect ( completedOutgoingPayment . sentAmount ) . toMatchObject ( {
428
445
assetCode : 'USD' ,
@@ -604,7 +621,6 @@ describe('Integration tests', (): void => {
604
621
const receiverAssetCode = receiver . incomingAmount . assetCode
605
622
const exchangeRate =
606
623
c9 . config . seed . rates [ senderAssetCode ] [ receiverAssetCode ]
607
- const fee = c9 . config . seed . fees . find ( ( fee : Fee ) => fee . asset === 'USD' )
608
624
609
625
// Expected amounts depend on the configuration of asset codes, scale, exchange rate, and fees.
610
626
assert ( receiverAssetCode === 'EUR' )
@@ -614,11 +630,6 @@ describe('Integration tests', (): void => {
614
630
)
615
631
assert ( senderWalletAddress . assetScale === 2 )
616
632
assert ( exchangeRate === 0.91 )
617
- assert ( fee )
618
- assert ( fee . fixed === 100 )
619
- assert ( fee . basisPoints === 200 )
620
- assert ( fee . asset === 'USD' )
621
- assert ( fee . scale === 2 )
622
633
expect ( completedOutgoingPayment . receiveAmount ) . toMatchObject ( {
623
634
assetCode : 'EUR' ,
624
635
assetScale : 2 ,
@@ -627,7 +638,7 @@ describe('Integration tests', (): void => {
627
638
expect ( completedOutgoingPayment . debitAmount ) . toMatchObject ( {
628
639
assetCode : 'USD' ,
629
640
assetScale : 2 ,
630
- value : 661n
641
+ value : 550n
631
642
} )
632
643
expect ( completedOutgoingPayment . sentAmount ) . toMatchObject ( {
633
644
assetCode : 'USD' ,
@@ -644,6 +655,55 @@ describe('Integration tests', (): void => {
644
655
} )
645
656
expect ( incomingPayment . state ) . toBe ( IncomingPaymentState . Completed )
646
657
} )
658
+
659
+ test ( 'Peer to Peer - Multiple Outgoing Payments into Incoming Payment' , async ( ) : Promise < void > => {
660
+ const {
661
+ createReceiver,
662
+ createOutgoingPaymentFromIncomingPayment,
663
+ getIncomingPayment
664
+ } = testActions . admin
665
+
666
+ const senderWalletAddress = await c9 . accounts . getByWalletAddressUrl (
667
+ 'https://cloud-nine-wallet-test-backend:3100/accounts/gfranklin'
668
+ )
669
+ assert ( senderWalletAddress ?. walletAddressID )
670
+
671
+ const senderWalletAddressId = senderWalletAddress . walletAddressID
672
+ const createReceiverInput = {
673
+ metadata : {
674
+ description : 'For lunch!'
675
+ } ,
676
+ walletAddressUrl :
677
+ 'https://cloud-nine-wallet-test-backend:3100/accounts/bhamchest'
678
+ }
679
+
680
+ const value = '500'
681
+ const receiver = await createReceiver ( createReceiverInput )
682
+
683
+ await createOutgoingPaymentFromIncomingPayment ( {
684
+ incomingPayment : receiver . id ,
685
+ walletAddressId : senderWalletAddressId ,
686
+ debitAmount : {
687
+ assetCode : 'USD' ,
688
+ assetScale : 2 ,
689
+ value : value as unknown as bigint
690
+ }
691
+ } )
692
+ await createOutgoingPaymentFromIncomingPayment ( {
693
+ incomingPayment : receiver . id ,
694
+ walletAddressId : senderWalletAddressId ,
695
+ debitAmount : {
696
+ assetCode : 'USD' ,
697
+ assetScale : 2 ,
698
+ value : value as unknown as bigint
699
+ }
700
+ } )
701
+
702
+ const incomingPaymentId = receiver . id . split ( '/' ) . slice ( - 1 ) [ 0 ]
703
+ const incomingPayment = await getIncomingPayment ( incomingPaymentId )
704
+ expect ( incomingPayment . receivedAmount . value ) . toBe ( BigInt ( value ) * 2n )
705
+ expect ( incomingPayment . state ) . toBe ( IncomingPaymentState . Processing )
706
+ } )
647
707
} )
648
708
} )
649
709
} )
0 commit comments