Skip to content

feat(contract): clean up upgrade support and add admin query (#927) - #1011

Closed
xtep103 wants to merge 1 commit into
Fracverse:masterfrom
xtep103:feature/cleanup-upgrade-contract
Closed

feat(contract): clean up upgrade support and add admin query (#927)#1011
xtep103 wants to merge 1 commit into
Fracverse:masterfrom
xtep103:feature/cleanup-upgrade-contract

Conversation

@xtep103

@xtep103 xtep103 commented Jul 27, 2026

Copy link
Copy Markdown

Closes #927

Summary

Cleans up the contract upgrade infrastructure: removes a duplicate upgrade_contract function, adds a public admin() query, and adds comprehensive tests for the upgrade path.

Changes

contracts/inheritance-contract/src/lib.rs

  • Removed duplicate upgrade_contract function (line 5677) — kept the well-documented upgrade function (line 3798) which includes version bumping, audit-trail event emission, logging, and env.deployer().update_current_contract_wasm()
  • Added pub fn admin(env: Env) -> Option<Address> — public query to retrieve the current contract admin address (exposes the existing private get_admin helper)

contracts/inheritance-contract/src/test.rs

Added 5 new tests:

  • test_admin_returns_none_before_initialization — verifies admin() returns None before setup
  • test_admin_returns_address_after_initialization — verifies admin() returns the correct address
  • test_upgrade_contract_rejects_duplicate_admin_init — verifies initialize_admin rejects second call
  • test_upgrade_version_bumps_correctly — verifies version tracking through multiple bumps
  • test_upgrade_preserves_plan_data — verifies inheritance plan data survives a version bump
  • test_migrate_rejects_when_already_current — verifies migrate is a no-op when version is current

Upgrade Architecture (existing, unchanged)

Function Purpose
upgrade(admin, new_wasm_hash) Admin-only WASM swap with version bump + audit event
migrate(admin) Post-upgrade data migration hook (no-op if current)
admin() NEW — public query for the current admin address
version() Returns current contract version
initialize_admin(admin) One-time admin setup (irreversible)

…se#927)

- Remove duplicate upgrade_contract function (kept well-documented upgrade function)
- Add public admin() query to retrieve the current contract admin address
- Add comprehensive tests for upgrade functionality:
  - admin() returns None before init, Some after init
  - initialize_admin rejects duplicate initialization
  - Version bumps correctly
  - Plan data preserved after upgrade
  - migrate is no-op when already current
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

@ONEONUORA

Copy link
Copy Markdown
Contributor

@xtep103
Run cargo fmt --all -- --check

@ONEONUORA ONEONUORA closed this Jul 29, 2026
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.

[Contract] Issue #16: Add upgrade contract ability

2 participants