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

Added tests #975

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Added tests #975

wants to merge 2 commits into from

Conversation

mirooon
Copy link
Contributor

@mirooon mirooon commented Feb 4, 2025

Which Jira task belongs to this PR?

Why did I implement it this way?

Checklist before requesting a review

Checklist for reviewer (DO NOT DEPLOY and contracts BEFORE CHECKING THIS!!!)

  • I have checked that any arbitrary calls to external contracts are validated and or restricted
  • I have checked that any privileged calls (i.e. storage modifications) are validated and or restricted
  • I have ensured that any new contracts have had AT A MINIMUM 1 preliminary audit conducted on by <company/auditor>

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

The pull request updates several Solidity test contracts by adding new test functions and error handling scenarios. Enhancements span access control validations, chain ID lookups, bridge refund operations, and deBridge chain ID management. New events, error types, and import statements are introduced where necessary. In addition, a mock contract is added to simulate external call failures, ensuring various revert scenarios are thoroughly tested.

Changes

File(s) Change Summary
test/solidity/Facets/.../AccessManagerFacet.t.sol, test/solidity/Facets/.../DexManagerFacet.t.sol Added tests for access control and authorization including checks for self-authorization errors, unauthorized actions, and validations for function approvals with owner simulation in setup.
test/solidity/Facets/.../AcrossFacetPacked.t.sol, test/solidity/Facets/.../AcrossFacetV3.t.sol Introduced tests for withdrawal failure and information mismatch errors with new imports and simulated failure scenarios.
test/solidity/Facets/.../AmarokFacetPacked.t.sol Added new function and tests to verify getChainIdForDomain across various domain IDs, including handling an invalid domain by returning 0.
test/solidity/Facets/.../CBridge.t.sol, test/solidity/Facets/.../CBridgeFacetPacked.t.sol Enhanced triggerRefund testing with added events, comprehensive error handling, and updated function selectors to cover both success and failure cases.
test/solidity/Facets/.../DeBridgeDlnFacet.t.sol Expanded tests for deBridge chain ID management, adding new errors (UnknownDeBridgeChain, NotInitialized), logging events, and updating setup with additional function selectors.
test/solidity/utils/MockFailingContract.sol Introduced a new mock contract with a fallback function that always reverts, simulating external call failures.

Suggested labels

AuditNotRequired

Suggested reviewers

  • ezynda3
  • maxklenk

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

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.

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.

@lifi-action-bot lifi-action-bot marked this pull request as draft February 4, 2025 22:39
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 (3)
test/solidity/Facets/DexManagerFacet.t.sol (1)

273-274: Consider using unchecked block for gas optimization.

The loop counters in these test functions could use unchecked blocks for gas optimization, similar to the pattern used in the existing test on line 128.

Apply this diff to optimize the loops:

-        for (uint256 i = 0; i < 3; i++) {
+        for (uint256 i = 0; i < 3; ) {
             assertTrue(dexMgr.isFunctionApproved(signatures[i]));
+            unchecked { ++i; }
         }

-        for (uint256 i = 0; i < 3; i++) {
+        for (uint256 i = 0; i < 3; ) {
             assertFalse(dexMgr.isFunctionApproved(signatures[i]));
+            unchecked { ++i; }
         }

Also applies to: 278-279

test/solidity/Facets/DeBridgeDlnFacet.t.sol (1)

411-430: LGTM! Good low-level storage testing.

The test effectively validates storage slot computation and access. Consider adding a comment explaining the storage layout pattern being tested.

Add a comment explaining the diamond storage pattern:

 function test_getStorage() public {
+    // Test diamond storage pattern where each facet's storage is namespaced
+    // to avoid collisions with other facets' storage variables
     bytes32 namespace = keccak256("com.lifi.facets.debridgedln");
test/solidity/Facets/AmarokFacetPacked.t.sol (1)

416-513: LGTM! Comprehensive chain ID mapping tests.

The test suite thoroughly covers chain ID mappings for all major chains and handles invalid cases. Consider refactoring to use parameterized testing for better maintainability.

Consider refactoring the chain-specific tests into a parameterized test:

struct ChainTestCase {
    string name;
    uint32 domainId;
    uint32 expectedChainId;
}

function test_getChainIdForDomain() public {
    ChainTestCase[] memory testCases = new ChainTestCase[](7);
    testCases[0] = ChainTestCase("ETH", 6648936, 1);
    testCases[1] = ChainTestCase("POL", 1886350457, 137);
    // ... add other cases

    for (uint i = 0; i < testCases.length; i++) {
        ChainTestCase memory tc = testCases[i];
        uint32 result = amarokFacetPacked.getChainIdForDomain(tc.domainId);
        assertEq(
            result,
            tc.expectedChainId,
            string.concat(tc.name, " domainId should return correct chainId")
        );
    }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ea9f3e and 63fc374.

📒 Files selected for processing (9)
  • test/solidity/Facets/AccessManagerFacet.t.sol (3 hunks)
  • test/solidity/Facets/AcrossFacetPacked.t.sol (2 hunks)
  • test/solidity/Facets/AcrossFacetV3.t.sol (2 hunks)
  • test/solidity/Facets/AmarokFacetPacked.t.sol (3 hunks)
  • test/solidity/Facets/CBridge.t.sol (4 hunks)
  • test/solidity/Facets/CBridgeFacetPacked.t.sol (2 hunks)
  • test/solidity/Facets/DeBridgeDlnFacet.t.sol (4 hunks)
  • test/solidity/Facets/DexManagerFacet.t.sol (5 hunks)
  • test/solidity/utils/MockFailingContract.sol (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: enforce-min-test-coverage
  • GitHub Check: run-unit-tests
🔇 Additional comments (18)
test/solidity/Facets/DexManagerFacet.t.sol (4)

9-9: LGTM! Import statement added for error types.

The import statement is correctly added to support the new authorization test cases.


50-56: LGTM! Improved test accuracy with explicit caller context.

The addition of vm.startPrank/stopPrank calls consistently ensures that all operations are performed with the correct owner context across all test cases.

Also applies to: 60-67, 71-84, 88-105, 109-115, 119-135, 139-143, 147-151, 155-163, 167-175


178-246: LGTM! Comprehensive authorization test coverage added.

The new test cases thoroughly verify access control by:

  • Testing all owner-restricted functions
  • Verifying proper error handling for unauthorized access
  • Including edge cases like self-authorization checks

248-283: LGTM! Complete function approval lifecycle tests added.

The new test cases properly verify:

  • Both single and batch operations
  • Both enabling and disabling of function approvals
  • Proper state verification through assertions
test/solidity/utils/MockFailingContract.sol (1)

4-8: LGTM! Well-designed mock contract.

The contract is well-designed for testing failure scenarios with a clear, single responsibility.

test/solidity/Facets/AccessManagerFacet.t.sol (3)

25-30: LGTM! Comprehensive setup of function selectors.

The setup correctly includes both setCanExecute and addressCanExecuteMethod selectors.


75-82: LGTM! Good test for self-authorization prevention.

Test verifies that a contract cannot authorize itself, which is a critical security check.


84-156: LGTM! Thorough test coverage for access control.

Excellent set of test cases covering:

  • Default access state
  • Access granting
  • Access revocation
  • Different method selectors
  • Different executors
test/solidity/Facets/CBridge.t.sol (3)

31-35: LGTM! Well-structured event definition.

The CBridgeRefund event properly indexes relevant parameters for efficient filtering.


206-227: LGTM! Thorough success case testing.

Test properly sets up the environment, mocks external calls, and verifies event emission.


229-285: LGTM! Comprehensive error case coverage.

Tests cover all critical error scenarios:

  • Unauthorized caller
  • Invalid call address
  • External call failures
test/solidity/Facets/AcrossFacetV3.t.sol (1)

276-293: LGTM! Good validation of information consistency.

Test properly verifies that mismatched receiver addresses between bridgeData and validAcrossData are caught.

test/solidity/Facets/DeBridgeDlnFacet.t.sol (3)

34-37: LGTM! Well-structured error and event declarations.

The error and event declarations follow best practices with clear naming and proper parameter indexing.


44-57: LGTM! Proper test setup initialization.

The setUp function is correctly updated to include new function selectors for the deBridge chain ID management functionality.


349-394: LGTM! Comprehensive test coverage for deBridge chain ID management.

The test suite effectively covers:

  • Setting and retrieving chain IDs
  • Handling uninitialized facet errors
  • Handling unknown chain ID errors
  • Event emission verification
test/solidity/Facets/CBridgeFacetPacked.t.sol (1)

495-551: LGTM! Thorough error handling tests for triggerRefund.

The test suite comprehensively covers error scenarios:

  • Unauthorized access control
  • Invalid contract address validation
  • External call failure handling
test/solidity/Facets/AmarokFacetPacked.t.sol (1)

50-76: LGTM! Proper test setup for new functionality.

The function selectors array is correctly updated to include the getChainIdForDomain selector.

test/solidity/Facets/AcrossFacetPacked.t.sol (1)

621-633: LGTM! Good failure scenario testing.

The test effectively validates the contract's behavior when a withdrawal operation fails using a mock contract.

@lifi-action-bot
Copy link
Collaborator

Test Coverage Report

Line Coverage: 80.14% (2280 / 2845 lines)
Function Coverage: 85.58% ( 392 / 458 functions)
Branch Coverage: 45.16% ( 252 / 558 branches)
Test coverage (80.14%) is above min threshold (76%). Check passed.

@mirooon mirooon marked this pull request as ready for review February 4, 2025 22:49
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.

2 participants