paykit-lib 0.1.0

Paykit library implementation
Documentation
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
use super::*;

fn app_id() -> PaykitAppId {
    PaykitAppId::new("bitkit").unwrap()
}

fn app_capabilities() -> PaykitAppCapabilities {
    PaykitAppCapabilities {
        private_payments: true,
        payment_requests: true,
        receipts: true,
        outgoing_payments: true,
    }
}

#[tokio::test]
async fn test_endpoint_repair_and_removal_use_raw_revisions() {
    let setup = TestSetup::new().await;
    let app = app_id();
    let identifier = PaymentEndpointIdentifier::new("btc-onchain").unwrap();
    let path = pubky_routing::payment_endpoint_path(&app, &identifier);
    for bytes in [
        vec![0xff],
        vec![b'x'; PAYMENT_ENDPOINT_PAYLOAD_MAX_BYTES + 1],
    ] {
        setup
            .session
            .storage()
            .put(&path, bytes.clone())
            .await
            .unwrap();
        assert!(
            get_payment_endpoint(&setup.public_storage, &setup.public_key, &app, &identifier)
                .await
                .is_err()
        );
        let revision =
            pubky_routing::fetch_payment_endpoint_revision(&setup.session, &app, &identifier)
                .await
                .unwrap()
                .unwrap();
        assert_eq!(revision, content_revision(&bytes));

        update_payment_endpoint(
            &setup.session,
            &app,
            identifier.clone(),
            PaymentEndpointPayload::new("repaired"),
            &revision,
        )
        .await
        .unwrap();
        let error = remove_payment_endpoint_if_revision(
            &setup.session,
            &app,
            identifier.clone(),
            &revision,
        )
        .await
        .unwrap_err();
        assert!(is_write_conflict(&error));

        setup.session.storage().put(&path, bytes).await.unwrap();
        remove_payment_endpoint_if_revision(&setup.session, &app, identifier.clone(), &revision)
            .await
            .unwrap();
        assert!(
            pubky_routing::fetch_payment_endpoint_revision(&setup.session, &app, &identifier)
                .await
                .unwrap()
                .is_none()
        );
    }
}

#[tokio::test]
async fn test_malformed_registry_can_be_conditionally_repaired() {
    let setup = TestSetup::new().await;
    setup
        .session
        .storage()
        .put(PAYKIT_APP_REGISTRY_PATH, vec![0xff])
        .await
        .unwrap();
    assert!(
        get_paykit_app_registry_with_revision(&setup.public_storage, &setup.public_key)
            .await
            .is_err()
    );
    let resource = format!("{}{PAYKIT_APP_REGISTRY_PATH}", setup.public_key)
        .parse()
        .unwrap();
    let revision = pubky_routing::fetch_resource_revision(
        &setup.public_storage,
        &resource,
        PAYKIT_APP_REGISTRY_MAX_BYTES,
    )
    .await
    .unwrap()
    .unwrap();
    let registry = PaykitAppRegistry::new(None);
    update_paykit_app_registry(&setup.session, &registry, &revision)
        .await
        .unwrap();
    assert_eq!(
        get_paykit_app_registry(&setup.public_storage, &setup.public_key)
            .await
            .unwrap(),
        Some(registry.clone())
    );
    assert!(is_write_conflict(
        &update_paykit_app_registry(&setup.session, &registry, &revision)
            .await
            .unwrap_err()
    ));
}

#[tokio::test]
async fn test_endpoint_cleanup_listing_accepts_overfull_lists() {
    let setup = TestSetup::new().await;
    let app = app_id();
    for index in 0..=PAYMENT_LIST_MAX_ENDPOINTS {
        let identifier = PaymentEndpointIdentifier::new(format!("endpoint-{index:03}")).unwrap();
        setup
            .session
            .storage()
            .put(
                pubky_routing::payment_endpoint_path(&app, &identifier),
                vec![0xff],
            )
            .await
            .unwrap();
    }
    assert!(
        get_payment_list(&setup.public_storage, &setup.public_key, &app)
            .await
            .is_err()
    );
    let identifiers = pubky_routing::list_payment_endpoint_identifiers(
        &setup.public_storage,
        &setup.public_key,
        &app,
    )
    .await
    .unwrap();
    assert_eq!(identifiers.len(), PAYMENT_LIST_MAX_ENDPOINTS + 1);
}

#[tokio::test]
async fn test_payment_list_exact_byte_budget_allows_trailing_empty_endpoint() {
    let setup = TestSetup::new().await;
    for (name, body) in [("a", "full"), ("b", "")] {
        set_payment_endpoint(
            &setup.session,
            &app_id(),
            PaymentEndpointIdentifier::new(name).unwrap(),
            PaymentEndpointPayload::new(body),
        )
        .await
        .unwrap();
    }
    let list =
        get_payment_list_with_limits(&setup.public_storage, &setup.public_key, &app_id(), 2, 4)
            .await
            .unwrap();
    assert_eq!(list.payment_endpoints.len(), 1);
}

#[tokio::test]
async fn test_write_lock_is_renewed_and_released_after_failure() {
    let setup = TestSetup::new().await;
    let path = format!("{PAYKIT_PATH_PREFIX}lock-test.json");
    let storage = setup.session.storage();
    let error = pubky_routing::with_write_lock_timeout(
        &setup.session,
        &path,
        std::time::Duration::from_secs(6),
        |lock| async move {
            tokio::time::sleep(lock.timeout() + std::time::Duration::from_secs(1)).await;
            let conflict = storage.lock(lock.path(), lock.timeout()).await.unwrap_err();
            assert!(matches!(conflict,
                pubky::Error::Request(pubky::errors::RequestError::Server { status, .. })
                    if status == pubky::StatusCode::LOCKED
            ));
            storage.put_locked(&lock, "renewed").await.unwrap();
            Err::<(), _>(PaykitError::Validation("operation failed".into()))
        },
    )
    .await
    .unwrap_err();
    assert!(
        matches!(error, PaykitError::Validation(_)),
        "expected operation validation error, got {error:?}"
    );
    let lock = setup
        .session
        .storage()
        .lock(&path, std::time::Duration::from_secs(30))
        .await
        .unwrap();
    let stored = setup
        .session
        .storage()
        .get(&path)
        .await
        .unwrap()
        .text()
        .await
        .unwrap();
    assert_eq!(stored, "renewed");
    setup.session.storage().unlock(&lock).await.unwrap();
    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_write_lock_waits_for_another_writer_before_running_operation() {
    let setup = TestSetup::new().await;
    let path = format!("{PAYKIT_PATH_PREFIX}contended.json");
    let storage = setup.session.storage();
    let lock = storage
        .lock(&path, std::time::Duration::from_secs(60))
        .await
        .unwrap();
    let waiting_storage = &storage;
    let operation = with_write_lock(&setup.session, &path, |lock| async move {
        waiting_storage
            .put_locked(&lock, "next writer")
            .await
            .unwrap();
        Ok::<_, PaykitError>(())
    });
    tokio::pin!(operation);
    assert!(
        tokio::time::timeout(std::time::Duration::from_millis(100), &mut operation)
            .await
            .is_err()
    );
    storage.unlock(&lock).await.unwrap();
    operation.await.unwrap();
    assert_eq!(
        storage.get(&path).await.unwrap().text().await.unwrap(),
        "next writer"
    );
}

#[tokio::test]
async fn test_empty_registry_is_invalid_for_both_read_apis() {
    let setup = TestSetup::new().await;
    setup
        .session
        .storage()
        .put(PAYKIT_APP_REGISTRY_PATH, Vec::new())
        .await
        .unwrap();
    assert!(matches!(
        get_paykit_app_registry(&setup.public_storage, &setup.public_key).await,
        Err(PaykitError::InvalidData { .. })
    ));
    assert!(matches!(
        get_paykit_app_registry_with_revision(&setup.public_storage, &setup.public_key).await,
        Err(PaykitError::InvalidData { .. })
    ));
}

#[tokio::test]
async fn test_renewal_loss_after_commit_is_not_a_retryable_conflict() {
    let setup = TestSetup::new().await;
    let path = format!("{PAYKIT_PATH_PREFIX}uncertain-write.json");
    let storage = setup.session.storage();
    let error = pubky_routing::with_write_lock_timeout(
        &setup.session,
        &path,
        std::time::Duration::from_secs(6),
        |lock| async move {
            storage.put_locked(&lock, "committed").await.unwrap();
            // Model ownership lost while the committed write's response is unresolved.
            storage.unlock(&lock).await.unwrap();
            std::future::pending::<Result<()>>().await
        },
    )
    .await
    .unwrap_err();
    assert!(!is_write_conflict(&error));
    assert!(matches!(error, PaykitError::Transport { .. }));
    let stored = setup
        .session
        .storage()
        .get(&path)
        .await
        .unwrap()
        .text()
        .await
        .unwrap();
    assert_eq!(stored, "committed");
    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_cancelled_write_does_not_unlock_an_unfinished_operation() {
    let setup = TestSetup::new().await;
    let path = format!("{PAYKIT_PATH_PREFIX}cancelled-write.json");
    let (started_tx, started_rx) = tokio::sync::oneshot::channel();
    let lock = {
        let operation = with_write_lock(&setup.session, &path, |lock| async {
            started_tx.send(lock).unwrap();
            std::future::pending::<Result<()>>().await
        });
        tokio::pin!(operation);
        tokio::select! {
            result = &mut operation => panic!("operation must remain pending: {result:?}"),
            lock = started_rx => lock.unwrap(),
        }
    };
    let conflict = setup
        .session
        .storage()
        .lock(&path, lock.timeout())
        .await
        .unwrap_err();
    assert!(matches!(conflict,
        pubky::Error::Request(pubky::errors::RequestError::Server { status, .. })
            if status == pubky::StatusCode::LOCKED
    ));
    setup.session.storage().unlock(&lock).await.unwrap();
    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_app_registry_round_trips_through_public_storage() {
    let setup = TestSetup::new().await;
    let mut registry = PaykitAppRegistry::new(Some(Keypair::random().public_key()));
    registry
        .register_app(
            app_id(),
            PaykitApp::new("Bitkit", app_capabilities()).unwrap(),
        )
        .unwrap();

    create_paykit_app_registry(&setup.session, &registry)
        .await
        .unwrap();
    let fetched = get_paykit_app_registry(&setup.public_storage, &setup.public_key)
        .await
        .unwrap();
    let versioned = get_paykit_app_registry_with_revision(&setup.public_storage, &setup.public_key)
        .await
        .unwrap()
        .unwrap();

    assert_eq!(fetched, Some(registry));
    assert_eq!(versioned.0, fetched.unwrap());
    assert!(!versioned.1.is_empty());
    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_app_registry_rejects_stale_revision_update() {
    let setup = TestSetup::new().await;
    let mut registry = PaykitAppRegistry::new(Some(Keypair::random().public_key()));
    registry
        .register_app(
            app_id(),
            PaykitApp::new("Bitkit", app_capabilities()).unwrap(),
        )
        .unwrap();
    create_paykit_app_registry(&setup.session, &registry)
        .await
        .unwrap();

    let (mut first_update, revision) =
        get_paykit_app_registry_with_revision(&setup.public_storage, &setup.public_key)
            .await
            .unwrap()
            .unwrap();
    let mut stale_update = first_update.clone();
    first_update
        .register_app(
            PaykitAppId::new("paykit-server").unwrap(),
            PaykitApp::new("Paykit Server", app_capabilities()).unwrap(),
        )
        .unwrap();
    stale_update
        .register_app(
            PaykitAppId::new("exchange").unwrap(),
            PaykitApp::new("Exchange", app_capabilities()).unwrap(),
        )
        .unwrap();

    update_paykit_app_registry(&setup.session, &first_update, &revision)
        .await
        .unwrap();
    let error = update_paykit_app_registry(&setup.session, &stale_update, &revision)
        .await
        .unwrap_err();
    assert!(pubky_routing::is_write_conflict(&error));

    let stored = get_paykit_app_registry(&setup.public_storage, &setup.public_key)
        .await
        .unwrap()
        .unwrap();
    assert!(stored.apps().contains_key(&app_id()));
    assert!(stored
        .apps()
        .contains_key(&PaykitAppId::new("paykit-server").unwrap()));
    assert!(!stored
        .apps()
        .contains_key(&PaykitAppId::new("exchange").unwrap()));
    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn endpoint_round_trip_and_update() {
    let setup = TestSetup::new().await;

    let method = PaymentEndpointIdentifier::new("onchain").unwrap();
    let endpoint = PaymentEndpointPayload::new("{\"address\":\"bc1...\"}");

    set_payment_endpoint(&setup.session, &app_id(), method.clone(), endpoint.clone())
        .await
        .unwrap();

    let fetched =
        get_payment_endpoint(&setup.public_storage, &setup.public_key, &app_id(), &method)
            .await
            .unwrap();
    assert_eq!(fetched, Some(endpoint.clone()));

    let list = get_payment_list(&setup.public_storage, &setup.public_key, &app_id())
        .await
        .unwrap();
    assert_eq!(
        list,
        PaymentList {
            payment_endpoints: vec![(method.clone(), endpoint.clone())]
                .into_iter()
                .collect()
        }
    );

    let new_endpoint = PaymentEndpointPayload::new("{\"address\":\"1c1...\"}");

    set_payment_endpoint(
        &setup.session,
        &app_id(),
        method.clone(),
        new_endpoint.clone(),
    )
    .await
    .unwrap();

    let updated =
        get_payment_endpoint(&setup.public_storage, &setup.public_key, &app_id(), &method)
            .await
            .unwrap();
    assert_eq!(updated, Some(new_endpoint.clone()));

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_endpoint_conditional_updates_reject_stale_revisions() {
    let setup = TestSetup::new().await;
    let identifier = PaymentEndpointIdentifier::new("btc-lightning-bolt11").unwrap();
    let initial = PaymentEndpointPayload::new("ln-initial");
    let updated = PaymentEndpointPayload::new("ln-updated");

    create_payment_endpoint(
        &setup.session,
        &app_id(),
        identifier.clone(),
        initial.clone(),
    )
    .await
    .unwrap();
    let (payload, initial_revision) = get_payment_endpoint_with_revision(
        &setup.public_storage,
        &setup.public_key,
        &app_id(),
        &identifier,
    )
    .await
    .unwrap()
    .unwrap();
    assert_eq!(payload, Some(initial));

    update_payment_endpoint(
        &setup.session,
        &app_id(),
        identifier.clone(),
        updated.clone(),
        &initial_revision,
    )
    .await
    .unwrap();
    let stale_delete = remove_payment_endpoint_if_revision(
        &setup.session,
        &app_id(),
        identifier.clone(),
        &initial_revision,
    )
    .await
    .unwrap_err();
    assert!(pubky_routing::is_write_conflict(&stale_delete));

    let (payload, current_revision) = get_payment_endpoint_with_revision(
        &setup.public_storage,
        &setup.public_key,
        &app_id(),
        &identifier,
    )
    .await
    .unwrap()
    .unwrap();
    assert_eq!(payload, Some(updated));
    remove_payment_endpoint_if_revision(
        &setup.session,
        &app_id(),
        identifier.clone(),
        &current_revision,
    )
    .await
    .unwrap();
    assert!(get_payment_endpoint_with_revision(
        &setup.public_storage,
        &setup.public_key,
        &app_id(),
        &identifier,
    )
    .await
    .unwrap()
    .is_none());

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn missing_endpoint_returns_none() {
    let setup = TestSetup::new().await;
    let method = PaymentEndpointIdentifier::new("btc-lightning-bolt11").unwrap();

    let missing =
        get_payment_endpoint(&setup.public_storage, &setup.public_key, &app_id(), &method)
            .await
            .unwrap();
    assert!(missing.is_none());

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn list_reflects_additions_and_removals() {
    let setup = TestSetup::new().await;

    let onchain = PaymentEndpointIdentifier::new("btc-bitcoin-p2tr").unwrap();
    let lightning = PaymentEndpointIdentifier::new("btc-lightning-bolt11").unwrap();
    let onchain_data = PaymentEndpointPayload::new("bc1p...");
    let lightning_data = PaymentEndpointPayload::new("ln...");

    set_payment_endpoint(
        &setup.session,
        &app_id(),
        onchain.clone(),
        onchain_data.clone(),
    )
    .await
    .unwrap();
    set_payment_endpoint(
        &setup.session,
        &app_id(),
        lightning.clone(),
        lightning_data.clone(),
    )
    .await
    .unwrap();

    let list = get_payment_list(&setup.public_storage, &setup.public_key, &app_id())
        .await
        .unwrap();
    let mut expected = HashMap::new();
    expected.insert(onchain.clone(), onchain_data.clone());
    expected.insert(lightning.clone(), lightning_data.clone());
    assert_eq!(list.payment_endpoints, expected);

    remove_payment_endpoint(&setup.session, &app_id(), onchain.clone())
        .await
        .unwrap();
    let list = get_payment_list(&setup.public_storage, &setup.public_key, &app_id())
        .await
        .unwrap();
    assert_eq!(
        list.payment_endpoints,
        vec![(lightning.clone(), lightning_data.clone())]
            .into_iter()
            .collect()
    );

    remove_payment_endpoint(&setup.session, &app_id(), lightning.clone())
        .await
        .unwrap();
    let empty = get_payment_list(&setup.public_storage, &setup.public_key, &app_id())
        .await
        .unwrap();
    assert!(empty.payment_endpoints.is_empty());

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn list_fetches_multiple_pages() {
    let setup = TestSetup::new().await;
    let mut expected = HashMap::new();

    for index in 0..105 {
        let identifier = PaymentEndpointIdentifier::new(format!("endpoint-{index:03}")).unwrap();
        let payload = PaymentEndpointPayload::new(format!("payload-{index:03}"));
        set_payment_endpoint(
            &setup.session,
            &app_id(),
            identifier.clone(),
            payload.clone(),
        )
        .await
        .unwrap();
        expected.insert(identifier, payload);
    }

    let list = get_payment_list(&setup.public_storage, &setup.public_key, &app_id())
        .await
        .unwrap();
    assert_eq!(list.payment_endpoints, expected);

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_payment_list_fetch_limits_endpoint_count_and_payload_bytes() {
    let setup = TestSetup::new().await;
    for (identifier, payload) in [("endpoint-1", "payload-1"), ("endpoint-2", "payload-2")] {
        set_payment_endpoint(
            &setup.session,
            &app_id(),
            PaymentEndpointIdentifier::new(identifier).unwrap(),
            PaymentEndpointPayload::new(payload),
        )
        .await
        .unwrap();
    }

    let list =
        get_payment_list_with_limits(&setup.public_storage, &setup.public_key, &app_id(), 2, 18)
            .await
            .unwrap();
    assert_eq!(list.payment_endpoints.len(), 2);

    let endpoint_limit =
        get_payment_list_with_limits(&setup.public_storage, &setup.public_key, &app_id(), 1, 18)
            .await;
    let endpoint_limit = endpoint_limit.unwrap_err();
    assert!(matches!(endpoint_limit, PaykitError::InvalidData { .. }));
    assert!(is_payment_list_limit_exceeded(&endpoint_limit));

    let payload_limit =
        get_payment_list_with_limits(&setup.public_storage, &setup.public_key, &app_id(), 2, 8)
            .await;
    let payload_limit = payload_limit.unwrap_err();
    assert!(matches!(payload_limit, PaykitError::InvalidData { .. }));
    assert!(is_payment_list_limit_exceeded(&payload_limit));

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn removing_missing_endpoint_is_idempotent() {
    let setup = TestSetup::new().await;
    let method = PaymentEndpointIdentifier::new("unused").unwrap();

    remove_payment_endpoint(&setup.session, &app_id(), method)
        .await
        .expect("removing non-existent endpoint should be idempotent");

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_invalid_utf8_endpoint_returns_invalid_data() {
    let setup = TestSetup::new().await;
    let identifier = PaymentEndpointIdentifier::new("btc-lightning-bolt11").unwrap();
    let path = crate::pubky_routing::payment_endpoint_path(&app_id(), &identifier);

    setup
        .session
        .storage()
        .put(path, vec![0xff])
        .await
        .expect("invalid UTF-8 fixture should be stored");

    let result = get_payment_endpoint(
        &setup.public_storage,
        &setup.public_key,
        &app_id(),
        &identifier,
    )
    .await;
    assert!(matches!(result, Err(PaykitError::InvalidData { .. })));

    setup.raw_session.signout().await.unwrap();
}

#[tokio::test]
async fn test_invalid_payment_endpoint_listing_entry_returns_invalid_data() {
    let setup = TestSetup::new().await;
    let invalid_identifier = "a".repeat(65);
    let path = format!(
        "{}{invalid_identifier}",
        crate::pubky_routing::payment_endpoint_path_prefix(&app_id())
    );

    setup
        .session
        .storage()
        .put(path, "non-empty payload".to_string())
        .await
        .expect("invalid listing entry fixture should be stored");

    let result = get_payment_list(&setup.public_storage, &setup.public_key, &app_id())
        .await
        .unwrap_err();
    assert!(matches!(result, PaykitError::InvalidData { .. }));
    assert!(!is_payment_list_limit_exceeded(&result));

    setup.raw_session.signout().await.unwrap();
}