Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src-tauri/crates/bridge-tally-write/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ impl LedgerMutation {
after: LedgerState,
source_lineage: SourceLineage,
) -> Result<Self, QualificationError> {
if after.parent.is_none() {
return Err(QualificationError::CreateParentRequired);
}
Self::new(
LedgerOperation::Create,
remote_id.into(),
Expand Down Expand Up @@ -772,6 +775,8 @@ pub enum QualificationError {
MissingIdempotencyReservation,
#[error("controlled ledger alter must change at least one verified field")]
NoOpMutation,
#[error("controlled ledger create requires an explicit parent")]
CreateParentRequired,
#[error("clearing controlled ledger field is not yet qualified: {0}")]
UnsupportedFieldClear(&'static str),
#[error("preflight readback did not exactly match the declared before state")]
Expand Down Expand Up @@ -1194,7 +1199,13 @@ mod tests {
let company = SyntheticCompany::new("BRIDGE & BOOK", "company-guid").unwrap();
let mutation = LedgerMutation::create(
"remote-\"<&",
LedgerState::new("LEDGER <&", None, None, Some("0".to_owned())).unwrap(),
LedgerState::new(
"LEDGER <&",
Some("PARENT <&".to_owned()),
None,
Some("0".to_owned()),
)
.unwrap(),
SourceLineage::new("synthetic", "record", "v1").unwrap(),
)
.unwrap();
Expand All @@ -1203,6 +1214,7 @@ mod tests {
assert!(xml.contains("remote-&quot;&lt;&amp;"));
assert!(xml
.contains("NAME=\"LEDGER &lt;&amp;\" ACTION=\"Create\"><NAME>LEDGER &lt;&amp;</NAME>"));
assert!(xml.contains("<PARENT>PARENT &lt;&amp;</PARENT>"));
}

#[test]
Expand Down
14 changes: 13 additions & 1 deletion src-tauri/crates/bridge-tally-write/tests/qualification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,13 @@ fn alter_approval_binds_the_exact_declared_before_state() {
fn prepared_import_is_deterministic_and_bytes_are_not_publicly_exposed() {
let mutation = create(
"bridge-&-identity",
LedgerState::new("BRIDGE <SYNTHETIC>", None, None, Some("0".to_owned())).unwrap(),
LedgerState::new(
"BRIDGE <SYNTHETIC>",
Some("BRIDGE SYNTHETIC GROUP".to_owned()),
None,
Some("0".to_owned()),
)
.unwrap(),
1,
);
let mut first_registry = IdempotencyRegistry::default();
Expand Down Expand Up @@ -448,6 +454,12 @@ fn invalid_decimal_gstin_limits_duplicates_noops_and_replays_are_rejected() {
LedgerState::new("BRIDGE", None, Some("not-a-gstin".to_owned()), None).unwrap_err(),
QualificationError::InvalidField("party_gstin")
);
let parentless = LedgerState::new("BRIDGE", None, None, None)
.expect("a parentless state remains usable as an alter snapshot");
assert_eq!(
LedgerMutation::create(REMOTE_ID, parentless, lineage(1)).unwrap_err(),
QualificationError::CreateParentRequired
);
let unchanged = state("BRIDGE", "0");
assert_eq!(
LedgerMutation::alter(REMOTE_ID, unchanged.clone(), unchanged.clone(), lineage(1),)
Expand Down