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

test(e2e): add more test cases for onAbort workflow #3543

Merged
merged 6 commits into from
Feb 20, 2025

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Feb 18, 2025

Description

Closes #3531

Add some more case for onAbort E2E tests:

  • create withdraw during onAbort call
  • cause onAbort to be called because amount can't cover the revert fee

Summary by CodeRabbit

  • New Features

    • Enhanced contract functionality for smoother deployment and improved handling of withdrawal requests.
  • Refactor

    • Consolidated metadata management by modernizing access methods and deprecating legacy identifiers.
  • Tests

    • Updated end-to-end tests for Ethereum and ERC20 workflows with revised values and descriptions to bolster reliability.

@lumtis lumtis added the no-changelog Skip changelog CI check label Feb 18, 2025
Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

📝 Walkthrough

Walkthrough

The pull request updates the TestAbort contract across multiple files by modifying its compiled bytecode and consolidating metadata. The Go and JSON files now reference the updated binary and ABI values from a central metadata structure. The Solidity contract is enhanced with a new RevertOptions struct and two interfaces (IGatewayZEVM and IZRC20) to better manage withdrawal logic in the abort process. Additionally, several end-to-end tests have been adjusted with updated descriptions, parameter values, and control flow checks to align with these contract modifications.

Changes

File(s) Change Summary
e2e/contracts/testabort/TestAbort.go
e2e/contracts/testabort/TestAbort.json
Updated the contract's binary representation and consolidated metadata. Deprecated standalone ABI and binary variables in favor of TestAbortMetaData.ABI and TestAbortMetaData.Bin.
e2e/contracts/testabort/TestAbort.sol Introduced new structure RevertOptions and interfaces IGatewayZEVM and IZRC20. Enhanced the onAbort function to handle withdrawal requests and added the isWithdrawMessage function.
e2e/e2etests/e2etests.go
e2e/e2etests/test_erc20_deposit_revert_and_abort.go
e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go
e2e/e2etests/test_eth_withdraw_revert_and_abort.go
Modified test cases: updated descriptions, adjusted default values (e.g., increasing test amount), removed invalid argument parsing, reformatted method call parameters, and altered abort message checks and withdrawal confirmation sequences.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Contract as TestAbort Contract
    participant ZRC20 as IZRC20 Interface
    participant Gateway as IGatewayZEVM Interface

    User->>Contract: Trigger abort with message "withdraw"
    Contract->>Contract: isWithdrawMessage("withdraw")
    Contract->>ZRC20: Call withdrawGasFee(...)
    ZRC20-->>Contract: Return fee amount
    Contract->>Contract: Validate fee and compute withdrawAmount
    Contract->>Gateway: Call withdraw(RevertOptions)
    Gateway-->>Contract: Confirm withdrawal processed
Loading

Possibly related PRs

Suggested labels

breaking:cli, UPGRADE_TESTS, SOLANA_TESTS

Suggested reviewers

  • fbac
  • skosito
  • kingpinXD
  • ws4charlie
✨ 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.

@lumtis lumtis changed the title On abort improve tests test(e2e): add more test cases for onAbort Feb 18, 2025
@lumtis lumtis changed the title test(e2e): add more test cases for onAbort test(e2e): add more test cases for onAbort workflow Feb 18, 2025
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.54%. Comparing base (d9b7aa0) to head (89dee3e).
Report is 9 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3543      +/-   ##
===========================================
- Coverage    64.68%   64.54%   -0.15%     
===========================================
  Files          453      456       +3     
  Lines        31310    31747     +437     
===========================================
+ Hits         20252    20490     +238     
- Misses       10189    10353     +164     
- Partials       869      904      +35     

see 11 files with indirect coverage changes

@lumtis lumtis marked this pull request as ready for review February 18, 2025 15:34
@lumtis lumtis requested a review from a team as a code owner February 18, 2025 15:34
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 (4)
e2e/contracts/testabort/TestAbort.sol (4)

13-19: Consider documenting the new struct for clarity.

The RevertOptions struct is well-defined, yet it lacks comments or documentation. Adding docstrings describing each field (e.g., revertAddress, callOnRevert, etc.) can help future readers understand the intended usage and constraints.


21-28: Add high-level comments or events to the interface.

The IGatewayZEVM interface’s withdraw function does not emit events or include comments describing its parameters or expected behavior. To improve maintainability, consider documenting the interface with a brief explanation of how the withdrawal mechanism is meant to operate.


56-72: Review approval logic for potential over-allowance.

When calling approve(msg.sender, abortContext.amount) before calling withdraw, you are approving the entire abortContext.amount rather than just withdrawAmount. While this may be intended (e.g., the msg.sender is a trusted gateway), it could present a risk of over-allowance in other scenarios. If more fine-grained control is desired, consider approving only withdrawAmount instead.


75-77: Use caution with string-based message identification.

Implementing isWithdrawMessage via a hash check is straightforward, but be aware of potential scenarios where a message with extra whitespace or unexpected casing might not match. If the system demands flexible matching, consider normalizing or parsing the message. Otherwise, this strict check should suffice.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d9b7aa0 and 89dee3e.

⛔ Files ignored due to path filters (1)
  • e2e/contracts/testabort/TestAbort.bin is excluded by !**/*.bin
📒 Files selected for processing (7)
  • e2e/contracts/testabort/TestAbort.go (1 hunks)
  • e2e/contracts/testabort/TestAbort.json (1 hunks)
  • e2e/contracts/testabort/TestAbort.sol (2 hunks)
  • e2e/e2etests/e2etests.go (2 hunks)
  • e2e/e2etests/test_erc20_deposit_revert_and_abort.go (2 hunks)
  • e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go (1 hunks)
  • e2e/e2etests/test_eth_withdraw_revert_and_abort.go (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • e2e/contracts/testabort/TestAbort.json
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go
  • e2e/e2etests/e2etests.go
  • e2e/e2etests/test_eth_withdraw_revert_and_abort.go
  • e2e/e2etests/test_erc20_deposit_revert_and_abort.go
  • e2e/contracts/testabort/TestAbort.go
🔇 Additional comments (12)
e2e/contracts/testabort/TestAbort.sol (1)

30-33: Verify usage of withdrawGasFee across implementations.

The IZRC20 interface is concise, which is good. However, ensure that withdrawGasFee() consistently returns the correct token and fee across all implementations to prevent unexpected revert scenarios.

e2e/e2etests/test_eth_deposit_and_call_revert_with_call.go (1)

27-34: Good clarity and structure in parameter formatting.

The updated formatting for ETHDepositAndCall with RevertOptions on separate lines makes the code more readable and maintains logical clarity. The approach looks well-structured.

e2e/e2etests/test_erc20_deposit_revert_and_abort.go (4)

18-18: Ensure the test can adapt to different scenarios.

require.Len(r, args, 0) mandates no additional arguments. If new scenarios arise requiring dynamic inputs, this restriction may need revisiting.


29-31: Fixed deposit amount helps demonstrate insufficient fee logic.

Using a hardcoded amount of 1 effectively forces the test to trigger an abort for insufficient fees. This is clear and intentional, though do note that it limits scenario flexibility.


34-34: Aligning RevertAddress with a valid contract address.

Switching from a non-existing address to r.TestDAppV2EVMAddr is sensible, ensuring the onRevert call can succeed if needed.


39-40: Confirm that AbortAddress supports the same interface requirements.

AbortAddress is now set to the newly deployed testAbort contract. Verify that this address implements any expected interface/logic for an abort flow, especially if other tests rely on it.

e2e/e2etests/test_eth_withdraw_revert_and_abort.go (3)

34-38: LGTM! Clear and purposeful configuration of RevertOptions.

The RevertOptions configuration is well-structured, with the revert message set to "withdraw" to create a withdrawal during onAbort execution.


55-57: LGTM! Consistent message verification.

The abort context verification is properly aligned with the new revert message "withdraw".


59-69: LGTM! Comprehensive withdrawal verification.

The test now properly verifies that:

  1. The withdrawal CCTX is mined
  2. The final status is OutboundMined
e2e/contracts/testabort/TestAbort.go (1)

45-45: LGTM! Updated contract bytecode.

This is an auto-generated file, and the bytecode update reflects the changes in the contract's implementation.

e2e/e2etests/e2etests.go (2)

323-325: LGTM! Enhanced test description and parameters.

The changes improve test clarity by:

  1. Adding explicit mention of CCTX creation verification
  2. Increasing the default amount to a more realistic value (1 ETH)

389-390: LGTM! Improved test configuration.

The test description now clearly indicates the abort condition (revert fee cannot be paid), and the removal of explicit arguments suggests the test uses internally defined values for better control.

@lumtis lumtis added this pull request to the merge queue Feb 20, 2025
Merged via the queue into develop with commit ae0b13b Feb 20, 2025
47 checks passed
@lumtis lumtis deleted the on-abort-improve-tests branch February 20, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add E2E test where a cctx is creating during a onAbort call
3 participants