test: Unit test for storage helpers#376
Open
nayt9 wants to merge 1 commit intoCommitlabs-Org:masterfrom
Open
Conversation
|
@nayt9 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.
Added comprehensive unit tests for the
shared_utilsstorage helper module, focusing on initialization flag management and admin default paths. This PR significantly improves test coverage for critical storage operations used across all contracts.Changes
Test Coverage Added
Initialization Flag Tests (10 tests)
test_is_initialized_returns_false_by_default- Verifies default uninitialized statetest_set_initialized_marks_contract_as_initialized- Tests initialization flag settingtest_set_initialized_is_idempotent- Ensures multiple calls are safetest_require_initialized_succeeds_when_initialized- Validates guard functiontest_require_initialized_panics_when_not_initialized- Tests panic behaviortest_require_not_initialized_succeeds_when_not_initialized- Validates inverse guardtest_require_not_initialized_panics_when_initialized- Tests double-init protectiontest_initialization_flag_persists_across_calls- Verifies storage persistencetest_initialization_flag_uses_correct_storage_key- Validates key usagetest_storage_key_constants_are_unique- Ensures no key collisionsAdmin Storage Tests (8 tests)
test_set_and_get_admin- Basic admin storage operationstest_admin_can_be_updated- Tests admin transfer functionalitytest_get_admin_panics_when_not_initialized- Validates initialization requirementtest_get_admin_panics_when_admin_not_set- Tests missing admin handlingtest_admin_persists_across_calls- Verifies storage persistencetest_admin_uses_correct_storage_key- Validates key usagetest_multiple_admins_in_different_contracts- Tests contract isolationtest_admin_can_be_set_before_initialization- Tests setup flexibilityGeneric Storage Helper Tests (10 tests)
test_get_or_default_returns_default_when_key_not_exists- Default value handlingtest_get_or_default_returns_stored_value_when_exists- Stored value retrievaltest_set_and_get_generic_value- Basic storage operationstest_get_returns_none_when_key_not_exists- Missing key handlingtest_has_returns_false_when_key_not_exists- Key existence check (negative)test_has_returns_true_when_key_exists- Key existence check (positive)test_storage_with_different_types- Multi-type support (i128, u64, bool)test_storage_key_isolation- Ensures keys don't interferetest_storage_value_can_be_overwritten- Tests value updatestest_storage_keys_are_short_symbols- Validates symbol constraintsIntegration Tests (3 tests)
test_typical_initialization_flow- End-to-end initialization workflowtest_cannot_reinitialize_after_initialization- Double-init protectiontest_admin_can_be_set_before_initialization- Flexible setup orderBug Fix
Fixed duplicate import issue in
lib.rsthat was causing compilation errors:pub use fees;statementTesting
Total of 31 new unit tests added covering:
Security Considerations
Files Changed
contracts/shared_utils/src/storage.rs- Added 31 comprehensive unit testscontracts/shared_utils/src/lib.rs- Fixed duplicate import compilation errorcloses #253