Repository navigation
feat(contract): #18 admin-only upgrade entrypoint with version tracking - #19
Merged
Merged
Conversation
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.
Summary
Resolves #18.
Implements admin-only contract upgradability for
YieldStreamDistributorvia Soroban'senv.deployer().update_current_contract_wasmwith monotonic version tracking, complete storage key preservation, aget_version()public view, and a detailed operational runbook and trust analysis indocs/UPGRADING.md.Changes Made
contracts/distributor/src/lib.rs):upgrade(env: Env, new_wasm_hash: BytesN<32>) -> Result<(), ContractError>:admin.require_auth().storage::set_version) with overflow checks.storage::bump_instance).env.deployer().update_current_contract_wasm(new_wasm_hash).contract_upgraded.get_version(env: Env) -> u32.version = 1ininitialize.contracts/distributor/src/storage.rs&types.rs):DataKey::Versionto instance storage.get_version(defaulting to 1 for unmigrated v1 contracts) andset_version.DataKey::Admin,DataKey::DistributionCount,DataKey::Distribution(id),DataKey::Claimed(id, index)) remain preserved and unaltered across upgrades.contracts/distributor/src/events.rs):contract_upgraded(&env, old_version, new_version, &new_wasm_hash)with topics("upgrade", old_version, new_version)and new hash payload.contracts/distributor/src/test/upgrade.rs):test_upgrade_contract_success_and_preserves_state: Initializes v1, creates campaign, claims leaf 0 under v1, uploads v2 WASM viaenv.deployer().upload_contract_wasm, invokesupgrade, verifies version bumps from 1 to 2, verifies upgrade event, verifies that v1 state (campaign metadata, admin, counts) remains intact, claims leaf 1 under v2, and verifies double-claim protection persists.test_upgrade_auth_matrix: Verifies authorization required specifically matches the admin address.test_upgrade_without_admin_auth_fails: Verifies that unauthorized callers cannot invokeupgrade.test_upgrade_uninitialized_fails: Verifies that an uninitialized contract returnsContractError::NotInitialized.test_upgrade_consecutive_versions: Verifies sequential version bumps (v1 -> v2 -> v3).docs/UPGRADING.md):Acceptance Verification
admin.require_auth())docs/UPGRADING.mdcargo fmt --checkcargo clippy --all-targets -- -D warnings