lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

receipt_snapshots.rs (26370B)


      1 use super::issuance::{claim, obtain, prepare, selection};
      2 use super::*;
      3 use radroots_execution::{
      4     BusinessInstallation, Delivery, Issuance, OperationReceipt, RecoveryRequirement,
      5     WaitTermination,
      6 };
      7 use radroots_storage::command::{ArtifactSnapshot, OperationSnapshot, RetainedOperation};
      8 
      9 #[tokio::test]
     10 async fn structural_reports_reject_incomplete_recipient_sets_and_cross_operation_evidence() {
     11     let fixture = Fixture::new();
     12     let (store, input, proof, binding) = fixture.create().await;
     13     let (prepared, digest, recipients) =
     14         prepare(&fixture, &store, &binding, &proof, 180, false).await;
     15     let first = claim(
     16         store
     17             .claim_attempt(
     18                 selection(&binding, &prepared, digest, recipients[0]),
     19                 copy(&proof),
     20             )
     21             .await
     22             .unwrap(),
     23     );
     24     let bytes = obtain(&first, true).await;
     25     store
     26         .capture_evidence(input.clone(), &proof, &bytes)
     27         .await
     28         .unwrap();
     29     let original = store
     30         .operation_snapshot(
     31             binding.clone(),
     32             prepared.identity().operation_id(),
     33             None,
     34             copy(&proof),
     35         )
     36         .await
     37         .unwrap()
     38         .unwrap();
     39     let (other, other_digest, other_recipients) =
     40         prepare(&fixture, &store, &binding, &proof, 181, false).await;
     41     let other_claim = claim(
     42         store
     43             .claim_attempt(
     44                 selection(&binding, &other, other_digest, other_recipients[0]),
     45                 copy(&proof),
     46             )
     47             .await
     48             .unwrap(),
     49     );
     50     let other_bytes = obtain(&other_claim, true).await;
     51     store
     52         .capture_evidence(input, &proof, &other_bytes)
     53         .await
     54         .unwrap();
     55     let other = store
     56         .operation_snapshot(
     57             binding.clone(),
     58             other.identity().operation_id(),
     59             None,
     60             copy(&proof),
     61         )
     62         .await
     63         .unwrap()
     64         .unwrap();
     65     let first = original.artifacts()[0];
     66     let second = original.artifacts()[1];
     67     let foreign = other.artifacts()[0];
     68     let cases = [
     69         (vec![], 100),
     70         (vec![first], 100),
     71         (vec![first, second, first], 100),
     72         (vec![second, first], 100),
     73         (vec![first, first], 100),
     74         (vec![first, second], 0),
     75         (
     76             vec![
     77                 ArtifactSnapshot::from_store_report(
     78                     first.recipient().unwrap(),
     79                     None,
     80                     first.claim(),
     81                     first.obtained(),
     82                 ),
     83                 second,
     84             ],
     85             100,
     86         ),
     87         (
     88             vec![
     89                 ArtifactSnapshot::from_store_report(
     90                     first.recipient().unwrap(),
     91                     first.expected_event(),
     92                     None,
     93                     first.obtained(),
     94                 ),
     95                 second,
     96             ],
     97             100,
     98         ),
     99         (
    100             vec![
    101                 ArtifactSnapshot::from_store_report(
    102                     first.recipient().unwrap(),
    103                     first.expected_event(),
    104                     foreign.claim(),
    105                     foreign.obtained(),
    106                 ),
    107                 second,
    108             ],
    109             100,
    110         ),
    111         (
    112             vec![
    113                 ArtifactSnapshot::from_store_report(
    114                     first.recipient().unwrap(),
    115                     first.expected_event(),
    116                     first.claim(),
    117                     foreign.obtained(),
    118                 ),
    119                 second,
    120             ],
    121             100,
    122         ),
    123     ];
    124     for (recipients, time) in cases {
    125         let bound = store
    126             .signing_plan(
    127                 binding.clone(),
    128                 prepared.identity().operation_id(),
    129                 prepared.identity().command_digest(),
    130                 copy(&proof),
    131             )
    132             .await
    133             .unwrap()
    134             .unwrap();
    135         assert!(matches!(
    136             OperationSnapshot::from_store_report(
    137                 RetainedOperation::Planned(Box::new(bound)),
    138                 recipients,
    139                 UnixSeconds::new(time).unwrap()
    140             ),
    141             Err(OperationError::RecoveryRequired)
    142         ));
    143     }
    144     let report = store
    145         .operation(
    146             binding,
    147             prepared.identity().operation_id(),
    148             None,
    149             copy(&proof),
    150         )
    151         .await
    152         .unwrap()
    153         .unwrap();
    154     assert!(matches!(
    155         OperationSnapshot::from_store_report(
    156             RetainedOperation::Prepared(report),
    157             original.artifacts().to_vec(),
    158             UnixSeconds::new(100).unwrap()
    159         ),
    160         Err(OperationError::RecoveryRequired)
    161     ));
    162     store.close().await.unwrap();
    163 }
    164 
    165 #[tokio::test]
    166 async fn expiry_blocks_remaining_first_issuance_without_erasing_obtained_or_unknown_facts() {
    167     for mode in 0u8..=3 {
    168         let fixture = Fixture::new();
    169         let (store, input, proof, binding) = fixture.create().await;
    170         let (prepared, planned) = if mode == 0 {
    171             (
    172                 committed(
    173                     store
    174                         .admit_command_and_hold(peer_request(&binding, 174), copy(&proof))
    175                         .await
    176                         .unwrap(),
    177                 ),
    178                 None,
    179             )
    180         } else {
    181             let (prepared, digest, recipients) =
    182                 prepare(&fixture, &store, &binding, &proof, 174 + mode, false).await;
    183             (prepared, Some((digest, recipients)))
    184         };
    185         if let Some((digest, recipients)) = planned
    186             && mode >= 2
    187         {
    188             for recipient in recipients.into_iter().take(if mode == 2 { 1 } else { 2 }) {
    189                 let original = claim(
    190                     store
    191                         .claim_attempt(
    192                             selection(&binding, &prepared, digest, recipient),
    193                             copy(&proof),
    194                         )
    195                         .await
    196                         .unwrap(),
    197                 );
    198                 if mode == 3 {
    199                     let bytes = obtain(&original, true).await;
    200                     store
    201                         .capture_evidence(input.clone(), &proof, &bytes)
    202                         .await
    203                         .unwrap();
    204                 }
    205             }
    206         }
    207         fixture.clock.now.store(151, Ordering::SeqCst);
    208         let snapshot = store
    209             .operation_snapshot(
    210                 binding,
    211                 prepared.identity().operation_id(),
    212                 None,
    213                 copy(&proof),
    214             )
    215             .await
    216             .unwrap()
    217             .unwrap();
    218         let receipt =
    219             OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    220         assert!(receipt.durable());
    221         assert_eq!(
    222             receipt.admission_transaction_id(),
    223             prepared.transaction_id()
    224         );
    225         assert_eq!(
    226             receipt.business_installation(),
    227             BusinessInstallation::NotInstalled
    228         );
    229         assert_eq!(receipt.delivery(), Delivery::NotStarted);
    230         match mode {
    231             0 | 1 => {
    232                 assert_eq!(
    233                     receipt.error().unwrap().code(),
    234                     radroots_execution::Code::DeadlineExceeded
    235                 );
    236                 assert!(
    237                     receipt
    238                         .recovery()
    239                         .contains(&RecoveryRequirement::ManualReconciliation)
    240                 );
    241                 assert!(!matches!(
    242                     receipt.issuance(),
    243                     Issuance::Obtained | Issuance::ProvablyUnissued
    244                 ));
    245             }
    246             2 => {
    247                 assert_eq!(receipt.issuance(), Issuance::Unknown);
    248                 assert_eq!(
    249                     receipt.error().unwrap().code(),
    250                     radroots_execution::Code::SigningUnknown
    251                 );
    252                 assert!(
    253                     receipt
    254                         .recovery()
    255                         .contains(&RecoveryRequirement::ReconcileIssuance)
    256                 );
    257             }
    258             3 => {
    259                 assert_eq!(receipt.issuance(), Issuance::Obtained);
    260                 assert_eq!(receipt.error(), None);
    261             }
    262             _ => unreachable!(),
    263         }
    264         store.close().await.unwrap();
    265     }
    266 }
    267 
    268 #[tokio::test]
    269 async fn full_receipts_keep_obtained_and_unknown_recipients_separate_and_bind_original_provenance()
    270 {
    271     let fixture = Fixture::new();
    272     let (store, input, proof, binding) = fixture.create().await;
    273     let (prepared, digest, recipients) =
    274         prepare(&fixture, &store, &binding, &proof, 173, false).await;
    275     let first = claim(
    276         store
    277             .claim_attempt(
    278                 selection(&binding, &prepared, digest, recipients[0]),
    279                 copy(&proof),
    280             )
    281             .await
    282             .unwrap(),
    283     );
    284     let first_bytes = obtain(&first, true).await;
    285     store
    286         .capture_evidence(input.clone(), &proof, &first_bytes)
    287         .await
    288         .unwrap();
    289     let second = claim(
    290         store
    291             .claim_attempt(
    292                 selection(&binding, &prepared, digest, recipients[1]),
    293                 copy(&proof),
    294             )
    295             .await
    296             .unwrap(),
    297     );
    298     let snapshot = store
    299         .operation_snapshot(
    300             binding.clone(),
    301             prepared.identity().operation_id(),
    302             None,
    303             copy(&proof),
    304         )
    305         .await
    306         .unwrap()
    307         .unwrap();
    308     let view =
    309         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    310     assert_eq!(view.command_digest(), prepared.identity().command_digest());
    311     assert_eq!(view.artifacts()[0].issuance(), Issuance::Obtained);
    312     assert_eq!(view.artifacts()[1].issuance(), Issuance::Unknown);
    313     assert_eq!(view.issuance(), Issuance::Unknown);
    314     assert_eq!(
    315         view.business_installation(),
    316         BusinessInstallation::NotInstalled
    317     );
    318     assert_eq!(view.business_result(), None);
    319     assert_eq!(view.delivery(), Delivery::NotStarted);
    320     assert!(view.delivery_observations().is_empty());
    321     assert!(view.conflicting_records().is_empty());
    322     assert!(view.conflicting_sources().is_empty());
    323     assert_eq!(
    324         view.missing_sources(),
    325         binding.input().checkpoint().missing()
    326     );
    327     assert!(
    328         view.recovery()
    329             .contains(&RecoveryRequirement::InstallObtainedEvidence)
    330     );
    331     assert!(
    332         view.recovery()
    333             .contains(&RecoveryRequirement::ReconcileIssuance)
    334     );
    335     let original = &view.artifacts()[0];
    336     assert_eq!(
    337         original.role(),
    338         radroots_protocol::intent::ArtifactRole::BusinessSeal
    339     );
    340     assert_eq!(
    341         original.recipient(),
    342         Some(first.seal().unwrap().recipient())
    343     );
    344     assert_eq!(
    345         original.expected_event().unwrap().as_bytes(),
    346         &first.seal().unwrap().event_id()
    347     );
    348     assert_eq!(original.attempt_id(), Some(first.attempt_id()));
    349     assert_eq!(
    350         original.claim_transaction_id(),
    351         Some(first.transaction_id())
    352     );
    353     assert_eq!(original.intent_digest(), Some(*first.binding().digest()));
    354     assert_eq!(original.obtained_digest(), Some(*first_bytes.digest()));
    355     assert_eq!(
    356         original.capture_transaction_id(),
    357         snapshot.artifacts()[0]
    358             .obtained()
    359             .map(|value| value.transaction_id())
    360     );
    361     assert_eq!(original.observed_at_unix_ms(), None);
    362     let second_bytes = obtain(&second, false).await;
    363     store
    364         .capture_evidence(input, &proof, &second_bytes)
    365         .await
    366         .unwrap();
    367     let snapshot = store
    368         .operation_snapshot(
    369             binding.clone(),
    370             prepared.identity().operation_id(),
    371             None,
    372             copy(&proof),
    373         )
    374         .await
    375         .unwrap()
    376         .unwrap();
    377     let completed =
    378         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    379     assert_eq!(completed.issuance(), Issuance::Obtained);
    380     assert_eq!(completed.error(), None);
    381     assert_eq!(
    382         completed.artifacts()[1].observed_at_unix_ms(),
    383         second_bytes.observed_at_unix_ms()
    384     );
    385     assert_ne!(
    386         completed.operation_checkpoint(),
    387         view.operation_checkpoint()
    388     );
    389     let checkpoint = completed.operation_checkpoint();
    390     fixture.clock.now.store(110, Ordering::SeqCst);
    391     let later = store
    392         .operation_snapshot(
    393             binding,
    394             prepared.identity().operation_id(),
    395             None,
    396             copy(&proof),
    397         )
    398         .await
    399         .unwrap()
    400         .unwrap();
    401     let later =
    402         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&later).unwrap();
    403     assert_eq!(later.observed_at().get(), 110);
    404     assert_eq!(later.operation_checkpoint(), checkpoint);
    405     assert_eq!(later.artifacts()[1].attempt_id(), Some(second.attempt_id()));
    406     assert_eq!(later.issuance_window(), prepared.issuance_window());
    407     store.close().await.unwrap();
    408 }
    409 
    410 #[tokio::test]
    411 async fn coherent_snapshots_retain_t0_t1_and_independent_recipient_claim_and_capture_after_reopen()
    412 {
    413     let fixture = Fixture::new();
    414     let (store, input, proof, binding) = fixture.create().await;
    415     let request = peer_request(&binding, 170);
    416     let operation = request.command().context().operation_id();
    417     let digest = request.command().digest();
    418     assert!(
    419         store
    420             .operation_snapshot(binding.clone(), operation, Some(digest), copy(&proof))
    421             .await
    422             .unwrap()
    423             .is_none()
    424     );
    425     let prepared = committed(
    426         store
    427             .admit_command_and_hold(request, copy(&proof))
    428             .await
    429             .unwrap(),
    430     );
    431     let snapshot = store
    432         .operation_snapshot(binding.clone(), operation, None, copy(&proof))
    433         .await
    434         .unwrap()
    435         .unwrap();
    436     assert_eq!(
    437         snapshot.prepared().transaction_id(),
    438         prepared.transaction_id()
    439     );
    440     assert!(snapshot.bound_plan().is_none());
    441     let receipt =
    442         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    443     assert!(receipt.durable());
    444     assert_eq!(receipt.issuance(), Issuance::None);
    445     assert_eq!(
    446         receipt.business_installation(),
    447         BusinessInstallation::NotInstalled
    448     );
    449     assert_eq!(receipt.delivery(), Delivery::NotStarted);
    450     assert!(receipt.business_result().is_none());
    451     assert!(receipt.record_ids().is_empty());
    452     assert_eq!(receipt.context(), prepared.request().command().context());
    453     assert_eq!(
    454         receipt.admission_transaction_id(),
    455         prepared.transaction_id()
    456     );
    457     assert_eq!(receipt.issuance_window(), prepared.issuance_window());
    458     assert_eq!(receipt.authority_checkpoint(), binding.input().checkpoint());
    459     let initial_checkpoint = receipt.operation_checkpoint();
    460     assert_eq!(snapshot.message_id(), None);
    461     assert_eq!(snapshot.artifacts().len(), 2);
    462     assert!(
    463         snapshot
    464             .artifacts()
    465             .iter()
    466             .all(|value| value.expected_event().is_none()
    467                 && value.claim().is_none()
    468                 && value.obtained().is_none())
    469     );
    470     let plan = plan(prepared.request().chat_command().unwrap(), 100, "snapshot");
    471     let plan_digest = *plan.digest();
    472     let message = plan.message_id();
    473     let plan_receipt = bound(
    474         store
    475             .bind_signing_intents(binding.clone(), (plan).into(), copy(&proof))
    476             .await
    477             .unwrap(),
    478     );
    479     let snapshot = store
    480         .operation_snapshot(binding.clone(), operation, Some(digest), copy(&proof))
    481         .await
    482         .unwrap()
    483         .unwrap();
    484     assert_eq!(snapshot.message_id(), Some(message));
    485     let receipt =
    486         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    487     assert_eq!(receipt.issuance(), Issuance::Pending);
    488     assert_ne!(receipt.operation_checkpoint(), initial_checkpoint);
    489     assert_eq!(
    490         snapshot.bound_plan().unwrap().transaction_id(),
    491         plan_receipt.transaction_id()
    492     );
    493     assert!(
    494         snapshot
    495             .artifacts()
    496             .iter()
    497             .all(|value| value.expected_event().is_some() && value.claim().is_none())
    498     );
    499     let first = snapshot.artifacts()[0].recipient().unwrap();
    500     let second = snapshot.artifacts()[1].recipient().unwrap();
    501     let attempt = claim(
    502         store
    503             .claim_attempt(
    504                 selection(&binding, &prepared, plan_digest, first),
    505                 copy(&proof),
    506             )
    507             .await
    508             .unwrap(),
    509     );
    510     let snapshot = store
    511         .operation_snapshot(binding.clone(), operation, None, copy(&proof))
    512         .await
    513         .unwrap()
    514         .unwrap();
    515     assert_eq!(
    516         snapshot.artifacts()[0].claim().unwrap().attempt_id(),
    517         attempt.attempt_id()
    518     );
    519     assert!(snapshot.artifacts()[0].obtained().is_none());
    520     let receipt =
    521         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    522     assert_eq!(receipt.issuance(), Issuance::Unknown);
    523     assert_eq!(receipt.artifacts()[0].issuance(), Issuance::Unknown);
    524     assert_eq!(receipt.artifacts()[1].issuance(), Issuance::Pending);
    525     assert_eq!(
    526         receipt.error().unwrap().code(),
    527         radroots_execution::Code::SigningUnknown
    528     );
    529     assert!(
    530         receipt
    531             .recovery()
    532             .contains(&RecoveryRequirement::ReconcileIssuance)
    533     );
    534     assert!(snapshot.artifacts()[1].claim().is_none());
    535     let evidence = obtain(&attempt, true).await;
    536     let receipt = match store
    537         .capture_evidence(input.clone(), &proof, &evidence)
    538         .await
    539         .unwrap()
    540     {
    541         radroots_storage::command::EvidenceCaptureOutcome::Committed(value) => value,
    542         _ => panic!("capture must confirm"),
    543     };
    544     let snapshot = store
    545         .operation_snapshot(binding.clone(), operation, None, copy(&proof))
    546         .await
    547         .unwrap()
    548         .unwrap();
    549     assert_eq!(snapshot.artifacts()[0].obtained(), Some(receipt));
    550     let view =
    551         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    552     assert_eq!(view.issuance(), Issuance::Pending);
    553     assert_eq!(view.artifacts()[0].issuance(), Issuance::Obtained);
    554     assert_eq!(view.artifacts()[1].issuance(), Issuance::Pending);
    555     assert_eq!(view.artifacts()[0].observed_at_unix_ms(), None);
    556     assert!(
    557         view.recovery()
    558             .contains(&RecoveryRequirement::InstallObtainedEvidence)
    559     );
    560     assert_eq!(view.error(), None);
    561     assert_eq!(format!("{view:?}"), "OperationReceipt(<redacted>)");
    562     assert_eq!(
    563         format!("{:?}", view.artifacts()[0]),
    564         "ArtifactObservation(<redacted>)"
    565     );
    566     let captured_checkpoint = view.operation_checkpoint();
    567     let stopped = view.with_wait_termination(WaitTermination::DeadlineExceeded);
    568     assert_eq!(
    569         stopped.wait_termination(),
    570         WaitTermination::DeadlineExceeded
    571     );
    572     assert_eq!(stopped.operation_checkpoint(), captured_checkpoint);
    573     assert_eq!(stopped.issuance(), Issuance::Pending);
    574     assert_eq!(
    575         stopped.business_installation(),
    576         BusinessInstallation::NotInstalled
    577     );
    578     assert_eq!(stopped.delivery(), Delivery::NotStarted);
    579     assert!(stopped.durable());
    580     assert_eq!(
    581         snapshot.artifacts()[0]
    582             .obtained()
    583             .unwrap()
    584             .observed_at_unix_ms(),
    585         None
    586     );
    587     assert_eq!(snapshot.artifacts()[1].recipient().unwrap(), second);
    588     assert!(snapshot.artifacts()[1].claim().is_none());
    589     assert_eq!(format!("{snapshot:?}"), "OperationSnapshot(<redacted>)");
    590     store.close().await.unwrap();
    591     fixture.clock.now.store(151, Ordering::SeqCst);
    592     let reopened = fixture.reopen(input.clone()).await;
    593     let snapshot = reopened
    594         .operation_snapshot(binding.clone(), operation, Some(digest), copy(&proof))
    595         .await
    596         .unwrap()
    597         .unwrap();
    598     assert_eq!(snapshot.prepared().identity(), prepared.identity());
    599     assert_eq!(snapshot.message_id(), Some(message));
    600     assert_eq!(snapshot.artifacts()[0].obtained(), Some(receipt));
    601     let view =
    602         OperationReceipt::<radroots_domain::ChatMessage>::try_from_snapshot(&snapshot).unwrap();
    603     assert_eq!(view.operation_checkpoint(), captured_checkpoint);
    604     assert_eq!(view.message_id(), Some(message));
    605     assert!(snapshot.artifacts()[1].obtained().is_none());
    606     assert!(matches!(
    607         reopened
    608             .operation_snapshot(
    609                 binding.clone(),
    610                 operation,
    611                 Some(CommandDigest::from_bytes([0; 32])),
    612                 copy(&proof)
    613             )
    614             .await,
    615         Err(OperationError::IdempotencyConflict)
    616     ));
    617     reopened.revoke(input, &proof).await.unwrap();
    618     assert!(matches!(
    619         reopened
    620             .operation_snapshot(binding, operation, None, copy(&proof))
    621             .await,
    622         Err(OperationError::Workspace(WorkspaceError::GrantRevoked))
    623     ));
    624     reopened.close().await.unwrap();
    625 }
    626 
    627 #[tokio::test]
    628 async fn complete_snapshot_rejects_extra_recipient_claims_and_orphan_parts_without_repair() {
    629     let fixture = Fixture::new();
    630     let (store, _, proof, binding) = fixture.create().await;
    631     let (prepared, digest, recipients) =
    632         prepare(&fixture, &store, &binding, &proof, 171, false).await;
    633     claim(
    634         store
    635             .claim_attempt(
    636                 selection(&binding, &prepared, digest, recipients[0]),
    637                 copy(&proof),
    638             )
    639             .await
    640             .unwrap(),
    641     );
    642     let mut database = fixture.database().await;
    643     sqlx::query("PRAGMA foreign_keys=OFF")
    644         .execute(&mut database)
    645         .await
    646         .unwrap();
    647     let third = keys(3).public_key();
    648     for number in 3u8..=12 {
    649         sqlx::query("INSERT INTO signing_attempts(workspace,operation_id,artifact_key,attempt_id,transaction_id,plan_digest,intent_digest,protected) SELECT workspace,operation_id,?,?,?,plan_digest,intent_digest,protected FROM signing_attempts LIMIT 1")
    650             .bind(keys(number).public_key().as_bytes().as_slice()).bind([number;32].as_slice()).bind([number;32].as_slice()).execute(&mut database).await.unwrap();
    651     }
    652     assert!(matches!(
    653         store
    654             .operation_snapshot(
    655                 binding.clone(),
    656                 prepared.identity().operation_id(),
    657                 None,
    658                 copy(&proof)
    659             )
    660             .await,
    661         Err(OperationError::RecoveryRequired)
    662     ));
    663     let count: i64 = sqlx::query_scalar("SELECT count(*) FROM signing_attempts")
    664         .fetch_one(&mut database)
    665         .await
    666         .unwrap();
    667     assert_eq!(count, 11);
    668     sqlx::query("DELETE FROM signing_attempts WHERE artifact_key!=?")
    669         .bind(recipients[0].as_bytes().as_slice())
    670         .execute(&mut database)
    671         .await
    672         .unwrap();
    673     for number in 3u8..=12 {
    674         sqlx::query("INSERT INTO artifact_evidence_parts(workspace,operation_id,artifact_key,part,protected) VALUES(?,?,?,1,zeroblob(1))")
    675             .bind(binding.input().workspace_id().as_bytes().as_slice()).bind(prepared.identity().operation_id().as_bytes().as_slice()).bind(keys(number).public_key().as_bytes().as_slice()).execute(&mut database).await.unwrap();
    676     }
    677     assert!(matches!(
    678         store
    679             .operation_snapshot(
    680                 binding.clone(),
    681                 prepared.identity().operation_id(),
    682                 None,
    683                 copy(&proof)
    684             )
    685             .await,
    686         Err(OperationError::RecoveryRequired)
    687     ));
    688     let count: i64 = sqlx::query_scalar("SELECT count(*) FROM artifact_evidence_parts")
    689         .fetch_one(&mut database)
    690         .await
    691         .unwrap();
    692     assert_eq!(count, 10);
    693     sqlx::query("DELETE FROM artifact_evidence_parts")
    694         .execute(&mut database)
    695         .await
    696         .unwrap();
    697     let missing = OperationId::from_bytes([237; 32]);
    698     sqlx::query("INSERT INTO artifact_evidence_parts(workspace,operation_id,artifact_key,part,protected) VALUES(?,?,?,1,zeroblob(1))")
    699         .bind(binding.input().workspace_id().as_bytes().as_slice()).bind(missing.as_bytes().as_slice()).bind(third.as_bytes().as_slice()).execute(&mut database).await.unwrap();
    700     assert!(matches!(
    701         store
    702             .operation_snapshot(binding.clone(), missing, None, copy(&proof))
    703             .await,
    704         Err(OperationError::RecoveryRequired)
    705     ));
    706     let count: i64 = sqlx::query_scalar("SELECT count(*) FROM artifact_evidence_parts")
    707         .fetch_one(&mut database)
    708         .await
    709         .unwrap();
    710     assert_eq!(count, 1);
    711     sqlx::query("DELETE FROM artifact_evidence_parts")
    712         .execute(&mut database)
    713         .await
    714         .unwrap();
    715     assert!(
    716         store
    717             .operation_snapshot(
    718                 binding,
    719                 prepared.identity().operation_id(),
    720                 None,
    721                 copy(&proof)
    722             )
    723             .await
    724             .unwrap()
    725             .is_some()
    726     );
    727     database.close().await.unwrap();
    728     store.close().await.unwrap();
    729 }
    730 
    731 #[tokio::test]
    732 async fn losing_a_snapshot_observer_does_not_detach_the_owner_or_prevent_safe_close() {
    733     let fixture = Fixture::new();
    734     let (store, input, proof, binding) = fixture.create().await;
    735     let (prepared, _, _) = prepare(&fixture, &store, &binding, &proof, 172, false).await;
    736     let (arrived, resume) = fixture.clock.arm(1);
    737     let mut query = store.operation_snapshot(
    738         binding.clone(),
    739         prepared.identity().operation_id(),
    740         None,
    741         copy(&proof),
    742     );
    743     assert!(futures::poll!(query.as_mut()).is_pending());
    744     reached(arrived).await;
    745     drop(query);
    746     resume.send(()).unwrap();
    747     store.close().await.unwrap();
    748     let reopened = fixture.reopen(input).await;
    749     assert_eq!(
    750         reopened
    751             .operation_snapshot(
    752                 binding,
    753                 prepared.identity().operation_id(),
    754                 None,
    755                 copy(&proof)
    756             )
    757             .await
    758             .unwrap()
    759             .unwrap()
    760             .prepared()
    761             .transaction_id(),
    762         prepared.transaction_id()
    763     );
    764     reopened.close().await.unwrap();
    765 }