Repository navigation
Expand file tree
/
Copy pathContactPaymentsServiceTests.swift
More file actions
1473 lines (1375 loc) · 76.4 KB
/
Copy pathContactPaymentsServiceTests.swift
File metadata and controls
1473 lines (1375 loc) · 76.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@testable import Bitkit
import Foundation
import struct Paykit.ContactRecord
import struct Paykit.PaykitProfile
import struct Paykit.PrivatePaymentListDeliveryReport
import XCTest
@MainActor
final class ContactPaymentsServiceTests: XCTestCase {
func testContactPaymentsRemainOffUntilDefaultPublicationCompletes() throws {
try withIsolatedDefaults { defaults in
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
func testConfirmedContactPaymentsReflectBothPublicationModes() throws {
try withIsolatedDefaults { defaults in
defaults.set(true, forKey: ContactPaymentsService.confirmedPreferenceKey)
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
defaults.set(true, forKey: PublicPaykitService.publishingEnabledKey)
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
defaults.set(false, forKey: PublicPaykitService.publishingEnabledKey)
defaults.set(true, forKey: PrivatePaykitService.publishingEnabledKey)
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
func testLegacyPaymentOptionsAreAlwaysReenabled() throws {
try withIsolatedDefaults { defaults in
defaults.set(false, forKey: PublicPaykitService.lightningPaymentOptionEnabledKey)
defaults.set(false, forKey: PublicPaykitService.onchainPaymentOptionEnabledKey)
ContactPaymentsService.enableAllPaymentOptions(defaults: defaults)
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.lightningPaymentOptionEnabledKey))
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.onchainPaymentOptionEnabledKey))
}
}
func testEnablingContactPaymentsPublishesPublicAndPrivateEndpoints() async throws {
try await withIsolatedDefaultsAsync { defaults in
let operations = OperationsSpy()
operations.onPreparePrivateEndpoints = {
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.publishingEnabledKey))
XCTAssertTrue(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertTrue(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey))
}
try await ContactPaymentsService.setEnabled(
true,
contactPublicKeys: ["contact-a", "contact-b"],
canUsePrivatePayments: true,
operations: operations.makeOperations(),
defaults: defaults
)
XCTAssertEqual(operations.publicPublicationValues, [true])
XCTAssertEqual(operations.privatePublications.count, 1)
XCTAssertEqual(operations.privatePublications[0].contactPublicKeys, ["contact-a", "contact-b"])
XCTAssertFalse(operations.privatePublications[0].requiresImmediatePublication)
XCTAssertEqual(operations.calls, ["public:true", "private:publish"])
XCTAssertEqual(operations.privateRemovalCount, 0)
XCTAssertEqual(operations.publicCleanupValues, [false])
XCTAssertEqual(operations.privateCleanupValues, [false])
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.publishingEnabledKey))
XCTAssertTrue(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertTrue(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey))
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.lightningPaymentOptionEnabledKey))
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.onchainPaymentOptionEnabledKey))
}
}
func testEnablingContactPaymentsWithoutPrivateCapabilityPublishesOnlyPublicEndpoints() async throws {
try await withIsolatedDefaultsAsync { defaults in
defaults.set(true, forKey: PrivatePaykitService.cleanupPendingKey)
let operations = OperationsSpy()
try await ContactPaymentsService.setEnabled(
true,
contactPublicKeys: ["contact-a"],
canUsePrivatePayments: false,
operations: operations.makeOperations(),
defaults: defaults
)
XCTAssertEqual(operations.publicPublicationValues, [true])
XCTAssertTrue(operations.privatePublications.isEmpty)
XCTAssertTrue(operations.privateCleanupValues.isEmpty)
XCTAssertTrue(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
func testEnablePreservesContactSavedWhilePublicPublicationIsPending() async throws {
snapshotAppDefaultsDomain()
PrivatePaykitService.setContactSharingCleanupPending(false)
try await withIsolatedDefaultsAsync { defaults in
let key = "pubky" + String(repeating: "y", count: 52)
let publicationStarted = expectation(description: "Public publication is pending")
let (resume, continuation) = AsyncStream<Void>.makeStream()
defer { continuation.finish() }
let profile = signedInProfile(ownerKey: "owner")
let contacts = ContactsManager()
contacts.hasLoaded = true
let service = PrivatePaykitService()
await service.setBackgroundWorkPaused(true)
let operations = OperationsSpy()
operations.syncPublicEndpoints = { _, _ in
publicationStarted.fulfill()
for await _ in resume {}
}
operations.preparePrivateEndpoints = { keys, immediate, isCurrent in
await service.prepareSavedContacts(
keys, wallet: WalletViewModel(), requireImmediatePublication: immediate, isSessionCurrent: isCurrent
)
}
let enable = Task {
try await ContactPaymentsService.setEnabled(
true, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(), defaults: defaults, privatePaymentAccess: { _ in true }
)
}
await fulfillment(of: [publicationStarted], timeout: 2)
contacts.contacts = [.init(publicKey: key, profile: PubkyProfile.placeholder(publicKey: key))]
_ = await service.rememberSavedContacts([key], replacing: false)
await service.scheduleExplicitContactLink(publicKey: key, identity: "owner")
let retry = await service.pendingMessageDrainRetries[key]
continuation.finish()
let applied = try await enable.value
XCTAssertTrue(applied)
let known = await service.knownSavedContactKeys
let retained = await service.pendingMessageDrainRetries[key]
XCTAssertEqual(known, [key])
XCTAssertNotNil(retry)
XCTAssertEqual(retained?.id, retry?.id)
XCTAssertEqual(retained?.foregroundUntil, retry?.foregroundUntil)
await service.invalidateContactPreparation()
await service.setBackgroundWorkPaused(false)
}
}
func testEnableQueuesCurrentContactsWhenMembershipChangesDuringPrivatePreparation() async throws {
snapshotAppDefaultsDomain()
PrivatePaykitService.clearDeletedContactCleanupPending()
let defaults = UserDefaults.standard
let firstKey = "pubky" + String(repeating: "y", count: 52)
let secondKey = "pubky3rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg"
for removesContact in [false, true] {
defaults.set(true, forKey: PrivatePaykitService.cleanupPendingKey)
let profile = signedInProfile(ownerKey: "owner")
let contacts = ContactsManager()
contacts.hasLoaded = true
let initialKeys = removesContact ? [firstKey, secondKey] : [firstKey]
let currentKeys = removesContact ? [firstKey] : [firstKey, secondKey]
contacts.contacts = initialKeys.map { .init(publicKey: $0, profile: PubkyProfile.placeholder(publicKey: $0)) }
let service = PrivatePaykitService()
await service.setBackgroundWorkPaused(true)
_ = await service.rememberSavedContacts(initialKeys, replacing: true)
let preparationStarted = expectation(description: "Private preparation is pending")
let (resume, release) = AsyncStream<Void>.makeStream()
defer { release.finish() }
let operations = OperationsSpy()
var held = false
operations.preparePrivateEndpoints = { keys, immediate, isCurrent in
if !held {
held = true
preparationStarted.fulfill()
for await _ in resume {}
}
return await service.prepareSavedContacts(
keys, wallet: WalletViewModel(), requireImmediatePublication: immediate, isSessionCurrent: isCurrent
)
}
let enable = Task {
try await ContactPaymentsService.setEnabled(
true, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(defaults: defaults), defaults: defaults, privatePaymentAccess: { _ in true }
)
}
await fulfillment(of: [preparationStarted], timeout: 2)
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
contacts.contacts = currentKeys.map { .init(publicKey: $0, profile: PubkyProfile.placeholder(publicKey: $0)) }
_ = await service.rememberSavedContacts(currentKeys, replacing: true)
await service.scheduleExplicitContactLink(publicKey: firstKey, identity: "owner")
let retry = await service.pendingMessageDrainRetries[firstKey]
release.finish()
let applied = try await enable.value
await service.retryPendingEndpointReconciliation(wallet: WalletViewModel(), savedPublicKeys: currentKeys)
let queued = await service.pendingPreparationKeys
let known = await service.knownSavedContactKeys
let retainedRetry = await service.pendingMessageDrainRetries[firstKey]
XCTAssertTrue(applied)
XCTAssertEqual(queued, Set(currentKeys), "Enabling must queue current membership after superseded preparation")
XCTAssertEqual(known, Set(currentKeys))
XCTAssertNotNil(retry)
XCTAssertEqual(retainedRetry?.id, retry?.id)
XCTAssertEqual(retainedRetry?.foregroundUntil, retry?.foregroundUntil)
XCTAssertTrue(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
XCTAssertEqual(operations.privateRemovalCount, 0)
await service.invalidateContactPreparation()
await service.setBackgroundWorkPaused(false)
}
}
func testEnableCancelledAfterPublicPublicationDoesNotReportApplied() async throws {
try await withIsolatedDefaultsAsync { defaults in
let contacts = ContactsManager()
contacts.hasLoaded = true
let profile = signedInProfile(ownerKey: "owner")
let publicationStarted = expectation(description: "Public publication is pending")
var release: CheckedContinuation<Void, Never>?
defer { release?.resume() }
let operations = OperationsSpy()
operations.syncPublicEndpoints = { publish, _ in
guard publish else { return }
await withCheckedContinuation { continuation in
release = continuation
publicationStarted.fulfill()
}
}
let enable = Task {
try await ContactPaymentsService.setEnabled(
true, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(defaults: defaults), defaults: defaults, privatePaymentAccess: { _ in true }
)
}
await fulfillment(of: [publicationStarted], timeout: 2)
enable.cancel()
let continuation = try XCTUnwrap(release)
release = nil
continuation.resume()
do {
_ = try await enable.value
XCTFail("Cancelled enable must not report that the preference was applied")
} catch {
XCTAssertTrue(error is CancellationError)
}
XCTAssertTrue(operations.privatePublications.isEmpty)
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
func testEnablingContactPaymentsDefersUnavailablePrivatePublication() async throws {
try await withIsolatedDefaultsAsync { defaults in
let service = PrivatePaykitService()
let wallet = WalletViewModel()
let contactPublicKey = "pubky3rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg"
let operations = OperationsSpy()
operations.preparePrivateEndpoints = { contactPublicKeys, requireImmediatePublication, _ in
await service.prepareSavedContacts(
contactPublicKeys,
wallet: wallet,
requireImmediatePublication: requireImmediatePublication
)
}
try await ContactPaymentsService.setEnabled(
true,
contactPublicKeys: [contactPublicKey],
canUsePrivatePayments: true,
operations: operations.makeOperations(),
defaults: defaults
)
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
XCTAssertTrue(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertEqual(operations.publicPublicationValues, [true])
XCTAssertEqual(operations.privateRemovalCount, 0)
let knownContacts = await service.knownSavedContactKeys
XCTAssertEqual(knownContacts, [contactPublicKey])
}
}
func testEnableDoesNotRestoreContactDeletedWhilePublicPublicationIsPending() async throws {
snapshotAppDefaultsDomain()
try await withIsolatedDefaultsAsync { defaults in
let key = "pubky" + String(repeating: "y", count: 52)
let contacts = ContactsManager()
contacts.hasLoaded = true
contacts.contacts = [.init(publicKey: key, profile: PubkyProfile.placeholder(publicKey: key))]
let service = PrivatePaykitService()
let operations = OperationsSpy()
operations.syncPublicEndpoints = { _, _ in contacts.contacts = [] }
operations.preparePrivateEndpoints = { keys, _, isCurrent in
await service.prepareSavedContacts(keys, wallet: WalletViewModel(), isSessionCurrent: isCurrent)
}
let applied = try await ContactPaymentsService.setEnabled(
true, pubkyProfile: signedInProfile(ownerKey: "owner"), contactsManager: contacts,
operations: operations.makeOperations(), defaults: defaults, privatePaymentAccess: { _ in true }
)
let known = await service.knownSavedContactKeys
XCTAssertTrue(applied)
XCTAssertTrue(known.isEmpty)
await service.invalidateContactPreparation()
}
}
func testPrivateAccessFailurePreservesPreferencesAndAllowsSetupRetry() async throws {
for failure in [KeychainError.failedToLoad as Error, CancellationError()] {
try await withIsolatedDefaultsAsync { defaults in
let profile = signedInProfile(ownerKey: "pubky-current")
let contactsLoaded = expectation(description: "Contacts loaded after access check")
let contacts = ContactsManager(contactRecords: { contactsLoaded.fulfill(); return [] })
let operations = OperationsSpy()
defaults.set(false, forKey: PrivatePaykitService.publishingEnabledKey)
defaults.set(true, forKey: PrivatePaykitService.cleanupPendingKey)
defaults.set(false, forKey: PublicPaykitService.lightningPaymentOptionEnabledKey)
defaults.set(false, forKey: PublicPaykitService.onchainPaymentOptionEnabledKey)
let previousPreferences = defaults.dictionaryRepresentation() as NSDictionary
do {
try await ContactPaymentsService.setEnabled(
true, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(defaults: defaults), defaults: defaults,
privatePaymentAccess: { publicKey in
XCTAssertEqual(publicKey, "pubky-current")
throw failure
}
)
XCTFail("Setup must surface the access failure")
} catch {
XCTAssertEqual(error is CancellationError, failure is CancellationError)
XCTAssertEqual(error is KeychainError, failure is KeychainError)
}
XCTAssertEqual(defaults.dictionaryRepresentation() as NSDictionary, previousPreferences)
XCTAssertFalse(contacts.hasLoaded)
XCTAssertTrue(operations.calls.isEmpty)
XCTAssertTrue(operations.publicCleanupValues.isEmpty)
XCTAssertTrue(operations.privateCleanupValues.isEmpty)
operations.onSyncPublicEndpoints = { publish in
XCTAssertTrue(publish)
XCTAssertTrue(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
}
let applied = try await ContactPaymentsService.setEnabled(
true, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(defaults: defaults), defaults: defaults,
privatePaymentAccess: { _ in true }
)
XCTAssertTrue(applied)
await fulfillment(of: [contactsLoaded], timeout: 2)
XCTAssertEqual(operations.calls, ["public:true", "private:publish"])
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
}
}
}
func testCancelledSetupDoesNotReadKeysOrPublish() async throws {
try await withIsolatedDefaultsAsync { defaults in
let profile = signedInProfile(ownerKey: "pubky-current")
let contacts = ContactsManager(contactRecords: { XCTFail("Cancelled setup must not load contacts"); return [] })
let operations = OperationsSpy()
let task = Task {
withUnsafeCurrentTask { $0?.cancel() }
return try await ContactPaymentsService.setEnabled(
true, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(), defaults: defaults,
privatePaymentAccess: { _ in XCTFail("Cancelled setup must not read keys"); return true }
)
}
do {
_ = try await task.value
XCTFail("Setup must remain cancelled")
} catch {
XCTAssertTrue(error is CancellationError)
}
XCTAssertTrue(operations.calls.isEmpty)
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
func testSetupWithoutPrivateAccessPublishesPublicOnlyAndDisableDoesNotReadKeys() async throws {
try await withIsolatedDefaultsAsync { defaults in
let profile = signedInProfile(ownerKey: "pubky-current")
let contacts = ContactsManager(contactRecords: { XCTFail("Public-only setup must not load contacts"); return [] })
let operations = OperationsSpy()
let enabled = try await ContactPaymentsService.setEnabled(
true, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(defaults: defaults), defaults: defaults,
privatePaymentAccess: { _ in false }
)
XCTAssertTrue(enabled)
XCTAssertEqual(operations.calls, ["public:true"])
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
let disabled = try await ContactPaymentsService.setEnabled(
false, pubkyProfile: profile, contactsManager: contacts,
operations: operations.makeOperations(defaults: defaults), defaults: defaults,
privatePaymentAccess: { _ in XCTFail("Disabling must not read keys"); throw KeychainError.failedToLoad }
)
XCTAssertTrue(disabled)
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
XCTAssertTrue(operations.privatePublications.isEmpty)
}
}
func testDisablingContactPaymentsRemovesBothEndpointTypes() async throws {
try await withIsolatedDefaultsAsync { defaults in
defaults.set(true, forKey: PublicPaykitService.publishingEnabledKey)
defaults.set(true, forKey: PrivatePaykitService.publishingEnabledKey)
defaults.set(true, forKey: ContactPaymentsService.confirmedPreferenceKey)
let operations = OperationsSpy()
try await ContactPaymentsService.setEnabled(
false,
contactPublicKeys: ["contact-a"],
canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults),
defaults: defaults
)
XCTAssertEqual(operations.publicPublicationValues, [false])
XCTAssertEqual(operations.privateRemovalCount, 1)
XCTAssertEqual(operations.calls, ["private:remove", "public:false"])
XCTAssertEqual(operations.publicCleanupValues, [true, false])
XCTAssertEqual(operations.privateCleanupValues, [true, false])
XCTAssertFalse(defaults.bool(forKey: PublicPaykitService.cleanupPendingKey))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
XCTAssertFalse(defaults.bool(forKey: PublicPaykitService.publishingEnabledKey))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertTrue(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey))
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
func testSwitchingToPublicOnlyMarksExistingPrivateEndpointsForCleanup() async throws {
try await withIsolatedDefaultsAsync { defaults in
defaults.set(true, forKey: PrivatePaykitService.publishingEnabledKey)
let operations = OperationsSpy()
operations.onSyncPublicEndpoints = { publish in
XCTAssertTrue(publish)
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertEqual(operations.privateCleanupValues, [true])
}
try await ContactPaymentsService.setEnabled(
true,
contactPublicKeys: ["contact-a"],
canUsePrivatePayments: false,
operations: operations.makeOperations(),
defaults: defaults
)
XCTAssertEqual(operations.privateCleanupValues, [true])
XCTAssertTrue(operations.privatePublications.isEmpty)
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
func testFailedPrivateSetupWithdrawsPublicEndpointAndRestoresDisabledState() async throws {
try await withIsolatedDefaultsAsync { defaults in
defaults.set(true, forKey: PublicPaykitService.cleanupPendingKey)
let operations = OperationsSpy()
operations.privatePublicationFailures = [1]
do {
try await ContactPaymentsService.setEnabled(
true,
contactPublicKeys: ["contact-a"],
canUsePrivatePayments: true,
operations: operations.makeOperations(),
defaults: defaults
)
XCTFail("Expected private endpoint publication to fail")
} catch {
XCTAssertEqual(error as? TestError, .operationFailed)
}
XCTAssertEqual(operations.publicPublicationValues, [true, false])
XCTAssertTrue(operations.calls.contains("public:true"))
XCTAssertEqual(operations.privatePublications.count, 1)
XCTAssertFalse(operations.privatePublications[0].requiresImmediatePublication)
XCTAssertEqual(operations.privateRemovalCount, 1)
XCTAssertEqual(operations.publicCleanupValues, [false, true])
XCTAssertEqual(operations.privateCleanupValues, [false, false])
XCTAssertFalse(defaults.bool(forKey: PublicPaykitService.publishingEnabledKey))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertFalse(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey))
}
}
func testFailedDisableKeepsContactPaymentsDisabledAndRetriesCleanup() async throws {
for (privateFails, publicFails) in [(true, false), (false, true), (true, true)] {
try await withIsolatedDefaultsAsync { defaults in
defaults.set(true, forKey: PublicPaykitService.publishingEnabledKey)
defaults.set(true, forKey: PrivatePaykitService.publishingEnabledKey)
defaults.set(true, forKey: ContactPaymentsService.confirmedPreferenceKey)
defaults.set(true, forKey: PublicPaykitService.cleanupPendingKey)
let operations = OperationsSpy()
operations.privateRemovalFailures = privateFails ? [1] : []
operations.publicPublicationFailures = publicFails ? [1] : []
do {
try await ContactPaymentsService.setEnabled(
false,
contactPublicKeys: ["contact-a"],
canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults),
defaults: defaults
)
XCTFail("Expected endpoint cleanup to fail")
} catch {
XCTAssertEqual(error as? TestError, .operationFailed)
}
XCTAssertEqual(operations.publicPublicationValues, [false])
XCTAssertEqual(operations.privateRemovalCount, 1)
XCTAssertTrue(operations.privatePublications.isEmpty)
XCTAssertEqual(operations.calls, ["private:remove", "public:false"])
XCTAssertEqual(operations.publicCleanupValues, [true, publicFails])
XCTAssertEqual(operations.privateCleanupValues, [true, privateFails])
XCTAssertEqual(defaults.bool(forKey: PublicPaykitService.cleanupPendingKey), publicFails)
XCTAssertEqual(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey), privateFails)
XCTAssertFalse(defaults.bool(forKey: PublicPaykitService.publishingEnabledKey))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey))
XCTAssertTrue(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey))
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
try await ContactPaymentsService.setEnabled(
false,
contactPublicKeys: ["contact-a"],
canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults),
defaults: defaults
)
XCTAssertEqual(operations.publicPublicationValues, [false, false])
XCTAssertEqual(operations.privateRemovalCount, 2)
XCTAssertTrue(operations.privatePublications.isEmpty)
XCTAssertEqual(operations.publicCleanupValues, [true, publicFails, true, false])
XCTAssertEqual(operations.privateCleanupValues, [true, privateFails, true, false])
XCTAssertFalse(defaults.bool(forKey: PublicPaykitService.cleanupPendingKey))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
}
}
}
func testForegroundReconciliationSkipsBothPhasesOfActiveDisable() async throws {
try await withIsolatedDefaultsAsync { defaults in
let operations = OperationsSpy()
let privateRemovalStarted = expectation(description: "Private removal started")
let publicRemovalStarted = expectation(description: "Public removal started")
let (privateRemoval, finishPrivateRemoval) = AsyncStream<Void>.makeStream()
let (publicRemoval, finishPublicRemoval) = AsyncStream<Void>.makeStream()
defer {
finishPrivateRemoval.finish()
finishPublicRemoval.finish()
}
operations.onRemovePrivateEndpoints = {
privateRemovalStarted.fulfill()
for await _ in privateRemoval {}
}
operations.onSyncPublicEndpoints = { _ in
publicRemovalStarted.fulfill()
for await _ in publicRemoval {}
}
let disable = Task {
try await ContactPaymentsService.setEnabled(
false, contactPublicKeys: [], canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults), defaults: defaults
)
}
await fulfillment(of: [privateRemovalStarted], timeout: 2)
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
XCTAssertTrue(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.cleanupPendingKey))
await ContactPaymentsService.reconcilePendingEndpoints {
XCTFail("Foreground cleanup must not restart private withdrawal")
}
finishPrivateRemoval.finish()
await fulfillment(of: [publicRemovalStarted], timeout: 2)
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
XCTAssertTrue(defaults.bool(forKey: PublicPaykitService.cleanupPendingKey))
await ContactPaymentsService.reconcilePendingEndpoints {
XCTFail("Foreground cleanup must not duplicate public withdrawal")
}
finishPublicRemoval.finish()
try await disable.value
XCTAssertEqual(operations.calls, ["private:remove", "public:false"])
XCTAssertFalse(defaults.bool(forKey: PublicPaykitService.cleanupPendingKey))
var reconciled = false
await ContactPaymentsService.reconcilePendingEndpoints { reconciled = true }
XCTAssertTrue(reconciled)
}
}
func testForegroundReconciliationRetainsRegistryRepairDuringDeletionOrCancellation() async {
snapshotAppDefaultsDomain()
for interruption in ["deletion", "deletionAfterPrivate", "cancelAfterPrivate"] {
PublicPaykitService.setCleanupPending(true)
if interruption == "deletion" { await PrivatePaykitService.shared.beginProfileDeletion() }
var registryUpdates = 0
let reconciliation = Task {
await ContactPaymentsService.reconcilePendingEndpoints(reconcilePrivate: {
if interruption == "deletionAfterPrivate" { await PrivatePaykitService.shared.beginProfileDeletion() }
if interruption == "cancelAfterPrivate" { withUnsafeCurrentTask { $0?.cancel() } }
}) {
registryUpdates += 1
PublicPaykitService.setCleanupPending(false)
}
}
await reconciliation.value
await PrivatePaykitService.shared.endProfileDeletion()
XCTAssertEqual(registryUpdates, 0, interruption)
XCTAssertTrue(PublicPaykitService.isCleanupPending, interruption)
await ContactPaymentsService.reconcilePendingEndpoints {
registryUpdates += 1
PublicPaykitService.setCleanupPending(false)
}
XCTAssertEqual(registryUpdates, 1, interruption)
XCTAssertFalse(PublicPaykitService.isCleanupPending, interruption)
}
}
func testEnablingWaitsForSuccessfulOrFailedDisable() async throws {
let ownerKey = try useLocalPubkySecretKey()
for (disableUI, removalFails) in [(false, false), (false, true), (true, false), (true, true)] {
try await withIsolatedDefaultsAsync { defaults in
defaults.set(true, forKey: PaykitFeatureFlags.uiEnabledKey)
defaults.set(true, forKey: PublicPaykitService.publishingEnabledKey)
defaults.set(true, forKey: PrivatePaykitService.publishingEnabledKey)
let pubkyProfile = signedInProfile(ownerKey: ownerKey)
let contactsManager = ContactsManager(contactRecords: { [] })
let operations = OperationsSpy()
operations.privateRemovalFailures = removalFails ? [1] : []
let removalStarted = expectation(description: "Withdrawal started")
let enableRequested = expectation(description: "Enable requested during withdrawal")
let (removal, finishRemoval) = AsyncStream<Void>.makeStream()
defer { finishRemoval.finish() }
operations.onRemovePrivateEndpoints = {
removalStarted.fulfill()
for await _ in removal {}
}
let disable = Task {
if disableUI {
return try await ContactPaymentsService.disablePaykitUI(
pubkyProfile: pubkyProfile, operations: operations.makeOperations(defaults: defaults), defaults: defaults
)
}
try await ContactPaymentsService.setEnabled(
false, contactPublicKeys: [], canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults), defaults: defaults
)
return true
}
await fulfillment(of: [removalStarted], timeout: 2)
if disableUI {
XCTAssertFalse(defaults.bool(forKey: PaykitFeatureFlags.uiEnabledKey))
XCTAssertFalse(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey))
}
let enable = Task {
enableRequested.fulfill()
if disableUI {
defaults.set(true, forKey: PaykitFeatureFlags.uiEnabledKey)
let applied = try await ContactPaymentsService.setEnabled(
true, pubkyProfile: pubkyProfile, contactsManager: contactsManager,
operations: operations.makeOperations(defaults: defaults), defaults: defaults
)
XCTAssertTrue(applied)
return
}
try await ContactPaymentsService.setEnabled(
true, contactPublicKeys: ["contact-a"], canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults), defaults: defaults
)
}
await fulfillment(of: [enableRequested], timeout: 2)
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
XCTAssertEqual(operations.calls, disableUI ? ["public:false", "private:remove"] : ["private:remove"])
finishRemoval.finish()
switch await disable.result {
case let .success(applied):
XCTAssertEqual(applied, !disableUI)
if !disableUI { XCTAssertFalse(removalFails) }
case let .failure(error):
XCTAssertTrue(removalFails)
XCTAssertEqual(error as? TestError, .operationFailed)
}
try await enable.value
let cleanupCalls = disableUI ? ["public:false", "private:remove"] : ["private:remove", "public:false"]
XCTAssertEqual(operations.calls, cleanupCalls + ["public:true", "private:publish"])
XCTAssertTrue(defaults.bool(forKey: PaykitFeatureFlags.uiEnabledKey))
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
XCTAssertFalse(defaults.bool(forKey: PrivatePaykitService.cleanupPendingKey))
XCTAssertFalse(defaults.bool(forKey: PublicPaykitService.cleanupPendingKey))
}
}
}
func testForegroundReconciliationCoalescesAndSerializesSharingChanges() async throws {
try await withIsolatedDefaultsAsync { defaults in
let operations = OperationsSpy()
let reconciliationStarted = expectation(description: "Reconciliation started")
let enableRequested = expectation(description: "Enable requested during reconciliation")
let (reconciliation, finishReconciliation) = AsyncStream<Void>.makeStream()
defer { finishReconciliation.finish() }
var reconciliations = 0
let retry = Task {
await ContactPaymentsService.reconcilePendingEndpoints {
reconciliations += 1
reconciliationStarted.fulfill()
for await _ in reconciliation {}
}
}
await fulfillment(of: [reconciliationStarted], timeout: 2)
await ContactPaymentsService.reconcilePendingEndpoints { reconciliations += 1 }
let enable = Task {
enableRequested.fulfill()
try await ContactPaymentsService.setEnabled(
true, contactPublicKeys: [], canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults), defaults: defaults
)
}
await fulfillment(of: [enableRequested], timeout: 2)
XCTAssertEqual(reconciliations, 1)
XCTAssertTrue(operations.calls.isEmpty)
finishReconciliation.finish()
await retry.value
try await enable.value
XCTAssertTrue(ContactPaymentsService.isEnabled(defaults: defaults))
XCTAssertEqual(operations.publicPublicationValues, [true])
}
}
func testCancelledSharingChangeDoesNotPublishAfterReconciliation() async throws {
try await withIsolatedDefaultsAsync { defaults in
let operations = OperationsSpy()
let reconciliationStarted = expectation(description: "Reconciliation started")
let enableRequested = expectation(description: "Enable requested during reconciliation")
let (reconciliation, finishReconciliation) = AsyncStream<Void>.makeStream()
defer { finishReconciliation.finish() }
let retry = Task {
await ContactPaymentsService.reconcilePendingEndpoints {
reconciliationStarted.fulfill()
for await _ in reconciliation {}
}
}
await fulfillment(of: [reconciliationStarted], timeout: 2)
let enable = Task {
enableRequested.fulfill()
try await ContactPaymentsService.setEnabled(
true, contactPublicKeys: [], canUsePrivatePayments: true,
operations: operations.makeOperations(defaults: defaults), defaults: defaults
)
}
await fulfillment(of: [enableRequested], timeout: 2)
enable.cancel()
finishReconciliation.finish()
await retry.value
switch await enable.result {
case .success:
XCTFail("Cancelled sharing change must not publish")
case let .failure(error):
XCTAssertTrue(error is CancellationError)
}
XCTAssertTrue(operations.calls.isEmpty)
XCTAssertFalse(ContactPaymentsService.isEnabled(defaults: defaults))
var reconciled = false
await ContactPaymentsService.reconcilePendingEndpoints { reconciled = true }
XCTAssertTrue(reconciled)
}
}
func testContactPaymentsChangeStopsWhenPubkySignsOutDuringTheContactsLoad() async throws {
enum SignOut {
case never, finished, running
}
let cases: [(name: String, signOut: SignOut, loadFails: Bool)] = [
("still signed in", .never, false),
("signed out", .finished, false),
("sign-out still running", .running, false),
("signed out, then the load failed", .finished, true),
]
let ownerKey = try useLocalPubkySecretKey()
let contactKey = "pubky" + String(repeating: "y", count: 52)
let record = contactRecord(publicKey: contactKey)
for testCase in cases {
try await withIsolatedDefaultsAsync { defaults in
let pubkyProfile = signedInProfile(ownerKey: ownerKey)
XCTAssertTrue(pubkyProfile.hasLocalSecretKeyForCurrentProfile, testCase.name)
let loadStarted = expectation(description: "\(testCase.name): contacts load started")
let (loadGate, releaseLoad) = AsyncStream<Void>.makeStream()
let loadFails = testCase.loadFails
let contactsManager = ContactsManager(contactRecords: {
loadStarted.fulfill()
for await _ in loadGate {}
if loadFails {
throw PubkyServiceError.sessionNotActive
}
return [record]
})
let operations = OperationsSpy()
let change = Task {
try await ContactPaymentsService.setEnabled(
true,
pubkyProfile: pubkyProfile,
contactsManager: contactsManager,
operations: operations.makeOperations(),
defaults: defaults
)
}
await fulfillment(of: [loadStarted], timeout: 10)
var runningSignOut: (task: Task<Void, Error>, release: AsyncStream<Void>.Continuation)?
switch testCase.signOut {
case .never:
break
case .finished:
try await pubkyProfile.signOut(performSessionCleanup: {})
case .running:
let cleanupStarted = expectation(description: "\(testCase.name): sign-out started")
let (cleanupGate, releaseCleanup) = AsyncStream<Void>.makeStream()
let signOut = Task {
try await pubkyProfile.signOut(performSessionCleanup: {
cleanupStarted.fulfill()
for await _ in cleanupGate {}
})
}
await fulfillment(of: [cleanupStarted], timeout: 2)
runningSignOut = (signOut, releaseCleanup)
}
releaseLoad.finish()
let result = await change.result
let enabled = testCase.signOut == .never
XCTAssertEqual(try result.get(), enabled, testCase.name)
if let runningSignOut {
runningSignOut.release.finish()
try await runningSignOut.task.value
}
XCTAssertEqual(operations.calls, enabled ? ["public:true", "private:publish"] : [], testCase.name)
XCTAssertEqual(operations.privatePublications.map(\.contactPublicKeys), enabled ? [[contactKey]] : [], testCase.name)
XCTAssertEqual(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey), enabled, testCase.name)
XCTAssertEqual(defaults.bool(forKey: PublicPaykitService.publishingEnabledKey), enabled, testCase.name)
XCTAssertEqual(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey), enabled, testCase.name)
}
}
}
/// A publication already holding its lock can finish; sign-out must remove it afterward and retain failed cleanup.
func testContactPaymentsEnableStopsWhenPubkySignsOutDuringPublication() async throws {
enum HeldPublication {
case publicBeforeLock, privateBeforeLock, publicHoldingLock
}
let cases: [(name: String, held: HeldPublication, calls: [String], writes: [String], keepsFlags: Bool)] = [
(
"public publication waiting for its lock", .publicBeforeLock,
["public:true"], ["private:removed", "public:removal failed"], false
),
(
"private publication waiting for its lock", .privateBeforeLock,
["public:true", "private:publish"], ["public:published", "private:removed", "public:removal failed"], false
),
(
"public publication holding its lock while sign-out fails", .publicHoldingLock,
["public:true"], ["private:removal failed", "public:published"], true
),
]
let ownerKey = try useLocalPubkySecretKey()
let record = contactRecord(publicKey: "pubky3rsduhcxpw74snwyct86m38c63j3pq8x4ycqikxg64roik8yw5xg")
let endpoint = PublicPaykitService.Endpoint(
methodId: .regtestOnchainP2wpkh, value: "bcrt1qendpoint", min: nil, max: nil, rawPayload: #"{"value":"bcrt1qendpoint"}"#
)
for testCase in cases {
let defaults = UserDefaults.standard
for key in [
ContactPaymentsService.confirmedPreferenceKey, PublicPaykitService.publishingEnabledKey,
PrivatePaykitService.publishingEnabledKey, PublicPaykitService.cleanupPendingKey,
PrivatePaykitService.cleanupPendingKey, PrivatePaykitService.cacheStateKey,
] {
defaults.removeObject(forKey: key)
}
let pubkyProfile = signedInProfile(ownerKey: ownerKey)
let contactsManager = ContactsManager(contactRecords: { [record] })
let privatePaykit = PrivatePaykitService()
let writes = WriteLog()
let publicationOperations = PrivatePaykitService.EndpointPublicationOperations(
currentPublicKey: { ownerKey },
ensureLink: { _ in .linked },
buildEndpoints: { _ in [endpoint] },
syncPaymentLists: { _ in
writes.append("private:published")
return PrivatePaymentListDeliveryReport(queued: [], cleared: [], failedToQueue: [], failedToDeliver: [])
}
)
let reachedHeldPoint = expectation(description: "\(testCase.name): publication reached its held point")
let (gate, release) = AsyncStream<Void>.makeStream()
let held = testCase.held
let operations = OperationsSpy()
operations.preparePrivateEndpoints = { contactPublicKeys, requireImmediatePublication, isSessionCurrent in
if held == .privateBeforeLock {
reachedHeldPoint.fulfill()
for await _ in gate {}
}
_ = await privatePaykit.rememberSavedContacts(contactPublicKeys, replacing: true)
return await privatePaykit.syncLocalEndpointPublication(
for: contactPublicKeys,
reason: "test",
requireImmediatePublication: requireImmediatePublication,
isSessionCurrent: isSessionCurrent,
operations: publicationOperations
)
}
operations.syncPublicEndpoints = { publish, isSessionCurrent in
guard publish else { return }
if held == .publicBeforeLock {
reachedHeldPoint.fulfill()
for await _ in gate {}
}
try await PublicPaykitService.withEndpointLock(unlessSessionEnded: isSessionCurrent) {
if held == .publicHoldingLock {
reachedHeldPoint.fulfill()
for await _ in gate {}
}
writes.append("public:published")
}
}
let enable = Task {
try await ContactPaymentsService.setEnabled(
true,
pubkyProfile: pubkyProfile,
contactsManager: contactsManager,
operations: operations.makeOperations(),
defaults: defaults
)
}
await fulfillment(of: [reachedHeldPoint], timeout: 2)
let privateRemovalFails = held == .publicHoldingLock
do {
try await pubkyProfile.signOut(performSessionCleanup: { @MainActor in
try await privatePaykit.withPublicationLock {
guard !privateRemovalFails else {
writes.append("private:removal failed")
throw TestError.operationFailed
}
writes.append("private:removed")
}
do {
try await PublicPaykitService.withEndpointLock {
writes.append("public:removal failed")
throw TestError.operationFailed
}
} catch {
PublicPaykitService.setCleanupPending(true)
}
})
XCTAssertFalse(privateRemovalFails, testCase.name)
} catch {
XCTAssertTrue(privateRemovalFails, testCase.name)
}
release.finish()
let result = await enable.result
XCTAssertFalse(try result.get(), testCase.name)
XCTAssertEqual(operations.calls, testCase.calls, testCase.name)
XCTAssertEqual(writes.entries, testCase.writes, testCase.name)
XCTAssertEqual(defaults.bool(forKey: ContactPaymentsService.confirmedPreferenceKey), testCase.keepsFlags, testCase.name)
XCTAssertEqual(defaults.bool(forKey: PublicPaykitService.publishingEnabledKey), testCase.keepsFlags, testCase.name)
XCTAssertEqual(defaults.bool(forKey: PrivatePaykitService.publishingEnabledKey), testCase.keepsFlags, testCase.name)
XCTAssertEqual(operations.publicCleanupValues, held == .privateBeforeLock ? [false] : [], testCase.name)
XCTAssertEqual(operations.privateCleanupValues, held == .privateBeforeLock ? [false] : [], testCase.name)
XCTAssertTrue(PublicPaykitService.isCleanupPending, testCase.name)
}
}
func testContactPaymentsChangeWritesNothingOnceThePubkySessionChanged() async throws {
let cases: [(name: String, enabled: Bool, calls: [String])] = [
("enable", true, []),
("disable", false, []),
]
for testCase in cases {
try await withIsolatedDefaultsAsync { defaults in
let sharing = !testCase.enabled
defaults.set(sharing, forKey: ContactPaymentsService.confirmedPreferenceKey)
defaults.set(sharing, forKey: PublicPaykitService.publishingEnabledKey)
defaults.set(sharing, forKey: PrivatePaykitService.publishingEnabledKey)
let operations = OperationsSpy()
try await ContactPaymentsService.setEnabled(
testCase.enabled,
contactPublicKeys: ["contact-a"],
canUsePrivatePayments: true,