feat(identity-registry): add contract upgrade functionality and corre…#68
Conversation
📝 WalkthroughWalkthroughThe PR implements standard WASM upgrade capability for the identity-registry-contract. It adds a new admin-only ChangesContract Upgrade Implementation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
contracts/identity-registry-contract/src/test.rs (1)
53-82: 💤 Low valueConsider adding a negative test for unauthorized upgrade attempts.
The test correctly validates state preservation through the upgrade. For completeness, consider adding a test that verifies non-admin callers are rejected (similar to
test_add_expert_unauthorizedandtest_ban_expert_unauthorizedpatterns in this file).#[test] #[should_panic] fn test_upgrade_contract_unauthorized() { let env = Env::default(); let contract_id = env.register(IdentityRegistryContract, ()); let client = IdentityRegistryContractClient::new(&env, &contract_id); let admin = Address::generate(&env); client.init(&admin); // No auth mocked — should panic let new_wasm_hash = BytesN::from_array(&env, &[1u8; 32]); client.upgrade_contract(&new_wasm_hash); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contracts/identity-registry-contract/src/test.rs` around lines 53 - 82, Add a negative test that asserts non-admin upgrade attempts are rejected: create a test function (e.g., test_upgrade_contract_unauthorized) that registers IdentityRegistryContract, creates IdentityRegistryContractClient, calls client.init(&admin) for some generated admin but does NOT call env.mock_all_auths(), then calls client.upgrade_contract(&new_wasm_hash) (using BytesN::from_array) and mark the test with #[should_panic] to ensure an unauthorized caller causes a panic; follow the existing unauthorized-test patterns like test_add_expert_unauthorized/test_ban_expert_unauthorized for structure and naming.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@contracts/identity-registry-contract/src/test.rs`:
- Around line 53-82: Add a negative test that asserts non-admin upgrade attempts
are rejected: create a test function (e.g., test_upgrade_contract_unauthorized)
that registers IdentityRegistryContract, creates IdentityRegistryContractClient,
calls client.init(&admin) for some generated admin but does NOT call
env.mock_all_auths(), then calls client.upgrade_contract(&new_wasm_hash) (using
BytesN::from_array) and mark the test with #[should_panic] to ensure an
unauthorized caller causes a panic; follow the existing unauthorized-test
patterns like test_add_expert_unauthorized/test_ban_expert_unauthorized for
structure and naming.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0630949a-77ff-410c-b741-a61b49fc7a79
📒 Files selected for processing (3)
contracts/identity-registry-contract/src/contract.rscontracts/identity-registry-contract/src/lib.rscontracts/identity-registry-contract/src/test.rs
Closes #40
Implemented identity registry contract WASM upgradability and regression coverage.
Changes made
contract.rs
upgrade_contract(env: &Env, new_wasm_hash: BytesN<32>) -> Result<(), RegistryError>env.deployer().update_current_contract_wasm(new_wasm_hash)lib.rs
pub fn upgrade_contract(env: Env, new_wasm_hash: BytesN<32>) -> Result<(), RegistryError>in the#[contractimpl]test.rs
test_upgrade_contract_preserves_expert_directory_statedata_uripersistence across upgradeNotes
Made changes.
Summary by CodeRabbit
New Features
Tests