Skip to content

Add dry-run execution simulation for governance proposals (#917) - #935

Merged
Mathews-25 merged 2 commits into
AgesEmpire:mainfrom
Kenisank:kenisank_#917
Aug 2, 2026
Merged

Add dry-run execution simulation for governance proposals (#917)#935
Mathews-25 merged 2 commits into
AgesEmpire:mainfrom
Kenisank:kenisank_#917

Conversation

@Kenisank

Copy link
Copy Markdown
Contributor

Closes #917

Summary

Add a simulation interface that runs proposal logic without mutating state, so maintainers can validate proposal effects before executing on-chain.

Changes

  1. proposals.rs

    • Define SimulationEffect and SimulationResult structs (contract types) that describe every storage mutation a proposal would cause.
    • Add simulate_proposal_action(env, proposal) — iterates over all ProposalType variants, reads current storage values, and records the proposed changes in a SimulationResult without writing anything.
    • Add simulate_proposal(env, proposal_id) — convenience wrapper that fetches the proposal by ID and delegates to simulate_proposal_action.
  2. lib.rs

    • Import simulate_proposal, SimulationEffect, SimulationResult from the proposals module.
    • Publicly export SimulationEffect, SimulationResult.
    • Add simulate_proposal as a public contract function that calls through to proposals::simulate_proposal.
    • Register est_simulation test module.
  3. test_simulation.rs (new)

    • simulate_signal_proposal_returns_effects_without_mutating — verifies simulation returns effects and does not change proposal status.
    • simulate_parameter_change_proposal_reports_current_and_proposed — checks that current/proposed values are surfaced for param changes.
    • simulate_treasury_spend_insufficient_balance_reports_failure — confirms simulation reports failure when treasury balance is too low.
    • simulate_nonexistent_proposal_returns_error — validates that ProposalNotFound is returned for invalid IDs.
    • simulate_feature_toggle_reports_effect — checks feature toggle effects contain the correct key.
    • simulation_is_read_only_no_storage_writes — runs simulation twice and confirms identical results + unchanged state.

Design notes

  • The simulation is read-only — no storage writes are performed. Only env.storage().instance().get() is called; no .set() or .remove().
  • No authentication required — safe to call via simulateTransaction RPC.
  • Simulation failure (e.g. insufficient treasury) is returned as a SimulationResult with success: false rather than a contract error, so the caller always receives structured diagnostic information.

Summary

Test plan

Security review checklist

Required for any change touching contracts/ (or shared crates consumed by
contracts, e.g. contracts/common). Not required for docs-only, CI-only, or
non-contract tooling changes — if this PR doesn't touch contract code, check
the box below and move on.

  • This PR does not touch contracts/ or contract-consumed shared crates,
    or it does, and
    docs/security/release_security_checklist.md
    was reviewed against this change (Logic, Access control, Upgrades,
    Arithmetic categories as applicable).

The automated portion of the release gate runs in
security-release-gate.yml
(fmt/clippy/tests/deployment-manifest/error-code checks). This checkbox
covers the human-judgement half that automation can't verify.

WASM ABI diff

CI posts a WASM ABI Export Diff Report as a PR comment. Check it for:

  • All export changes are intentional.
  • Removed or modified exports have a documented migration path.
  • Any .breaking.txt file is removed in the follow-up PR.

Related issue

…#917)

Summary
-------
Add a simulation interface that runs proposal logic without mutating
state, so maintainers can validate proposal effects before executing
on-chain.

Changes
-------
1. proposals.rs
   - Define SimulationEffect and SimulationResult structs (contract
     types) that describe every storage mutation a proposal would cause.
   - Add simulate_proposal_action(env, proposal) — iterates over all
     ProposalType variants, reads current storage values, and records
     the proposed changes in a SimulationResult without writing anything.
   - Add simulate_proposal(env, proposal_id) — convenience wrapper that
     fetches the proposal by ID and delegates to simulate_proposal_action.

2. lib.rs
   - Import simulate_proposal, SimulationEffect, SimulationResult
     from the proposals module.
   - Publicly export SimulationEffect, SimulationResult.
   - Add simulate_proposal as a public contract function that calls
     through to proposals::simulate_proposal.
   - Register 	est_simulation test module.

3. test_simulation.rs (new)
   - simulate_signal_proposal_returns_effects_without_mutating —
     verifies simulation returns effects and does not change proposal status.
   - simulate_parameter_change_proposal_reports_current_and_proposed —
     checks that current/proposed values are surfaced for param changes.
   - simulate_treasury_spend_insufficient_balance_reports_failure —
     confirms simulation reports failure when treasury balance is too low.
   - simulate_nonexistent_proposal_returns_error —
     validates that ProposalNotFound is returned for invalid IDs.
   - simulate_feature_toggle_reports_effect —
     checks feature toggle effects contain the correct key.
   - simulation_is_read_only_no_storage_writes —
     runs simulation twice and confirms identical results + unchanged state.

Design notes
------------
- The simulation is **read-only** — no storage writes are performed.
  Only env.storage().instance().get() is called; no .set() or .remove().
- No authentication required — safe to call via simulateTransaction RPC.
- Simulation failure (e.g. insufficient treasury) is returned as a
  SimulationResult with success: false rather than a contract error,
  so the caller always receives structured diagnostic information.
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Kenisank 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

@Mathews-25
Mathews-25 merged commit ff747ed into AgesEmpire:main Aug 2, 2026
0 of 3 checks passed
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 dry-run execution simulation for governance proposals

2 participants