Skip to content

Latest commit

 

History

History
236 lines (195 loc) · 11.3 KB

CONTRIBUTING.md

File metadata and controls

236 lines (195 loc) · 11.3 KB

Contributing to docforum-escrow

A Rust/Soroban escrow contract + a thin TypeScript SDK. This repo is deliberately generic — no healthcare domain logic, no dependency on the other two repos in the DocForum org. This guide is for humans picking up a scoped issue — if you're an AI coding agent, read `AGENTS.md' instead.

1. Set up locally

Requires a Rust toolchain with the wasm32v1-none target.

git clone https://github.com/DocForum/docforum-escrow.git
cd docforum-escrow/contracts/escrow
cargo test

# Build the deployable contract
cargo build --target wasm32v1-none --release
# → target/wasm32v1-none/release/docforum_escrow.wasm

The stellar CLI is needed to deploy to testnet yourself (see docs/testnet-deployments.md for the existing deployment) and to regenerate the SDK's generated bindings (scripts/check-generated-bindings.sh). It is not required just to build and test the contract; pin the version in scripts/stellar-cli-version when you do need it.

The TypeScript SDK lives in sdk/. Install its dependencies and run its checks with:

cd sdk
npm ci
npm run typecheck
npm run build
npm run test:offline   # no network: event fixtures + quorum input validation
npm test               # also runs the live-testnet suite — see below

npm test includes tests/testnet-integration.test.ts, which funds accounts through Friendbot and talks to the live testnet contract. CI deliberately runs only offline checks (test:offline, test:runtime, browser smoke) for the SDK; run npm test locally when your change touches network calls, and expect it to need a testnet deployment that actually has the methods you're testing.

The SDK is published to npm as @docforum/escrow-sdk via an automated, provenance-signed release workflow — see Releasing the SDK below. The GitHub Release tarball is still attached for existing consumers.

An HTML API reference is generated from the SDK's doc comments with npm run docs in sdk/ (TypeDoc, config in sdk/typedoc.json). It also acts as a missing-doc lint: every exported symbol must have a doc comment, or the command fails — so document new exports as you add them. CI builds the reference on every PR and publishes it to GitHub Pages from main (.github/workflows/docs.yml); enabling Pages is a one-time maintainer step, documented in that workflow. Runnable examples live in sdk/examples/ (from sdk/: npm run build && node examples/<flow>.ts) and run against testnet with runtime-generated, Friendbot-funded keys — never a committed secret; CI type-checks them (npm run typecheck:examples) but does not run them.

2. Find something to work on

Open issues are scoped, real, and tagged with a complexity/point value (Trivial/100, Medium/150, High/200) in the issue body — see the issue list. Comment on an issue to claim it before starting, and check it's still open.

ROADMAP.md shows the bigger picture: E1–E3 are done (E2/E4 verified live on testnet), E4's independent security review is still open and blocking for any mainnet use, and E5/E7 are the active contract-feature and verification/release-engineering tracks.

3. Before you open a PR

  • Tests are required in the same PR as the logic, not a follow-up — see AGENTS.md hard rule 2. release/refund in particular need tests covering unauthorized-caller and double-release/refund attempts, not just the happy path — this is a funds-moving contract.
  • If your change starts, completes, or blocks a roadmap-tracked item, tick or update that item's line in ROADMAP.md and add a changelog entry as a new file in changelog.d/, in the same PR. Don't append to the end of ROADMAP.md; that is what made every PR conflict. See changelog.d/README.md.
  • Don't add new lines to ROADMAP.md, ARCHITECTURE_ESSENTIALS.md, README.md or docs/threat-model.md. Put new items, rows, paragraphs and sections in a fragment under docs.d/ that names the doc and the heading (or line) they go under; a maintainer folds them in. Editing existing lines in place is fine. CI enforces this. See docs.d/README.md.
  • If you change the contract (contracts/escrow/src/), add a fragment under contract-changes.d/ with the bump level and a one-line summary. Don't edit CONTRACT_VERSION: a maintainer bumps it once per batch. New Error variants use a provisional code (your issue number × 100 + n); never renumber or remove an existing one. CI checks all three. See contract-changes.d/README.md.
  • Changes to escrow lifecycle semantics must also update the TLA+ specification under spec/ and rerun TLC. That includes changes to settlement auth, status transitions, timeouts, payee acceptance, release/refund rules, or quorum behavior.
  • Keep doc edits to your own lines: new lines go in docs.d/, and don't rewrite other people's paragraphs. See AGENTS.md → "Shared docs".
  • Run cargo test and cargo build --target wasm32v1-none --release locally — this is exactly what CI checks.
  • cargo test also rewrites contracts/escrow/test_snapshots/. Review that diff (it shows events, auth entries and storage writes) and commit any intentional change with your PR — CI fails if the committed snapshots no longer match a test run. See Test snapshots below.
  • If you changed the contract's public surface, regenerate the SDK bindings and run ./scripts/check-generated-bindings.sh. See Generated SDK bindings.
  • For SDK changes, run npm run typecheck && npm run build in sdk/, plus npm run test:integration when the change touches network calls.
  • Any change to the SDK's public surface is a contract change and needs tests and a changeset entry (see Releasing the SDK). Strict semver applies to the SDK.
  • If your change touches a file listed as in scope in docs/audit/README.md, say so in the PR so it can get a delta review instead of silently changing the reviewed surface.

Test snapshots

The Soroban test environment writes one snapshot per test to contracts/escrow/test_snapshots/<test-name>.<n>.json when the Env is dropped, and those files are committed (issue #120). They make "this PR changed which events are emitted" or "the storage layout moved" a visible diff instead of something a reviewer has to infer from the code.

  • Update them intentionally: run cargo test, inspect git diff contracts/escrow/test_snapshots/, and commit the change with an explanation in the PR. Never hand-edit a snapshot; regenerate by running the test.
  • Never delete a snapshot to make CI pass. If a test stops producing a snapshot, that usually means it no longer touches storage/events — check why.
  • Event capture caveat: the SDK clears the event buffer at the start of every top-level contract invocation, so a snapshot only contains the events of the test's last call. A test that ends with a read (get_status, a token balance call, ...) therefore records no events. tests/top_up.rs's top_up_emits_an_event deliberately ends on the emitting call so the event path stays visible in a diff.
  • Snapshots must be deterministic: fresh keypairs come from the SDK's seeded Address::generate, so a second cargo test must produce a byte-identical snapshot. CI's snapshot step catches both drift and nondeterminism.

Generated SDK bindings

sdk/src/generated/contract-client.ts is machine-generated from the compiled WASM and must never be hand-edited (issue #121). After any change to the contract's public functions, types or doc comments (contracts/escrow/src/):

# Uses the Stellar CLI version pinned in scripts/stellar-cli-version.
./scripts/check-generated-bindings.sh   # prints the regeneration command on drift

The sdk-bindings CI job rewrites nothing: it fails and tells you to regenerate. Full steps live in sdk/src/generated/README.md. A regenerated binding that changes the SDK's public surface is also a semver bump (hard rule 3) and needs a changeset.

4. Opening the PR

  • Branch off main.
  • Reference the issue you're closing (Closes #N).
  • State what changed, why, and which ROADMAP.md Item it maps to.
  • CI (cargo test + wasm release build, plus SDK typecheck/build/test) must pass before merge — it runs automatically on your PR.

Releasing the SDK

The SDK is released by pushing an sdk-v* tag (e.g. sdk-v0.5.0). The release workflow (.github/workflows/release-sdk.yml) then

  1. installs dependencies and runs typecheck + build + test for the SDK,
  2. refuses to publish if the tag version does not match sdk/package.json,
  3. publishes to npm with provenance via npm trusted publishing (OIDC — no long-lived token in secrets), and
  4. attaches the npm pack tarball to the GitHub Release for existing consumers.

Version bumps and changelogs are managed with changesets. Add a changeset file with every SDK change:

npx changeset add

Commit the generated .changeset/*.md file with your PR. Release managers run npx changeset version to bump sdk/package.json and update sdk/CHANGELOG.md, then tag the resulting commit.

One-time human setup (npm org)

Before the first automated release, a maintainer must do the following once:

  1. Create (or join) the docforum npm org and ensure the @docforum scope is available.
  2. Configure npm trusted publishing for the @docforum/escrow-sdk package, pointing at this repository and the release workflow file. Trusted publishing uses GitHub Actions OIDC (id-token: write) and requires no long-lived npm token.
  3. If trusted publishing is not yet available for the org, fall back to a granular automation token stored as the NPM_TOKEN repository secret (bypass 2fa) and remove it once trusted publishing is enabled.
  4. Enable branch protection so only maintainers can push sdk-v* tags.

The release process itself is documented in docs/adr/0005 (npm publishing), which supersedes ADR 0003 (tarball-only releases). Note: that ADR file is referenced by ROADMAP.md Phase E6 but is not present in this tree.

Security reports and the audit package

docs/audit/ holds what an independent reviewer needs: the reviewed commit, the files in and out of scope, and reproducible test and build results. SECURITY.md is the reporting path; the threat model is docs/threat-model.md.

What this means for contributors:

  • Report privately. A suspected vulnerability goes through SECURITY.md, never a public issue or PR. Do not describe it in docs/audit/, in a test name, or in a commit message; reference the private advisory ID instead.
  • Respect the reviewed scope. docs/audit/README.md names the commit under review and the in-scope files. A change to one of those files after the freeze needs a delta note in docs/audit/ (a new delta-<n>.md), not an edit to the frozen documents.
  • Keep the threat model current. If you change contract behaviour that the threat model covers, update docs/threat-model.md in the same PR. Planned-but-unimplemented features belong in its "planned" section, marked as such — do not describe them as current behaviour.

Found a bug instead?

Use the bug report template, not a comment on an unrelated issue — keeps scope and Wave points honest.