Description
A protocol-wide solvency invariant is that the total of all active investments held in escrow must never exceed the sum of accepted invoice amounts denominated per currency. This issue introduces a stateful test that asserts this invariant after every public state transition driven by a randomized scenario, and exposes a runtime validate_solvency_invariant(env) admin helper that can be wired into a periodic off-chain check.
Requirements and context
- Secure: helper is admin-gated and read-only.
- Tested: invariant checked after every transition in the model.
- Documented:
docs/solvency-invariant.md.
- Reference:
src/lib.rs, src/investment.rs, src/payments.rs.
Suggested execution
git checkout -b feature/solvency-invariant
- Add
src/invariants.rs::validate_solvency_invariant.
- Add
src/test_solvency_invariant.rs driving randomized lifecycles.
- Docs:
docs/solvency-invariant.md.
- Rust doc comments stating the invariant in plain language.
- Validate that pause, default, and dispute paths preserve the invariant.
Test and commit
Run cargo test test_solvency_invariant -- --nocapture. Cover edge cases: default refunds, dispute resolutions, partial settlements. Include security note classifying any violation as a P0.
Example commit message
feat(invariants): add protocol-wide solvency invariant and stateful enforcement tests
Guidelines
- Minimum 95% test coverage
- Clear documentation in
docs/solvency-invariant.md
- Timeframe: 96 hours
Description
A protocol-wide solvency invariant is that the total of all active investments held in escrow must never exceed the sum of accepted invoice amounts denominated per currency. This issue introduces a stateful test that asserts this invariant after every public state transition driven by a randomized scenario, and exposes a runtime
validate_solvency_invariant(env)admin helper that can be wired into a periodic off-chain check.Requirements and context
docs/solvency-invariant.md.src/lib.rs,src/investment.rs,src/payments.rs.Suggested execution
git checkout -b feature/solvency-invariantsrc/invariants.rs::validate_solvency_invariant.src/test_solvency_invariant.rsdriving randomized lifecycles.docs/solvency-invariant.md.Test and commit
Run
cargo test test_solvency_invariant -- --nocapture. Cover edge cases: default refunds, dispute resolutions, partial settlements. Include security note classifying any violation as a P0.Example commit message
feat(invariants): add protocol-wide solvency invariant and stateful enforcement testsGuidelines
docs/solvency-invariant.md