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

add some refactors to airdrop contract #111

Merged
merged 3 commits into from
Jan 5, 2024
Merged

Conversation

jgimeno
Copy link
Contributor

@jgimeno jgimeno commented Jan 5, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced security checks for ownership and authorization during reward distributions in airdrop campaigns.
  • Bug Fixes

    • Improved error handling for insufficient funds scenarios in airdrop campaigns.
  • Tests

    • Added a new test to ensure proper behavior when allocating more funds than available.
  • Refactor

    • Streamlined access to types and traits in external modules by modifying re-exports.

Copy link
Contributor

coderabbitai bot commented Jan 5, 2024

Walkthrough

The airdrop contract has been enhanced for better security and error handling; it now verifies ownership and authorization before rewarding users and efficiently handles cases of insufficient funds. The associated tests have been expanded to cover these new scenarios. Additionally, the nibiru-std library has seen a streamlining of its exports, removing direct re-exports of certain types, possibly to encourage more explicit module interactions.

Changes

Files Change Summary
contracts/airdrop/src/contract.rs Updated to include ownership verification, authorization checks, and improved error handling for insufficient funds.
contracts/airdrop/src/tests/execute/reward_users.rs Added new test for insufficient funds scenario and updated imports.
nibiru-std/src/proto/mod.rs Removed re-exports of type_url_cosmos and type_url_nibiru.

🐇✨
In the realm where smart contracts thrive,
A rabbit hopped in, code in drive.
With a flip and a hop, security's tight,
Bugs scatter away in the moonlit night. 🌙🚀

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's AI:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate 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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Jan 5, 2024

Codecov Report

Attention: 55 lines in your changes are missing coverage. Please review.

Comparison is base (444f243) 85.53% compared to head (902b788) 85.16%.
Report is 7 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
contracts/airdrop/src/state.rs 100.00% <100.00%> (ø)
nibiru-std/src/proto/mod.rs 100.00% <ø> (ø)
contracts/airdrop/src/msg.rs 40.00% <40.00%> (ø)
contracts/airdrop/src/contract.rs 71.58% <71.58%> (ø)

... and 8 files with indirect coverage changes

@jgimeno jgimeno marked this pull request as ready for review January 5, 2024 18:00
@jgimeno jgimeno merged commit dd90c9a into main Jan 5, 2024
4 of 5 checks passed
@jgimeno jgimeno deleted the feat/some-refactors-airdrop branch January 5, 2024 18:00
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bd792e4 and 902b788.
Files selected for processing (3)
  • contracts/airdrop/src/contract.rs (1 hunks)
  • contracts/airdrop/src/tests/execute/reward_users.rs (2 hunks)
  • nibiru-std/src/proto/mod.rs (1 hunks)
Additional comments: 5
contracts/airdrop/src/tests/execute/reward_users.rs (2)
  • 5-5: The import of StdError is added to support error handling in the new test case.

  • 175-216: The new test case test_fails_when_we_try_to_allocate_more_than_available correctly checks the contract's behavior when the reward allocation exceeds the available funds. It asserts that the response is an error with the message "Not enough funds in the campaign", which aligns with the PR objectives.

nibiru-std/src/proto/mod.rs (1)
  • 5-5: The removal of pub use type_url_cosmos::*; and pub use type_url_nibiru::*; may impact how external modules access these types and traits. Ensure that all references to these modules in the codebase are updated to the new access pattern.
Verification successful

Based on the executed scripts and their results, there are no direct or indirect references to type_url_cosmos or type_url_nibiru in the codebase outside of the mod.rs file. This suggests that the removal of the pub use declarations for these modules has not resulted in any unresolved references. The codebase appears to be consistent with the changes made in the pull request.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for direct usage of types and traits from type_url_cosmos and type_url_nibiru.
rg --type rust --glob '!mod.rs' 'type_url_cosmos::|type_url_nibiru::'

Length of output: 71



Script:

#!/bin/bash
# Search for indirect usage of types and traits that might have been re-exported from type_url_cosmos and type_url_nibiru.
rg --type rust 'type_url_cosmos|type_url_nibiru'

Length of output: 148



Script:

#!/bin/bash
# Search for any wildcard imports or aliased imports from type_url_cosmos and type_url_nibiru.
rg --type rust 'use .*type_url_cosmos.*;|use .*type_url_nibiru.*;'

Length of output: 68

contracts/airdrop/src/contract.rs (2)
  • 106-114: The addition of ownership and authorization checks in the reward_users function is a critical security improvement. It ensures that only the owner or managers can distribute rewards.

  • 118-121: The updated error handling for insufficient funds uses early returns, which simplifies the logic and makes it more readable. This change aligns with the PR objectives to improve error handling.

Unique-Divine added a commit that referenced this pull request Jan 11, 2024
commit 2296e6f1e91db857318632089aa2cf888a4ce8ae
Merge: c14558d dd90c9a
Author: Unique-Divine <[email protected]>
Date:   Wed Jan 10 21:25:41 2024 -0600

    Merge branch 'main' into realu/std

commit c14558de1b80b739701ff3b146355ea815327192
Author: Unique-Divine <[email protected]>
Date:   Wed Jan 10 15:43:00 2024 -0600

    quick save wip!

commit dd90c9a
Merge: bd792e4 902b788
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 19:00:52 2024 +0100

    Merge pull request #111 from NibiruChain/feat/some-refactors-airdrop

    add some refactors to airdrop contract

commit 902b788
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:41:16 2024 +0100

    remove unused imports

commit 0f337d1
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:39:21 2024 +0100

    it fails when there are not enough funds

commit 1d42220
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:31:57 2024 +0100

    add some refactors, part 1

commit bd792e4
Author: Kevin Yang <[email protected]>
Date:   Wed Jan 3 14:22:23 2024 -0800

    feat: initial airdrop contract (#110)

    * feat: initial airdrop contract

    * create cargo config

    * test: instantiate message

    * remove owner from instantiate msg

    * test: query functions

    * test: execute functions

    * feat: add manager list

    * feat: implement manager list

    * Create README.md

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * Update contracts/airdrop/src/contract.rs

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

    * fix error messages

    ---------

    Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

commit 88ae9fd
Author: Matthias <[email protected]>
Date:   Wed Jan 3 15:32:33 2024 +0100

    doc: Add cookbook for live smart contracts (#109)
Unique-Divine added a commit that referenced this pull request Jan 11, 2024
* fix(bash-rs): type corrections for e2e tests

* build: artifacts + just tidy + docs + merge main

commit 2296e6f1e91db857318632089aa2cf888a4ce8ae
Merge: c14558d dd90c9a
Author: Unique-Divine <[email protected]>
Date:   Wed Jan 10 21:25:41 2024 -0600

    Merge branch 'main' into realu/std

commit c14558de1b80b739701ff3b146355ea815327192
Author: Unique-Divine <[email protected]>
Date:   Wed Jan 10 15:43:00 2024 -0600

    quick save wip!

commit dd90c9a
Merge: bd792e4 902b788
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 19:00:52 2024 +0100

    Merge pull request #111 from NibiruChain/feat/some-refactors-airdrop

    add some refactors to airdrop contract

commit 902b788
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:41:16 2024 +0100

    remove unused imports

commit 0f337d1
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:39:21 2024 +0100

    it fails when there are not enough funds

commit 1d42220
Author: Jonathan Gimeno <[email protected]>
Date:   Fri Jan 5 17:31:57 2024 +0100

    add some refactors, part 1

commit bd792e4
Author: Kevin Yang <[email protected]>
Date:   Wed Jan 3 14:22:23 2024 -0800

    feat: initial airdrop contract (#110)

    * feat: initial airdrop contract

    * create cargo config

    * test: instantiate message

    * remove owner from instantiate msg

    * test: query functions

    * test: execute functions

    * feat: add manager list

    * feat: implement manager list

    * Create README.md

    * Update contracts/airdrop/src/contract.rs

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