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

feat: DateTime ADO that returns current time and day of week. #519

Merged

Conversation

mdjakovic0920
Copy link
Contributor

@mdjakovic0920 mdjakovic0920 commented Jul 22, 2024

Motivation

This ADO returns current date, time and day of week(for example: "Mon", "Tue", ...) specified to UTC timezone as a query result.
Default is UTC timezone.

Implementation

Instantiate

#[andr_instantiate]
#[cw_serde]
pub struct InstantiateMsg {}

Query

#[andr_query]
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(GetDateTimeResponse)]
    GetDateTime { 
        timezone: Timezone,
    },
}

#[cw_serde]
pub struct GetDateTimeResponse {
    pub day_of_week: String,
    pub date_time: String,
}

#[cw_serde]
pub enum Timezone {
    UtcMinus12,
    UtcMinus11,
    UtcMinus10,
    UtcMinus9_30,
    UtcMinus9,
    UtcMinus8,
    UtcMinus7,
    UtcMinus6,
    UtcMinus5,
    UtcMinus4,
    UtcMinus3,
    UtcMinus2_30,
    UtcMinus2,
    UtcMinus1,
    Utc,
    UtcPlus1,
    UtcPlus2,
    UtcPlus3,
    UtcPlus3_30,
    UtcPlus4,
    UtcPlus4_30,
    UtcPlus5,
    UtcPlus5_45,
    UtcPlus5_30,
    UtcPlus6,
    UtcPlus6_30,
    UtcPlus7,
    UtcPlus8,
    UtcPlus8_45,
    UtcPlus9,
    UtcPlus9_30,
    UtcPlus10,
    UtcPlus10_30,
    UtcPlus11,
    UtcPlus12,
    UtcPlus12_45,
    UtcPlus13,
    UtcPlus14,
}

Testing

Unit test cases are added to testing.

Version Changes

Version is set as 1.0.0

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new date and time module that allows querying and managing date and time information based on various time zones.
    • Added functionalities for smart contract management, including instantiation, execution, querying, and migration.
    • Documented the integration of the "Date Time ADO" feature in the CHANGELOG.
  • Bug Fixes

    • Improved error handling for timestamp calculations.
  • Documentation

    • Updated CHANGELOG to reflect recent feature additions.
  • Chores

    • Established foundational module structure for better organization and future enhancements.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The recent updates enhance the Andromeda Date Time module by introducing a new "Date Time ADO," establishing a foundational Cargo.toml for dependency management, and implementing essential smart contract functionalities for date and time operations. These changes improve usability and facilitate effective testing, bolstering the module's functionality within the Andromeda framework.

Changes

File(s) Change Summary
.../andromeda-date-time/Cargo.toml Established foundational configuration, defined crate types, features, and dependencies for the library.
.../andromeda-date-time/src/contract.rs Implemented smart contract functions: instantiate, execute, query, and migrate for date/time management.
CHANGELOG.md Documented the addition of the "Date Time ADO" feature in the changelog.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract
    participant API

    User->>Contract: Instantiate contract
    Contract->>User: Confirmation response
    User->>API: Request date/time (with timezone)
    API->>Contract: Query date/time
    Contract->>API: Return date/time response
    API->>User: Send date/time information
Loading

🐰 In the meadow, the rabbit hops,
With new features, the coding stops!
Date and time, now easy to find,
With mocks and tests, all neatly aligned.
Hooray for Rust, oh what a delight,
In the Andromeda glow, the future is bright! 🌟

Tip

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73c76db and 721ea79.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (11)
  • contracts/modules/andromeda-date-time/.cargo/config (1 hunks)
  • contracts/modules/andromeda-date-time/Cargo.toml (1 hunks)
  • contracts/modules/andromeda-date-time/examples/schema.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/contract.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/lib.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/mock.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/mock.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/mod.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/tests.rs (1 hunks)
  • packages/andromeda-modules/src/date_time.rs (1 hunks)
  • packages/andromeda-modules/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • contracts/modules/andromeda-date-time/.cargo/config
  • contracts/modules/andromeda-date-time/examples/schema.rs
Additional comments not posted (37)
contracts/modules/andromeda-date-time/src/testing/mod.rs (2)

1-1: LGTM! Module declaration for mock.

The mock module is correctly declared.


2-2: LGTM! Module declaration for tests.

The tests module is correctly declared.

packages/andromeda-modules/src/lib.rs (1)

4-4: LGTM! Module declaration for date_time.

The date_time module is correctly declared.

contracts/modules/andromeda-date-time/src/lib.rs (3)

1-1: LGTM! Module declaration for contract.

The contract module is correctly declared.


2-3: LGTM! Conditional module declaration for testing.

The testing module is correctly declared with the conditional compilation attribute.


5-6: LGTM! Conditional module declaration for mock.

The mock module is correctly declared with the conditional compilation attribute.

contracts/modules/andromeda-date-time/Cargo.toml (6)

1-5: Package metadata looks correct.

The package name, version, edition, and rust-version are specified correctly.


7-8: Library configuration is correct.

The crate types cdylib and rlib are correctly specified.


10-15: Feature flags are correctly specified.

The feature flags backtraces, library, and testing are well-defined and useful.


18-25: Dependencies are correctly specified.

The dependencies are well-defined and aligned with the project's requirements.


27-27: Additional dependency is correct.

The chrono crate is correctly specified for date and time operations.


29-34: Target-specific and dev-dependencies are correctly specified.

The target-specific dependencies cw-multi-test and andromeda-testing, and the dev-dependency andromeda-app are well-defined and useful for testing.

packages/andromeda-modules/src/date_time.rs (7)

1-4: Imports are correctly specified.

The imports from andromeda_std, cosmwasm_schema, and derive macros are necessary and correctly specified.


6-8: InstantiateMsg struct is correctly defined.

The InstantiateMsg struct is correctly defined and annotated for instantiation.


10-12: ExecuteMsg enum is correctly defined.

The ExecuteMsg enum is correctly defined and annotated for execution messages.


14-22: QueryMsg enum is correctly defined.

The QueryMsg enum is correctly defined and annotated for query messages. The GetDateTime variant allows querying the current date and time with a specified timezone.


24-28: GetDateTimeResponse struct is correctly defined.

The GetDateTimeResponse struct is correctly defined and annotated for the response of the GetDateTime query.


30-58: Timezone enum is correctly defined.

The Timezone enum is correctly defined and annotated for specifying timezones. The variants cover a comprehensive range of UTC offsets.


1-59: Overall file structure is correct.

The structure and organization of the file are clean, maintainable, and follow Rust conventions.

contracts/modules/andromeda-date-time/src/testing/mock.rs (5)

1-13: Imports are correctly specified.

The imports from andromeda_modules::date_time, andromeda_std, cosmwasm_std, and crate-specific contract functions are necessary and correctly specified for mock testing.


15-15: MockDeps type alias is correctly defined.

The MockDeps type alias is correctly defined and useful for simplifying mock dependency declarations.


17-28: proper_initialization function is correctly defined.

The proper_initialization function initializes mock dependencies and instantiates the contract with the necessary fields.


30-36: query_date_time function is correctly defined.

The query_date_time function queries the date and time with a specified timezone and handles the response appropriately.


1-36: Overall file structure is correct.

The structure and organization of the file are clean, maintainable, and follow Rust conventions.

contracts/modules/andromeda-date-time/src/testing/tests.rs (2)

6-9: LGTM!

The test_instantiation test case correctly calls the proper_initialization function to test the instantiation logic.


11-51: LGTM! But verify the correctness of the query_date_time function.

The test_query_date_time test case covers different timezones and the assertions are correct.

However, ensure that the query_date_time function correctly handles all timezones.

contracts/modules/andromeda-date-time/src/mock.rs (5)

17-36: LGTM!

The MockDateTime::instantiate function correctly instantiates the mock DateTime contract with the provided parameters.


38-42: LGTM!

The MockDateTime::query_date_time function correctly queries the mock DateTime contract for the current date and time in the specified timezone.


45-48: LGTM!

The mock_andromeda_date_time function correctly returns a boxed Contract for the DateTime ADO.


50-57: LGTM!

The mock_date_time_instantiate_msg function correctly constructs the InstantiateMsg for the DateTime ADO.


14-14: LGTM!

The mock_ado! macro correctly generates mock implementations for the DateTime ADO.

contracts/modules/andromeda-date-time/src/contract.rs (6)

23-44: LGTM!

The instantiate function correctly instantiates the DateTime ADO contract with the provided parameters.


47-60: LGTM!

The execute function correctly handles the execution of the specified message for the DateTime ADO contract.


62-80: LGTM!

The handle_execute function correctly handles the execution logic for the DateTime ADO contract.


83-87: LGTM!

The query function correctly handles the query messages for the DateTime ADO contract and returns the correct response.


90-123: LGTM!

The get_date_time function correctly calculates the current date and time in the specified timezone and returns the correct response.


127-129: LGTM!

The migrate function correctly handles the migration logic for the DateTime ADO contract.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 721ea79 and 9e6a1a5.

Files selected for processing (4)
  • contracts/modules/andromeda-date-time/src/contract.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/mock.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/tests.rs (1 hunks)
  • packages/andromeda-modules/src/date_time.rs (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • contracts/modules/andromeda-date-time/src/contract.rs
  • contracts/modules/andromeda-date-time/src/testing/mock.rs
  • contracts/modules/andromeda-date-time/src/testing/tests.rs
  • packages/andromeda-modules/src/date_time.rs

@mdjakovic0920 mdjakovic0920 changed the title feat: DateTime ADO that returns current time and day pf week. feat: DateTime ADO that returns current time and day of week. Jul 24, 2024
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e6a1a5 and d0f974e.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (9)
  • contracts/modules/andromeda-date-time/examples/schema.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/contract.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/lib.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/mock.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/mock.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/mod.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/tests.rs (1 hunks)
  • packages/andromeda-modules/src/date_time.rs (1 hunks)
  • packages/andromeda-modules/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/modules/andromeda-date-time/src/testing/mod.rs
Additional comments not posted (23)
packages/andromeda-modules/src/lib.rs (1)

2-2: New module added: date_time.

The addition of the date_time module expands the library's capabilities for handling date and time operations.

contracts/modules/andromeda-date-time/src/lib.rs (3)

1-1: New module added: contract.

The contract module is introduced, likely containing the core contract logic for date and time operations.


2-3: New module added: testing.

The testing module is introduced, facilitating unit tests for the date and time contract.


5-6: New module added: mock.

The mock module is introduced, enabling mock testing for the date and time contract.

contracts/modules/andromeda-date-time/examples/schema.rs (1)

1-10: Schema generation example added.

The example demonstrates how to generate API schema for InstantiateMsg, QueryMsg, and ExecuteMsg using cosmwasm_schema::write_api.

packages/andromeda-modules/src/date_time.rs (5)

4-6: LGTM!

The InstantiateMsg struct is correctly defined and follows best practices.


8-10: LGTM!

The ExecuteMsg enum is correctly defined. Having it empty is acceptable if no execution messages are needed at this time.


12-18: LGTM!

The QueryMsg enum is correctly defined with a well-structured GetDateTime variant to handle timezone queries.


20-24: LGTM!

The GetDateTimeResponse struct is correctly defined and follows best practices.


26-55: LGTM!

The Timezone enum is correctly defined and provides comprehensive timezone support with offsets from -12 to +14.

contracts/modules/andromeda-date-time/src/testing/mock.rs (2)

17-28: LGTM!

The proper_initialization function is correctly defined and follows best practices for mock initialization.


30-39: LGTM!

The query_date_time function is correctly defined and handles the query result appropriately.

contracts/modules/andromeda-date-time/src/testing/tests.rs (2)

4-7: LGTM!

The test_instantiation function is correctly defined and follows best practices for testing initialization.


9-51: LGTM!

The test_query_date_time function is correctly defined and covers multiple timezone scenarios.

contracts/modules/andromeda-date-time/src/mock.rs (4)

13-14: LGTM!

The struct MockDateTime and the mock_ado! macro usage look good.


38-42: LGTM!

The function query_date_time looks good and correctly constructs and sends the query message.


45-48: LGTM!

The function mock_andromeda_date_time looks good and correctly creates and returns a new mock contract.


50-58: LGTM!

The function mock_date_time_instantiate_msg looks good and correctly creates and returns the instantiation message.

contracts/modules/andromeda-date-time/src/contract.rs (5)

19-41: LGTM!

The function instantiate looks good and correctly initializes the contract using the provided instantiation message.


43-57: LGTM!

The function execute looks good and correctly handles contract execution messages.


59-77: LGTM!

The function handle_execute looks good and correctly handles the execution logic.


79-84: LGTM!

The function query looks good and correctly handles contract query messages.


123-126: LGTM!

The function migrate looks good and correctly handles contract migration.

contracts/modules/andromeda-date-time/src/contract.rs Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0f974e and 9de45bd.

Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • contracts/modules/andromeda-date-time/src/contract.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • contracts/modules/andromeda-date-time/src/contract.rs
Additional comments not posted (1)
CHANGELOG.md (1)

19-19: LGTM! The changelog entry for "Date Time ADO" is well-formatted.

The entry follows the existing format and includes a reference to the pull request.

@mdjakovic0920 mdjakovic0920 requested a review from joemonem August 5, 2024 15:01
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.

Aren't there timezones that have half hour differences? These wouldn't be covered by this implementation

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9de45bd and f35c8b1.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (4)
  • DEADJOE (1 hunks)
  • contracts/modules/andromeda-date-time/src/contract.rs (1 hunks)
  • contracts/modules/andromeda-date-time/src/testing/tests.rs (1 hunks)
  • packages/andromeda-modules/src/date_time.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • DEADJOE
Additional comments not posted (12)
packages/andromeda-modules/src/date_time.rs (4)

1-6: LGTM!

The imports and InstantiateMsg struct are correctly defined.

The code changes are approved.


8-18: LGTM!

The ExecuteMsg and QueryMsg enums are correctly defined.

The code changes are approved.


20-24: LGTM!

The GetDateTimeResponse struct is correctly defined.

The code changes are approved.


26-66: LGTM!

The Timezone enum is correctly defined with a comprehensive range of UTC offsets.

The code changes are approved.

contracts/modules/andromeda-date-time/src/testing/tests.rs (2)

4-7: LGTM!

The test_instantiation function is correctly defined.

The code changes are approved.


9-81: LGTM!

The test_query_date_time function is correctly defined and tests various timezone offsets.

The code changes are approved.

contracts/modules/andromeda-date-time/src/contract.rs (6)

19-41: LGTM!

The instantiate function is correctly defined and initializes the contract.

The code changes are approved.


43-57: LGTM!

The execute function is correctly defined and handles execution messages.

The code changes are approved.


59-77: LGTM!

The handle_execute function is correctly defined and processes execution messages.

The code changes are approved.


79-84: LGTM!

The query function is correctly defined and handles query messages.

The code changes are approved.


87-134: LGTM!

The get_date_time function is correctly defined and includes appropriate error handling.

The code changes are approved.


136-139: LGTM!

The migrate function is correctly defined and handles contract migration.

The code changes are approved.

@mdjakovic0920
Copy link
Contributor Author

Aren't there timezones that have half hour differences? These wouldn't be covered by this implementation

Added half and quarter-hour time zone options.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f35c8b1 and 2489d3c.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

DEADJOE Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2489d3c and 816d43c.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 816d43c and b75b849.

Files selected for processing (2)
  • contracts/modules/andromeda-date-time/Cargo.toml (1 hunks)
  • contracts/modules/andromeda-date-time/src/contract.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • contracts/modules/andromeda-date-time/Cargo.toml
Files skipped from review as they are similar to previous changes (1)
  • contracts/modules/andromeda-date-time/src/contract.rs

@mdjakovic0920
Copy link
Contributor Author

@crnbarr93
Is it OK to merge?

@crnbarr93 crnbarr93 merged commit f999257 into andromedaprotocol:development Sep 3, 2024
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 16, 2024
@mdjakovic0920 mdjakovic0920 deleted the mdjakovic/date-time branch November 28, 2024 15:05
@coderabbitai coderabbitai bot mentioned this pull request Dec 10, 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