Skip to content

feat: implement WASM upgradeable contract pattern#58

Merged
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
marvs8:feature/34-upgradeable-contract
May 28, 2026
Merged

feat: implement WASM upgradeable contract pattern#58
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
marvs8:feature/34-upgradeable-contract

Conversation

@marvs8

@marvs8 marvs8 commented May 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the Soroban upgradeable contract pattern using env.deployer().update_current_contract_wasm(), as described in issue #34.

Changes

lib.rs:

  • Added BytesN to imports
  • Added admin_key() — instance storage key for the admin address
  • Added initialize(admin) — sets the admin once; panics with "already initialized" on repeat calls
  • Added upgrade(new_wasm_hash) — loads admin from storage, calls admin.require_auth(), then calls env.deployer().update_current_contract_wasm(new_wasm_hash)

test.rs:

  • test_initialize_twice_panics — verifies double-init panics
  • test_upgrade_preserves_storage — creates an invoice, upgrades, then asserts the invoice storage key still exists in persistent storage
  • test_upgrade_requires_admin_auth — disables mock auths via env.set_auths(&[]), verifies upgrade panics without admin auth

Acceptance Criteria

  • upgrade() requires admin auth
  • upgrade() calls update_current_contract_wasm with provided hash
  • Non-admin call panics with auth error
  • Existing storage is preserved after upgrade (verified via env.storage().persistent().has())
  • All existing cargo test pass (10/10)
  • cargo clippy passes with zero warnings

Closes #34

- Import BytesN from soroban_sdk
- Add admin_key() storage helper (instance storage)
- Add initialize(admin) — sets admin once, panics if called again
- Add upgrade(new_wasm_hash) — requires admin auth, calls update_current_contract_wasm
- Tests: initialize_twice_panics, upgrade_preserves_storage, upgrade_requires_admin_auth
- All 10 tests pass, clippy clean

Closes Stellar-split#34
@drips-wave

drips-wave Bot commented May 28, 2026

Copy link
Copy Markdown

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

@Kingsman-99 Kingsman-99 merged commit 3a8ec32 into Stellar-split:main May 28, 2026
1 check failed
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.

Implement WASM upgradeable contract pattern

2 participants