tests.rs (26997B)
1 //! Actual native issuance tests. The captured request is deliberately only 2 //! command data; these tests do not assert causal admission or stock holds. 3 use super::*; 4 use crate::workspace::{tests::CryptoFixture, tests::participant}; 5 use radroots_domain::{CommandContextData, PoolId}; 6 use radroots_protocol::command::CapturedOrderAcceptance; 7 use radroots_storage::inventory::{InventoryOutcome, InventoryRequest, InventoryStore}; 8 use std::sync::atomic::{AtomicU64, Ordering}; 9 #[path = "test_provider.rs"] 10 mod provider; 11 12 struct Clock(AtomicU64); 13 impl WorkspaceClock for Clock { 14 fn now(&self) -> Result<UnixSeconds, WorkspaceError> { 15 UnixSeconds::new(self.0.load(Ordering::SeqCst)).map_err(|_| WorkspaceError::Unavailable) 16 } 17 } 18 struct Rig { 19 fixture: CryptoFixture, 20 path: std::path::PathBuf, 21 store: NativeWorkspace, 22 input: AttachmentInput, 23 proof: AttachmentProof, 24 binding: WorkspaceBinding, 25 minimum: InventoryCheckpointRef, 26 clock: Arc<Clock>, 27 } 28 impl Rig { 29 async fn new() -> Self { 30 Self::with_catalog(None).await 31 } 32 async fn with_catalog(catalog: Option<i64>) -> Self { 33 let fixture = CryptoFixture::new(); 34 let path = fixture.root().join("consent"); 35 let clock = Arc::new(Clock(AtomicU64::new(100))); 36 let (input, proof, store) = if let Some(catalog) = catalog { 37 let (input, proof) = 38 crate::workspace::stock::tests::literal_catalog(&fixture, &path, catalog).await; 39 let store = NativeWorkspace::open_seller_stock( 40 &path, 41 input.clone(), 42 fixture.crypto(), 43 clock.clone(), 44 ) 45 .await 46 .unwrap(); 47 (input, proof, store) 48 } else { 49 let enrollment = StockEnrollment::prepare( 50 SellerStockConfig::new( 51 participant(), 52 participant(), 53 "consent-owner", 54 UnixSeconds::new(200).unwrap(), 55 ) 56 .unwrap(), 57 clock.as_ref(), 58 ) 59 .unwrap(); 60 let input = enrollment.input().clone(); 61 let proof = enrollment 62 .proof() 63 .with_secret(|v| AttachmentProof::from_protected_input(v)) 64 .unwrap(); 65 let store = NativeWorkspace::initialize_seller_stock( 66 &path, 67 &enrollment, 68 fixture.crypto(), 69 clock.clone(), 70 ) 71 .await 72 .unwrap(); 73 (input, proof, store) 74 }; 75 let binding = store.authenticate(input.clone(), &proof).await.unwrap(); 76 let minimum = store 77 .stock_authority(input.clone(), &proof) 78 .await 79 .unwrap() 80 .inventory_checkpoint() 81 .unwrap(); 82 Self { 83 fixture, 84 path, 85 store, 86 input, 87 proof, 88 binding, 89 minimum, 90 clock, 91 } 92 } 93 fn command(&self, binding: &WorkspaceBinding, id: u8) -> CapturedOrderAcceptance { 94 let context = CommandContextData::new( 95 OperationId::from_bytes([id; 32]), 96 binding.actor(), 97 self.input.workspace_id(), 98 self.input.authority(), 99 self.input.route_digest(), 100 None, 101 None, 102 UnixSeconds::new(150).unwrap(), 103 None, 104 ) 105 .unwrap(); 106 let mut wire = serde_json::json!({"type":"orders.accept","context":context,"input":{"request":"21".repeat(32),"terms_digest":"24".repeat(32),"allocation":{"type":"automatic"}}}); 107 wire["context"]["expected"] = serde_json::json!({"agreement":null,"buyer_head":"21".repeat(32),"checkpoint":{"coverage":"scope_satisfied","digest":"22".repeat(32),"missing":[],"sequence":"1"},"order_id":"23".repeat(32),"seller_sequence":"0"}); 108 let captured = CapturedOrderAcceptance::parse(&serde_json::to_vec(&wire).unwrap()).unwrap(); 109 wire["context"]["approval"] = serde_json::json!({"intent_digest":captured.approval_intent_digest(),"scope":"orders.accept","expires_at":"150"}); 110 CapturedOrderAcceptance::parse(&serde_json::to_vec(&wire).unwrap()).unwrap() 111 } 112 fn capture(&self, binding: &WorkspaceBinding, id: u8) -> StockConsentCapture { 113 StockConsentCapture::prepare( 114 SellerAuthoritySelection::from_attachment(&self.input), 115 binding.input().grant_id(), 116 StockConsentMode::ExecuteAndRecover, 117 StockResources::all_pools(), 118 UnixSeconds::new(150).unwrap(), 119 self.command(binding, id), 120 ) 121 .unwrap() 122 } 123 async fn physical(&self, id: u8, minimum: InventoryCheckpointRef) -> InventoryCheckpointRef { 124 let context = CommandContextData::new( 125 OperationId::from_bytes([id; 32]), 126 self.binding.actor(), 127 self.input.workspace_id(), 128 self.input.authority(), 129 self.input.route_digest(), 130 None, 131 None, 132 UnixSeconds::new(190).unwrap(), 133 None, 134 ) 135 .unwrap(); 136 let wire = serde_json::json!({"type":"stock.create_pool","context":context,"input":{"id":PoolId::from_bytes([id;32]),"label":"consent-boundary","unit":"each","tick_scale":"0","initial_quantity":"1"}}); 137 let request = InventoryRequest::from_protected_wire( 138 self.binding.clone(), 139 minimum, 140 &serde_json::to_vec(&wire).unwrap(), 141 ) 142 .unwrap(); 143 match self 144 .store 145 .execute_inventory( 146 request, 147 self.proof 148 .with_secret(|v| AttachmentProof::from_protected_input(v)) 149 .unwrap(), 150 ) 151 .await 152 .unwrap() 153 { 154 InventoryOutcome::Committed(receipt) => receipt.checkpoint(), 155 _ => panic!("physical operation must confirm"), 156 } 157 } 158 } 159 fn committed(outcome: StockConsentOutcome) -> StockConsentReceipt { 160 match outcome { 161 StockConsentOutcome::Committed(value) => *value, 162 _ => panic!("issuance must confirm"), 163 } 164 } 165 166 #[tokio::test] 167 async fn retained_catalog_cannot_mint_initial_consent_for_captured_replacement_terms() { 168 for catalog in [9, 19] { 169 let r = Rig::with_catalog(Some(catalog)).await; 170 let initial = r.command(&r.binding, 0x31); 171 let mut wire: serde_json::Value = serde_json::from_slice(initial.protected_wire()).unwrap(); 172 wire["type"] = serde_json::json!("orders.install_terms"); 173 wire["input"] = serde_json::json!({"proposal":"61".repeat(32),"authorization":"62".repeat(32),"terms_digest":"24".repeat(32),"allocation":{"type":"automatic"}}); 174 wire["context"]["expected"]["agreement"] = serde_json::json!("63".repeat(32)); 175 wire["context"]["expected"]["seller_sequence"] = serde_json::json!("1"); 176 wire["context"]["approval"] = serde_json::Value::Null; 177 let command = radroots_protocol::command::CapturedTermsInstallation::parse( 178 &serde_json::to_vec(&wire).unwrap(), 179 ) 180 .unwrap(); 181 wire["context"]["approval"] = serde_json::json!({"intent_digest":command.approval_intent_digest(),"scope":"orders.install_terms","expires_at":"150"}); 182 let command = radroots_protocol::command::CapturedTermsInstallation::parse( 183 &serde_json::to_vec(&wire).unwrap(), 184 ) 185 .unwrap(); 186 let capture = StockConsentCapture::prepare( 187 SellerAuthoritySelection::from_attachment(&r.input), 188 r.input.grant_id(), 189 StockConsentMode::ExecuteAndRecover, 190 StockResources::all_pools(), 191 UnixSeconds::new(150).unwrap(), 192 command, 193 ) 194 .unwrap(); 195 assert_eq!( 196 r.store 197 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 198 .await 199 .unwrap_err(), 200 OperationError::UnsupportedOperation 201 ); 202 let mut raw = SqliteConnection::connect_with( 203 &sqlx::sqlite::SqliteConnectOptions::new() 204 .filename(r.path.join("stock_execution_v1.sqlite")), 205 ) 206 .await 207 .unwrap(); 208 assert_eq!( 209 sqlx::query_scalar::<_, i64>("SELECT count(*) FROM stock_operations") 210 .fetch_one(&mut raw) 211 .await 212 .unwrap(), 213 0 214 ); 215 assert_eq!( 216 sqlx::query_scalar::<_, i64>("PRAGMA user_version") 217 .fetch_one(&mut raw) 218 .await 219 .unwrap(), 220 catalog 221 ); 222 raw.close().await.unwrap(); 223 let receipt = committed( 224 r.store 225 .issue_stock_consent( 226 r.binding.clone(), 227 r.minimum, 228 &r.capture(&r.binding, 0x32), 229 &r.proof, 230 ) 231 .await 232 .unwrap(), 233 ); 234 assert_eq!(receipt.checkpoint().revision().get(), 1); 235 r.store.close().await.unwrap(); 236 } 237 } 238 239 #[tokio::test] 240 async fn original_consent_replays_after_expiry_and_survives_physical_progress_and_reopen() { 241 let r = Rig::new().await; 242 let capture = r.capture(&r.binding, 0x31); 243 let receipt = committed( 244 r.store 245 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 246 .await 247 .unwrap(), 248 ); 249 assert_eq!( 250 receipt.control_operation_id(), 251 capture.control_operation_id() 252 ); 253 assert_eq!(receipt.transaction_id(), capture.transaction_id()); 254 assert_eq!(receipt.command_digest(), capture.command().digest()); 255 assert_eq!(receipt.checkpoint().revision().get(), 1); 256 let minimum = r.physical(0x41, receipt.checkpoint()).await; 257 assert_eq!(minimum.revision().get(), 2); 258 let replay = r.capture(&r.binding, 0x31); 259 assert_ne!( 260 replay.control_operation_id(), 261 capture.control_operation_id() 262 ); 263 r.clock.0.store(160, Ordering::SeqCst); 264 assert_eq!( 265 committed( 266 r.store 267 .issue_stock_consent(r.binding.clone(), minimum, &replay, &r.proof) 268 .await 269 .unwrap() 270 ), 271 receipt 272 ); 273 let fresh = r.capture(&r.binding, 0x32); 274 assert_eq!( 275 r.store 276 .issue_stock_consent(r.binding.clone(), minimum, &fresh, &r.proof) 277 .await, 278 Err(OperationError::DeadlineExceeded) 279 ); 280 assert_eq!( 281 r.store 282 .stock_consent( 283 r.binding.clone(), 284 minimum, 285 capture.command().context().operation_id(), 286 r.input.grant_id(), 287 &r.proof 288 ) 289 .await 290 .unwrap(), 291 Some(receipt.clone()) 292 ); 293 assert_eq!( 294 r.store 295 .inventory_operation( 296 r.binding.clone(), 297 minimum, 298 capture.control_operation_id(), 299 None, 300 r.proof 301 .with_secret(|v| AttachmentProof::from_protected_input(v)) 302 .unwrap() 303 ) 304 .await, 305 Err(OperationError::IdempotencyConflict) 306 ); 307 r.store.close().await.unwrap(); 308 let store = NativeWorkspace::open_seller_stock( 309 &r.path, 310 r.input.clone(), 311 r.fixture.crypto(), 312 r.clock.clone(), 313 ) 314 .await 315 .unwrap(); 316 let binding = store.authenticate(r.input.clone(), &r.proof).await.unwrap(); 317 assert_eq!( 318 store 319 .stock_consent( 320 binding, 321 minimum, 322 capture.command().context().operation_id(), 323 r.input.grant_id(), 324 &r.proof 325 ) 326 .await 327 .unwrap(), 328 Some(receipt) 329 ); 330 store.close().await.unwrap(); 331 } 332 333 #[tokio::test] 334 async fn physical_grant_cannot_issue_business_consent_but_can_read_its_own_issuance() { 335 let r = Rig::new().await; 336 let subject = StockGrantEnrollment::prepare( 337 &SellerAuthoritySelection::from_attachment(&r.input), 338 "physical-device".into(), 339 UnixSeconds::new(190).unwrap(), 340 StockGrantScope::full_inventory(), 341 ) 342 .unwrap(); 343 assert!(matches!( 344 r.store 345 .enroll_stock_grant(r.binding.clone(), r.minimum, &r.proof, &subject) 346 .await 347 .unwrap(), 348 StockGrantOutcome::Committed(_) 349 )); 350 let minimum = r 351 .store 352 .stock_authority(r.input.clone(), &r.proof) 353 .await 354 .unwrap() 355 .inventory_checkpoint() 356 .unwrap(); 357 let child = r 358 .store 359 .authenticate(subject.input().clone(), subject.proof()) 360 .await 361 .unwrap(); 362 let capture = r.capture(&child, 0x31); 363 assert_eq!( 364 r.store 365 .issue_stock_consent(child.clone(), minimum, &capture, subject.proof()) 366 .await, 367 Err(OperationError::Unauthorized) 368 ); 369 let admin = r 370 .store 371 .authenticate(r.input.clone(), &r.proof) 372 .await 373 .unwrap(); 374 let receipt = committed( 375 r.store 376 .issue_stock_consent(admin, minimum, &capture, &r.proof) 377 .await 378 .unwrap(), 379 ); 380 assert_eq!( 381 r.store 382 .stock_consent( 383 child, 384 receipt.checkpoint(), 385 capture.command().context().operation_id(), 386 subject.input().grant_id(), 387 subject.proof() 388 ) 389 .await 390 .unwrap(), 391 Some(receipt.clone()) 392 ); 393 assert_eq!( 394 r.store 395 .stock_consent( 396 r.binding.clone(), 397 receipt.checkpoint(), 398 OperationId::from_bytes([0x55; 32]), 399 r.input.grant_id(), 400 &r.proof 401 ) 402 .await 403 .unwrap(), 404 None 405 ); 406 r.store.close().await.unwrap(); 407 } 408 409 #[tokio::test] 410 async fn changed_natural_index_cannot_turn_retained_consent_into_absence() { 411 let r = Rig::new().await; 412 let capture = r.capture(&r.binding, 0x31); 413 let receipt = committed( 414 r.store 415 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 416 .await 417 .unwrap(), 418 ); 419 let minimum = r.physical(0x41, receipt.checkpoint()).await; 420 let mut raw = SqliteConnection::connect_with( 421 &sqlx::sqlite::SqliteConnectOptions::new() 422 .filename(r.path.join("stock_execution_v1.sqlite")), 423 ) 424 .await 425 .unwrap(); 426 sqlx::query("UPDATE stock_operations SET related_operation=? WHERE operation_id=?") 427 .bind([0x77_u8; 32].as_slice()) 428 .bind(receipt.control_operation_id().as_bytes().as_slice()) 429 .execute(&mut raw) 430 .await 431 .unwrap(); 432 assert_eq!( 433 r.store 434 .stock_consent( 435 r.binding.clone(), 436 minimum, 437 capture.command().context().operation_id(), 438 r.input.grant_id(), 439 &r.proof 440 ) 441 .await, 442 Err(OperationError::RecoveryRequired) 443 ); 444 assert_eq!( 445 r.store 446 .issue_stock_consent(r.binding.clone(), minimum, &capture, &r.proof) 447 .await, 448 Err(OperationError::RecoveryRequired) 449 ); 450 sqlx::query("UPDATE stock_operations SET related_operation=? WHERE operation_id=?") 451 .bind( 452 capture 453 .command() 454 .context() 455 .operation_id() 456 .as_bytes() 457 .as_slice(), 458 ) 459 .bind(receipt.control_operation_id().as_bytes().as_slice()) 460 .execute(&mut raw) 461 .await 462 .unwrap(); 463 assert_eq!( 464 r.store 465 .stock_consent( 466 r.binding.clone(), 467 minimum, 468 capture.command().context().operation_id(), 469 r.input.grant_id(), 470 &r.proof 471 ) 472 .await 473 .unwrap(), 474 Some(receipt) 475 ); 476 raw.close().await.unwrap(); 477 r.store.close().await.unwrap(); 478 } 479 480 #[tokio::test] 481 async fn every_issuance_write_window_rolls_back_without_advancing_the_root() { 482 for trigger in [ 483 "CREATE TRIGGER fault BEFORE INSERT ON stock_operations BEGIN SELECT RAISE(ABORT,'fixture'); END", 484 "CREATE TRIGGER fault BEFORE INSERT ON stock_operation_parts BEGIN SELECT RAISE(ABORT,'fixture'); END", 485 "CREATE TRIGGER fault BEFORE UPDATE ON stock_authority BEGIN SELECT RAISE(ABORT,'fixture'); END", 486 ] { 487 let r = Rig::new().await; 488 let capture = r.capture(&r.binding, 0x31); 489 let mut raw = SqliteConnection::connect_with( 490 &sqlx::sqlite::SqliteConnectOptions::new() 491 .filename(r.path.join("stock_execution_v1.sqlite")), 492 ) 493 .await 494 .unwrap(); 495 sqlx::raw_sql(trigger).execute(&mut raw).await.unwrap(); 496 assert_eq!( 497 r.store 498 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 499 .await, 500 Err(OperationError::StorageFailure) 501 ); 502 assert_eq!( 503 r.store 504 .stock_authority(r.input.clone(), &r.proof) 505 .await 506 .unwrap() 507 .inventory_checkpoint() 508 .unwrap(), 509 r.minimum 510 ); 511 let count:i64=sqlx::query_scalar("SELECT (SELECT count(*) FROM stock_operations)+(SELECT count(*) FROM stock_operation_parts)").fetch_one(&mut raw).await.unwrap(); 512 assert_eq!(count, 0); 513 sqlx::raw_sql("DROP TRIGGER fault") 514 .execute(&mut raw) 515 .await 516 .unwrap(); 517 assert_eq!( 518 committed( 519 r.store 520 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 521 .await 522 .unwrap() 523 ) 524 .transaction_id(), 525 capture.transaction_id() 526 ); 527 raw.close().await.unwrap(); 528 r.store.close().await.unwrap(); 529 } 530 } 531 532 #[tokio::test] 533 async fn failed_commit_keeps_the_original_anchor_and_fences_until_close_and_reopen() { 534 let r = Rig::new().await; 535 let capture = r.capture(&r.binding, 0x31); 536 let mut raw = SqliteConnection::connect_with( 537 &sqlx::sqlite::SqliteConnectOptions::new() 538 .filename(r.path.join("stock_execution_v1.sqlite")), 539 ) 540 .await 541 .unwrap(); 542 sqlx::raw_sql("CREATE TABLE deferred_fault(value INTEGER REFERENCES stock_authority(singleton) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER fault AFTER INSERT ON stock_operations BEGIN INSERT INTO deferred_fault VALUES(2); END").execute(&mut raw).await.unwrap(); 543 assert_eq!( 544 r.store 545 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 546 .await 547 .unwrap(), 548 StockConsentOutcome::Unknown { 549 control_operation: capture.control_operation_id(), 550 transaction: capture.transaction_id(), 551 command_operation: capture.command().context().operation_id(), 552 subject: r.input.grant_id() 553 } 554 ); 555 assert_eq!( 556 r.store 557 .stock_consent( 558 r.binding.clone(), 559 r.minimum, 560 capture.command().context().operation_id(), 561 r.input.grant_id(), 562 &r.proof 563 ) 564 .await, 565 Err(OperationError::RecoveryRequired) 566 ); 567 r.store.close().await.unwrap(); 568 sqlx::raw_sql("DROP TRIGGER fault; DROP TABLE deferred_fault") 569 .execute(&mut raw) 570 .await 571 .unwrap(); 572 raw.close().await.unwrap(); 573 let store = NativeWorkspace::open_seller_stock( 574 &r.path, 575 r.input.clone(), 576 r.fixture.crypto(), 577 r.clock.clone(), 578 ) 579 .await 580 .unwrap(); 581 assert_eq!( 582 store 583 .stock_consent( 584 r.binding.clone(), 585 r.minimum, 586 capture.command().context().operation_id(), 587 r.input.grant_id(), 588 &r.proof 589 ) 590 .await 591 .unwrap(), 592 None 593 ); 594 assert_eq!( 595 committed( 596 store 597 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 598 .await 599 .unwrap() 600 ) 601 .transaction_id(), 602 capture.transaction_id() 603 ); 604 store.close().await.unwrap(); 605 } 606 607 #[tokio::test] 608 async fn exact_resources_are_immutable_and_current_access_precedes_replay() { 609 let r = Rig::new().await; 610 let capture = r.capture(&r.binding, 0x31); 611 let receipt = committed( 612 r.store 613 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 614 .await 615 .unwrap(), 616 ); 617 let changed = StockConsentCapture::prepare( 618 SellerAuthoritySelection::from_attachment(&r.input), 619 r.input.grant_id(), 620 StockConsentMode::ExecuteAndRecover, 621 StockResources::pools(vec![PoolId::from_bytes([0x41; 32])]).unwrap(), 622 UnixSeconds::new(150).unwrap(), 623 r.command(&r.binding, 0x31), 624 ) 625 .unwrap(); 626 assert_eq!( 627 r.store 628 .issue_stock_consent(r.binding.clone(), receipt.checkpoint(), &changed, &r.proof) 629 .await, 630 Err(OperationError::IdempotencyConflict) 631 ); 632 let wrong = AttachmentProof::from_protected_input(&[0xA7; 32]).unwrap(); 633 assert_eq!( 634 r.store 635 .issue_stock_consent(r.binding.clone(), receipt.checkpoint(), &capture, &wrong) 636 .await, 637 Err(OperationError::Workspace(WorkspaceError::Unauthorized)) 638 ); 639 r.clock.0.store(99, Ordering::SeqCst); 640 assert!( 641 r.store 642 .issue_stock_consent(r.binding.clone(), receipt.checkpoint(), &capture, &r.proof) 643 .await 644 .is_err() 645 ); 646 r.clock.0.store(200, Ordering::SeqCst); 647 assert_eq!( 648 r.store 649 .stock_consent( 650 r.binding.clone(), 651 receipt.checkpoint(), 652 capture.command().context().operation_id(), 653 r.input.grant_id(), 654 &r.proof 655 ) 656 .await, 657 Err(OperationError::Workspace(WorkspaceError::GrantExpired)) 658 ); 659 r.store.close().await.unwrap(); 660 } 661 662 #[tokio::test] 663 async fn recovery_only_can_bind_an_expired_original_command_to_an_explicit_replacement() { 664 let r = Rig::new().await; 665 let replacement = StockGrantEnrollment::prepare( 666 &SellerAuthoritySelection::from_attachment(&r.input), 667 "replacement".into(), 668 UnixSeconds::new(190).unwrap(), 669 StockGrantScope::full_inventory(), 670 ) 671 .unwrap(); 672 assert!(matches!( 673 r.store 674 .enroll_stock_grant(r.binding.clone(), r.minimum, &r.proof, &replacement) 675 .await 676 .unwrap(), 677 StockGrantOutcome::Committed(_) 678 )); 679 let minimum = r 680 .store 681 .stock_authority(r.input.clone(), &r.proof) 682 .await 683 .unwrap() 684 .inventory_checkpoint() 685 .unwrap(); 686 let command = r.command(&r.binding, 0x31); 687 assert!( 688 StockConsentCapture::prepare( 689 SellerAuthoritySelection::from_attachment(&r.input), 690 replacement.input().grant_id(), 691 StockConsentMode::ExecuteAndRecover, 692 StockResources::all_pools(), 693 UnixSeconds::new(150).unwrap(), 694 r.command(&r.binding, 0x31) 695 ) 696 .is_err() 697 ); 698 let capture = StockConsentCapture::prepare( 699 SellerAuthoritySelection::from_attachment(&r.input), 700 replacement.input().grant_id(), 701 StockConsentMode::RecoverOnly, 702 StockResources::all_pools(), 703 UnixSeconds::new(180).unwrap(), 704 command, 705 ) 706 .unwrap(); 707 r.clock.0.store(160, Ordering::SeqCst); 708 let admin = r 709 .store 710 .authenticate(r.input.clone(), &r.proof) 711 .await 712 .unwrap(); 713 let receipt = committed( 714 r.store 715 .issue_stock_consent(admin, minimum, &capture, &r.proof) 716 .await 717 .unwrap(), 718 ); 719 assert_eq!(receipt.mode(), StockConsentMode::RecoverOnly); 720 assert_eq!(receipt.command_digest(), capture.command().digest()); 721 let subject = r 722 .store 723 .authenticate(replacement.input().clone(), replacement.proof()) 724 .await 725 .unwrap(); 726 assert_eq!( 727 r.store 728 .stock_consent( 729 subject, 730 receipt.checkpoint(), 731 capture.command().context().operation_id(), 732 replacement.input().grant_id(), 733 replacement.proof() 734 ) 735 .await 736 .unwrap(), 737 Some(receipt) 738 ); 739 r.store.close().await.unwrap(); 740 } 741 742 #[tokio::test] 743 async fn retained_catalog7_issues_original_consent_without_gaining_public_source_tables() { 744 use radroots_domain::listing::ListingCoordinate; 745 use radroots_storage::workspace::seller_stock::StockListingCheckpointRef; 746 let r = Rig::with_catalog(Some(7)).await; 747 let capture = r.capture(&r.binding, 0x31); 748 let receipt = committed( 749 r.store 750 .issue_stock_consent(r.binding.clone(), r.minimum, &capture, &r.proof) 751 .await 752 .unwrap(), 753 ); 754 assert!( 755 r.store 756 .stock_authority(r.input.clone(), &r.proof) 757 .await 758 .unwrap() 759 .listing_checkpoint() 760 .is_none() 761 ); 762 let public = StockListingCheckpointRef::from_host_metadata( 763 r.input.authority(), 764 Sequence::new(0).unwrap(), 765 None, 766 ) 767 .unwrap() 768 .with_optional_authorization(r.minimum.authorization()); 769 assert!(matches!( 770 r.store 771 .stock_listing_head( 772 r.binding.clone(), 773 public, 774 ListingCoordinate::new(r.input.participant(), "04".repeat(16).parse().unwrap()), 775 &r.proof 776 ) 777 .await, 778 Err(OperationError::UnsupportedOperation) 779 )); 780 let minimum = r.physical(0x41, receipt.checkpoint()).await; 781 r.store.close().await.unwrap(); 782 let store = NativeWorkspace::open_seller_stock( 783 &r.path, 784 r.input.clone(), 785 r.fixture.crypto(), 786 r.clock.clone(), 787 ) 788 .await 789 .unwrap(); 790 assert_eq!( 791 store 792 .stock_consent( 793 r.binding.clone(), 794 minimum, 795 capture.command().context().operation_id(), 796 r.input.grant_id(), 797 &r.proof 798 ) 799 .await 800 .unwrap(), 801 Some(receipt) 802 ); 803 store.close().await.unwrap(); 804 }