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

contract permissioned/less hybdrid validation for game_end #15

Merged
merged 8 commits into from
May 12, 2024

Conversation

magiodev
Copy link
Owner

No description provided.

Copy link

vercel bot commented May 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prudent-pots ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2024 7:25pm

Copy link

coderabbitai bot commented May 12, 2024

Important

Auto Review Skipped

Review was skipped due to path filters

Files ignored due to path filters (6)
  • schema/prudent-pots.json is excluded by !**/*.json
  • schema/raw/execute.json is excluded by !**/*.json
  • schema/raw/instantiate.json is excluded by !**/*.json
  • schema/raw/query.json is excluded by !**/*.json
  • schema/raw/response_to_game_config.json is excluded by !**/*.json
  • schema/raw/response_to_player_reallocations.json is excluded by !**/*.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent update enhances the Prudent Pots contract with a game_end_threshold parameter, improving game end functionalities and administrative controls. These changes span various components like message structures, state management, and validation processes, ensuring a more dynamic and controlled gaming environment.

Changes

File Path Change Summary
contract.rs, execute.rs, msg.rs Added game_end_threshold parameter, reallocations_limit, updated functions for game control.
helpers/game_end.rs, validate.rs Introduced new functions, updated return types, enhanced validation for admin and game end.
state.rs, query.rs Updated state with game_end_threshold, added query function for player reallocations count.
tests/... Modified tests to accommodate new configurations and thresholds.
.gitignore Adjusted file ignore list, toggled Cargo.lock, added .env ignores.
.github/workflows/ci.yml Docker run command path adjusted in CI workflow for target path.

🐰 "In lines of code, a tale unfolds,
🎩 Magic woven in commits, stories untold.
New thresholds set, games now unfold,
With Prudent Pots, a story of code gold.
Cheers to changes, big and small,
In this digital wonderland, we trust them all!" 🥕


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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.

@magiodev magiodev marked this pull request as ready for review May 12, 2024 14:21
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: 3

Out of diff range and nitpick comments (2)
contracts/prudent-pots/src/execute.rs (1)

Line range hint 158-158: Ensure fee deduction logic is optimized to prevent unnecessary calculations.

- let fee = amount.multiply_ratio(game_config.fee_reallocation, 100u128);
- let net_amount = amount.checked_sub(fee)?;
+ let net_amount = amount.checked_sub(amount.multiply_ratio(game_config.fee_reallocation, 100u128))?;
contracts/prudent-pots/src/helpers/game_end.rs (1)

Line range hint 173-243: Complex raffle processing logic could be simplified for better readability and maintainability.

- // TODO: Early return here if there is no raffle
- // if raffle.nft_id && addr is none and denom_prize is_zero() return all default values.
+ // Simplify raffle processing by consolidating conditions and early returns
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 14cb60d and 5411069.
Files selected for processing (10)
  • contracts/prudent-pots/src/contract.rs (3 hunks)
  • contracts/prudent-pots/src/execute.rs (7 hunks)
  • contracts/prudent-pots/src/helpers/game_end.rs (10 hunks)
  • contracts/prudent-pots/src/helpers/validate.rs (4 hunks)
  • contracts/prudent-pots/src/msg.rs (2 hunks)
  • contracts/prudent-pots/src/state.rs (1 hunks)
  • contracts/prudent-pots/src/tests/distribute_tokens.rs (1 hunks)
  • contracts/prudent-pots/src/tests/instantiate.rs (1 hunks)
  • contracts/prudent-pots/src/tests/integration/fixtures.rs (3 hunks)
  • contracts/prudent-pots/src/tests/integration/update_config.rs (2 hunks)
Additional comments not posted (10)
contracts/prudent-pots/src/state.rs (1)

14-14: Addition of game_end_threshold aligns with the PR's objectives to enhance game end logic.

contracts/prudent-pots/src/tests/integration/update_config.rs (1)

25-25: Proper inclusion of game_end_threshold in configuration update tests.

contracts/prudent-pots/src/tests/instantiate.rs (1)

22-22: Correct initialization of game_end_threshold in game setup for tests.

contracts/prudent-pots/src/msg.rs (1)

24-24: Inclusion of game_end_threshold in ExecuteMsg allows external configuration updates.

contracts/prudent-pots/src/tests/distribute_tokens.rs (1)

68-70: Adjustments in test to match updated function signature of get_distribution_send_msgs.

contracts/prudent-pots/src/contract.rs (1)

Line range hint 77-91: Handling of game_end_threshold in execute function enables dynamic updates to game end configuration.

contracts/prudent-pots/src/helpers/validate.rs (1)

28-61: Addition of validate_is_contract_admin_game_end implements hybrid validation logic for game end.

contracts/prudent-pots/src/tests/integration/fixtures.rs (1)

123-123: Correct initialization of game_end_threshold in integration test fixtures.

Also applies to: 196-196

contracts/prudent-pots/src/execute.rs (1)

207-207: Correctly added admin validation for game end.

contracts/prudent-pots/src/helpers/game_end.rs (1)

Line range hint 25-98: Updated function signature and logic for preparing the next game correctly.

Comment on lines +79 to +81
if let Some(game_end_threshold) = game_end_threshold {
game_config.game_end_threshold = game_end_threshold;
}
Copy link

Choose a reason for hiding this comment

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

Add validation for game_end_threshold to ensure it's within an acceptable range.

+ if let Some(game_end_threshold) = game_end_threshold {
+     if game_end_threshold < 1 || game_end_threshold > 10000 {
+         return Err(ContractError::InvalidInput {});
+     }
+     game_config.game_end_threshold = game_end_threshold;
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if let Some(game_end_threshold) = game_end_threshold {
game_config.game_end_threshold = game_end_threshold;
}
if let Some(game_end_threshold) = game_end_threshold {
if game_end_threshold < 1 || game_end_threshold > 10000 {
return Err(ContractError::InvalidInput {});
}
game_config.game_end_threshold = game_end_threshold;
}

Comment on lines +211 to +212
// TODO: Decide if we want the prizes to be part of whitelisted cw721_addrs in GameConfig,
// or if the whitelist should jsut be the ones that gives minBid discount eligibility
Copy link

Choose a reason for hiding this comment

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

Consider simplifying the raffle prize logic to improve maintainability.

- // TODO: Decide if we want the prizes to be part of whitelisted cw721_addrs in GameConfig,
- // or if the whitelist should just be the ones that gives minBid discount eligibility
+ // Simplify raffle prize logic by consolidating prize conditions

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// TODO: Decide if we want the prizes to be part of whitelisted cw721_addrs in GameConfig,
// or if the whitelist should jsut be the ones that gives minBid discount eligibility
// Simplify raffle prize logic by consolidating prize conditions

Comment on lines 54 to 56
// Reset player allocations for the next game, and first bidder
PLAYER_ALLOCATIONS.clear(deps.storage);
FIRST_BIDDER.clear(deps.storage);
Copy link

Choose a reason for hiding this comment

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

Consider adding comments to explain the purpose of clearing player allocations and the first bidder.

+ // Clear player allocations to reset the game state for the next round
  PLAYER_ALLOCATIONS.clear(deps.storage);
+ // Clear the first bidder information as part of game reset
  FIRST_BIDDER.clear(deps.storage);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// Reset player allocations for the next game, and first bidder
PLAYER_ALLOCATIONS.clear(deps.storage);
FIRST_BIDDER.clear(deps.storage);
// Reset player allocations for the next game, and first bidder
// Clear player allocations to reset the game state for the next round
PLAYER_ALLOCATIONS.clear(deps.storage);
// Clear the first bidder information as part of game reset
FIRST_BIDDER.clear(deps.storage);

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 5411069 and 2339ee7.
Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
Additional comments not posted (2)
.github/workflows/ci.yml (2)

Line range hint 1-30: The build-and-test job configuration looks good and follows best practices for setting up Rust projects on GitHub Actions.


42-45: Ensure the Docker volume mounts are correctly configured for caching. The use of $(basename "$(pwd)")_cache for the source volume might not behave as expected if the working directory's name contains spaces or special characters. Consider using a simpler, more predictable naming convention for the cache volume.

- --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target
+ --mount type=volume,source="workspace_cache",target=/target

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 2339ee7 and 5ff58ae.
Files ignored due to path filters (5)
  • Cargo.lock is excluded by !**/*.lock, !**/*.lock
  • schema/prudent-pots.json is excluded by !**/*.json
  • schema/raw/execute.json is excluded by !**/*.json
  • schema/raw/instantiate.json is excluded by !**/*.json
  • schema/raw/response_to_game_config.json is excluded by !**/*.json
Files selected for processing (10)
  • .gitignore (2 hunks)
  • contracts/prudent-pots/src/contract.rs (3 hunks)
  • contracts/prudent-pots/src/execute.rs (9 hunks)
  • contracts/prudent-pots/src/helpers/game_end.rs (10 hunks)
  • contracts/prudent-pots/src/helpers/validate.rs (5 hunks)
  • contracts/prudent-pots/src/msg.rs (2 hunks)
  • contracts/prudent-pots/src/state.rs (2 hunks)
  • contracts/prudent-pots/src/tests/instantiate.rs (1 hunks)
  • contracts/prudent-pots/src/tests/integration/fixtures.rs (3 hunks)
  • contracts/prudent-pots/src/tests/integration/update_config.rs (2 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Files skipped from review as they are similar to previous changes (9)
  • contracts/prudent-pots/src/contract.rs
  • contracts/prudent-pots/src/execute.rs
  • contracts/prudent-pots/src/helpers/game_end.rs
  • contracts/prudent-pots/src/helpers/validate.rs
  • contracts/prudent-pots/src/msg.rs
  • contracts/prudent-pots/src/state.rs
  • contracts/prudent-pots/src/tests/instantiate.rs
  • contracts/prudent-pots/src/tests/integration/fixtures.rs
  • contracts/prudent-pots/src/tests/integration/update_config.rs

@magiodev magiodev merged commit 25be2a3 into main May 12, 2024
2 of 3 checks passed
@magiodev magiodev deleted the feat/contract_v2 branch May 12, 2024 19:25
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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5ff58ae and b9e2372.
Files selected for processing (3)
  • contracts/prudent-pots/src/contract.rs (4 hunks)
  • contracts/prudent-pots/src/msg.rs (3 hunks)
  • contracts/prudent-pots/src/query.rs (2 hunks)
Additional comments not posted (3)
contracts/prudent-pots/src/msg.rs (2)

24-27: Addition of game_end_threshold enhances game configuration flexibility.


119-122: Addition of PlayerReallocationsResponse supports new player reallocation queries.

contracts/prudent-pots/src/contract.rs (1)

Line range hint 78-96: Enhancements to ExecuteMsg::UpdateConfig support new game configuration options.

Comment on lines +73 to +83
pub fn query_player_reallocations(
deps: Deps,
address: String,
) -> StdResult<PlayerReallocationsResponse> {
// Attempt to load player reallocations count. If not found, return an deafult PlayerReallocations count 0.
let reallocations = PLAYER_REALLOCATIONS
.may_load(deps.storage, address)?
.unwrap_or_default();

Ok(PlayerReallocationsResponse { reallocations })
}
Copy link

Choose a reason for hiding this comment

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

Implementation of player reallocations querying supports new functionality. Consider clarifying the comment in line 77 to specify what the default count is.

-    // Attempt to load player reallocations count. If not found, return an deafult PlayerReallocations count 0.
+    // Attempt to load player reallocations count. If not found, return a default PlayerReallocations count of 0.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
pub fn query_player_reallocations(
deps: Deps,
address: String,
) -> StdResult<PlayerReallocationsResponse> {
// Attempt to load player reallocations count. If not found, return an deafult PlayerReallocations count 0.
let reallocations = PLAYER_REALLOCATIONS
.may_load(deps.storage, address)?
.unwrap_or_default();
Ok(PlayerReallocationsResponse { reallocations })
}
pub fn query_player_reallocations(
deps: Deps,
address: String,
) -> StdResult<PlayerReallocationsResponse> {
// Attempt to load player reallocations count. If not found, return a default PlayerReallocations count of 0.
let reallocations = PLAYER_REALLOCATIONS
.may_load(deps.storage, address)?
.unwrap_or_default();
Ok(PlayerReallocationsResponse { reallocations })
}

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.

1 participant