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

[Law-stone] Remove instantiate context state and use reply payload #607

Merged
merged 3 commits into from
Aug 7, 2024

Conversation

bdeneux
Copy link
Contributor

@bdeneux bdeneux commented Aug 7, 2024

On the law-stone contract, replace current instantiation context state by the new payload on Reply sub message introduced in cosmwasm v2.0.0, following @amimart suggestion

Summary by CodeRabbit

  • New Features

    • Enhanced clarity and efficiency in the smart contract's instantiation and reply message handling.
  • Bug Fixes

    • Improved error handling for string conversion in reply messages.
  • Tests

    • Updated tests to ensure correct payload handling and validate error management for invalid data.

Copy link

coderabbitai bot commented Aug 7, 2024

Walkthrough

The changes streamline the smart contract's handling of instantiation and reply processes in Rust. The removal of the INSTANTIATE_CONTEXT constant simplifies state management, while direct payload conversion enhances clarity and error handling. Tests have been updated accordingly, ensuring robustness and correctness in the new logic. Overall, these modifications improve the efficiency, clarity, and reliability of the contract's operations.

Changes

Files Change Summary
contracts/axone-law-stone/src/contract.rs Simplified instantiation by removing INSTANTIATE_CONTEXT, enhancing response creation and error handling in the reply logic. Tests updated to reflect changes.
contracts/axone-law-stone/src/state.rs Removed declaration of constant INSTANTIATE_CONTEXT, indicating a refactor in instantiation context management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract
    participant Storage

    User->>Contract: Instantiate Contract
    Contract->>Storage: Store Address
    Contract-->>User: Send Submessage
    User->>Contract: Reply with Payload
    Contract->>Storage: Process Payload
    Contract-->>User: Response
Loading

🐰 In the garden of code so bright,
A change has brought a new delight.
With clearer paths and errors tamed,
Our smart contract now is famed!
Hops of joy, we celebrate,
A cleaner code, oh, isn’t it great? 🌼


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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@bdeneux bdeneux changed the title Refactor/use payload reply [Law-stone] Remove instantiate context state and use reply payload Aug 7, 2024
@bdeneux bdeneux marked this pull request as ready for review August 7, 2024 09:59
@bot-anik
Copy link
Member

bot-anik commented Aug 7, 2024

size-limit report 📦

Path Size
target/wasm32-unknown-unknown/release/axone_objectarium.wasm 458.07 KB (0%)
target/wasm32-unknown-unknown/release/axone_law_stone.wasm 647.92 KB (-0.24% 🔽)
target/wasm32-unknown-unknown/release/axone_cognitarium.wasm 831.35 KB (0%)
target/wasm32-unknown-unknown/release/axone_dataverse.wasm 670.43 KB (0%)

Copy link

@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 18e2930 and 994be53.

Files selected for processing (2)
  • contracts/axone-law-stone/src/contract.rs (13 hunks)
  • contracts/axone-law-stone/src/state.rs (1 hunks)
Additional comments not posted (6)
contracts/axone-law-stone/src/state.rs (1)

Line range hint 1-14:
Removal of INSTANTIATE_CONTEXT constant.

The constant INSTANTIATE_CONTEXT has been removed, indicating a shift in how instantiation context is managed. Ensure that this aligns with the new payload mechanism introduced in CosmWasm 2.x.x.

contracts/axone-law-stone/src/contract.rs (5)

46-49: Streamlined instantiation process.

The instantiate function now directly adds a submessage with the storage address as a payload, enhancing clarity and reducing state management overhead. Ensure that the payload handling is correct and aligns with the new payload mechanism.


222-232: Improved reply handling and error management.

The reply function now handles the conversion of the payload from the submessage into a string address with added error handling. This improves robustness and simplifies the reply logic by removing INSTANTIATE_CONTEXT.


360-368: Updated tests for new instantiation logic.

The tests have been updated to check for the correct payload in submessages and verify that INSTANTIATE_CONTEXT is no longer used. These updates ensure robustness and correctness in the new logic.


698-700: Updated tests for reply handling.

The tests now include checks for the correct handling of the payload in the reply function, ensuring robustness and correctness in the new logic.


Line range hint 786-826:
New test cases for error handling.

New test cases have been added to validate error handling for invalid UTF-8 sequences in the reply function. These tests ensure that the function correctly handles conversion failures.

Copy link

codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
contracts/axone-law-stone/src/contract.rs 96.09% <100.00%> (+0.10%) ⬆️
contracts/axone-law-stone/src/state.rs 100.00% <ø> (ø)

@bdeneux bdeneux requested review from ccamel and amimart August 7, 2024 10:10
@bdeneux bdeneux self-assigned this Aug 7, 2024
Copy link
Member

@ccamel ccamel left a comment

Choose a reason for hiding this comment

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

lgtm 👍

Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

Perfect thx :)

@bdeneux bdeneux merged commit a4f4117 into main Aug 7, 2024
17 checks passed
@bdeneux bdeneux deleted the refactor/use-payload-reply branch August 7, 2024 12:15
Copy link

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Nice

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.

5 participants