Skip to content

Comments

Fix Fail test#120

Merged
mubarak23 merged 10 commits intomainfrom
pr-119
Jun 30, 2025
Merged

Fix Fail test#120
mubarak23 merged 10 commits intomainfrom
pr-119

Conversation

@mubarak23
Copy link
Contributor

@mubarak23 mubarak23 commented Jun 30, 2025

Summary by CodeRabbit

  • New Features

    • Campaigns now support specifying a unique donation token per campaign, rather than using a single global token.
    • Campaign creation validates the donation token address and rejects invalid tokens.
  • Bug Fixes

    • Added a new error message for invalid donation tokens to improve error handling.
  • Tests

    • Updated and expanded test coverage to verify correct handling of campaign-specific donation tokens and validation of invalid tokens.
  • Style

    • Minor formatting and whitespace improvements for better code readability (no impact on functionality).

@mubarak23 mubarak23 self-assigned this Jun 30, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 30, 2025

Walkthrough

The changes introduce support for specifying a donation token on a per-campaign basis instead of using a global token. This involves updating function signatures, internal logic, error handling, and tests to accept, validate, and use a campaign-specific donation token. Minor formatting and import order adjustments are also included.

Changes

File(s) Summary
src/base/errors.cairo Added INVALID_DONATION_TOKEN error constant for invalid donation token cases.
src/campaign_donation.cairo Refactored to support per-campaign donation tokens; updated function signatures, logic, and error handling.
src/interfaces/ICampaignDonation.cairo Updated create_campaign interface to require a donation_token parameter and updated documentation.
tests/test_campaign_donation.cairo Updated all tests to supply donation_token to create_campaign; added tests for invalid donation tokens.
src/payment_stream.cairo, tests/test_payment_stream.cairo Minor formatting, import order, and whitespace adjustments; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract
    participant ERC20Token

    User->>Contract: create_campaign(campaign_ref, target_amount, donation_token)
    Contract->>Contract: validate donation_token != 0
    alt valid token
        Contract->>Contract: store campaign with donation_token
        Contract-->>User: campaign created
    else invalid token
        Contract-->>User: revert with INVALID_DONATION_TOKEN
    end

    User->>Contract: donate_to_campaign(campaign_id, amount)
    Contract->>Contract: get campaign's donation_token
    Contract->>ERC20Token: transferFrom(User, Contract, amount)
    ERC20Token-->>Contract: transfer success/failure
    Contract-->>User: donation result

    User->>Contract: withdraw_from_campaign(campaign_id)
    Contract->>Contract: get campaign's donation_token
    Contract->>ERC20Token: transfer(Contract, campaign_owner, amount)
    ERC20Token-->>Contract: transfer result
    Contract-->>User: withdrawal result
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers

  • Utilitycoder

Poem

A token for each cause, how neat!
Campaigns now choose which coin to greet.
No more global, one-size-fits—
Each campaign’s purse now truly fits!
With tests and code both up to date,
The rabbits cheer and celebrate!
🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc2c67e and bf58df3.

📒 Files selected for processing (1)
  • tests/test_campaign_donation.cairo (35 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_campaign_donation.cairo
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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: 1

🔭 Outside diff range comments (2)
tests/test_campaign_donation.cairo (1)

1198-1211: Fix missing donation_token parameter.

The test is using the old create_campaign signature without the required donation_token parameter.

Apply this fix:

-    let campaign_id = campaign_donation.create_campaign('Test', target_amount);
+    let campaign_id = campaign_donation.create_campaign('Test', target_amount, token_address);
src/campaign_donation.cairo (1)

407-445: Fix inconsistent donation token usage in refunds.

The claim_refund function still uses the global donation token instead of the campaign-specific token. This is inconsistent with the new per-campaign token design.

Apply this fix:

-    // Transfer tokens back to donor
-    let donation_token = self.donation_token.read();
-    let token = IERC20Dispatcher { contract_address: donation_token };
+    // Transfer tokens back to donor
+    let donation_token = campaign.donation_token;
+    let token = IERC20Dispatcher { contract_address: donation_token };
🧹 Nitpick comments (1)
tests/test_campaign_donation.cairo (1)

308-321: Remove duplicate test.

This test duplicates the functionality of test_create_campaign_invalid_donation_token (lines 109-121). Both tests verify the same scenario of creating a campaign with a zero address as the donation token.

Consider removing this duplicate test to avoid redundancy in the test suite.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc6d1d2 and cc2c67e.

📒 Files selected for processing (6)
  • src/base/errors.cairo (1 hunks)
  • src/campaign_donation.cairo (6 hunks)
  • src/interfaces/ICampaignDonation.cairo (2 hunks)
  • src/payment_stream.cairo (4 hunks)
  • tests/test_campaign_donation.cairo (33 hunks)
  • tests/test_payment_stream.cairo (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests
🔇 Additional comments (15)
src/base/errors.cairo (1)

136-137: LGTM! Well-defined error constant for donation token validation.

The new error constant follows established naming conventions and will be used to validate donation token addresses during campaign creation.

tests/test_payment_stream.cairo (1)

647-648: Good formatting improvement for readability.

The multi-line format makes the chained method call more readable without affecting functionality.

src/interfaces/ICampaignDonation.cairo (1)

20-20: Good documentation for the new donation_token parameter.

The parameter documentation clearly explains its purpose and aligns with the per-campaign token support objectives.

src/payment_stream.cairo (4)

25-28: Minor import reordering for consistency.

The reordering of error constant imports doesn't affect functionality and may improve organization.


466-466: Good cleanup of unnecessary blank line.

Removing the extraneous blank line improves code consistency.


807-810: Improved readability with multi-line event emission.

The multi-line format makes the event emission more readable and consistent with similar patterns in the codebase.


915-915: Good cleanup of unnecessary blank line.

Removing the extraneous blank line improves code consistency within the cancel function.

tests/test_campaign_donation.cairo (4)

71-79: LGTM!

The test correctly passes the donation token to create_campaign, aligning with the new per-campaign donation token feature.


98-106: LGTM!

The test correctly includes the donation token parameter while maintaining its focus on zero amount validation.


109-121: LGTM!

Good test coverage for the new invalid donation token validation. The test correctly verifies that campaign creation fails with a zero address as the donation token.


358-375: LGTM!

Excellent test coverage for multiple campaigns with different donation tokens. This properly validates the per-campaign donation token feature.

src/campaign_donation.cairo (4)

166-192: LGTM!

The function signature correctly includes the new donation_token parameter and properly passes it to the internal implementation.


469-500: LGTM!

The internal implementation correctly validates the donation token (ensuring it's not zero) and stores it in the campaign struct.


502-528: LGTM!

The function correctly retrieves the donation token from the specific campaign, properly implementing the per-campaign token feature.


561-596: LGTM!

The function correctly retrieves the donation token from the campaign for withdrawal operations.

Comment on lines 29 to 34
fn create_campaign(
ref self: TContractState, campaign_ref: felt252, target_amount: u256,
ref self: TContractState,
campaign_ref: felt252,
target_amount: u256,
donation_token: ContractAddress,
) -> u256;
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify consistent implementation of the new donation_token parameter.

The interface change correctly adds support for per-campaign donation tokens. Ensure that all implementations and calls to this method are updated to include the new parameter.


🏁 Script executed:

#!/bin/bash
# Description: Verify all implementations and calls to create_campaign include the donation_token parameter

# Search for create_campaign implementations
ast-grep --pattern $'fn create_campaign($$$) -> $_ {
  $$$
}'

# Search for create_campaign method calls
rg -A 5 "create_campaign\(" --type cairo

Length of output: 135


🏁 Script executed:

#!/bin/bash
# Locate the ICampaignDonation interface file
INTERFACE_FILE=$(fd ICampaignDonation.cairo)

# Show the interface and its method signature
echo "== Interface: $INTERFACE_FILE =="
sed -n '1,200p' "$INTERFACE_FILE"

# Search for any impl blocks of this interface
echo "== Implementations of ICampaignDonation =="
rg -n "impl ICampaignDonation" --glob "*.cairo" || echo "No impl blocks found"

# Search for all create_campaign definitions (to catch overrides)
echo "== Definitions of fn create_campaign =="
rg -n "fn create_campaign" --glob "*.cairo" || echo "No fn create_campaign definitions found"

# Search for all calls to create_campaign(
echo "== Calls to create_campaign( =="
rg -n "create_campaign\(" --glob "*.cairo" || echo "No calls to create_campaign found"

Length of output: 13621


Fix missing donation_token in test calls

The interface and contract implementation already include the new donation_token parameter. However, there’s at least one test invoking create_campaign with only two arguments:

• tests/test_campaign_donation.cairo:1211

- let campaign_id = campaign_donation.create_campaign('Test', target_amount);
+ let campaign_id = campaign_donation.create_campaign('Test', target_amount, donation_token);

Please update this call (and any others missing the third argument) to include donation_token so tests compile and run as expected.

📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn create_campaign(
ref self: TContractState, campaign_ref: felt252, target_amount: u256,
ref self: TContractState,
campaign_ref: felt252,
target_amount: u256,
donation_token: ContractAddress,
) -> u256;
- let campaign_id = campaign_donation.create_campaign('Test', target_amount);
+ let campaign_id = campaign_donation.create_campaign('Test', target_amount, donation_token);
🤖 Prompt for AI Agents
In src/interfaces/ICampaignDonation.cairo around lines 29 to 34, the
create_campaign function signature includes a new donation_token parameter, but
test calls such as in tests/test_campaign_donation.cairo at line 1211 are
missing this argument. Update all calls to create_campaign in the test files to
pass the donation_token argument as the third parameter to match the updated
interface and ensure tests compile and run correctly.

@mubarak23 mubarak23 changed the title Pr 119 Fix Fail test Jun 30, 2025
@mubarak23 mubarak23 merged commit 6c9278d into main Jun 30, 2025
2 of 3 checks passed
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