Skip to content

Add settlement state transition tests (issue #254) - #326

Open
d3vobed wants to merge 1 commit into
zkpayroll:devfrom
d3vobed:feat/254-settlement-state-transition-tests
Open

Add settlement state transition tests (issue #254)#326
d3vobed wants to merge 1 commit into
zkpayroll:devfrom
d3vobed:feat/254-settlement-state-transition-tests

Conversation

@d3vobed

@d3vobed d3vobed commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a dedicated tests/settlement crate that pins down the settlement state machine defined by PayrollRunState / is_allowed_payroll_state_transition_internal in contracts/payroll/src/lib.rs.

  • Full transition-matrix oracle: a 10×10 grid test proving every allowed transition matches the contract's is_allowed_payroll_state_transition_internal rules, and every disallowed one is rejected predictably (no silent drift from the documented matrix).
  • Terminal / retryable semantics: is_payroll_state_terminal and is_payroll_state_retryable are verified — only Failed is retryable; Completed/Cancelled are terminal and immutable.
  • Authorization: transition_payroll_run_state is admin-only; a non-admin call panics with Unauthorized.
  • End-to-end lifecycle: prepared run starts in pending (Submitted) and settling reaches settled (Completed).

Also adds docs/settlement-state-machine.md and fixtures/state-machine/settlement-state-machine.json documenting the settlement phase → concrete state mapping (pendingSubmitted, executingConfirming, settledCompleted, failedFailed, cancelledCancelled).

This supersedes the previously opened PR #324 (which targeted main; the repo requires PRs against dev).

Note on CI

The upstream workspace currently fails cargo clippy --workspace --all-targets -D warnings due to unrelated pre-existing breakage (audit_module is missing the initialize method required by tests/migrations). That is out of scope for this issue; this PR keeps the settlement_state_tests crate clippy-clean and all 14 of its tests passing.

Closes #254

…oll#254)

Add a tests/settlement crate that exercises the canonical PayrollRunState
machine (is_allowed_payroll_state_transition_internal) across the full
10x10 transition matrix, plus terminal/retryable semantics and the
admin-only transition_payroll_run_state authorization guard.

- docs/state-machine.md documents the settlement phase -> state mapping
  (pending->Submitted, executing->Confirming, settled->Completed,
  failed->Failed, cancelled->Cancelled).
- fixtures/state-machine/settlement-state-machine.json captures the same
  matrix for external tooling.

Minimal build fixes to contracts/payroll so the contract compiles (the
upstream main was broken at HEAD): add the missing symbol_short import,
add the DataKey::AllowedAsset variant referenced by set/is_asset_allowed,
remove a stale duplicate cancel_payroll_run, and drop an unused helper.

Note: the upstream workspace currently fails cargo clippy --workspace -D
warnings due to unrelated breakage (audit_module missing initialize, used
by tests/migrations). This PR is scoped to the settlement tests; that
pre-existing breakage is out of scope.

Closes zkpayroll#254
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

@d3vobed this PR currently has merge conflicts.

Please resolve the conflicts before it can be merged automatically.

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.

Add contract settlement state transition matrix tests

2 participants