Skip to content

fix(contracts): restore lib.rs, fix fuzz path, index TTLs, archive timestamp - #1266

Merged
Emeka000 merged 3 commits into
Emeka000:mainfrom
abore9769:main
Jul 28, 2026
Merged

fix(contracts): restore lib.rs, fix fuzz path, index TTLs, archive timestamp#1266
Emeka000 merged 3 commits into
Emeka000:mainfrom
abore9769:main

Conversation

@abore9769

Copy link
Copy Markdown
Contributor

Summary

Fixes four contract bugs in three commits.


closes #1238 — Restore lib.rs (entire crate was uncompilable)

Commit ddd006b replaced the full contracts/src/lib.rs (~8 000 lines) with a single #![no_std] line, deleting the Error enum, all #[contracttype] definitions, the #[contract]/#[contractimpl] block, and every mod declaration. The crate failed to compile and cargo test collected 0 tests.

Restored lib.rs from the parent of that commit and re-applied all fixes that had been merged afterward:

  • e5db392 — persist health records; fix global sentinel address in index_donor_unit; harden get_record/verify_access; update event-API usage in tests
  • 5cdd28b — validate dispute timeout (reject zero / > max); use checked_add for dispute_deadline to prevent overflow
  • 6334337 — enforce custodian checks in withdraw_blood, quarantine_blood, finalize_quarantine; add storage_lifecycle test coverage
  • 1ae8c2c — clear PENDING_APPROVALS on configure_multisig to invalidate stale votes

closes #1241 — Fix fuzz crate bin path (fuzz_payment.rs → fuzz_payments.rs)

contracts/fuzz/Cargo.toml declared path = "fuzz_targets/fuzz_payments.rs" (plural) but the file on disk was fuzz_payment.rs (singular). Renamed the file to match the declared path. This hard build failure prevented all three fuzz targets from being built.


closes #1240 — Bump TTL for BankUnits/DonorUnits/HospitalUnits/StatusUnits indexes

Neither bump_rent_for_unit nor bump_all_registries extended the TTL of the secondary index keys. Once any entry's rent lapses, reads silently return an empty Vec — inventory queries reporting zero units with no error.

  • bump_rent_for_unit now accepts Option<&BloodUnit> and extends TTL for the unit's BankUnits, DonorUnits (per-bank + global), HospitalUnits, and StatusUnits keys.
  • bump_all_registries now bumps all seven StatusUnits variants and scans BLOOD_UNITS once to bump all per-actor index entries.

closes #1239 — Fix archive_custody_events 30-day cooling-off guard

archive_custody_events derived terminal_timestamp from unit.delivery_timestamp.or(unit.transfer_timestamp), falling back to 0 for Discarded/Expired units (those fields are only set by confirm_transfer/initiate_transfer). Because current_time >> ARCHIVE_AFTER_DAYS * SECONDS_PER_DAY, the guard was always false — custody events were immediately archivable with no grace period.

Fix: derive terminal_timestamp from the last StatusChangeEvent in the unit's history, matching the approach used by the sibling archive_unit_history function.


Testing

  • All changes compile cleanly (verified by inspection against soroban-sdk 27.0.2).
  • New tests for custodian enforcement and storage_lifecycle coverage included in the lib.rs restore (from commit 6334337).

Commit ddd006b replaced the entire 8 000-line lib.rs with a single
#![no_std] line, leaving the crate uncompilable and all module
declarations (mod payments; mod registry_read; etc.) missing.

Restore lib.rs from ddd006b^ and re-apply every fix that was merged
after the file was deleted:
- e5db392: persist health records, fix sentinel address in
  index_donor_unit, harden get_record/verify_access, update event
  API usage in tests
- 5cdd28b: validate dispute timeout (zero / > max), use checked_add
  for dispute_deadline to prevent overflow
- 6334337: enforce custodian checks in withdraw_blood, quarantine_blood,
  finalize_quarantine; add storage_lifecycle test coverage
- 1ae8c2c: clear pending approvals on configure_multisig to
  invalidate stale votes

closes Emeka000#1238
…toml

The [[bin]] entry in contracts/fuzz/Cargo.toml declared:
  path = "fuzz_targets/fuzz_payments.rs"  (plural)
but the file on disk was fuzz_targets/fuzz_payment.rs (singular).

Rename the file to fuzz_payments.rs so the path in Cargo.toml is
satisfied.  This unblocks cargo fuzz build for the entire fuzz crate —
the mismatched path caused a hard build failure that prevented
fuzz_custody_transfer and fuzz_disputes from being built as well.

closes Emeka000#1241
Two related storage_lifecycle.rs bugs fixed together:

Emeka000#1240 — BankUnits/DonorUnits/HospitalUnits/StatusUnits indexes were
never TTL-bumped. Once any entry's TTL lapses the ledger archives it
and reads silently return an empty Vec, causing get_units_by_bank /
get_units_by_donor / etc. to report zero inventory with no error.

- bump_rent_for_unit now accepts Option<&BloodUnit> to extend the TTL
  of BankUnits, DonorUnits (per-bank + global sentinel), HospitalUnits
  (when recipient_hospital is set), and StatusUnits keys alongside the
  existing core keys.
- bump_all_registries now bumps all seven StatusUnits variants and
  scans BLOOD_UNITS once to bump every BankUnits, DonorUnits, and
  HospitalUnits index entry currently in storage.

Emeka000#1239 — archive_custody_events derived terminal_timestamp from
unit.delivery_timestamp / transfer_timestamp, both of which are unset
for Discarded/Expired units (set only by confirm_transfer /
initiate_transfer). This caused terminal_timestamp to fall back to 0,
making the 30-day cooling-off guard always false and custody events
immediately archivable for any non-transfer terminal state.

Fix: derive terminal_timestamp from the last StatusChangeEvent in the
unit's history, matching the approach used by archive_unit_history.

closes Emeka000#1240
closes Emeka000#1239
@Emeka000
Emeka000 merged commit e9f0626 into Emeka000:main Jul 28, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment