-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: String Storage ADO #512
feat: String Storage ADO #512
Conversation
WalkthroughThe updates enhance the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Contract
participant Storage
User->>Contract: Instantiate(InstantiateMsg)
Contract->>Storage: Save initial state
Storage-->>Contract: Acknowledgement
Contract-->>User: Response
User->>Contract: Execute(ExecuteMsg)
Contract->>Storage: Perform action based on ExecuteMsg
Storage-->>Contract: Acknowledgement
Contract-->>User: Response
User->>Contract: Query(QueryMsg)
Contract->>Storage: Retrieve data
Storage-->>Contract: Data
Contract-->>User: QueryResponse
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
Files selected for processing (14)
- contracts/data-storage/andromeda-string-storage/.cargo/config (1 hunks)
- contracts/data-storage/andromeda-string-storage/Cargo.toml (1 hunks)
- contracts/data-storage/andromeda-string-storage/examples/schema.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/contract.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/execute.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/lib.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/mock.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/query.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/state.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/testing/mock.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/testing/mod.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/testing/tests.rs (1 hunks)
- packages/andromeda-data-storage/src/lib.rs (1 hunks)
- packages/andromeda-data-storage/src/string_storage.rs (1 hunks)
Files skipped from review due to trivial changes (4)
- contracts/data-storage/andromeda-string-storage/.cargo/config
- contracts/data-storage/andromeda-string-storage/src/state.rs
- contracts/data-storage/andromeda-string-storage/src/testing/mod.rs
- packages/andromeda-data-storage/src/lib.rs
Additional comments not posted (58)
contracts/data-storage/andromeda-string-storage/src/lib.rs (6)
1-1
: Module importcontract
is appropriate.The
contract
module is necessary for the main contract logic.
2-2
: Module importexecute
is appropriate.The
execute
module is necessary for handling execution messages.
3-4
: Module importmock
is appropriate.The
mock
module is necessary for testing and is conditionally compiled.
5-5
: Module importquery
is appropriate.The
query
module is necessary for handling query messages.
6-6
: Module importstate
is appropriate.The
state
module is necessary for managing the contract's state.
8-9
: Module importtesting
is appropriate.The
testing
module is necessary for testing and is conditionally compiled.contracts/data-storage/andromeda-string-storage/examples/schema.rs (4)
1-1
: Schema definition forInstantiateMsg
is appropriate.The
InstantiateMsg
schema is necessary for instantiating the contract.
1-1
: Schema definition forQueryMsg
is appropriate.The
QueryMsg
schema is necessary for querying the contract.
1-1
: Schema definition forExecuteMsg
is appropriate.The
ExecuteMsg
schema is necessary for executing the contract.
3-10
: Schema generation usingwrite_api
is appropriate.The
write_api
macro is necessary for generating the schema for instantiation, query, and execution messages.contracts/data-storage/andromeda-string-storage/Cargo.toml (6)
1-6
: Package metadata is appropriate.The package metadata includes necessary information such as name, version, authors, edition, and rust-version.
8-12
: Exclude section is appropriate.The exclude section lists files that should not be part of the source code publication.
16-17
: Lib section is appropriate.The lib section defines the crate types as
cdylib
andrlib
.
19-24
: Features section is appropriate.The features section defines optional features such as backtraces, library, and testing.
26-36
: Dependencies section is appropriate.The dependencies section lists the necessary dependencies for the package.
38-40
: Target dependencies section is appropriate.The target dependencies section lists dependencies for non-Wasm targets.
contracts/data-storage/andromeda-string-storage/src/query.rs (3)
6-20
: Functionhas_permission
is appropriate.The function checks if an address has permission to access the stored data based on the restriction type and ownership.
22-27
: Functionget_value
is appropriate.The function retrieves the stored value and returns it in a response structure.
29-34
: Functionget_data_owner
is appropriate.The function retrieves the owner of the stored data and returns it in a response structure.
contracts/data-storage/andromeda-string-storage/src/testing/mock.rs (5)
18-29
: LGTM!The
proper_initialization
function correctly initializes the mock dependencies and calls theinstantiate
function with the appropriate parameters.
31-37
: LGTM!The
query_value
function correctly handles the query and returns the expected result.
39-49
: LGTM!The
set_value
function correctly sets the value in the contract by calling theexecute
function with the appropriate parameters.
51-62
: LGTM!The
set_value_with_funds
function correctly sets the value in the contract with the provided funds by calling theexecute
function with the appropriate parameters.
64-71
: LGTM!The
delete_value
function correctly deletes the value from the contract by calling theexecute
function with the appropriate parameters.contracts/data-storage/andromeda-string-storage/src/contract.rs (4)
23-44
: LGTM!The
instantiate
function correctly initializes the contract and saves the restriction to the state.
47-60
: LGTM!The
execute
function correctly handles execution messages by creating anExecuteContext
and dispatching the message to the appropriate handler.
63-69
: LGTM!The
query
function correctly handles query messages by dispatching the message to the appropriate handler.
72-74
: LGTM!The
migrate
function correctly handles migration by calling theADOContract
'smigrate
method.packages/andromeda-data-storage/src/string_storage.rs (8)
5-9
: LGTM!The
InstantiateMsg
type definition is correct and follows best practices.
11-21
: LGTM!The
ExecuteMsg
type definition is correct and follows best practices.
23-31
: LGTM!The
QueryMsg
type definition is correct and follows best practices.
33-49
: LGTM!The
StringStorage
type definition and validation logic are correct and follow best practices.
74-79
: LGTM!The
StringStorageRestriction
type definition is correct and follows best practices.
81-84
: LGTM!The
GetValueResponse
type definition is correct and follows best practices.
86-89
: LGTM!The
GetDataOwnerResponse
type definition is correct and follows best practices.
91-141
: LGTM!The tests module includes comprehensive test cases that cover various scenarios for the string storage contract. The test functions follow best practices and ensure the correctness of the contract.
contracts/data-storage/andromeda-string-storage/src/mock.rs (8)
16-40
: LGTM!The
MockStringStorage
struct and its implementation provide mock functions for instantiating and interacting with the string storage contract. The functions follow best practices and ensure the correctness of the contract interactions.
42-56
: LGTM!The
execute_set_value
function correctly sets the value in the contract by calling theexecute_contract
function with the appropriate parameters.
58-66
: LGTM!The
execute_add_rate
function correctly adds the rate to the contract by calling theexecute
function with the appropriate parameters.
68-72
: LGTM!The
query_value
function correctly handles the query and returns the expected result.
74-78
: LGTM!The
query_data_owner
function correctly handles the query and returns the expected result.
81-84
: LGTM!The
mock_andromeda_string_storage
function correctly returns a boxed contract for the string storage.
86-95
: LGTM!The
mock_string_storage_instantiate_msg
function correctly creates the instantiation message for the string storage contract.
98-113
: LGTM!The utility functions correctly create various messages for interacting with the string storage contract.
contracts/data-storage/andromeda-string-storage/src/execute.rs (5)
22-48
: LGTM! Verify the message handling logic.The function is well-structured and handles various execution messages. Ensure that the logic for handling different message types is correct and that all necessary checks and balances are in place.
51-65
: LGTM!The function includes necessary checks for authorization and ensures the transaction is non-payable. The logic appears correct.
67-101
: LGTM!The function is comprehensive and includes necessary checks and balances. The logic for handling tax deductions is well-implemented.
104-117
: LGTM!The function includes necessary checks for authorization and ensures the transaction is non-payable. The logic appears correct.
119-158
: LGTM!The function is well-implemented and includes necessary logic for handling tax calculations and refunds. The use of
ADOContract::default().query_deducted_funds
is appropriate.contracts/data-storage/andromeda-string-storage/src/testing/tests.rs (9)
20-23
: LGTM!The test function is well-structured and covers the initialization scenario adequately.
25-56
: LGTM!The test function covers both setting and updating scenarios and includes assertions to verify the correctness of the operations.
58-157
: LGTM!The test function is comprehensive and covers various scenarios for handling tax deductions. The assertions verify the correctness of the operations.
159-185
: LGTM!The test function covers invalid scenarios and includes assertions to verify the correctness of error handling.
188-195
: LGTM!The test function covers the deletion scenario and includes assertions to verify the correctness of the operation.
197-220
: LGTM!The test function covers various scenarios for the private restriction mode and includes assertions to verify the correctness of the operations.
222-247
: LGTM!The test function covers various scenarios for the public restriction mode and includes assertions to verify the correctness of the operations.
249-292
: LGTM!The test function covers various scenarios for the restricted restriction mode and includes assertions to verify the correctness of the operations.
294-311
: LGTM!The test function covers the scenario for querying the data owner and includes assertions to verify the correctness of the operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- contracts/data-storage/andromeda-string-storage/src/mock.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- contracts/data-storage/andromeda-string-storage/src/mock.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (11)
contracts/data-storage/andromeda-string-storage/src/testing/mock.rs (3)
39-49
: Clarify the purpose ofset_value
.The function
set_value
sets a value using theExecuteMsg::SetValue
message. Ensure that the function's purpose is clear and documented, especially regarding its use in tests.
51-62
: Clarify the purpose ofset_value_with_funds
.The function
set_value_with_funds
is similar toset_value
but includes a coin. Ensure that the function's purpose and differences fromset_value
are clear and documented.
64-68
: Clarify the purpose ofdelete_value
.The function
delete_value
deletes a value using theExecuteMsg::DeleteValue
message. Ensure that the function's purpose is clear and documented, especially regarding its use in tests.packages/andromeda-data-storage/src/string_storage.rs (8)
5-9
: Consider documenting theInstantiateMsg
structure.The
InstantiateMsg
structure defines the initialization parameters. Consider adding documentation to clarify its fields and usage.
11-21
: Consider documenting theExecuteMsg
variants.The
ExecuteMsg
enum defines the execution messages. Consider adding documentation to clarify each variant's purpose and usage.
23-31
: Consider documenting theQueryMsg
variants.The
QueryMsg
enum defines the query messages. Consider adding documentation to clarify each variant's purpose and usage.
33-36
: Consider documenting theStringStorage
enum.The
StringStorage
enum defines the storage type. Consider adding documentation to clarify its purpose and usage.
63-69
: Consider documenting thetry_get_value
function.The
try_get_value
function retrieves the string value. Consider adding documentation to clarify its purpose and usage.
71-76
: Consider documenting theStringStorageRestriction
enum.The
StringStorageRestriction
enum defines access restrictions. Consider adding documentation to clarify each variant's purpose and usage.
78-81
: Consider documenting theGetValueResponse
structure.The
GetValueResponse
structure defines the response for a value query. Consider adding documentation to clarify its fields and usage.
83-86
: Consider documenting theGetDataOwnerResponse
structure.The
GetDataOwnerResponse
structure defines the response for a data owner query. Consider adding documentation to clarify its fields and usage.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
Files selected for processing (10)
- contracts/data-storage/andromeda-string-storage/examples/schema.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/contract.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/execute.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/mock.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/query.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/state.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/testing/mock.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/testing/mod.rs (1 hunks)
- contracts/data-storage/andromeda-string-storage/src/testing/tests.rs (1 hunks)
- packages/andromeda-data-storage/src/string_storage.rs (1 hunks)
Files skipped from review due to trivial changes (1)
- contracts/data-storage/andromeda-string-storage/src/testing/mod.rs
Additional comments not posted (36)
contracts/data-storage/andromeda-string-storage/examples/schema.rs (1)
1-10
: LGTM!The code correctly uses the
write_api
macro to generate schema for the contract messages.contracts/data-storage/andromeda-string-storage/src/state.rs (1)
1-7
: LGTM!The constants for storing data, data owner, and restriction type are well-defined using
cw_storage_plus::Item
.contracts/data-storage/andromeda-string-storage/src/query.rs (3)
1-19
: LGTM!The
has_permission
function effectively checks permissions based on the restriction type and usesADOContract
for permission checks.
21-24
: LGTM!The
get_value
function correctly retrieves the stored value fromDATA
.
26-30
: LGTM!The
get_data_owner
function correctly retrieves the data owner and converts it toAndrAddr
.contracts/data-storage/andromeda-string-storage/src/testing/mock.rs (1)
1-3
: Ensure imports are necessary and used.The imports from
andromeda_data_storage::string_storage
are comprehensive. Verify that all imported entities are utilized within the file.contracts/data-storage/andromeda-string-storage/src/contract.rs (4)
22-44
: Ensure instantiation handles all edge cases.The
instantiate
function sets up the contract with initial parameters. Ensure that all edge cases, such as invalid input or storage errors, are handled.
46-60
: Ensure execution logic covers all message types.The
execute
function delegates message handling tohandle_execute
. Ensure that all possibleExecuteMsg
variants are covered and handled appropriately.
62-69
: Ensure query logic covers all message types.The
query
function handles differentQueryMsg
variants. Ensure that all possible query types are covered and handled appropriately.
71-74
: Ensure migration logic is complete.The
migrate
function updates the contract version. Ensure that all necessary migration steps are included and that the function handles potential errors.packages/andromeda-data-storage/src/string_storage.rs (4)
1-3
: Ensure all imports are necessary.Verify that all imported entities from
andromeda_std
andcosmwasm_schema
are utilized within the file.
38-46
: Ensurevalidate
function covers all cases.The
validate
function checks for an empty string. Ensure that all potential invalid cases are covered and handled.
49-61
: Ensure conversion implementations are correct.The
From
implementations convert betweenStringStorage
andString
. Verify that these conversions are correct and cover all cases.
88-137
: Ensure test coverage is comprehensive.The test module includes tests for conversion, validation, and retrieval functions. Ensure that all edge cases and potential errors are covered in the tests.
contracts/data-storage/andromeda-string-storage/src/mock.rs (8)
16-17
: LGTM! Struct definition is correct.The
MockStringStorage
struct is appropriately defined for mocking purposes.
19-40
: LGTM! Function implementation is correct.The
instantiate
function correctly handles contract instantiation and returns the expected result.
42-55
: LGTM! Function implementation is correct.The
execute_set_value
function correctly handles the execution logic, including the optional funds parameter.
57-65
: LGTM! Function implementation is correct.The
execute_add_rate
function correctly handles rate addition logic.
67-71
: LGTM! Function implementation is correct.The
query_value
function correctly handles the query logic.
73-77
: LGTM! Function implementation is correct.The
query_data_owner
function correctly handles the query logic.
80-83
: LGTM! Function implementation is correct.The
mock_andromeda_string_storage
function correctly wraps the execute, instantiate, and query functions for testing.
85-112
: LGTM! Function implementations are correct.The functions for generating mock messages are correctly implemented for testing purposes.
contracts/data-storage/andromeda-string-storage/src/execute.rs (5)
18-44
: LGTM! Function implementation is correct.The
handle_execute
function correctly processes execution messages and delegates to specific handlers.
47-61
: LGTM! Function implementation is correct.The
update_restriction
function correctly updates the restriction setting with proper authorization checks.
63-98
: LGTM! Function implementation is correct.The
set_value
function correctly handles permissions, validation, and tax logic for setting a value.
100-112
: LGTM! Function implementation is correct.The
delete_value
function correctly removes a value with proper authorization checks.
114-152
: LGTM! Function implementation is correct.The
tax_set_value
function correctly calculates and handles tax for setting a value, including refund logic.contracts/data-storage/andromeda-string-storage/src/testing/tests.rs (9)
21-24
: LGTM! Test implementation is correct.The
test_instantiation
function correctly tests the proper initialization of the String Storage ADO.
26-52
: LGTM! Test implementation is correct.The
test_set_and_update_value
function correctly tests setting and updating a value in the String Storage ADO.
54-146
: LGTM! Test implementation is correct.The
test_set_value_with_tax
function correctly tests setting a value with tax considerations, covering various scenarios.
156-172
: LGTM! Test implementation is correct.The
test_set_value_invalid
function correctly tests setting an invalid value, covering invalid input scenarios.
175-182
: LGTM! Test implementation is correct.The
test_delete_value
function correctly tests the deletion of a value in the String Storage ADO.
184-207
: LGTM! Test implementation is correct.The
test_restriction_private
function correctly tests the private restriction mode, covering various scenarios.
209-234
: LGTM! Test implementation is correct.The
test_restriction_public
function correctly tests the public restriction mode, covering various scenarios.
236-279
: LGTM! Test implementation is correct.The
test_restriction_restricted
function correctly tests the restricted restriction mode, covering various scenarios.
281-304
: LGTM! Test implementation is correct.The
test_query_data_owner
function correctly tests querying the data owner in the String Storage ADO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- CHANGELOG.md (1 hunks)
- packages/andromeda-data-storage/src/string_storage.rs (1 hunks)
Files skipped from review due to trivial changes (1)
- CHANGELOG.md
Files skipped from review as they are similar to previous changes (1)
- packages/andromeda-data-storage/src/string_storage.rs
Motivation
Make an ADO that is similar to key/value primitive ADO but it also stores only single string value.
Implementation
String Storage can be set to be one of the following:
Private: Only the owner is allowed to set/remove values.
Public: String Storage is open to anyone similar to a public database.
Restricted: Only the user that set the value is able to modify/remove it.
Testing
Added unit-testing of smart contract
Version Changes
Contract version is set at 1.0.0
Summary by CodeRabbit
New Features
Bug Fixes
Tests