Skip to content

Build Trustless Work End-to-End Test Suite #68

Description

@Kalchaqui

Issue: Build Trustless Work End-to-End Test Suite

Depends on: Existing webhook sync (src/webhooks/webhooks.service.ts) and escrow write helper (src/internal-trustless/escrow-write.helper.ts)

Task Description

Develop an end-to-end test suite covering the integration between Thalos and Trustless Work (TW), validating that Agreements stay synchronized across their lifecycle under both success and failure scenarios. This must build on the existing Jest + supertest setup, not introduce a new framework.

Background / Current State

Verified against main: synchronization is driven by inbound webhooks (POST handled in webhooks.service.ts), which map TW events to agreement status changes:

  • escrow.funded → funded
  • escrow.released → completed
  • escrow.disputed / dispute.created → disputed
  • contract.completed → completed
  • contract.cancelled → cancelled
  • milestone updates → milestone sync

Resilience today is a per-request withRetry() helper, not a persistent retry queue. Tests must target this actual mechanism.

Deliverable

End-to-end *.spec.ts tests covering the Trustless Work integration, runnable via the existing jest / test:integration scripts.

Requirements

Validate:

  • Agreement creation → escrow write via escrow-write.helper.ts (deployer/single-release, deployer/multi-release).
  • Contract linking (PATCH /agreements/:id/link-contract) and by-contract lookup.
  • Status synchronization via webhook events (escrow.funded, escrow.released, escrow.disputed, contract.completed, contract.cancelled).
  • Milestone synchronization (agreement.milestone_updated / escrow.milestone_updated).
  • HMAC signature verification in verifySignature() (valid + invalid signatures).
  • withRetry() behavior on transient failures (succeeds after N attempts; surfaces error after exhaustion).
  • Idempotency (a duplicate webhook event does not double-apply a status change).
  • Activity logging entries produced by synced transitions.

Validation System

  • Each webhook event drives the final agreement to the expected status.
  • Invalid HMAC signatures are rejected; valid ones pass.
  • A transient-failure simulation recovers via withRetry() and a persistent failure surfaces the error.
  • Replaying the same event twice leaves the status unchanged after the first apply.

Technical Requirements

  • Mock external TW calls (relayToTrustless) and Supabase — do not hit live services.
  • Simulate network/provider failures to exercise withRetry().
  • Validate synchronization integrity (final agreement status matches the event).
  • Executable in CI via pnpm test (respect testRegex: .*\.spec\.ts$).

Additional Notes

The original issue referenced a "retry queue" — there is no persistent queue in main, only in-request retry. Scope tests to the real webhook + withRetry design; if a durable queue is later added, extend the suite then.

Testing (required)

  • E2E spec: full lifecycle create → link-contract → funded → released/completed passes.
  • Signature spec: valid vs invalid HMAC handled correctly.
  • Retry spec: recovery after N transient failures and error after exhaustion.
  • Idempotency spec: duplicate webhook event does not double-apply.

Proof of Completion (required)

  • Link the merged PR.
  • Paste the passing pnpm test output showing the TW integration specs.
  • Attach a short summary/log mapping each webhook event to its resulting status assertion.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions