This document describes contract event ingestion, deduplication, and persistence semantics implemented for the backend test-focused pipeline.
The current implementation is intentionally minimal and reviewable.
- Provides an in-process event handler for HTTP-ingested contract events.
- Uses deterministic dedupe identity to make replay behavior explicit.
- Uses repository abstraction with an in-memory implementation.
- Prioritizes deterministic tests and clear behavior contracts over production infrastructure.
Accepted payload fields:
contractId(string, non-empty)eventId(string, non-empty)sequence(non-negative integer)timestamp(parseable ISO string)type(one ofCONTRACT_CREATED,CONTRACT_FUNDED,CONTRACT_COMPLETED,CONTRACT_CANCELLED)payload(JSON object)
- Validate payload shape and required fields.
- Normalize identifiers (trim string fields) and keep canonical type values.
- Build dedupe key as:
contractId:eventId:sequence
- Check repository for prior processing of the same key.
- Persist event only when key is new.
accepted: event is valid and persisted.duplicate: event identity was already processed; request is idempotent.invalid: payload violated schema or semantic constraints.error: unexpected runtime failure in processor/repository interaction.
- Replay events
- Threat: repeated event submissions attempt duplicate state transitions.
- Mitigation: deterministic dedupe key and duplicate no-op response.
- Malformed payload injection
- Threat: invalid or ambiguous payloads cause undefined behavior.
- Mitigation: strict ingress validation and structured invalid response.
- Oversized request bodies
- Threat: memory pressure from very large payloads.
- Mitigation: JSON body parser size limit.
- Storage resource exhaustion
- Threat: unbounded in-memory growth under sustained traffic.
- Current state: accepted non-goal for this iteration.
- Future hardening: bounded retention, backpressure, durable storage, and operational quotas.
- Authenticity of upstream events
- Threat: forged events from untrusted producers.
- Current state: not implemented in this scope.
- Future hardening: signature verification, authenticated sources, and chain finality checks.
- Confirm tests cover accepted, duplicate, invalid, and failure paths.
- Confirm dedupe identity matches documented key composition.
- Confirm repository abstraction is used by processor and app wiring.
- Confirm coverage threshold enforcement is active in Jest configuration.
- Confirm docs match route behavior and status codes.