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: move btc revertAddress test to advanced group to avoid upgrade test failure #3205

Merged
merged 3 commits into from
Nov 25, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Nov 22, 2024

Description

Move bitcoin_std_memo_deposit_and_call_revert_other_address to advanced test group.

Closes: #3204

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Added a new section "Unreleased" in the changelog for future updates.
    • Introduced a new test case for Bitcoin deposit functionalities to enhance testing coverage.
  • Bug Fixes

    • Updated assertion methods in Bitcoin deposit tests to ensure immediate test failure on assertion failure, improving test reliability.
  • Documentation

    • Changelog updated to reflect new sections and test entries.

Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

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

Walkthrough

The pull request introduces updates to the changelog and several test files related to Bitcoin deposit functionalities. A new section titled "Unreleased" is added to the changelog, including a note about relocating a Bitcoin revert address test to an advanced group. Additionally, new test cases are introduced, and existing assertions in the Bitcoin deposit tests are modified to use stricter failure conditions, enhancing the robustness of the test suite without altering the overall control flow.

Changes

File Path Change Summary
changelog.md - Added new section ## Unreleased
- Added subsections ### Features and ### Tests
- Added entry for moving Bitcoin revert address test to advanced group.
cmd/zetae2e/local/local.go - Added new test case TestBitcoinStdMemoDepositAndCallRevertOtherAddressName to bitcoinDepositTestsAdvanced slice.
e2e/e2etests/test_bitcoin_deposit_and_call_revert.go - Replaced assert.Equal and assert.Positive with require.Equal and require.True in TestBitcoinDepositAndCallRevert.
e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go - Replaced assert.Equal and assert.Positive with require.Equal and require.True in TestBitcoinStdMemoDepositAndCallRevert.
e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_other_address.go - Replaced assert.Equal and assert.Positive with require.Equal and require.True in TestBitcoinStdMemoDepositAndCallRevertOtherAddress.

Assessment against linked issues

Objective Addressed Explanation
Ensure that errors in tests are treated as fatal (e.g., #3204)

Possibly related PRs

Suggested labels

no-changelog, UPGRADE_TESTS, UPGRADE_LIGHT_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • swift1337
  • skosito
  • brewmaster012
  • lumtis

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 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.

@ws4charlie ws4charlie added test Tests related chain:bitcoin Bitcoin chain related zetaclient Issues related to ZetaClient and removed breaking:cli labels Nov 22, 2024
@ws4charlie ws4charlie marked this pull request as ready for review November 22, 2024 19:14
@lumtis lumtis added the UPGRADE_TESTS Run make start-upgrade-tests label Nov 22, 2024
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: 1

🧹 Outside diff range and nitpick comments (5)
e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go (2)

Line range hint 11-11: Move test to advanced group per PR objectives

This test should be moved to the advanced test group to prevent upgrade test failures as specified in the PR objectives. Consider adding a group identifier or moving the file to an advanced test directory.

Consider one of these approaches:

  1. Add a test group identifier:
-func TestBitcoinStdMemoDepositAndCallRevert(r *runner.E2ERunner, args []string) {
+func TestBitcoinStdMemoDepositAndCallRevert_Advanced(r *runner.E2ERunner, args []string) {
  1. Move the file to an advanced test directory:
mkdir -p e2e/e2etests/advanced/
git mv e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go e2e/e2etests/advanced/

47-47: Improve logging format and information

The current logging statement could be enhanced to provide more structured and detailed information about the test execution.

Consider updating the log message:

-	r.Logger.Info("Sent %f BTC to TSS to call non-existing contract, got refund of %d satoshis", amount, value)
+	r.Logger.Info("Bitcoin deposit and call revert test completed",
+		"sent_btc", amount,
+		"refund_satoshis", value,
+		"receiver", receiver,
+		"test_group", "advanced")
e2e/e2etests/test_bitcoin_deposit_and_call_revert.go (1)

42-43: LGTM! Consider enhancing error messages for better debugging.

The change from assert to require is a good improvement as it ensures immediate test failure on invalid conditions. However, we could make the error messages more descriptive.

Consider adding more descriptive error messages:

-require.Equal(r, r.BTCDeployerAddress.EncodeAddress(), receiver)
-require.True(r, value > 0)
+require.Equal(r, r.BTCDeployerAddress.EncodeAddress(), receiver, "refund should be sent to deployer address")
+require.True(r, value > 0, "refund amount should be positive")

Additionally, consider validating that the refund amount matches the expected value (minus fees) for stronger verification.

e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_other_address.go (2)

Line range hint 1-47: Consider improving test robustness and explicitness

A few suggestions to enhance the test:

  1. Consider extracting the hardcoded revert address to a test constant or generating it dynamically
  2. Add explicit verification that the target contract doesn't exist before proceeding with the test
  3. Consider adding a comment explaining why sample.EthAddress() is used for a non-existing contract

Example improvement:

+ // Verify contract doesn't exist
+ exist := r.QueryContractExistence(sample.EthAddress())
+ require.False(r, exist, "Contract should not exist")

48-54: LGTM! Consider enhancing value assertions

The switch to require is appropriate as these are critical assertions. Two minor suggestions for improvement:

  1. Consider adding descriptive error messages to the require statements
  2. The value check could be more specific, verifying that the reverted amount is less than or equal to the original amount (accounting for fees)

Example improvements:

- require.Equal(r, cctx.InboundParams.Sender, r.BTCDeployerAddress.EncodeAddress())
+ require.Equal(r, cctx.InboundParams.Sender, r.BTCDeployerAddress.EncodeAddress(), "Inbound sender should match deployer address")
- require.True(r, value > 0)
+ require.True(r, value > 0 && value <= amount*1e8, "Reverted amount should be positive and not exceed original amount")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cda3398 and a88b3d3.

📒 Files selected for processing (5)
  • changelog.md (1 hunks)
  • cmd/zetae2e/local/local.go (1 hunks)
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert.go (1 hunks)
  • e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go (1 hunks)
  • e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_other_address.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • changelog.md
🧰 Additional context used
📓 Path-based instructions (4)
cmd/zetae2e/local/local.go (1)

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

e2e/e2etests/test_bitcoin_deposit_and_call_revert.go (1)

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

e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go (1)

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

e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_other_address.go (1)

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

🔇 Additional comments (2)
e2e/e2etests/test_bitcoin_deposit_and_call_revert.go (1)

Line range hint 1-47: Verify error handling for critical refund path.

This test verifies a critical path where user funds must be refunded correctly. We should ensure comprehensive error handling.

Let's verify the error handling implementation:

✅ Verification successful

Error handling for critical refund path is well-implemented.

The verification shows comprehensive error handling across the Bitcoin deposit and refund paths:

  • The test verifies both the happy and error paths, including refund scenarios for invalid memos and dust amounts
  • Error handling is implemented at multiple layers:
    • Deposit fee calculation errors in zetaclient/chains/bitcoin/observer/witness.go
    • Amount validation against minimum deposit fees
    • Proper error propagation through the RPC layer
    • End-to-end test coverage for refund scenarios with invalid memos and dust amounts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check error handling in Bitcoin deposit related code
# Look for error handling patterns in related files

# Check for error handling in Bitcoin deposit related files
rg -A 5 "Error|err|panic" --type go | grep -i "bitcoin.*deposit"

# Look for other revert test cases
ast-grep --pattern 'func Test.*Bitcoin.*Revert.*\(.*\) {
  $$$
}'

Length of output: 16036

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

341-341: LGTM! Test correctly moved to advanced group.

The test case has been appropriately placed in the bitcoinDepositTestsAdvanced slice, which aligns with the PR objective of moving it to prevent upgrade test failures.

Let's verify that the test constant exists in the e2etests package:

✅ Verification successful

✓ Test constant properly defined and referenced

The test constant TestBitcoinStdMemoDepositAndCallRevertOtherAddressName is correctly defined in e2e/e2etests/e2etests.go and appropriately referenced in the advanced test group.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test constant exists in e2etests package
rg -l "TestBitcoinStdMemoDepositAndCallRevertOtherAddressName.*=.*" 

Length of output: 94


Script:

#!/bin/bash
# Let's verify the actual constant declaration to ensure it's properly defined
rg "TestBitcoinStdMemoDepositAndCallRevertOtherAddressName.*=.*" -A 1

Length of output: 340

@ws4charlie ws4charlie enabled auto-merge November 23, 2024 06:34
Copy link

gitguardian bot commented Nov 25, 2024

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
14567965 Triggered Generic Password 69391aa cmd/zetaclientd/start.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@ws4charlie ws4charlie added this pull request to the merge queue Nov 25, 2024
Merged via the queue into develop with commit fffbcab Nov 25, 2024
40 of 41 checks passed
@ws4charlie ws4charlie deleted the e2e-replace-asset-with-require branch November 25, 2024 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli chain:bitcoin Bitcoin chain related test Tests related UPGRADE_TESTS Run make start-upgrade-tests zetaclient Issues related to ZetaClient
Projects
None yet
Development

Successfully merging this pull request may close these issues.

e2e: test_bitcoin_std_deposit_and_call_revert_other_address error logged but no failure
3 participants