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

F/dummy contract auction #246

Merged
merged 3 commits into from
Oct 8, 2024
Merged

F/dummy contract auction #246

merged 3 commits into from
Oct 8, 2024

Conversation

maxrobot
Copy link
Contributor

@maxrobot maxrobot commented Oct 8, 2024

Makes some fixes to the auction protos in injective-std

Summary by CodeRabbit

  • New Features

    • Enhanced smart contract functionality with new state management for tracking runs and activity.
    • Added support for new message types in the contract's execution and query functions.
  • Bug Fixes

    • Updated field types in auction-related structs for better compatibility, changing from strings to optional coin types.
  • Chores

    • Updated dependency versions and paths in multiple Cargo.toml files to streamline project configuration.

@maxrobot maxrobot requested a review from jbernal87 October 8, 2024 16:58
Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

The pull request includes several modifications primarily centered around updates to the Cargo.toml files across multiple packages. Key changes involve updating the version of the injective-std dependency and altering dependency specifications in the injective-testing package to use local paths without version constraints. Additionally, new dependencies were added to the dummy package, and significant structural updates were made to the contract.rs file, enhancing its functionality. Changes to the injective-std package's Cargo.toml and the type definitions in the auction module were also implemented.

Changes

File Path Change Summary
Cargo.toml Updated injective-std version from 1.13.0 to 1.13.2-auction.
packages/injective-testing/Cargo.toml Removed version specifications for injective-cosmwasm, injective-math, and injective-std.
contracts/dummy/Cargo.toml Added injective-std dependency from local path.
packages/injective-cosmwasm/Cargo.toml Changed injective-math dependency from workspace to direct path.
packages/injective-std/Cargo.toml Updated version from 1.13.0 to 1.13.2-auction.
packages/injective-std/src/types/injective/auction/v1beta1.rs Changed amount field type from string to Option<super::super::super::cosmos::base::v1beta1::Coin in multiple structs.
contracts/dummy/src/contract.rs Enhanced instantiate, execute, sudo, and query functions to manage new states and messages.

Possibly related PRs

Suggested reviewers

  • Kishan-Dhakan
  • jbernal87

Poem

In the meadow where code does play,
A version updated, hip-hip-hooray!
With paths now clear and structs refined,
Our contracts dance, perfectly aligned.
So hop along, let changes bloom,
In the world of Rust, we make room! 🐇✨


🪧 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

@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: 5

🧹 Outside diff range and nitpick comments (12)
contracts/dummy/Cargo.toml (1)

34-34: LGTM! Consider adding a version constraint.

The addition of the injective-std dependency aligns with the PR objectives and enhances the functionality of the dummy contract. However, to ensure better dependency management and avoid potential compatibility issues in the future, consider adding a version constraint.

You could modify the dependency line as follows:

-injective-std      = { path = "../../packages/injective-std" }
+injective-std      = { path = "../../packages/injective-std", version = "0.1.0" }

Replace "0.1.0" with the appropriate version number of the injective-std package.

contracts/injective-cosmwasm-stargate-example/src/testing/authz.rs (3)

49-49: Improved iterator chaining in grant combination.

The simplification of the grant combination logic enhances both readability and potentially performance. By removing the unnecessary into_iter() call on response_user2.grants, the code becomes more concise while maintaining its functionality.

Consider further simplifying this line by using the extend method:

let mut combined_grants = response_user0.grants;
combined_grants.extend(response_user2.grants);

This approach may be more idiomatic and slightly more efficient, as it avoids creating an intermediate iterator.


131-131: Enhanced error handling in test_query_grants.

The introduction of the panic! macro improves the test's error handling by explicitly failing with a detailed error message when an unexpected success occurs. This change enhances the test's robustness and aids in debugging by including the actual response in the panic message.

For consistency with Rust's testing conventions, consider using assert! instead of panic!:

assert!(false, "Expected an error, but got a success: {:?}", contract_response);

This achieves the same result but aligns more closely with standard test assertions in Rust.


Line range hint 1-155: Overall improvements in test implementation and error handling.

The changes in this file enhance the quality of the tests and improve error handling. The simplification of iterator chaining in test_query_grantee_grants and the introduction of explicit error handling in test_query_grants contribute to more robust and maintainable test code. These modifications align well with Rust best practices and should make debugging easier in the future.

Consider applying similar improvements to other test functions in this file for consistency. Additionally, it might be beneficial to add more detailed comments explaining the purpose and expected outcomes of each test, especially for complex scenarios involving multiple users and authorizations.

packages/injective-std/src/types/injective/auction/v1beta1.rs (4)

24-25: Remove commented-out code to maintain code cleanliness

The old amount field definition is commented out. It is advisable to remove unused code to keep the codebase clean, as version control systems retain history.


38-39: Remove commented-out code to maintain code cleanliness

Consider removing the commented-out amount field to keep the codebase clean and maintainable.


59-60: Remove commented-out code to maintain code cleanliness

Please remove the commented-out amount field to keep the code clean, as version control retains the history.


80-81: Remove commented-out code to maintain code cleanliness

Consider removing the commented-out code for the amount field to keep the codebase clean.

contracts/dummy/src/contract.rs (4)

Line range hint 46-50: Return structured JSON object in ExecuteMsg::Ping response

In the execute function, when handling ExecuteMsg::Ping, consider returning a structured JSON object for better extensibility and clarity.

Proposed change:

 ExecuteMsg::Ping { .. } => {
     let mut response = Response::new();
-    response.data = Some(to_json_binary("pong")?);
+    response.data = Some(to_json_binary(&serde_json::json!({"message": "pong"}))?);
     Ok(response)
 }

Line range hint 66-71: Directly serialize data types in query responses

In the query function, for QueryMsg::Runs and QueryMsg::Active, avoid converting values to strings before serialization. Directly serializing the data types improves efficiency.

Apply this change:

 QueryMsg::Runs {} => {
     let runs_count = COUNTER.load(deps.storage)?;
-    to_json_binary(&format!("{runs_count}"))
+    to_json_binary(&runs_count)
 }
 QueryMsg::Active {} => {
     let is_active = ACTIVE.load(deps.storage)?;
-    to_json_binary(&format!("{is_active}"))
+    to_json_binary(&is_active)
 }

Line range hint 54-56: Clarify the intentional error in ExecuteMsg::Error

The ExecuteMsg::Error variant returns an error intentionally. Ensure this is documented clearly to prevent confusion for users interacting with the contract.


Line range hint 62-64: Handle potential overflow when incrementing COUNTER

When incrementing COUNTER in the sudo function for SudoMsg::BeginBlocker, there's a potential for overflow if COUNTER reaches u32::MAX. Consider adding overflow handling.

Proposed change:

 SudoMsg::BeginBlocker {} => {
     let runs = COUNTER.load(deps.storage)?;
+    let (new_runs, overflowed) = runs.overflowing_add(1);
+    if overflowed {
+        return Err(ContractError::Std(StdError::generic_err("COUNTER has reached its maximum value")));
+    }
-    let runs = COUNTER.load(deps.storage)? + 1;
-    COUNTER.save(deps.storage, &runs)?;
+    COUNTER.save(deps.storage, &new_runs)?;
     ACTIVE.save(deps.storage, &true)?;
     Ok(Response::new())
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fd72a3a and c6203c7.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • Cargo.toml (1 hunks)
  • contracts/dummy/Cargo.toml (1 hunks)
  • contracts/dummy/src/contract.rs (1 hunks)
  • contracts/injective-cosmwasm-stargate-example/src/testing/authz.rs (2 hunks)
  • packages/injective-cosmwasm/Cargo.toml (1 hunks)
  • packages/injective-std/Cargo.toml (1 hunks)
  • packages/injective-std/src/types/injective/auction/v1beta1.rs (4 hunks)
  • packages/injective-testing/Cargo.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/injective-std/Cargo.toml
🧰 Additional context used
🔇 Additional comments (3)
packages/injective-testing/Cargo.toml (1)

15-17: Consider the implications of removing version constraints for local dependencies.

The changes to the dependency specifications for injective-cosmwasm, injective-math, and injective-std remove the version constraints, leaving only the path specifications. While this allows for more flexibility in development by always using the latest local versions, it may lead to potential compatibility issues if these local packages are updated independently.

To ensure this change is intentional and consistent with other packages, let's check the dependency specifications in other Cargo.toml files:

Please review the results of this check and consider:

  1. Is this change intentional and part of a broader strategy for managing local dependencies?
  2. Are there any potential risks in removing version constraints for these packages?
  3. Should we add a comment in the Cargo.toml file explaining this decision to help future maintainers?

Consider implementing a workspace-level version management strategy for local packages to ensure consistency across the project while maintaining flexibility for development.

✅ Verification successful

Dependency specifications are consistently managed across the codebase.

The removal of version constraints for injective-cosmwasm, injective-math, and injective-std is consistent across all relevant Cargo.toml files. This approach aligns with the project's strategy to use the latest local versions, ensuring flexibility during development.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check dependency specifications in other Cargo.toml files
# Expected result: Consistent use of path-only specifications for local dependencies

# Search for injective-cosmwasm, injective-math, and injective-std in all Cargo.toml files
rg --type toml 'injective-(cosmwasm|math|std).*path\s*=\s*"\.\./' -g 'Cargo.toml'

Length of output: 1753

packages/injective-cosmwasm/Cargo.toml (1)

17-17: Clarify the rationale for removing the workspace attribute for injective-math

The dependency specification for injective-math has been changed from a workspace dependency to a direct path dependency. While this gives more precise control over the dependency version, it may lead to potential inconsistencies if other packages in the workspace use a different version of injective-math.

Could you please clarify the reasoning behind this change? Additionally, it would be beneficial to verify that this modification doesn't introduce any version inconsistencies across the project.

To ensure consistency, let's check the usage of injective-math across the project:

This will help us understand if the change is consistent across the project and if injective-math is still defined in the workspace.

✅ Verification successful

Verified removal of the workspace attribute for injective-math

The workspace = true attribute for injective-math has been successfully removed from packages/injective-cosmwasm/Cargo.toml. All references to injective-math across the project are consistently managed via direct path dependencies, ensuring no version inconsistencies or build issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of injective-math across the project

# Search for injective-math in all Cargo.toml files
echo "Searching for injective-math in Cargo.toml files:"
rg --type toml 'injective-math' -A 3 -B 1

# Check if injective-math is still defined in the workspace
echo "\nChecking if injective-math is defined in the workspace root Cargo.toml:"
rg --type toml '^\[workspace\]' -A 20 ./Cargo.toml | rg 'injective-math'

Length of output: 5665

contracts/dummy/src/contract.rs (1)

30-32: Initialization of COUNTER and ACTIVE is correct

The initialization of COUNTER and ACTIVE in the instantiate function is properly implemented and follows best practices.

@@ -22,7 +22,7 @@ ethereum-types = { version = "0.5.2" }
hex = { version = "0.4.3", features = [ "serde" ] }
injective-cosmwasm = { version = "0.3.0", path = "./packages/injective-cosmwasm" }
injective-math = { version = "0.3.0", path = "./packages/injective-math" }
injective-std = { version = "1.13.0", path = "./packages/injective-std" }
injective-std = { version = "1.13.2-auction", path = "./packages/injective-std" }
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Issues Found:

  • Malformed Version in Cargo.toml: The injective-std dependency in Cargo.toml has an incorrect version specification:

    injective-std = { version = "1.13.2-auction
    1.13.0", path = "./packages/injective-std" }
    

    This should be corrected to:

    injective-std = { version = "1.13.2-auction", path = "./packages/injective-std" }
    
  • Missing injective-std Dependencies: The following Cargo.toml files are missing the injective-std dependency and should be updated accordingly:

    • contracts/atomic-order-example/Cargo.toml
    • contracts/dummy/Cargo.toml
    • contracts/injective-cosmwasm-mock/Cargo.toml
    • contracts/injective-cosmwasm-stargate-example/Cargo.toml
    • packages/injective-cosmwasm/Cargo.toml
    • packages/injective-math/Cargo.toml
    • packages/injective-std/Cargo.toml
    • packages/injective-std-derive/Cargo.toml
    • packages/injective-testing/Cargo.toml

Please address these issues to ensure consistency and prevent potential build or runtime errors.

🔗 Analysis chain

LGTM: Version update for injective-std looks good.

The update of injective-std to version "1.13.2-auction" aligns with the PR objectives, suggesting improvements to auction-related functionality. This minor version bump should maintain compatibility while introducing new features or fixes.

To ensure consistency across the project, please run the following script:

This script will help identify any inconsistencies in the injective-std version across the project and highlight direct imports that might need attention due to the version change.


This script will iterate through all Cargo.toml files in the project, extract the version of injective-std, and report any instances where the version does not match 1.13.2-auction. This will help ensure that the dependency update is consistent across the entire codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the version of injective-std across the project

# Check for any occurrences of injective-std with different versions
rg --type toml 'injective-std.*version\s*=\s*"(?!1\.13\.2-auction)' -g 'Cargo.toml'

# If the above command returns no results, it means all occurrences are consistent
# with the new version. Otherwise, it will show the inconsistent entries.

echo "Checking for any direct imports of injective-std to ensure they are compatible with the new version:"
rg --type rust '^use injective_std' -g '!packages/injective-std/**'

Length of output: 1373


Script:

#!/bin/bash
# Description: Verify the version of injective-std across all Cargo.toml files

# Find all Cargo.toml files
fd -g 'Cargo.toml' | while read -r file; do
  # Extract the version of injective-std in each Cargo.toml
  version=$(grep 'injective-std' "$file" | grep -oP 'version\s*=\s*"\K[^"]+')
  if [[ -z "$version" ]]; then
    echo "injective-std not found in $file"
  elif [[ "$version" != "1.13.2-auction" ]]; then
    echo "Version mismatch in $file: found $version, expected 1.13.2-auction"
  fi
done

Length of output: 2958

Comment on lines +23 to +27
// #[prost(string, tag = "2")]
// pub amount: ::prost::alloc::string::String,
// NOTE: THIS IS A FIX FOR RUST BINDINGS, PLEASE COPY IN FUTURE RELEASES
#[prost(message, optional, tag = "2")]
pub amount: ::core::option::Option<super::super::super::cosmos::base::v1beta1::Coin>,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Changing field type may cause backward compatibility issues

Modifying the amount field type from String to Option<Coin> in the Bid struct can lead to compatibility issues with existing data or services. Please ensure that this change is safe and compatible with all clients and services that use this struct.

Comment on lines +37 to +41
// #[prost(string, tag = "2")]
// pub amount: ::prost::alloc::string::String,
// NOTE: THIS IS A FIX FOR RUST BINDINGS, PLEASE COPY IN FUTURE RELEASES
#[prost(message, optional, tag = "2")]
pub amount: ::core::option::Option<super::super::super::cosmos::base::v1beta1::Coin>,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Changing field type may cause backward compatibility issues

The amount field in the LastAuctionResult struct has been changed from String to Option<Coin>, which might affect compatibility with existing data and services. Please verify that this change does not introduce any issues.

Comment on lines +58 to +62
// #[prost(string, tag = "2")]
// pub amount: ::prost::alloc::string::String,
// NOTE: THIS IS A FIX FOR RUST BINDINGS, PLEASE COPY IN FUTURE RELEASES
#[prost(message, optional, tag = "2")]
pub amount: ::core::option::Option<super::super::super::cosmos::base::v1beta1::Coin>,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Changing field type may cause backward compatibility issues

The amount field in the EventBid struct has been updated from String to Option<Coin>. Ensure that this change is compatible with all clients and services using this struct.

Comment on lines +79 to +83
// #[prost(string, tag = "2")]
// pub amount: ::prost::alloc::string::String,
// NOTE: THIS IS A FIX FOR RUST BINDINGS, PLEASE COPY IN FUTURE RELEASES
#[prost(message, optional, tag = "2")]
pub amount: ::core::option::Option<super::super::super::cosmos::base::v1beta1::Coin>,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Changing field type may cause backward compatibility issues

The amount field in the EventAuctionResult struct has been modified from String to Option<Coin>. Verify that this change does not introduce compatibility issues with existing data or services.

@@ -5,7 +5,7 @@ license = "MIT OR Apache-2.0"
name = "injective-std"
readme = "README.md"
repository = "https://github.com/InjectiveLabs/cw-injective/tree/dev/packages/injective-std"
version = "1.13.0"
version = "1.13.2-auction"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why -auction ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it's got some hacks for the auction module

Copy link
Contributor

@jbernal87 jbernal87 left a comment

Choose a reason for hiding this comment

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

Single coment but LGTM

@maxrobot maxrobot merged commit 5626480 into dev Oct 8, 2024
4 checks passed
@maxrobot maxrobot deleted the f/dummy-contract-auction branch October 8, 2024 21:48
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.

2 participants