Skip to content

test(audit): expand buzz-audit unit test coverage (12 → 32) - #3466

Closed
jewoos2921 wants to merge 1 commit into
block:mainfrom
jewoos2921:test/buzz-audit-coverage
Closed

test(audit): expand buzz-audit unit test coverage (12 → 32)#3466
jewoos2921 wants to merge 1 commit into
block:mainfrom
jewoos2921:test/buzz-audit-coverage

Conversation

@jewoos2921

Copy link
Copy Markdown

Summary

The audit crate's core chain logic had thin unit test coverage — most existing service.rs tests require Postgres and are #[ignore]'d, leaving the hash-chain integrity logic under-tested in just test-unit.

This PR adds 20 new DB-free unit tests, bringing runnable coverage from 12 → 32 tests.

What's covered

hash.rs (+12 tests)

canonical_json depth:

  • Nested object key sorting (recursion into sub-objects, not just top level)
  • Array order preservation (arrays are sequences, not sets)
  • Empty values ({}, [], null, scalars)
  • Special-character escaping with round-trip verification

compute_hash edge cases:

  • object_id presence tag (None vs Some("") — the same invariant actor_pubkey has)
  • detail None-vs-empty-object distinction
  • detail key-order invariance (canonical JSON working as designed)
  • detail value sensitivity
  • created_at field sensitivity (1µs shift changes hash)
  • Sub-microsecond jitter invariance (500ns truncates away — the whole point of to_storage_precision)
  • GENESIS_HASH is all-zero sentinel
  • prev_hash = None hashes identically to prev_hash = Some(GENESIS_HASH)

action.rs (+4 tests)

  • serde JSON roundtrip for all variants
  • serde snake_case agrees with as_str() (catches variant drift)
  • as_str() values are unique (no ambiguous DB strings)
  • as_str()/FromStr are exact inverses

service.rs (+3 tests)

  • log_timestamp is idempotent under re-truncation (write/read preimage safety)
  • Advisory lock key format is namespaced + community-scoped
  • Different communities produce different lock keys (per-community serialization invariant)

Verification

  • cargo test -p buzz-audit --lib32 passed, 6 ignored (Postgres), 0 failed
  • cargo clippy -p buzz-audit -- -D warnings — clean
  • cargo fmt --check -p buzz-audit — clean

The audit crate's core chain logic (hash computation, canonical JSON,
action serialization, timestamp precision) had thin unit test coverage —
most existing service tests require Postgres and are #[ignore]'d.

Add 20 new DB-free unit tests covering:

hash.rs (12 new):
- canonical_json: nested key sorting recursion, array order preservation,
  empty/scalar values, special-character escaping with round-trip
- compute_hash: object_id presence-tag, detail None-vs-empty, detail
  key-order invariance, detail value sensitivity, created_at sensitivity,
  sub-microsecond jitter invariance, genesis hash sentinel properties

action.rs (4 new):
- serde JSON roundtrip for all variants
- serde snake_case agrees with as_str()
- as_str values are unique (no ambiguous DB strings)
- as_str/FromStr are exact inverses

service.rs (3 new):
- log_timestamp is idempotent under re-truncation
- advisory lock key format is namespaced + community-scoped
- different communities produce different lock keys

All 32 runnable tests pass; clippy clean; fmt clean.
@jewoos2921
jewoos2921 requested a review from a team as a code owner July 29, 2026 04:52
@jewoos2921 jewoos2921 closed this by deleting the head repository Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant