Skip to content

[TEST]: expand test coverage for execute_edit_permission_transaction #149

Merged
codebestia merged 3 commits intoSpherre-Labs:mainfrom
martinvibes:improve_test_for_execute_edit_permission_transaction
Jul 28, 2025
Merged

[TEST]: expand test coverage for execute_edit_permission_transaction #149
codebestia merged 3 commits intoSpherre-Labs:mainfrom
martinvibes:improve_test_for_execute_edit_permission_transaction

Conversation

@martinvibes
Copy link

@martinvibes martinvibes commented Jul 25, 2025

Description 📝

Expand & Refactor Permission Edit Transaction Tests

Summary:

  • Adds comprehensive edge case tests for execute_edit_permission_transaction, including invalid transaction types, missing permissions, unapproved transactions, and more.
  • Adds/updates event emission tests for TransactionApproved, TransactionExecuted, and PermissionEditExecuted.
  • Refactors imports and event assertions for clarity and linter compliance.

Related Issues 🔗

closes #146

Changes Made 🚀

  • [] ✨ Feature Implementation
  • 🐛 Bug Fix
  • 📚 Documentation Update
  • 🔨 Refactoring
  • ❓ Others (Specify)

Screenshots/Screen-record (if applicable) 🖼

Checklist ✅

  • 🛠 I have tested these changes.
  • 📖 I have updated the documentation (if applicable).
  • 🎨 This PR follows the project's coding style.
  • 🧪 I have added necessary tests (if applicable).

Additional Notes 🗒

Summary by CodeRabbit

  • Bug Fixes

    • Improved accessibility of transaction event details for end-users.
  • Tests

    • Added comprehensive tests for member permission transaction execution, including edge cases and event emission verification.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

"""

Walkthrough

The changes make the fields of the TransactionApproved and TransactionExecuted event structs in src/account_data.cairo publicly accessible. The test suite for member permission transactions is expanded with multiple new tests covering failure scenarios and verifying event emissions related to executing permission edit transactions. No other logic or control flow is modified.

Changes

File(s) Change Summary
src/account_data.cairo Made transaction_id, date_approved fields of TransactionApproved and transaction_id, executor, date_executed fields of TransactionExecuted structs public.
src/tests/actions/test_member_permission_tx.cairo Added multiple new tests covering failure scenarios and event emission verification for permission edit transaction execution; updated imports and fixed permission setup in tests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops through code so bright,
New tests ensure permissions are right.
Events are public, no secrets to keep,
Edge cases caught—no bugs will creep.
With every hop and every test,
This code is stronger than the rest! 🐇✨
"""

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 af32975 and a4676cf.

📒 Files selected for processing (1)
  • src/tests/actions/test_member_permission_tx.cairo (10 hunks)
🔇 Additional comments (15)
src/tests/actions/test_member_permission_tx.cairo (15)

2-8: LGTM! Proper imports for enhanced test capabilities.

The added imports for event spying (EventSpyAssertionsTrait, spy_events, EventSpyTrait) and event structs (TransactionExecuted, TransactionApproved, PermissionEditExecuted) are correctly imported and necessary for the new event emission tests.


31-31: Good addition of section comments for better organization.

The section comment helps organize the test file structure, making it easier to navigate between different test categories.


34-34: Excellent addition of descriptive test comments.

The detailed comments explaining what each test does significantly improve code readability and maintenance. This follows testing best practices by clearly documenting test intent.

Also applies to: 63-63, 81-81, 100-100, 118-118, 139-139, 149-149, 173-173


243-244: Well-organized test structure with clear section separation.

The addition of section comments (// --- EXECUTION EDGE CASE TESTS ---) provides excellent organization and makes the test file easier to navigate.


245-255: Comprehensive edge case testing for non-existent transactions.

This test properly validates that the system correctly handles attempts to execute non-existent transactions with the expected panic message.


257-272: Excellent test for transaction type validation.

This test ensures that the system properly validates transaction types during execution, preventing execution of incorrect transaction types with the appropriate error message.


274-292: Good permission validation test with proper setup.

The test correctly validates executor permission requirements. The "FIX" comment on line 286 indicates a correction was made to assign voter permission, which is proper test setup.


316-332: Invalid permission mask test is well-structured.

This test correctly validates that invalid permission masks are rejected during execution with the appropriate error message.


334-350: Proper test for unapproved transaction execution.

This test ensures that transactions cannot be executed without proper approval, which is a critical security validation.


352-353: Clear section organization for event tests.

The section comment properly separates event emission tests, maintaining good test file organization.


354-376: Comprehensive event emission testing for transaction approval.

The test properly sets up event spying and validates the TransactionApproved event emission with correct data. The use of get_block_timestamp() for the expected timestamp is appropriate.


378-404: Well-implemented event emission test for transaction execution.

The test correctly validates the TransactionExecuted event with proper event data including transaction ID, executor, and execution timestamp retrieved from the actual transaction.


406-429: Excellent test for permission edit event emission.

This test properly validates the PermissionEditExecuted event emission with correct transaction ID, member address, and new permissions data.


266-266: Good fixes for voter permission assignments.

The "FIX" comments indicate proper corrections were made to assign voter permissions where needed for test setup. This ensures tests have the correct prerequisites for approval and execution operations.

Also applies to: 286-286, 365-365, 390-390, 419-419


294-314: Fix missing member removal in non-existent-member test
The test is adding the member but never actually removes them before calling execute_edit_permission_transaction_pub, so it will never panic with “Member does not exist”. You need to either skip adding the member or invoke the removal flow to simulate a non-member.

Please update src/tests/actions/test_member_permission_tx.cairo (around lines 294–314) accordingly. For example, you could:

  • Use a fresh address that was never added:
     // let member = member_to_edit();
    - mock_contract.add_member_pub(caller);
    - mock_contract.assign_proposer_permission_pub(caller);
    + // skip adding `member` so it truly doesn’t exist
     let tx_id = mock_contract.propose_edit_permission_transaction_pub(member, new_permissions);
  • Or drive the removal transaction before testing:
     mock_contract.add_member_pub(caller);
     mock_contract.assign_proposer_permission_pub(caller);
     let tx_id = mock_contract.propose_edit_permission_transaction_pub(member, new_permissions);
     mock_contract.approve_transaction_pub(tx_id, caller);
  • // remove the member so it no longer exists
  • let remove_tx = mock_contract.propose_remove_member_transaction_pub(member);
  • mock_contract.approve_transaction_pub(remove_tx, caller);
  • mock_contract.execute_remove_member_transaction_pub(remove_tx);
    stop_cheat_caller_address(mock_contract.contract_address);
    start_cheat_caller_address(mock_contract.contract_address, caller);
    mock_contract.execute_edit_permission_transaction_pub(tx_id);



> Likely an incorrect or invalid review comment.

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZ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AA== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

<details>
<summary>🧪 Generate unit tests</summary>

- [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Create PR with unit tests
- [ ] <!-- {"checkboxId": "07f1e7d6-8a8e-4e23-9900-8731c2c87f58", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Post copyable unit tests in a comment

</details>

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=Spherre-Labs/spherre&utm_content=149):

- 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](https://www.coderabbit.ai/contact-us/support) 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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai generate unit tests` to generate unit tests for 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@martinvibes
Copy link
Author

@codebestia kindly review :)

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/tests/actions/test_member_permission_tx.cairo (1)

334-355: Consider removing or fixing the commented-out test.

The commented-out transaction approval event test references a date_approved field that may not exist on the transaction object. Either fix this test or remove it to keep the codebase clean.

-// #[test]
-// fn test_event_emitted_transaction_approved() {
-//     let mock_contract = deploy_mock_contract();
-//     let caller = proposer();
-//     let member = member_to_edit();
-//     let new_permissions: u8 = 6;
-//     start_cheat_caller_address(mock_contract.contract_address, caller);
-//     mock_contract.add_member_pub(caller);
-//     mock_contract.add_member_pub(member);
-//     mock_contract.assign_proposer_permission_pub(caller);
-//     let tx_id = mock_contract.propose_edit_permission_transaction_pub(member, new_permissions);
-//     let mut spy = spy_events();
-//     mock_contract.approve_transaction_pub(tx_id, caller);
-//     stop_cheat_caller_address(mock_contract.contract_address);
-//     let expected_event = spherre::tests::mocks::mock_account_data::Event::AccountDataEvent(
-//         spherre::account_data::Event::TransactionApproved {
-//             transaction_id: tx_id,
-//             date_approved: mock_contract.get_transaction_pub(tx_id).date_approved,
-//         }
-//     );
-//     spy.assert_emitted(@array![(mock_contract.contract_address, expected_event)]);
-// }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4e71ac and 1dc1dab.

📒 Files selected for processing (2)
  • src/account_data.cairo (1 hunks)
  • src/tests/actions/test_member_permission_tx.cairo (2 hunks)
🔇 Additional comments (4)
src/account_data.cairo (1)

122-125: LGTM! Event field visibility change supports enhanced testing.

Making the TransactionExecuted event struct fields publicly accessible is appropriate for enabling direct event field access in tests. This change aligns well with the expanded test coverage in the test file.

src/tests/actions/test_member_permission_tx.cairo (3)

2-9: LGTM! Imports properly support event testing functionality.

The added imports for event spying traits and event types are correctly structured and necessary for the new event verification tests.


230-331: Excellent edge case test coverage!

These comprehensive edge case tests effectively validate all failure scenarios for execute_edit_permission_transaction:

  • Transaction existence validation
  • Transaction type validation
  • Permission requirements (executor)
  • Member existence validation
  • Permission mask validation
  • Transaction approval status

The added voter permission assignments (lines 251, 270) are necessary fixes for proper test setup.


357-411: Excellent event emission test coverage!

Both event emission tests are well-implemented:

  1. test_event_emitted_transaction_executed properly verifies the TransactionExecuted event with correct transaction data
  2. test_event_emitted_permission_edit_executed effectively tests the PermissionEditExecuted event

The tests follow good practices with proper setup, event spying, and assertion patterns. The voter permission fix on line 368 maintains consistency with other test improvements.

Copy link
Member

@codebestia codebestia left a comment

Choose a reason for hiding this comment

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

LGTM!
Thank you for contribution @martinvibes

@codebestia codebestia merged commit 65c6f01 into Spherre-Labs:main Jul 28, 2025
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.

[TEST] Expand Test Coverage for execute_edit_permission_transaction

2 participants