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

Adding tests for Crosschain_Base and PP_Connext_Crosschain - DRAFT #694

Draft
wants to merge 92 commits into
base: feature/crosschain-paymentProcessor
Choose a base branch
from

Conversation

leeftk
Copy link

@leeftk leeftk commented Nov 21, 2024

Pull Request Note

Overview

This pull request introduces significant updates to the PP_Connext_Crosschain_v1_Test contract and related modules. The changes primarily focus on enhancing the cross-chain functionality, fixing compilation issues, and adding comprehensive unit tests to ensure the reliability of the new implementations.

Key Changes

  • Cross-Chain Module Integration: Added logic to support cross-chain operations in the PP_Connext_Crosschain contract.
  • Refactoring: Refactored the template module for better structure and maintainability.
  • Compilation Fixes: Resolved various compilation issues that arose during the integration of new features and dependencies.
  • Unit Tests:
    • Added unit tests for the processPayments function, including edge cases for insufficient balances and payment ID checks.
    • Implemented fuzz tests to validate the robustness of payment processing under various conditions.
    • Verified the execution data and bridge data integrity through dedicated tests.
  • Code Cleanup: Removed unnecessary state variables and old templates to streamline the codebase.

Notable Commit

======= First half of these commits were already reviewed =======

  • Nov 1, 2024: Added cross-chain module and ensured contracts compile.
  • Nov 4, 2024: Refactored template module for improved clarity.
  • Nov 5-8, 2024: Addressed compilation issues and added the Everclear implementation.

======= These are the new changes after the last PR =======

  • Nov 12-20, 2024: Focused on unit tests, including edge cases and fuzz testing, to ensure the reliability of the cross-chain functionality.

Future Work

  • Explore additional test cases to cover more edge scenarios.
  • Consider further optimizations based on feedback from the testing phase.
  • Refactor and adding comments

Focus Areas

  • Please focus on the tests related to the logic implemented in the cross-chain module. Ensure that our setup is correct when instantiating contracts and that all dependencies are properly accounted for.
  • Provide feedback on test coverage, identifying any blind spots or areas where we can improve.
  • We still need to add tests for the base/abtracts, if they aren't added by the time you review this please add what we should be testing there

@leeftk leeftk force-pushed the zuhaibmohd-branch-tests branch 4 times, most recently from 238a99e to 2b4b9c5 Compare November 22, 2024 00:01
@leeftk leeftk marked this pull request as draft November 22, 2024 00:07
Copy link
Contributor

@FHieser FHieser left a comment

Choose a reason for hiding this comment

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

Didnt have time to go through this fully, but this should give you enough material to work on.

@leeftk leeftk force-pushed the zuhaibmohd-branch-tests branch 2 times, most recently from 1d6c23d to 4aa8384 Compare November 27, 2024 21:49
Copy link
Collaborator

@Zitzak Zitzak left a comment

Choose a reason for hiding this comment

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

I think looks good in general. I do have a bit of a harder time reviewing the tests as we are starting right away with the implementation and not the base contracts first. This means I need to check back and forth with the underlying contracts.

Additionally there are different formatting related things concerning the written gherkin as well as the functions names. I'm wondering if it might make sense to merge the other PR, update this one and then maybe have a peer-programming session to do some quick clean up? Lmk what you think

.vscode/settings.json Outdated Show resolved Hide resolved
src/modules/paymentProcessor/PP_Connext_Crosschain_v1.sol Outdated Show resolved Hide resolved
│ ├── When processing through Connext bridge
│ │ ├── Then it should emit PaymentProcessed event
│ │ ├── Then it should transfer tokens correctly
│ │ └── Then it should create Connext intent
Copy link
Collaborator

Choose a reason for hiding this comment

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

How can we check that an intent has been created?

Copy link
Author

Choose a reason for hiding this comment

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

Good point, in our mock we're changing the status of the intent to ADDED but we should be verifying that in the test.


        // Set intent status to ADDED and emit the event
        status[_intentId] = IntentStatus.ADDED;
        
        ```

Copy link
Author

Choose a reason for hiding this comment

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

I think processPayments will need to return the intentID, at least for the tests, this will allow us to check if the status has been changed in the mock

Copy link
Author

Choose a reason for hiding this comment

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

@leeftk this is a general comment for testing the intentID

Copy link
Author

Choose a reason for hiding this comment

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

I added this as we discussed, there's now a mapping in the payment process that stores the payment -> receive -> bridge data. We're now getting that value from the payment processor, and then checking that the status in the mock contract for that intentID has flipped to added. Please take a look at this to see if it follow what we discuss on the call, any feedback is welcome.

@leeftk
Copy link
Author

leeftk commented Dec 4, 2024

I think looks good in general. I do have a bit of a harder time reviewing the tests as we are starting right away with the implementation and not the base contracts first. This means I need to check back and forth with the underlying contracts.

Additionally there are different formatting related things concerning the written gherkin as well as the functions names. I'm wondering if it might make sense to merge the other PR, update this one and then maybe have a peer-programming session to do some quick clean up? Lmk what you think

I didn't understand this comment do you mean that the CrossChainBase isn't tested or something else? Sorry Im not following, however we might have added the tests after your initial review and so that's why you didn't see them but they are there now.

@leeftk leeftk force-pushed the zuhaibmohd-branch-tests branch from 8eb89d9 to 197a65a Compare December 17, 2024 00:19
@leeftk
Copy link
Author

leeftk commented Dec 17, 2024

Quick update here

  • Addressed all the comments from the last PR
  • Added functionality for cancelling and retrying failed payments
  • Added tests for this
  • Added a path to the mock that returns bytes(0) for a "failed" payment, this allows us to test the new functionality
  • Cleaned up and refactored both PP_Connext and Crosschain_base as per the standard
  • Rebased onto feature branch
  • Removed redundant files after the rebase
  • Updated gherkin as per our call
  • Addressed almost all of the comments from the last PR

There is a core issue I couldn't wrap my head around, seems like in cancel payments I need to update amountPaid for the client however when I do Im getting an overflow/underflow issue. I believe the issue is from this _outstandingTokenAmounts[token] -= amount; Im not sure how we should be handling this, maybe we discuss this on a call or you can go in and fix it if you find that to be easier. For now I left it uncommented cause Im still not completely sure on why we need to do this.

For this review I'd love the focus to be on the added functionality however as you review if you find anything else that's wrong and doesn't meet the standard please add that here and I'll make those changes. Thanks again and looking forward to the feedback.

@Zitzak
Copy link
Collaborator

Zitzak commented Dec 23, 2024

@Zitzak notes for my review

  • Focus on failed payment
  • Focus on canceling payment if keeps failing
  • Addresses all the comments

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

Successfully merging this pull request may close these issues.

5 participants