fix: validate governance on scheduled update path with regression tests - #709
Open
Nife-tanny wants to merge 1 commit into
Open
fix: validate governance on scheduled update path with regression tests#709Nife-tanny wants to merge 1 commit into
Nife-tanny wants to merge 1 commit into
Conversation
|
@Nife-tanny 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Issue #562 asks that the scheduled
_update_governancepath validate a new governance address exactly like the directupdate_governancepath, and that both paths be tested ("Test both", "Show the scheduled-path validation test").Finding from the actual code: both paths already route through the same
validate_governancehelper — direct path atsettlement_contract/src/admin.rs(update_governance, ~line 90) and scheduled path at_update_governance(~line 451, reached viaOperation::UpdateGovernanceinexecute). This has been true in upstream history since before the July module-split refactor. What was genuinely missing was the issue-required regression test for the scheduled path and any in-code documentation of the shared-check invariant. This PR adds both, so the two paths cannot drift apart again.What the validation actually checks (confirmed from code, not assumed)
validate_governance(settlement_contract/src/storage.rs) does not perform a cross-contract fee-interface probe. Such a call duringinit/update_governancewas intentionally removed in issue #124 (PR #679) because it creates a reentrancy/DoS vector — a broken or self-recursive governance contract can trap or call back into the not-yet-initialized contract. Governance fee-config validity is instead deferred to first use viatry_invoke_contract. The shared check is therefore: reject empty/zero addresses withInvalidGovernance(#309).I deliberately did not re-add a cross-contract fee-interface probe to either path: that would contradict #124's documented rationale, and the issue asks both paths to share the same validation, which they now demonstrably do.
The scheduled-path validation test (issue requirement)
scheduleis admin-gated but never inspects the operation payload, so validation must happen at execution time on the scheduled path. This test fails on any tree where_update_governanceomits the check (the zero address would be stored and no panic would occur), and passes once both paths callvalidate_governance— it exercises the scheduled execution path end-to-end, not the direct one.Additional tests added:
scheduled_update_governance_accepts_valid_address— scheduled path still accepts a valid governance address.update_governance_rejects_zero_address— direct-path negative control (sameInvalidGovernancerejection).New ledger snapshot files for the three new tests are committed per repo convention (
CONTRIBUTING.md).Summary
validate_governance; no code-path divergence exists. This is now documented directly onupdate_governanceand_update_governance(shared-validation policy, issueupdate_governancedoesn't validate the new governance supports the fee interface #562).cargo test -p settlement_contract update_governance→ 6 passed; 0 failed (including both scheduled-path tests and the direct-path negative test), run in an isolated throwaway worktree with only the documented base compile fixes applied.cargo test --workspaceon the committed tree is still blocked by pre-existing base breakage (below); the error inventory after this change is identical to base — no new errors are introduced by this PR.Pre-existing failures (base branch
300cd07, intentionally left untouched)These fail identically on the base branch with a clean tree, before this change:
settlement_contract(lib):Val: From<Symbol>unsatisfied atstorage.rs:326.settlement_contract(lib test): stale 4-argclient.init(...)calls ingovernance_error_tests.rs(missingdeployer), missingdeployerinadmin_tests.rs(×2),client.execute(&op)arity errors intimelock_tests.rs(×10), missingadminsinschedule_collision_tests.rs/timelock_tests.rs, and unresolvedGovernanceContract/Symbol/events().all()ingovernance_error_tests.rs.governance_contract(lib test): stale 3-arginitcalls andvec![env, ...]vsvec![&env, ...]inreal_auth_tests.rs,anchor_no_event_error_tests.rs, andlib.rstest code.cargo fmt --all --check: fails on pre-existing formatting drift (e.g.bettapay_common/src/storage.rs).cargo clippy --workspace --all-targets --all-features -- -D warnings: cannot complete for the same compile errors.Per the task constraints these were left untouched and are flagged rather than silently fixed.
Local verification status
cargo test --workspace: does not pass on the base due to the pre-existing failures above (this is not caused by this PR). New tests were verified passing in isolation as described above.cargo fmt --all -- --check: pre-existing failure (unchanged by this PR).cargo clippy --workspace --all-targets -- -D warnings: pre-existing failure (unchanged by this PR).Closes #562