-
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
Distance ADO #570
base: development
Are you sure you want to change the base?
Distance ADO #570
Conversation
WalkthroughThe changes introduce a new Andromeda Distance module, which includes updates to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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 using PR comments)
Other keywords and placeholders
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: 5
Outside diff range and nitpick comments (16)
contracts/modules/andromeda-distance/src/testing/mod.rs (1)
1-2
: LGTM! Consider adding documentation comments.The structure of the testing module looks good. It follows best practices by separating mock implementations and actual tests into different modules.
Consider adding documentation comments to provide more context about the purpose of each module. For example:
/// Mock implementations for testing purposes mod mock; /// Test cases for the andromeda-distance module mod tests;This will improve code clarity and make it easier for other developers to understand the purpose of each module at a glance.
contracts/modules/andromeda-distance/.cargo/config (1)
1-4
: LGTM! Consider adding aclippy
alias for linting.The Cargo configuration looks good and aligns well with the project's objectives. The aliases provided will streamline the development workflow for WebAssembly compilation, unit testing, and schema generation.
Consider adding a
clippy
alias for running the Rust linter. This can help maintain code quality and catch potential issues early. You can add the following line:clippy = "clippy -- -D warnings"This will run Clippy with all warnings treated as errors, ensuring a high standard of code quality.
contracts/modules/andromeda-distance/src/lib.rs (3)
2-3
: LGTM: Testing module declaration with a minor suggestion.The conditional compilation of the
testing
module is appropriate for isolating test code. This aligns with the PR objectives mentioning the addition of unit test cases.Consider adding a brief doc comment explaining the purpose of this module:
/// Module containing test utilities and helpers for the Andromeda distance functionality. #[cfg(test)] pub mod testing;
5-6
: LGTM: Mock module declaration with a minor suggestion.The conditional compilation of the
mock
module is well-structured, ensuring it's only included in non-WebAssembly builds with the "testing" feature enabled. This setup allows for effective mocking during tests without affecting the production WebAssembly build.Consider adding a brief doc comment explaining the purpose of this module:
/// Module containing mock implementations for testing the Andromeda distance functionality. #[cfg(all(not(target_arch = "wasm32"), feature = "testing"))] pub mod mock;
1-6
: Overall structure looks good, with a minor suggestion.The file structure is clean and well-organized, properly separating the main contract logic from testing and mocking utilities. This aligns well with the PR objectives of implementing distance calculation functionality and adding unit tests.
Consider adding a module-level doc comment at the beginning of the file to provide an overview of the Andromeda distance functionality:
//! Andromeda Distance Module //! //! This module provides functionality for calculating distances between points //! in a three-dimensional space, as part of the Andromeda protocol. pub mod contract; // ... (rest of the file)This addition would improve the overall documentation and make it easier for other developers to understand the purpose of this module at a glance.
contracts/modules/andromeda-distance/examples/schema.rs (1)
4-9
: LGTM: Correct API schema generation with a minor suggestion.The
write_api!
macro is correctly used to generate the API schema for the Andromeda Distance module. It includes all necessary message types (InstantiateMsg
,QueryMsg
, andExecuteMsg
) as mentioned in the PR objectives.Consider removing the blank line (line 8) within the
write_api!
macro for better code consistency:write_api! { instantiate: InstantiateMsg, query: QueryMsg, execute: ExecuteMsg, - }
packages/andromeda-modules/src/distance.rs (4)
4-6
: LGTM: InstantiateMsg is correctly defined, but consider future extensibility.The
InstantiateMsg
struct is correctly defined and uses appropriate attributes. Its empty state suggests that no initialization parameters are currently required for this module.Consider adding a comment explaining why
InstantiateMsg
is empty and how it might be extended in the future if initialization parameters become necessary. This can help maintain the code's clarity as the project evolves.
12-22
: QueryMsg structure is good, but consider type safety and clarity improvements.The
QueryMsg
enum is well-structured for a distance calculation module. However, there are a few points to consider:
- Returning a
String
for the distance calculation might not be the most type-safe or efficient approach.- The purpose of the
decimal
parameter is not immediately clear from the context.Consider the following improvements:
Instead of returning a
String
, use a more specific type for the distance result. For example:#[returns(f64)] GetDistanceBetween2Points { ... }This ensures type safety and avoids unnecessary string conversions.
Rename the
decimal
parameter to clarify its purpose, e.g.,precision
ordecimal_places
. Also, consider adding a comment explaining how this parameter affects the calculation.If the
decimal
parameter is used for formatting the output, consider separating the formatting concern from the calculation. You could return af64
and handle formatting elsewhere.Example:
#[returns(f64)] GetDistanceBetween2Points { point_1: Coordinate, point_2: Coordinate, precision: u16, // Number of decimal places for internal calculation precision }These changes would improve the API's clarity and type safety.
24-29
: LGTM: Coordinate struct is well-designed, consider adding documentation.The
Coordinate
struct is well-designed to support both 2D and 3D coordinates. The use off64
for coordinate values provides good precision for most use cases.Consider the following minor improvements:
Add documentation comments to the struct and its fields to explain their purpose and any constraints. For example:
/// Represents a point in 2D or 3D space #[cw_serde] pub struct Coordinate { /// X-coordinate value pub x_coordinate: f64, /// Y-coordinate value pub y_coordinate: f64, /// Optional Z-coordinate value. If None, represents a 2D point pub z_coordinate: Option<f64>, }Consider adding a constructor method or associated functions for creating 2D and 3D coordinates. This can improve usability and make the intention clearer when creating coordinates. For example:
impl Coordinate { pub fn new_2d(x: f64, y: f64) -> Self { Self { x_coordinate: x, y_coordinate: y, z_coordinate: None, } } pub fn new_3d(x: f64, y: f64, z: f64) -> Self { Self { x_coordinate: x, y_coordinate: y, z_coordinate: Some(z), } } }These additions would enhance the struct's usability and self-documentation.
1-29
: Overall, the distance module provides a solid foundation, with room for minor improvements.The
distance.rs
file establishes a good structure for a distance calculation module within the Andromeda framework. Here's a summary of the main points:
- The use of custom attributes and Cosmos SDK utilities is appropriate and consistent.
- The
Coordinate
struct is well-designed to support both 2D and 3D coordinates.- The
QueryMsg
enum provides a clear interface for distance calculations.Areas for improvement:
- Consider adding execution messages to
ExecuteMsg
or provide clarification on why it's empty.- Improve type safety in
QueryMsg
by returning a more specific type thanString
for distance results.- Enhance documentation, especially for the
Coordinate
struct and its usage.- Clarify the purpose of the
decimal
parameter in theGetDistanceBetween2Points
query.Addressing these points will further improve the module's clarity, usability, and maintainability.
contracts/modules/andromeda-distance/src/testing/mock.rs (1)
17-28
: LGTM: Well-structured initialization function with a minor suggestion.The
proper_initialization
function is well-implemented, following good practices for CosmWasm contract testing. It correctly sets up the mock environment, initializes the contract, and verifies that no messages are returned upon instantiation.Consider adding a comment explaining the purpose of this function and what it returns. This would improve the readability and maintainability of the test code. For example:
/// Sets up a properly initialized mock environment for testing. /// Returns a tuple containing the mock dependencies and message info. pub fn proper_initialization() -> (MockDeps, MessageInfo) { // ... (existing implementation) }contracts/modules/andromeda-distance/src/testing/tests.rs (1)
11-63
: LGTM: Comprehensive test cases for distance calculations.The test function covers various scenarios for distance calculations, including 2D and 3D coordinates, as well as larger distances. This provides good coverage of the
query_distance
function's capabilities.Suggestions for potential improvements:
- Consider adding a test case for very small distances to ensure precision for nearby points.
- Add a test case where z-coordinate is provided for one point but not the other, to ensure proper handling of mixed dimensionality.
- Consider testing with negative z-coordinates as well.
- Add comments explaining the expected results for better readability.
Here's an example of how you could add these improvements:
// Test case for very small distances let query_res = query_distance( deps.as_ref(), Coordinate { x_coordinate: 0.0001_f64, y_coordinate: 0.0001_f64, z_coordinate: None, }, Coordinate { x_coordinate: 0_f64, y_coordinate: 0_f64, z_coordinate: None, }, 5, ) .unwrap(); // Expected result: sqrt(0.0001^2 + 0.0001^2) ≈ 0.00014142 assert_eq!(query_res, "0.00014".to_string()); // Test case for mixed dimensionality let query_res = query_distance( deps.as_ref(), Coordinate { x_coordinate: 1_f64, y_coordinate: 1_f64, z_coordinate: Some(1_f64), }, Coordinate { x_coordinate: 0_f64, y_coordinate: 0_f64, z_coordinate: None, }, 5, ) .unwrap(); // Expected result: sqrt(1^2 + 1^2 + 1^2) ≈ 1.73205 assert_eq!(query_res, "1.73205".to_string()); // Test case with negative z-coordinate let query_res = query_distance( deps.as_ref(), Coordinate { x_coordinate: 1_f64, y_coordinate: 1_f64, z_coordinate: Some(-1_f64), }, Coordinate { x_coordinate: 0_f64, y_coordinate: 0_f64, z_coordinate: Some(1_f64), }, 5, ) .unwrap(); // Expected result: sqrt(1^2 + 1^2 + 2^2) ≈ 2.44949 assert_eq!(query_res, "2.44949".to_string());contracts/modules/andromeda-distance/src/mock.rs (4)
12-13
: LGTM: Well-structured MockDistance definition.The
MockDistance
struct and its trait implementation using themock_ado!
macro are well-defined.Consider adding a brief doc comment to explain the purpose of the
MockDistance
struct:/// Represents a mock implementation of the Distance contract for testing purposes. pub struct MockDistance(Addr);
15-35
: LGTM: Well-implemented instantiate method.The
instantiate
method correctly sets up a new contract instance using the provided parameters.Consider improving error handling by propagating the error instead of using
unwrap()
:pub fn instantiate( code_id: u64, sender: Addr, app: &mut MockApp, kernel_address: String, owner: Option<String>, ) -> Result<MockDistance, anyhow::Error> { let msg = mock_distance_instantiate_msg(kernel_address, owner); let addr = app .instantiate_contract( code_id, sender.clone(), &msg, &[], "Distance Contract", Some(sender.to_string()), )?; Ok(MockDistance(Addr::unchecked(addr))) }This change would allow callers to handle potential errors more gracefully.
37-51
: LGTM: Well-implemented query_distance method.The
query_distance
method correctly constructs the query message and executes it.Consider using a more specific return type instead of
String
to improve type safety:pub fn query_distance( &self, app: &mut MockApp, point_1: Coordinate, point_2: Coordinate, decimal: u16, ) -> Result<f64, StdError> { let msg = QueryMsg::GetDistanceBetween2Points { point_1, point_2, decimal, }; let res: String = self.query(app, msg); res.parse::<f64>().map_err(StdError::parse_err) }This change would ensure that the returned value is a valid floating-point number and make it easier for callers to use the result directly in calculations.
54-67
: LGTM: Well-implemented utility functions.The
mock_andromeda_distance
andmock_distance_instantiate_msg
functions are correctly implemented for their purposes.Consider adding brief doc comments to explain the purpose of these utility functions:
/// Creates a mock Contract implementation for the Andromeda Distance module. pub fn mock_andromeda_distance() -> Box<dyn Contract<Empty>> { // ... (existing implementation) } /// Creates an InstantiateMsg for the Andromeda Distance module with the given parameters. pub fn mock_distance_instantiate_msg( kernel_address: String, owner: Option<String>, ) -> InstantiateMsg { // ... (existing implementation) }These comments would improve the code's self-documentation and make it easier for other developers to understand and use these functions.
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 (11)
- contracts/modules/andromeda-distance/.cargo/config (1 hunks)
- contracts/modules/andromeda-distance/Cargo.toml (1 hunks)
- contracts/modules/andromeda-distance/examples/schema.rs (1 hunks)
- contracts/modules/andromeda-distance/src/contract.rs (1 hunks)
- contracts/modules/andromeda-distance/src/lib.rs (1 hunks)
- contracts/modules/andromeda-distance/src/mock.rs (1 hunks)
- contracts/modules/andromeda-distance/src/testing/mock.rs (1 hunks)
- contracts/modules/andromeda-distance/src/testing/mod.rs (1 hunks)
- contracts/modules/andromeda-distance/src/testing/tests.rs (1 hunks)
- packages/andromeda-modules/src/distance.rs (1 hunks)
- packages/andromeda-modules/src/lib.rs (1 hunks)
Additional comments not posted (21)
packages/andromeda-modules/src/lib.rs (1)
3-3
: LGTM! Verify module implementation.The addition of the
distance
module aligns with the PR objectives for implementing distance calculation functionality. The module is correctly declared as public and placed in alphabetical order.To ensure the module is properly implemented, please run the following verification script:
This script will help verify the existence of the
distance.rs
file, check its basic structure, and look for potential naming conflicts with other modules.Verification successful
Action Required: Re-verify Potential Naming Conflicts in the
distance
ModuleThe initial verification script encountered an error while checking for potential naming conflicts. Please run the updated verification script below to ensure there are no naming conflicts with the
distance
module.This updated script corrects the previous error by properly excluding
distance.rs
when searching for the term "distance" to identify any potential naming conflicts with other modules.
Action Required: Re-verify Potential Naming Conflicts in the
distance
Module with Corrected ScriptThe previous verification script encountered an error while excluding
distance.rs
. Please run the updated verification script below, which correctly excludes thedistance.rs
file using the--glob
flag with a negation pattern.This updated script uses the
--glob
flag with the negation pattern!packages/andromeda-modules/src/distance.rs
to properly exclude thedistance.rs
file when searching for the term "distance" across the codebase. This should eliminate the previous error and accurately check for any naming conflicts with other modules.
Verification Successful: No Naming Conflicts Found in the
distance
ModuleThe
distance
module has been successfully added with the correct structure and placement. No naming conflicts were detected in the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence and basic structure of the distance module # Test 1: Check if the distance.rs file exists echo "Checking for distance.rs file..." fd --type f "^distance\.rs$" packages/andromeda-modules/src # Test 2: Verify basic structure of the distance module echo "Verifying basic structure of the distance module..." rg --type rust "^(pub )?(struct|enum|fn) \w+" packages/andromeda-modules/src/distance.rs # Test 3: Check for potential naming conflicts echo "Checking for potential naming conflicts..." rg --type rust "\bdistance\b" packages/andromeda-modules/src --files-without-match distance.rsLength of output: 940
Script:
#!/bin/bash # Description: Verify the existence and basic structure of the distance module, and check for potential naming conflicts # Test 1: Check if the distance.rs file exists echo "Checking for distance.rs file..." fd --type f "^distance\.rs$" packages/andromeda-modules/src # Test 2: Verify basic structure of the distance module echo "Verifying basic structure of the distance module..." rg --type rust "^(pub )?(struct|enum|fn) \w+" packages/andromeda-modules/src/distance.rs # Test 3: Check for potential naming conflicts excluding distance.rs echo "Checking for potential naming conflicts excluding distance.rs..." rg --type rust "\bdistance\b" packages/andromeda-modules/src --ignore 'distance.rs'Length of output: 909
Script:
#!/bin/bash # Description: Verify the existence and basic structure of the distance module, and check for potential naming conflicts # Test 1: Check if the distance.rs file exists echo "Checking for distance.rs file..." fd --type f "^distance\.rs$" packages/andromeda-modules/src # Test 2: Verify basic structure of the distance module echo "Verifying basic structure of the distance module..." rg --type rust "^(pub )?(struct|enum|fn) \w+" packages/andromeda-modules/src/distance.rs # Test 3: Check for potential naming conflicts excluding distance.rs echo "Checking for potential naming conflicts excluding distance.rs..." rg --type rust "\bdistance\b" packages/andromeda-modules/src --glob '!packages/andromeda-modules/src/distance.rs'Length of output: 889
contracts/modules/andromeda-distance/src/lib.rs (1)
1-1
: LGTM: Main contract module declaration.The public declaration of the
contract
module is appropriate. This module will likely contain the core logic for the Andromeda distance functionality, as described in the PR objectives.contracts/modules/andromeda-distance/examples/schema.rs (3)
1-2
: LGTM: Appropriate imports for schema generation.The import statements are correct and necessary for the file's purpose. They bring in the required message types from the
andromeda_modules::distance
module and thewrite_api
macro fromcosmwasm_schema
for generating the API schema.
3-3
: LGTM: Correct main function declaration.The
main
function is correctly declared as the entry point for the schema generation script. It doesn't take any parameters or return a value, which is appropriate for this use case.
1-10
: Overall assessment: Well-structured and correct schema generation.This file correctly implements the API schema generation for the Andromeda Distance module. It aligns well with the PR objectives, defining the necessary message types (
InstantiateMsg
,QueryMsg
, andExecuteMsg
) as mentioned. The code is concise, focused, and follows best practices for CosmWasm schema generation.packages/andromeda-modules/src/distance.rs (1)
1-2
: LGTM: Imports are appropriate and concise.The import statements are well-structured and import only the necessary components from the Andromeda framework and Cosmos SDK. This promotes clean and efficient code organization.
contracts/modules/andromeda-distance/Cargo.toml (6)
1-5
: LGTM: Package metadata is well-defined.The package metadata is correctly specified:
- The name "andromeda-distance" follows the convention for Andromeda modules.
- The version (1.0.0) matches the PR objectives.
- The Rust edition (2021) is up-to-date.
- The Rust version (1.75.0) is specific and recent.
7-8
: LGTM: Library configuration is correct for a CosmWasm smart contract.The crate-type is correctly set to both "cdylib" and "rlib":
- "cdylib" is used for creating a dynamic library, which is necessary for WebAssembly smart contracts.
- "rlib" allows the crate to be used as a dependency by other Rust crates, enabling code reuse.
10-15
: LGTM: Features are well-defined and appropriate.The features section is correctly configured:
- The "backtraces" feature is properly tied to "cosmwasm-std/backtraces" for explicit tests.
- The "library" feature is correctly defined to disable exports when needed.
- The "testing" feature appropriately depends on "cw-multi-test" and "andromeda-testing".
18-29
: LGTM: Dependencies are correctly specified and organized.The dependencies section is well-structured:
- Workspace-level versions are used, ensuring consistency across the project.
- All necessary libraries for a CosmWasm smart contract in the Andromeda ecosystem are included.
- Target-specific dependencies for non-WASM32 targets are correctly marked as optional.
31-32
: LGTM: Dev-dependencies are appropriately specified.The dev-dependencies section is concise and correct:
- The "andromeda-app" dependency is properly sourced from the workspace.
- It's appropriate to have fewer dev-dependencies, as many testing dependencies are already included in the main dependencies section.
1-32
: Overall assessment: Cargo.toml is well-structured and complete.The Cargo.toml file for the andromeda-distance package is correctly configured and aligns well with the PR objectives. It includes all necessary sections:
- Package metadata with correct name, version, and Rust specifications.
- Library configuration suitable for a CosmWasm smart contract.
- Well-defined features for various use cases.
- Comprehensive list of dependencies, including workspace-level versions.
- Appropriate dev-dependencies.
The file structure and content demonstrate good practices for an Andromeda module.
contracts/modules/andromeda-distance/src/testing/mock.rs (2)
1-15
: LGTM: Imports and type definitions are appropriate.The imports and type definitions are well-structured and appropriate for a testing module in the Andromeda ecosystem. The use of
MockDeps
as a type alias is a good practice for CosmWasm contract testing.
1-49
: Overall, well-structured testing module with minor improvement suggestions.This file provides essential testing utilities for the Andromeda distance module. It includes mock setup, contract initialization, and a query function for distance calculation. The structure and implementation are generally good, following CosmWasm testing practices.
Key points:
- Proper mock environment setup in
proper_initialization
.- Convenient
query_distance
function for testing the main functionality.The suggested improvements (adding comments, enhancing error handling, and improving type safety) will further increase the robustness and maintainability of this testing module.
contracts/modules/andromeda-distance/src/testing/tests.rs (2)
1-2
: LGTM: Imports are appropriate for the tests.The import statements correctly bring in the necessary components from the mock module and the
andromeda_modules
crate, which are essential for the tests in this file.
4-7
: LGTM: Test function verifies proper initialization.The
test_instantiation
function correctly calls theproper_initialization
function to verify the module's initialization. This is a good basic test to ensure the module sets up correctly.contracts/modules/andromeda-distance/src/mock.rs (1)
1-10
: LGTM: Appropriate attributes and imports.The conditional compilation attribute and imports are well-structured and appropriate for a mock implementation used in testing.
contracts/modules/andromeda-distance/src/contract.rs (4)
17-39
: Initialization logic ininstantiate
function looks goodThe
instantiate
function correctly initializes the contract usingADOContract
, setting up the necessary contract metadata and ensuring proper configuration.
67-69
: Ensure all execute messages are properly handledThe
handle_execute
function matches onmsg
but only has a catch-all case delegating toADOContract::execute
. This might lead to unhandled messages if new variants are added toExecuteMsg
in the future.Consider explicitly matching on all variants of
ExecuteMsg
to ensure that all execute messages are properly handled and to make the code more maintainable.
85-86
: Ensure all query messages are properly handledIn the
query
function, the catch-all case delegates toADOContract::query
. Similar toexecute
, this might lead to unhandled messages if new variants are added toQueryMsg
.Consider explicitly matching on all variants of
QueryMsg
to ensure comprehensive handling of query messages.
107-110
: Migration logic inmigrate
function is properly handledThe
migrate
function correctly delegates migration toADOContract
, ensuring that contract upgrades are managed appropriately.
} | ||
} | ||
|
||
pub fn get_distance( |
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.
Adding a Manhattan distance query could be useful as well!
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.
Sounds great.
I added Manhattan Distance Query.
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
🧹 Outside diff range and nitpick comments (3)
CHANGELOG.md (3)
27-27
: LGTM! Consider adding more details about the IBC Distance ADO.The new entry is correctly formatted and placed in the "Added" section of the changelog. It accurately reflects the addition of the IBC Distance ADO as mentioned in the PR objectives.
To provide more context for users, consider expanding the entry with a brief description of the IBC Distance ADO's purpose or key features. For example:
- Added IBC Distance ADO [(#570)](https://github.com/andromedaprotocol/andromeda-core/pull/570) + Added IBC Distance ADO for calculating distances between points in a three-dimensional space [(#570)](https://github.com/andromedaprotocol/andromeda-core/pull/570)
Line range hint
1-70
: Consider adding a version number for the unreleased changes.The changelog is well-structured and follows the Keep a Changelog format. However, to improve version management and provide more context for users, consider adding a version number for the unreleased changes.
You could update the "Unreleased" header to include the expected version number. For example:
- ## Unreleased + ## [Unreleased] - 1.x.xReplace "1.x.x" with the appropriate version number based on your versioning strategy and the nature of the changes (e.g., 1.1.0 for new features, 1.0.1 for bug fixes, etc.).
27-27
: Align the changelog entry with the PR objectives.While the current entry correctly mentions the addition of the IBC Distance ADO, it doesn't fully capture the specific functionality described in the PR objectives.
Consider updating the changelog entry to more closely reflect the PR objectives. For example:
- Added IBC Distance ADO [(#570)](https://github.com/andromedaprotocol/andromeda-core/pull/570) + Added IBC Distance ADO for calculating distances between points in a three-dimensional space, including structures for coordinates and query messages [(#570)](https://github.com/andromedaprotocol/andromeda-core/pull/570)This change would provide users with a clearer understanding of the new functionality introduced by this ADO.
📜 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 (1)
- CHANGELOG.md (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
CHANGELOG.md (1)
Line range hint
1-70
: LGTM! Changelog update is appropriate with minor suggestions for improvement.The addition of the IBC Distance ADO to the changelog is correct and follows the established format. The suggestions provided in the previous comments will help improve clarity and version management:
- Consider adding more details about the IBC Distance ADO's functionality.
- Add a version number for the unreleased changes.
- Align the changelog entry more closely with the PR objectives.
These minor improvements will enhance the changelog's usefulness for users and contributors.
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.
This could be a great addition to the map/point ADOs added in #576!
Maybe being able to calculate the distance between two points using the Point
ADO or some points on the Graph
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.
I added Manhattan Distance Query
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: 7
🧹 Outside diff range and nitpick comments (3)
contracts/modules/andromeda-distance/src/testing/mock.rs (1)
17-28
: LGTM: Well-structured initialization function with a minor suggestion.The
proper_initialization
function provides a solid setup for testing. It correctly initializes mock dependencies, creates necessary messages, and asserts the result of instantiation.Consider adding a comment explaining why
owner
is set toNone
in theInstantiateMsg
. This would improve code clarity and prevent potential confusion in the future.contracts/modules/andromeda-distance/src/testing/tests.rs (1)
10-121
: Consider adding edge case tests.While the current test cases cover a good range of scenarios, consider adding tests for edge cases to further improve robustness.
Some suggestions for additional test cases:
- Test with very large coordinate values to check for potential overflow issues.
- Test with very small coordinate differences to ensure precision in near-zero distances.
- Test with negative z-coordinates for 3D points.
- Test with the maximum allowed decimal places to ensure correct rounding behavior.
Example:
// Test with very large coordinates let query_res = query_distance( deps.as_ref(), Coordinate { x_coordinate: 1e15, y_coordinate: 1e15, z_coordinate: None, }, Coordinate { x_coordinate: 1e15 + 1.0, y_coordinate: 1e15 + 1.0, z_coordinate: None, }, 5, ) .unwrap(); assert_approx_eq(&query_res, "1.41421", 1e-5);contracts/modules/andromeda-distance/src/mock.rs (1)
16-35
: Add documentation comments to public methodsTo enhance code readability and maintainability, consider adding documentation comments (
///
) to the public methods and functions, explaining their purpose, parameters, and return values.Also applies to: 37-51, 53-67, 75-83
📜 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 (7)
- CHANGELOG.md (1 hunks)
- contracts/modules/andromeda-distance/src/contract.rs (1 hunks)
- contracts/modules/andromeda-distance/src/mock.rs (1 hunks)
- contracts/modules/andromeda-distance/src/testing/mock.rs (1 hunks)
- contracts/modules/andromeda-distance/src/testing/tests.rs (1 hunks)
- packages/andromeda-modules/src/distance.rs (1 hunks)
- packages/andromeda-modules/src/lib.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/andromeda-modules/src/lib.rs
🧰 Additional context used
🔇 Additional comments (8)
contracts/modules/andromeda-distance/src/testing/mock.rs (2)
1-15
: LGTM: Imports and type alias are well-structured.The imports cover all necessary modules for testing, and the
MockDeps
type alias enhances code readability.
30-49
: Skipping comment generation.The existing review comment from the previous review is still valid and addresses the issues in this function.
contracts/modules/andromeda-distance/src/testing/tests.rs (3)
1-3
: LGTM: Imports are appropriate and concise.The import statements are well-structured and import the necessary components for the tests. They cover the mock functions, the
Coordinate
struct, and theContractError
enum, which are all used in the subsequent test functions.
5-8
: LGTM: Initialization test is concise and focused.The
test_instantiation
function effectively tests the proper initialization of the module. It's a simple yet crucial test that ensures the basic setup of the contract is correct.
10-121
: LGTM: Comprehensive test coverage for distance calculations.The
test_query_distance
function provides thorough testing for bothquery_distance
andquery_manhattan_distance
functions. It covers various scenarios including 2D and 3D coordinates, and includes error handling tests. The function name appropriately reflects its purpose, addressing the previous review comment.CHANGELOG.md (1)
28-28
: LGTM! Changelog entry correctly added.The new changelog entry for the Distance ADO is well-formatted and properly placed in the "Added" section. It follows the suggestion from the previous review and aligns with the PR objectives.
packages/andromeda-modules/src/distance.rs (1)
37-41
:⚠️ Potential issueVerify the usage of the
DistanceType
enumThe
DistanceType
enum is defined but not used within this module. Verify whether it is intended for future use or if it can be removed to clean up the code.Run the following script to check for usages of
DistanceType
in the codebase:✅ Verification successful
The
DistanceType
enum is actively used in other modules and serves its intended purpose. No removal is necessary.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for usages of `DistanceType` outside its definition. # Test: Find all occurrences of `DistanceType` excluding its own definition. Expect: Identifying if it's used elsewhere. rg --type rust 'DistanceType' | grep -v 'pub enum DistanceType'Length of output: 758
contracts/modules/andromeda-distance/src/mock.rs (1)
13-13
:⚠️ Potential issueMissing import of
ExecuteMsg
The macro
mock_ado!
is invoked withExecuteMsg
andQueryMsg
, butExecuteMsg
is not imported in this file. This will lead to a compilation error.Apply this diff to fix the missing import:
+ use andromeda_modules::distance::ExecuteMsg;
Likely invalid or redundant comment.
Motivation
The purpose of this ADO is to calculate the distance between 2 points on Graph.
Implementation
Testing
Unit test cases are added.
Version Changes
The version is set as 1.0.0
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation