receipt_installation_reports.rs (7266B)
1 //! Structural report validation is separate from the actual native T2 tests. 2 use super::*; 3 use radroots_domain::TransactionId; 4 use radroots_storage::command::PublicationWork; 5 6 fn restamp_plan(source: &BoundSigningPlan, transaction: TransactionId) -> BoundSigningPlan { 7 let original = source.prepared(); 8 let request = AdmissionRequest::from_protected_wire( 9 original.request().binding().clone(), 10 original.request().command().protected_wire(), 11 ) 12 .unwrap(); 13 let prepared = PreparedOperation::from_committed_store( 14 request, 15 original.transaction_id(), 16 original.revision(), 17 original.issuance_window(), 18 ) 19 .unwrap(); 20 let plan = ChatSigningPlan::parse( 21 prepared.request().chat_command().unwrap(), 22 source.plan().protected_wire(), 23 ) 24 .unwrap(); 25 BoundSigningPlan::from_committed_store(prepared, plan, transaction, source.bound_at()).unwrap() 26 } 27 28 #[tokio::test] 29 async fn structural_installation_reports_bind_original_plan_capture_and_complete_sorted_work_scope() 30 { 31 let fixture = Fixture::new(); 32 let (store, input, proof, binding) = fixture.create().await; 33 let (prepared, digest, recipients) = 34 prepare(&fixture, &store, &binding, &proof, 227, false).await; 35 let mut captures = Vec::new(); 36 for recipient in recipients { 37 let attempt = claim( 38 store 39 .claim_attempt( 40 selection(&binding, &prepared, digest, recipient), 41 copy(&proof), 42 ) 43 .await 44 .unwrap(), 45 ); 46 captures.push(capture(&store, &input, &proof, &attempt).await); 47 } 48 let state = snapshot(&store, &binding, &prepared, &proof).await; 49 let bound = state.bound_plan().unwrap(); 50 let transaction = TransactionId::from_bytes([0xa1; 32]); 51 let time = UnixSeconds::new(110).unwrap(); 52 let installation = 53 ChatInstallation::from_committed_store(bound, captures[0], transaction, time).unwrap(); 54 let first = 55 PublicationWork::from_committed_store(bound, installation, captures[0], transaction, time) 56 .unwrap(); 57 let second = 58 PublicationWork::from_committed_store(bound, installation, captures[1], transaction, time) 59 .unwrap(); 60 assert!(matches!( 61 ChatInstallation::from_committed_store( 62 bound, 63 captures[0], 64 transaction, 65 UnixSeconds::new(99).unwrap() 66 ), 67 Err(OperationError::RecoveryRequired) 68 )); 69 assert!(matches!( 70 PublicationWork::from_committed_store( 71 bound, 72 installation, 73 captures[0], 74 transaction, 75 UnixSeconds::new(109).unwrap() 76 ), 77 Err(OperationError::RecoveryRequired) 78 )); 79 for (installed, work) in [ 80 (None, vec![first]), 81 (Some(installation), vec![]), 82 (Some(installation), vec![first, second, first]), 83 (Some(installation), vec![second, first]), 84 (Some(installation), vec![first, first]), 85 (Some(installation), vec![second]), 86 ] { 87 assert!(matches!( 88 snapshot(&store, &binding, &prepared, &proof) 89 .await 90 .with_installation(installed, work), 91 Err(OperationError::RecoveryRequired) 92 )); 93 } 94 let reported = snapshot(&store, &binding, &prepared, &proof) 95 .await 96 .with_installation(Some(installation), vec![first, second]) 97 .unwrap(); 98 assert_eq!(reported.installation(), Some(installation)); 99 assert_eq!( 100 reported.installed_message().unwrap().text(), 101 prepared.request().chat_command().unwrap().text() 102 ); 103 // No actual installation was performed by constructing any of these values. 104 assert!( 105 snapshot(&store, &binding, &prepared, &proof) 106 .await 107 .installation() 108 .is_none() 109 ); 110 111 let restamped = restamp_plan(bound, TransactionId::from_bytes([0xa2; 32])); 112 let changed = 113 ChatInstallation::from_committed_store(&restamped, captures[0], transaction, time).unwrap(); 114 let changed_work = 115 PublicationWork::from_committed_store(&restamped, changed, captures[0], transaction, time) 116 .unwrap(); 117 assert!(matches!( 118 snapshot(&store, &binding, &prepared, &proof) 119 .await 120 .with_installation(Some(changed), vec![changed_work]), 121 Err(OperationError::RecoveryRequired) 122 )); 123 assert!(matches!( 124 PublicationWork::from_committed_store( 125 &restamped, 126 installation, 127 captures[0], 128 transaction, 129 time 130 ), 131 Err(OperationError::RecoveryRequired) 132 )); 133 let wrong_installation = ChatInstallation::from_committed_store( 134 bound, 135 captures[0], 136 TransactionId::from_bytes([0xa3; 32]), 137 time, 138 ) 139 .unwrap(); 140 assert!(matches!( 141 snapshot(&store, &binding, &prepared, &proof) 142 .await 143 .with_installation(Some(wrong_installation), vec![first]), 144 Err(OperationError::RecoveryRequired) 145 )); 146 147 let (foreign, foreign_digest, foreign_recipients) = 148 prepare(&fixture, &store, &binding, &proof, 228, false).await; 149 let attempt = claim( 150 store 151 .claim_attempt( 152 selection(&binding, &foreign, foreign_digest, foreign_recipients[0]), 153 copy(&proof), 154 ) 155 .await 156 .unwrap(), 157 ); 158 let foreign_capture = capture(&store, &input, &proof, &attempt).await; 159 let foreign_state = snapshot(&store, &binding, &foreign, &proof).await; 160 let foreign_installation = ChatInstallation::from_committed_store( 161 foreign_state.bound_plan().unwrap(), 162 foreign_capture, 163 transaction, 164 time, 165 ) 166 .unwrap(); 167 assert!(matches!( 168 ChatInstallation::from_committed_store(bound, foreign_capture, transaction, time), 169 Err(OperationError::RecoveryRequired) 170 )); 171 assert!(matches!( 172 PublicationWork::from_committed_store( 173 bound, 174 installation, 175 foreign_capture, 176 transaction, 177 time 178 ), 179 Err(OperationError::RecoveryRequired) 180 )); 181 assert!(matches!( 182 PublicationWork::from_committed_store( 183 bound, 184 foreign_installation, 185 captures[0], 186 transaction, 187 time 188 ), 189 Err(OperationError::RecoveryRequired) 190 )); 191 assert!(matches!( 192 snapshot(&store, &binding, &prepared, &proof) 193 .await 194 .with_installation(Some(foreign_installation), vec![first]), 195 Err(OperationError::RecoveryRequired) 196 )); 197 198 let unbound = committed( 199 store 200 .admit_command_and_hold( 201 request(&binding, 229, "original unbound", "trace"), 202 copy(&proof), 203 ) 204 .await 205 .unwrap(), 206 ); 207 assert!(matches!( 208 snapshot(&store, &binding, &unbound, &proof) 209 .await 210 .with_installation(Some(installation), vec![first]), 211 Err(OperationError::RecoveryRequired) 212 )); 213 store.close().await.unwrap(); 214 }