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

fix(x/accounts): TestPeriodicAccountSendCoinsUnauthorized doesn't test correctly #23694

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lilasxie
Copy link
Contributor

@lilasxie lilasxie commented Feb 13, 2025

Description

TestPeriodicAccountSendCoinsUnauthorized doesn't make a correct test for sendcoin unauthorized case.

Before this fix, the error returns by acc.SendCoins is
"invalid owner address: collections: not found: key 'no_key' of type bytes"

After this fix, the error returns is
"sender is not the owner of this vesting account"

Summary by CodeRabbit

  • Bug Fixes
    • Improved error feedback for unauthorized fund transfers by providing a clear and specific message when a sender does not own the vesting account.
  • New Features
    • Introduced a new periodic locking account with enhanced context initialization for testing.

@lilasxie lilasxie requested a review from a team as a code owner February 13, 2025 08:35
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

📝 Walkthrough

Walkthrough

The pull request modifies the test function TestPeriodicAccountSendCoinsUnauthorized in the periodic locking account tests. It introduces a new import for stakingtypes and updates the mock context initialization to return an additional KVStoreService variable (ss2). The changes also update the time assignment from a fixed start time to the current time, create a new periodic locking account (acc2), and refine the error handling to provide a specific error message indicating that the sender is not the owner of the vesting account.

Changes

File(s) Change Summary
x/accounts/.../periodic_locking_account_test.go - Added new import for stakingtypes from cosmossdk.io/x/staking/types
- Modified context initialization in TestPeriodicAccountSendCoinsUnauthorized to return ss2 instead of ignoring it
- Updated sdkCtx2 time assignment to use time.Now()
- Created a new periodic locking account acc2 using the updated context and store service
- Refined error handling to specify that the sender is not the vesting account owner

Sequence Diagram(s)

sequenceDiagram
    participant Test as TestPeriodicAccountSendCoinsUnauthorized
    participant CTX as newMockContext2
    participant Store as KVStoreService
    participant Account as setupPeriodicAccount
    participant Error as Error Handler

    Test->>CTX: Call newMockContext2(t)
    CTX-->>Test: Return ctx2 and ss2 (Store)
    Test->>Test: Set sdkCtx2 time to time.Now()
    Test->>Account: Create new periodic account (acc2) with sdkCtx2 and ss2
    Account-->>Test: Return acc2
    Test->>Error: Attempt to send coins with updated context
    Error-->>Test: Return specific unauthorized error (sender not vesting account owner)
Loading

Suggested reviewers

  • sontrinh16
  • julienrbrt
  • akhilkumarpilli
  • testinginprod

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0b37a8 and 139bab5.

📒 Files selected for processing (1)
  • x/accounts/defaults/lockup/periodic_locking_account_test.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Ub...

**/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

  • x/accounts/defaults/lockup/periodic_locking_account_test.go
`**/*_test.go`: "Assess the unit test code assessing suffici...

**/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

  • x/accounts/defaults/lockup/periodic_locking_account_test.go
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: Analyze
  • GitHub Check: golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (4)
x/accounts/defaults/lockup/periodic_locking_account_test.go (4)

19-19: LGTM: Import addition is appropriate.

The new import for stakingtypes is correctly placed and follows the Go style guidelines.


243-254: LGTM: Test setup improvements enhance clarity and isolation.

The changes improve the test by:

  • Creating a separate test context with a different sender
  • Setting up an isolated periodic account
  • Maintaining clear separation of concerns

260-260: LGTM: Error assertion now correctly tests unauthorized access.

The error message now properly reflects that the sender is not the owner of the vesting account, which aligns with the PR objectives and provides better test coverage for the unauthorized access scenario.


279-281: LGTM: Mock context handler addition is appropriate.

The addition of the staking query params handler follows the established pattern and maintains consistency with the existing mock implementations.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant