Skip to content

feat(contracts): pausable, batch ops, fuzz tests, upgrade harness#741

Open
Simcrypt wants to merge 1 commit into
BrainTease:mainfrom
Simcrypt:feat/contracts-662-663-664-665
Open

feat(contracts): pausable, batch ops, fuzz tests, upgrade harness#741
Simcrypt wants to merge 1 commit into
BrainTease:mainfrom
Simcrypt:feat/contracts-662-663-664-665

Conversation

@Simcrypt

@Simcrypt Simcrypt commented Jun 27, 2026

Copy link
Copy Markdown

Summary

Resolves #662, #663, #664, #665.


#663 – Pausable / Emergency-Stop

  • pause / unpause / is_paused added to MarketContract and RegistryContract
  • All mutating functions guarded with require_not_paused
  • paused / unpaused events emitted; only admin can toggle
  • Tests: pause blocks all mutations, non-admin rejected, operations resume after unpause

#662 – Batch Operations & Gas Optimisation

  • Market: batch_settle_escrows + batch_refund_escrows — single auth check, sequential storage writes reduce round-trips vs N individual calls
  • Registry: batch_register_users (one list read + one write vs N), batch_set_verification_levels
  • All batch ops blocked when paused; auth enforced identically to singular ops
  • Tests cover batch happy-path, admin-only enforcement, and paused-state rejection

#664 – Property-Based & Fuzz Testing

  • contracts/market/src/fuzz_tests.rs: proptest invariants — fee + net = amount, fee ≤ amount, net ≥ 0, overflow safety, batch fee summation
  • contracts/registry/src/fuzz_tests.rs: proptest invariants — level filter monotonicity, pagination bounds, skill expiry logic, deduplication
  • proptest = "1.4" added to market and registry Cargo.toml dev-dependencies
  • Wired via #[cfg(test)] mod fuzz_tests in each contract's lib.rs

#665 – Contract Upgrade Test Harness

  • contracts/shared/src/upgrade_tests.rs: 12 tests covering:
    • schedule stores pending upgrade
    • non-admin schedule/cancel/execute rejected
    • timelock enforced (execute before delay panics)
    • cancel clears pending
    • state preserved after schedule and after cancel
    • storage-layout migration compatibility scenario
    • upgrade history initially empty
    • direct upgrade() by non-admin rejected
  • docs/smart-contract-upgrade-guide.md updated with harness section, test table, flow diagram, and run instructions

Files changed

File Change
contracts/market/src/lib.rs pause mechanism + batch ops + tests
contracts/market/src/fuzz_tests.rs new: property tests
contracts/market/Cargo.toml add proptest dev-dep
contracts/registry/src/lib.rs pause mechanism + batch ops
contracts/registry/src/test.rs pause + batch tests
contracts/registry/src/fuzz_tests.rs new: property tests
contracts/registry/Cargo.toml add proptest dev-dep
contracts/shared/src/lib.rs wire upgrade_tests module
contracts/shared/src/upgrade_tests.rs new: upgrade test harness
docs/smart-contract-upgrade-guide.md harness documentation

Closes #662
Closes #663
Closes #664
Closes #665

…ainTease#662-BrainTease#665)

BrainTease#663 – Pausable / Emergency-Stop
- Add pause/unpause/is_paused to MarketContract and RegistryContract
- Guard all mutating functions with require_not_paused
- Emit paused/unpaused events; only admin can toggle
- Tests: pause blocks mutations, non-admin rejected, resume works

BrainTease#662 – Batch Operations & Gas Optimisation
- MarketContract: batch_settle_escrows, batch_refund_escrows
  (single auth check + sequential storage writes vs N round-trips)
- RegistryContract: batch_register_users (single list write),
  batch_set_verification_levels
- Tests cover batch edge cases and auth

BrainTease#664 – Property-Based & Fuzz Testing
- contracts/market/src/fuzz_tests.rs: proptest invariants for fee math
  (fee+net=amount, fee≤amount, net≥0, overflow safety, batch summation)
- contracts/registry/src/fuzz_tests.rs: proptest invariants for level
  filtering, pagination bounds, skill expiry, deduplication
- Add proptest = "1.4" dev-dep to market and registry Cargo.toml

BrainTease#665 – Contract Upgrade Test Harness
- contracts/shared/src/upgrade_tests.rs: 12 tests covering schedule,
  cancel, timelock enforcement, unauthorised-upgrade rejection,
  state preservation, storage-layout migration scenario, history
- Wire upgrade_tests module into shared/src/lib.rs
- Document harness in docs/smart-contract-upgrade-guide.md
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@Simcrypt Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant