Skip to content
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

[IBC / Release 1] feat: IBC Registry #566

Merged
merged 13 commits into from
Sep 19, 2024
Merged

Conversation

joemonem
Copy link
Contributor

@joemonem joemonem commented Sep 17, 2024

Motivation

Part of [Q4 | RC1] IBC / Release 1
This OS contract, ibc-registry, stores a mapping of String to DenomInfo with the ability to query the mapping.

Implementation

service_address is set by the user during Instantiation; It's the only address (alongside the contract owner) that can call StoreDenomInfo.
The structs are as follows:

pub struct DenomInfo {
    pub path: String,
    pub base_denom: String,
}
pub struct IBCDenomInfo {
    pub denom: String,
    pub denom_info: DenomInfo,
}

There's only one Map in state:

pub const REGISTRY: Map<String, DenomInfo> = Map::new("registry");

The two queries are:

    #[returns(DenomInfoResponse)]
    DenomInfo { denom: String },
    #[returns(AllDenomInfoResponse)]
    AllDenomInfo {
        limit: Option<u64>, // Defaults to 100,
        start_after: Option<u64>,
    },

Testing

Unit test that tests validate_denom.
Integration test that goes through instantiation, execution, and querying the results. Also tests authorization.

Version Changes

Should this be set as 2.0.0 or 1.0.0?

Notes

Should we remove owner's ability to call StoreDenomInfo?

Future work

Needs a README file

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced the IBC (Inter-Blockchain Communication) registry for managing denomination information.
    • Enhanced interoperability with the addition of the IBC Registry ADO.
    • Implemented new error handling capabilities for better clarity in denomination validation.
  • Bug Fixes

    • Enhanced error messages for invalid denominations to include more detailed information.
  • Testing Enhancements

    • Added integration tests for the IBC registry, ensuring proper functionality for storing and querying denominations.
    • Introduced a mock implementation for easier testing of the IBC Registry contract.
    • Expanded the testing framework to include new modules and functionalities related to the IBC registry.
  • Documentation

    • Updated configuration files to streamline build and testing processes.

Copy link
Contributor

coderabbitai bot commented Sep 17, 2024

Walkthrough

This pull request introduces multiple enhancements to the Andromeda project, primarily focusing on the implementation of the IBC Registry ADO. Key changes include the addition of a new contract for managing IBC denomination information, updates to error handling structures, and the introduction of integration tests to ensure the functionality of the new features. The modifications also encompass configuration improvements for easier project management and testing capabilities.

Changes

File Path Change Summary
contracts/os/andromeda-ibc-registry/.cargo/config Added command aliases for building, testing, and schema generation.
contracts/os/andromeda-ibc-registry/Cargo.toml Defined package metadata, dependencies, and features for the andromeda-ibc-registry package.
contracts/os/andromeda-ibc-registry/src/contract.rs Implemented core functionalities for the IBC registry, including instantiation, execution, and querying.
contracts/os/andromeda-ibc-registry/src/lib.rs Added public modules for contract, state, and testing, enhancing modularity.
contracts/os/andromeda-ibc-registry/src/mock.rs Developed a mock implementation for testing the IBC Registry contract.
contracts/os/andromeda-ibc-registry/src/state.rs Introduced a persistent storage map for managing denomination information.
contracts/os/andromeda-ibc-registry/src/testing/mod.rs Added a new module for unit and integration tests related to the IBC registry.
contracts/os/andromeda-ibc-registry/src/testing/tests.rs Implemented a unit test for the instantiate function of the IBC Registry.
packages/andromeda-data-storage/src/primitive.rs Modified error handling for empty denomination validation to include a message field.
packages/std/src/error.rs Introduced new error variants and modified existing ones for better error reporting.
packages/std/src/os/ibc_registry.rs Added structures and functions for managing IBC denominations and processing AMP packets.
packages/std/src/os/mod.rs Introduced a new public module for the IBC registry.
tests-integration/Cargo.toml Added dependency for andromeda-ibc-registry with testing feature for integration tests.
tests-integration/tests/ibc_registry.rs Implemented integration tests for storing and querying denomination information in the IBC registry.
tests-integration/tests/mod.rs Added a new test module for the IBC registry.

Possibly related PRs

Suggested labels

ci: skip-changelog

🐰 In the garden, changes bloom,
New errors handled, dispelling gloom.
IBC registry, a wondrous feat,
With tests to ensure, our code's complete!
Hops of joy, we celebrate,
In Andromeda's world, we innovate! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6092b71 and 893541f.

Files selected for processing (4)
  • contracts/os/andromeda-ibc-registry/src/contract.rs (1 hunks)
  • packages/std/src/os/economics.rs (0 hunks)
  • packages/std/src/os/ibc_registry.rs (1 hunks)
  • tests-integration/tests/ibc_registry.rs (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • packages/std/src/os/economics.rs
Files skipped from review as they are similar to previous changes (3)
  • contracts/os/andromeda-ibc-registry/src/contract.rs
  • packages/std/src/os/ibc_registry.rs
  • tests-integration/tests/ibc_registry.rs

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (2)
contracts/os/andromeda-ibc-registry/src/testing/tests.rs (1)

11-23: Great start with the instantiation test!

The proper_initialization test function provides good coverage for the basic instantiation flow of the contract. It correctly sets up the mock environment, constructs the InstantiateMsg, and validates that the instantiate function returns no messages on successful initialization.

To further improve the test coverage, consider adding more test cases to handle edge cases and error scenarios, such as:

  • Instantiating with an invalid kernel_address or service_address.
  • Instantiating with a non-empty owner field.
  • Checking the state of the contract after instantiation to ensure the parameters are set correctly.

These additional tests will help ensure the robustness of the instantiation logic and catch potential issues early in the development process.

tests-integration/tests/ibc_registry.rs (1)

123-144: The authorization test looks good, but consider enabling the owner test.

The test for the unauthorized user is implemented correctly. It attempts to execute the store method with an unauthorized user wallet and verifies that an Unauthorized error is returned.

However, the test for the owner's authorization is currently commented out. It's important to test both the positive and negative cases for authorization.

Consider enabling the owner authorization test by uncommenting the code:

// Owner doesn't error
let err: ContractError = ibc_registry
    .execute_execute_store_denom_info(&mut router, owner.clone(), None, vec![ibc_denom_info])
    .unwrap_err()
    .downcast()
    .unwrap();
assert_eq!(err, ContractError::Unauthorized {});

This test will ensure that the owner can successfully execute the store method without encountering an Unauthorized error.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a0e9bb2 and 160c590.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (17)
  • contracts/data-storage/andromeda-primitive/src/testing/tests.rs (1 hunks)
  • contracts/os/andromeda-ibc-registry/.cargo/config (1 hunks)
  • contracts/os/andromeda-ibc-registry/Cargo.toml (1 hunks)
  • contracts/os/andromeda-ibc-registry/examples/schema.rs (1 hunks)
  • contracts/os/andromeda-ibc-registry/src/contract.rs (1 hunks)
  • contracts/os/andromeda-ibc-registry/src/lib.rs (1 hunks)
  • contracts/os/andromeda-ibc-registry/src/mock.rs (1 hunks)
  • contracts/os/andromeda-ibc-registry/src/state.rs (1 hunks)
  • contracts/os/andromeda-ibc-registry/src/testing/mod.rs (1 hunks)
  • contracts/os/andromeda-ibc-registry/src/testing/tests.rs (1 hunks)
  • packages/andromeda-data-storage/src/primitive.rs (2 hunks)
  • packages/std/src/error.rs (3 hunks)
  • packages/std/src/os/ibc_registry.rs (1 hunks)
  • packages/std/src/os/mod.rs (1 hunks)
  • tests-integration/Cargo.toml (1 hunks)
  • tests-integration/tests/ibc_registry.rs (1 hunks)
  • tests-integration/tests/mod.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/os/andromeda-ibc-registry/src/testing/mod.rs
Additional comments not posted (49)
packages/std/src/os/mod.rs (1)

4-4: Approve the addition of the ibc_registry module.

The new public module follows the existing naming convention and does not appear to impact the other modules in the file.

However, to better understand the purpose and scope of this module, please provide more information about its functionality and how it relates to inter-blockchain communication (IBC). This will help in conducting a more thorough review and identifying any potential issues or dependencies.

contracts/os/andromeda-ibc-registry/.cargo/config (3)

2-2: LGTM!

The wasm alias is a useful shorthand for building the project for the WebAssembly target with optimizations. This will help streamline the development workflow.


3-3: LGTM!

The unit-test alias provides a convenient way to run unit tests for the library components. This will facilitate a more efficient testing workflow.


4-4: LGTM!

The schema alias makes it easier to execute the specific example related to schema generation or manipulation without needing to remember the full command.

contracts/os/andromeda-ibc-registry/src/state.rs (3)

1-1: LGTM!

The import statement is necessary and correct.


2-2: LGTM!

The import statement is necessary and correct.


4-4: LGTM!

The REGISTRY constant is defined correctly using the Map type from cw_storage_plus. The chosen namespace "registry" is appropriate for the purpose of this map.

contracts/os/andromeda-ibc-registry/src/lib.rs (4)

1-1: LGTM!

The contract module is declared correctly as a public module, which is appropriate for encapsulating the core contract logic.


2-2: LGTM!

The state module is declared correctly as a public module, which is appropriate for encapsulating the state management logic of the contract.


3-4: LGTM!

The testing module is declared correctly as a public module with conditional compilation based on the test configuration. This is a good practice for encapsulating testing utilities and ensuring they are only included when running tests.


6-7: LGTM!

The mock module is declared correctly as a public module with conditional compilation based on the target architecture and the testing feature. This is a good practice for encapsulating mocking utilities and ensuring they are only included when running tests in a non-wasm32 environment.

contracts/os/andromeda-ibc-registry/examples/schema.rs (1)

1-10: LGTM!

The schema.rs file correctly defines the API schema for the Andromeda IBC Registry module. It follows the expected structure and uses the write_api! macro appropriately to generate the necessary API endpoints for instantiation, querying, and execution.

The imports from the andromeda_std library are correct and the message types are used as expected in the write_api! macro.

This file will facilitate interaction with the IBC Registry by clearly defining how to instantiate the contract, query its state, and execute transactions.

tests-integration/tests/mod.rs (1)

10-12: LGTM!

The addition of the ibc_registry test module is a valuable enhancement to the testing framework. It demonstrates a commitment to ensuring the correctness and reliability of the IBC registry functionality.

contracts/os/andromeda-ibc-registry/Cargo.toml (5)

1-11: LGTM!

The [package] section correctly defines the package's metadata, including the name, version, edition, and Rust version. The exclusion list is also properly configured to exclude the contract.wasm and hash.txt files, which are considered artifacts not meant for source code publication.


15-16: LGTM!

The [lib] section correctly specifies the crate types as cdylib and rlib, indicating that the crate can be compiled as both a dynamic library and a static library. This configuration is suitable for a library crate that can be used in both dynamic and static linking contexts.


18-23: LGTM!

The [features] section correctly defines optional features for the package, including backtraces, library, and testing. These features provide flexibility in configuring the package for different use cases and testing scenarios.

  • The backtraces feature enables backtraces for more explicit tests.
  • The library feature disables all instantiate/execute/query exports.
  • The testing feature includes dependencies on cw-multi-test and andromeda-testing, which are essential for running tests in a multi-contract environment.

25-34: LGTM!

The [dependencies] section correctly lists the package's dependencies, including several workspace dependencies that are crucial for building CosmWasm smart contracts and leveraging the Andromeda ecosystem.

  • The workspace dependencies include cosmwasm-std, cosmwasm-schema, cw-storage-plus, cw-utils, and cw20, which are essential for building CosmWasm smart contracts.
  • The andromeda-std dependency includes a specific feature for rates, indicating a reliance on Andromeda's rate functionality.
  • The andromeda-data-storage dependency is also included, suggesting integration with Andromeda's data storage capabilities.

37-39: LGTM!

The [target.'cfg(not(target_arch = "wasm32"))'.dependencies] section correctly lists optional dependencies for non-WASM targets, including cw-multi-test and andromeda-testing. These dependencies enhance the testing capabilities of the package, particularly for running tests in a multi-contract environment.

contracts/os/andromeda-ibc-registry/src/mock.rs (6)

1-14: LGTM!

The conditional compilation directive and imports are appropriate for the mock implementation.


15-16: LGTM!

The MockIbcRegistry struct and mock_ado macro usage are appropriate for the mock implementation.


18-72: LGTM!

The MockIbcRegistry implementation provides a clean and well-structured set of methods for instantiating, executing, and querying the mock contract. The usage of andromeda_testing and cosmwasm_std libraries is appropriate.


74-77: LGTM!

The mock_andromeda_ibc_registry function correctly creates and returns a boxed ContractWrapper as a mock contract.


79-89: LGTM!

The mock_ibc_registry_instantiate_msg function correctly creates and returns an InstantiateMsg struct with the provided parameters.


91-93: LGTM!

The mock_execute_store_denom_info_msg function correctly creates and returns an ExecuteMsg::StoreDenomInfo variant with the provided ibc_denom_info.

packages/std/src/os/ibc_registry.rs (6)

10-15: LGTM!

The InstantiateMsg struct is well-defined with appropriate fields and attributes.


16-20: LGTM!

The DenomInfo struct is well-defined with appropriate fields and attributes.


21-25: LGTM!

The IBCDenomInfo struct is well-defined with appropriate fields and attributes.


27-36: LGTM!

The ExecuteMsg enum is well-defined with appropriate variants and attributes.


38-58: LGTM!

The verify_denom function correctly validates the denom parameter and returns appropriate errors if the checks fail.


82-119: LGTM!

The test_validate_denom function thoroughly tests the verify_denom function with various input scenarios and asserts the expected behavior.

tests-integration/Cargo.toml (1)

104-106: LGTM!

The addition of the andromeda-ibc-registry dependency with the "testing" feature is a positive change that aligns with the PR objective of introducing the IBC registry contract. This will enable the integration tests to cover scenarios involving the IBC registry functionality, enhancing the overall testing capabilities of the project.

tests-integration/tests/ibc_registry.rs (4)

1-13: LGTM!

The imports are correct and necessary for the integration test.


14-57: LGTM!

The mock environment setup is comprehensive and follows the necessary steps to initialize the app, create wallets, deploy contracts, and instantiate the IBC registry app component. The code is well-structured and easy to understand.


59-86: LGTM!

The test for storing and querying denom info is implemented correctly. It creates an IBCDenomInfo instance, executes the store method, and verifies the stored denom info using the query method. The assertions ensure that the stored denom info matches the expected values.


88-121: LGTM!

The test for storing an additional denom info and querying all denom info is implemented correctly. It creates another IBCDenomInfo instance, executes the store method, and verifies all stored denom info using the query method. The assertions ensure that the retrieved denom info matches the expected values, including both previously stored denom info instances.

contracts/os/andromeda-ibc-registry/src/contract.rs (7)

27-63: LGTM!

The instantiate function correctly initializes the contract by:

  • Using the ADOContract to handle the instantiation process.
  • Saving the service address and granting it the STORE_DENOM_INFO permission.
  • Returning a response with the service address as an attribute.

65-79: LGTM!

The execute function correctly handles incoming messages by:

  • Creating an ExecuteContext from the provided parameters.
  • Matching on the message type and calling the appropriate handler function.
  • For AMPReceive messages, calling the execute_amp_receive function of the ADOContract.
  • For other messages, calling the handle_execute function.

81-103: LGTM!

The handle_execute function correctly processes various execution messages by:

  • Extracting the action from the message.
  • Calling the call_action function to handle the message and get an action_response.
  • Matching on the message type and calling the appropriate handler function.
  • For StoreDenomInfo messages, calling the execute_store_denom_info function.
  • For other messages, calling the execute function of the ADOContract.
  • Returning a response with the action_response added to it.

105-143: LGTM!

The execute_store_denom_info function correctly handles the StoreDenomInfo action by:

  • Verifying that the sender has the required permissions to execute the action.
  • Ensuring that the ibc_denom_info vector is not empty.
  • Iterating over the ibc_denom_info vector and:
    • Verifying the denomination using the verify_denom function.
    • Checking for duplicates using a HashSet.
    • Storing the denomination information securely using the REGISTRY map.
  • Returning a response with the action and sender as attributes.

145-153: LGTM!

The query function correctly handles querying the contract state by:

  • Matching on the query message type.
  • For DenomInfo messages, calling the get_denom_info function.
  • For AllDenomInfo messages, calling the get_all_denom_info function.
  • Encoding the result of the query function using encode_binary.

155-161: LGTM!

The get_denom_info function correctly retrieves information for a specific denomination by:

  • Loading the denomination information from the REGISTRY map using the provided denom key.
  • Returning the denomination information wrapped in a DenomInfoResponse.

163-189: LGTM!

The get_all_denom_info function correctly retrieves all denominations with pagination support by:

  • Converting the start_after parameter into a Bound for pagination.
  • Setting the limit to the provided value or defaulting to 100 if none is provided.
  • Querying the REGISTRY map with pagination using the range method.
  • Collecting the results into a vector of DenomInfo.
  • Returning the vector of DenomInfo wrapped in an AllDenomInfoResponse.
packages/andromeda-data-storage/src/primitive.rs (2)

65-68: LGTM!

The change improves the clarity and consistency of the error handling by explicitly setting the msg field to None in the ContractError::InvalidDenom variant. This change does not introduce any logical or functional issues.


305-305: Test case updated correctly.

The change in the test case correctly updates the expected error to include the msg: None field. This maintains consistency with the change made in the validate method and ensures that the test case correctly verifies the error handling behavior.

contracts/data-storage/andromeda-primitive/src/testing/tests.rs (1)

245-245: Approved: The change enhances error handling in the test suite.

The modification introduces a msg field to the ContractError::InvalidDenom variant, which is explicitly set to None. This change may improve the test suite's ability to handle and report errors related to invalid denominations by allowing for more detailed error messages or logging in the future.

While the change does not directly affect the contract's core functionality, it lays the groundwork for better error handling and reporting within the test suite.

packages/std/src/error.rs (4)

55-56: LGTM!

The new EmptyDenom error variant is a valid addition to handle scenarios where a denomination is empty or missing.


58-59: LGTM!

The new NoDenomInfoProvided error variant is a valid addition to handle scenarios where the required denomination information is not provided.


444-445: LGTM!

The new DuplicateDenoms error variant is a valid addition to handle scenarios where duplicate denominations are encountered. The associated denom field allows specifying the problematic denomination for better error reporting.


464-464: LGTM!

The modification to the InvalidDenom error variant to include an optional msg field is a valid change. It allows providing additional context about the invalid denomination while maintaining backward compatibility.

@crnbarr93
Copy link
Contributor

Should this be set as 2.0.0 or 1.0.0?

1.0.0

Should we remove owner's ability to call StoreDenomInfo?

I think this is fine

Copy link
Contributor

@crnbarr93 crnbarr93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a small integration test change

let service_address = andr.get_wallet("service_address");
let user1 = andr.get_wallet("user1");

let app_code_id = andr.get_code_id(&mut router, "app-contract");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan is to have this be an OS module under the key ibc-registry, we should add it as such for more realistic tests.

@joemonem joemonem requested a review from crnbarr93 September 18, 2024 05:46
Copy link
Contributor

@crnbarr93 crnbarr93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@joemonem joemonem requested a review from SlayerAnsh September 19, 2024 07:58
@crnbarr93 crnbarr93 merged commit ca41a84 into development Sep 19, 2024
9 checks passed
@crnbarr93 crnbarr93 deleted the joe/ibc-registry branch September 19, 2024 09:44
@coderabbitai coderabbitai bot mentioned this pull request Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants