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

feat: support Bitcoin for onAbort and add e2e test cases for no asset calls #3552

Merged
merged 10 commits into from
Feb 20, 2025

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Feb 19, 2025

Description

Closes #3530 #3532

Finally seems it's already supported so this PR just add the test
no asset call evm -> zevm aborts
no asset call zevm -> evm reverts (was actually missing in the first place)
no asset call zevm -> evm aborts

Summary by CodeRabbit

  • New Features
    • Enhanced error handling for cross-chain transactions, improving reliability for deposit and call operations.
  • Tests
    • Expanded end-to-end test coverage to simulate and verify revert and abort scenarios in Bitcoin and Ethereum interactions.
  • Chores
    • Refined transaction messaging to better incorporate abort context, ensuring improved clarity during error conditions.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request introduces several new end-to-end test cases covering cross-chain interactions between ZEVM, EVM, and Bitcoin. The tests focus on scenarios involving transaction reversion and abort, adding cases for both Bitcoin deposits and cross-chain calls. Additionally, the observer module in the Bitcoin chain has been updated to include an abort address in the revert options of vote messages. Existing control flows remain unchanged while expanding test coverage and error handling validation.

Changes

File(s) Summary of Changes
cmd/zetae2e/local/bitcoin.go
cmd/zetae2e/local/evm.go
Extended local test suites with additional entries for Bitcoin deposit and EVM revert/abort scenarios in the respective test groups.
e2e/e2etests/e2etests.go
e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_and_abort.go
e2etests/test_evm_to_zevm_call_abort.go
e2etests/test_zevm_to_evm_call_revert.go
e2etests/test_zevm_to_evm_call_revert_and_abort.go
Added multiple new end-to-end test functions to cover cross-chain call scenarios, including revert and abort conditions for both Bitcoin and EVM-related transactions.
zetaclient/chains/bitcoin/observer/event.go Modified the message construction to include the AbortAddress in the revert options, ensuring that the inbound vote messages correctly handle abort scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as Test Runner
    participant BNode as Bitcoin Node
    participant Abort as Abort Contract
    Runner->>BNode: Initiate Bitcoin deposit test with minimal satoshi deposit
    BNode->>Runner: Mine blocks and process the deposit transaction
    Runner->>Abort: Trigger onAbort callback due to revert/abort condition
    Abort-->>Runner: Confirm call execution and token balance update
    Runner->>Runner: Assert transaction status is aborted
Loading
sequenceDiagram
    participant Runner as Test Runner
    participant Abort as Test Abort Contract
    participant EVM as EVM Contract
    Runner->>Abort: Deploy test abort contract
    Runner->>EVM: Initiate cross-chain call (ZEVM/EVM) with revert options
    EVM-->>Runner: Process cross-chain call and return status (Reverted/Aborted)
    Runner->>Abort: Trigger onAbort callback based on execution outcome
    Runner->>Runner: Verify transaction status and onAbort execution
Loading

Possibly related PRs

Suggested labels

chain:bitcoin, SOLANA_TESTS, UPGRADE_TESTS, E2E

Suggested reviewers

  • fbac
  • kingpinXD
  • skosito
  • swift1337
  • brewmaster012

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 added the no-changelog Skip changelog CI check label Feb 19, 2025
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.70%. Comparing base (c080298) to head (fdf7e5d).
Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3552      +/-   ##
===========================================
+ Coverage    64.61%   64.70%   +0.08%     
===========================================
  Files          458      460       +2     
  Lines        31825    31900      +75     
===========================================
+ Hits         20565    20640      +75     
  Misses       10355    10355              
  Partials       905      905              
Files with missing lines Coverage Δ
zetaclient/chains/bitcoin/observer/event.go 95.86% <100.00%> (+0.02%) ⬆️

... and 5 files with indirect coverage changes

@lumtis lumtis linked an issue Feb 19, 2025 that may be closed by this pull request
@lumtis lumtis changed the title test(e2e): no asset call test cases for onAbort feat: support Bitcoin for onAbort and add e2e test cases for no asset calls Feb 19, 2025
@lumtis lumtis marked this pull request as ready for review February 19, 2025 17:41
@lumtis lumtis requested a review from a team as a code owner February 19, 2025 17:41
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 (5)
e2e/e2etests/test_evm_to_zevm_call_abort.go (1)

17-43: Consider adding test cleanup and using constants.

The test structure is clear, but consider these improvements:

  1. Add cleanup for the deployed contract
  2. Extract magic values like "revert" into constants
+const (
+    testRevertMessage = "revert"
+)

 func TestEVMToZEVMCallAbort(r *runner.E2ERunner, args []string) {
     require.Len(r, args, 0)
+    defer func() {
+        // Cleanup deployed contract
+        _ = r.ZEVMClient.Close()
+    }()
     
     // ... rest of the test
-    []byte("revert"),
+    []byte(testRevertMessage),
e2e/e2etests/test_zevm_to_evm_call_revert.go (1)

16-49: Add documentation and extract magic numbers.

The test would benefit from:

  1. Documentation explaining the test's purpose and expected behavior
  2. Extracting the hardcoded gas limit into a constant
  3. Ensuring randomPayload helper is properly defined
+// TestZEVMToEVMCallRevert verifies that a cross-chain call from ZEVM to EVM
+// properly reverts when calling a non-existing address, and the revert message
+// is correctly propagated back to the sender.
+
+const (
+    defaultRevertGasLimit = 200000
+)

 func TestZEVMToEVMCallRevert(r *runner.E2ERunner, args []string) {
     // ... rest of the test
-    OnRevertGasLimit: big.NewInt(200000),
+    OnRevertGasLimit: big.NewInt(defaultRevertGasLimit),
e2e/e2etests/test_zevm_to_evm_call_revert_and_abort.go (1)

17-54: Validate gas limit and reuse constants.

Consider these improvements:

  1. Validate that the gas limit is sufficient
  2. Reuse the revert message constant
  3. Add validation for the abort context values
+const (
+    minRevertGasLimit = 100000
+    defaultRevertGasLimit = 200000
+    revertMessage = "revert"
+)

 func TestZEVMToEVMCallRevertAndAbort(r *runner.E2ERunner, args []string) {
     require.Len(r, args, 0)
+    
+    // Validate gas limit
+    gasLimit := big.NewInt(defaultRevertGasLimit)
+    require.True(r, gasLimit.Cmp(big.NewInt(minRevertGasLimit)) >= 0, 
+        "Gas limit must be at least %d", minRevertGasLimit)

     // ... rest of the test
-    []byte("revert"),
+    []byte(revertMessage),
e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_and_abort.go (2)

15-62: Document memo fields and extract constants.

The test has good structure but could benefit from:

  1. Documentation for memo fields and their purpose
  2. Constants for the deposit amount
  3. Validation of the balance check
+const (
+    // oneStaoshi is intentionally low to trigger insufficient gas error
+    oneSatoshi = 0.00000001
+)

 func TestBitcoinStdMemoDepositAndCallRevertAndAbort(r *runner.E2ERunner, args []string) {
     // Start mining blocks
     stop := r.MineBlocksIfLocalBitcoin()
     defer stop()

     require.Len(r, args, 0)
-    amount := 0.00000001 // 1 satoshi so revert fails because of insufficient gas
+    amount := oneSatoshi

     // ... rest of the test

     // check abort contract received the tokens
     balance, err := r.BTCZRC20.BalanceOf(&bind.CallOpts{}, testAbortAddr)
     require.NoError(r, err)
-    require.True(r, balance.Uint64() > 0)
+    require.True(r, balance.Uint64() > 0, 
+        "Expected non-zero balance, got %d", balance.Uint64())

28-41: Add documentation for memo fields.

The memo structure would benefit from documentation explaining the purpose of each field.

+    // Create a memo to call non-existing contract with the following fields:
+    // - Version: 0 (current version)
+    // - EncodingFmt: Compact short format for efficiency
+    // - OpCode: Deposit and call operation
+    // - Receiver: Non-existing contract to trigger revert
+    // - RevertOptions: Configuration for abort handling
     inboundMemo := &memo.InboundMemo{
         Header: memo.Header{
             Version:     0,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c080298 and 7232567.

📒 Files selected for processing (8)
  • cmd/zetae2e/local/bitcoin.go (1 hunks)
  • cmd/zetae2e/local/evm.go (1 hunks)
  • e2e/e2etests/e2etests.go (5 hunks)
  • e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_and_abort.go (1 hunks)
  • e2e/e2etests/test_evm_to_zevm_call_abort.go (1 hunks)
  • e2e/e2etests/test_zevm_to_evm_call_revert.go (1 hunks)
  • e2e/e2etests/test_zevm_to_evm_call_revert_and_abort.go (1 hunks)
  • zetaclient/chains/bitcoin/observer/event.go (1 hunks)
🧰 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.

  • cmd/zetae2e/local/bitcoin.go
  • zetaclient/chains/bitcoin/observer/event.go
  • cmd/zetae2e/local/evm.go
  • e2e/e2etests/test_evm_to_zevm_call_abort.go
  • e2e/e2etests/test_zevm_to_evm_call_revert_and_abort.go
  • e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_and_abort.go
  • e2e/e2etests/test_zevm_to_evm_call_revert.go
  • e2e/e2etests/e2etests.go
🔇 Additional comments (9)
cmd/zetae2e/local/evm.go (1)

66-68: LGTM! The new test cases enhance error handling coverage.

The added test cases provide comprehensive coverage for cross-chain call scenarios involving reverts and aborts between ZEVM and EVM.

cmd/zetae2e/local/bitcoin.go (1)

35-35: LGTM! The new test case enhances Bitcoin error handling coverage.

The added test case provides coverage for Bitcoin deposit and call scenarios involving both revert and abort conditions.

zetaclient/chains/bitcoin/observer/event.go (1)

220-220:

✅ Verification successful

LGTM! The abort address support enhances error handling for Bitcoin transactions.

The addition of AbortAddress to RevertOptions enables proper handling of onAbort functionality for Bitcoin transactions.

Run the following script to verify that the abort address is properly handled in other Bitcoin-related code:


🏁 Script executed:

#!/bin/bash
# Description: Verify abort address handling in Bitcoin-related code.

# Test: Search for other occurrences of AbortAddress to ensure consistent handling.
rg -A 5 $'AbortAddress'

# Test: Search for potential missing abort address handling in Bitcoin-related code.
rg -g 'bitcoin/**' -A 5 $'RevertOptions'

Length of output: 31575


Approval: Abort Address Enhancement Verified

The integration of the AbortAddress field into RevertOptions in the Bitcoin observer is consistent with its usage throughout the codebase and documentation. The search results confirm that this new field is referenced appropriately in tests, contract integrations, and the standard memo format. Note that the secondary search for RevertOptions within the Bitcoin directory did not yield output due to filtering limitations; however, manual inspection of zetaclient/chains/bitcoin/observer/event.go shows the correct incorporation of AbortAddress.

  • Confirmed usage in documentation (RFC) and in multiple test files.
  • Consistent implementation alongside related fields (e.g., RevertMessage) in standard memo handling.
  • Suggest a manual re-check of Bitcoin modules if extra caution is needed during regression testing.

LGTM.

e2e/e2etests/e2etests.go (6)

49-50: LGTM! The new test case constants enhance test coverage for ZEVM to EVM calls.

The added test case constants follow the established naming convention and provide clear descriptions of their purpose.


53-53: LGTM! The new test case constant enhances test coverage for EVM to ZEVM calls.

The added test case constant follows the established naming convention and provides a clear description of its purpose.


99-99: LGTM! The new test case constant enhances test coverage for Bitcoin transactions.

The added test case constant follows the established naming convention and provides a clear description of its purpose.


471-482: LGTM! The new test definitions enhance test coverage for ZEVM to EVM calls.

The added test definitions include appropriate descriptions and follow the established pattern for test registration.


495-500: LGTM! The new test definition enhances test coverage for EVM to ZEVM calls.

The added test definition includes an appropriate description and follows the established pattern for test registration.


740-745: LGTM! The new test definition enhances test coverage for Bitcoin transactions.

The added test definition includes an appropriate description and follows the established pattern for test registration.

Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

LGTM

@lumtis lumtis added this pull request to the merge queue Feb 19, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 19, 2025
@lumtis lumtis enabled auto-merge February 20, 2025 08:48
@lumtis lumtis added this pull request to the merge queue Feb 20, 2025
Merged via the queue into develop with commit 01e20db Feb 20, 2025
45 checks passed
@lumtis lumtis deleted the onAbort-no-asset branch February 20, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support onAbort for non EVM chain Add support for onAbort for no asset calls
3 participants