Skip to content

refactor(e2e): sign bitcoin transactions locally#3753

Merged
gartnera merged 7 commits intodevelopfrom
bitcoin-localsign
Mar 27, 2025
Merged

refactor(e2e): sign bitcoin transactions locally#3753
gartnera merged 7 commits intodevelopfrom
bitcoin-localsign

Conversation

@gartnera
Copy link
Contributor

@gartnera gartnera commented Mar 24, 2025

Sign bitcoin transactions locally rather than making an RPC call. This removes the need to load private keys into the bitcoin node.

Also:

  • remove all references to the deployer account from each test routine. Now each routine is fully stand alone to prevent race conditions
  • use the bitcoin_deposit test to fund the withdraw test just like we do on the ethereum side
  • check balance before actually running withdraw to avoid opaque execution reverted errors. Related to Return raw revert code if not unpackable ethermint#234

We probably should be a bit more intelligent about the input UTXOs but that does not seem to be necessary right now.

Summary by CodeRabbit

  • Refactor

    • Unified Bitcoin address and key handling by switching to a keypair-based approach and removing deployer-specific references.
  • Tests

    • Enhanced Bitcoin deposit, withdrawal, swap, and memo tests with improved validations and error handling.
    • Increased the default deposit amount from 0.001 BTC to 1.0 BTC.
  • Chores

    • Removed deprecated raw transaction and signing features.
    • Adjusted balance calculations to incorporate all applicable outputs for more accuracy.

@gartnera gartnera added the no-changelog Skip changelog CI check label Mar 24, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 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 refactors Bitcoin handling across multiple components by replacing deployer-specific methods with generalized ones. The changes update address retrieval to return keypairs via GetBtcKeypair(), revise UTXO listing and transaction sending methods (transitioning from deployer-specific calls to ListUTXOs() and SendToTSSFromWithMemo()), and adjust various test cases accordingly. In addition, some deprecated raw transaction and signing functions have been removed from the Bitcoin client interface, and balance calculation logic has been simplified.

Changes

File(s) Change Summaries
cmd/zetae2e/bitcoin_address.go
e2e/runner/setup_bitcoin.go
Renamed GetBtcAddress() to GetBtcKeypair() and updated address retrieval logic; in setup, a new GetBtcAddress() now wraps the keypair method.
cmd/zetae2e/local/bitcoin.go
cmd/zetae2e/run.go
e2e/e2etests/e2etests.go
Updated test configurations: new Bitcoin deposit test case added, deposit default value changed, and removal of BTC deployer address assignment in test runner.
Multiple test files in e2e/e2etests/
(e.g., test_bitcoin_deposit.go, test_bitcoin_deposit_and_call_revert.go, test_bitcoin_deposit_call.go, test_bitcoin_donation.go, test_crosschain_swap.go, etc.)
Replaced deployer-specific method calls with generalized ones (e.g., from ListDeployerUTXOs() to ListUTXOs(), from SendToTSSFromDeployerWithMemo() to SendToTSSFromWithMemo(), and from using BTCDeployerAddress.EncodeAddress() to GetBtcAddress().EncodeAddress()).
e2e/runner/balances.go
e2e/runner/bitcoin.go
e2e/runner/runner.go
In the runner, the balance calculation logic was simplified, Bitcoin transaction methods were refactored to remove hardcoded deployer dependencies, and the BTCDeployerAddress field was removed.
zetaclient/chains/bitcoin/client/commands.go
zetaclient/chains/bitcoin/client/mockgen.go
Deprecated raw transaction methods and signing methods (CreateRawTransaction, SignRawTransactionWithWallet2, and ImportPrivKeyRescan) were removed from the client interface and corresponding mocks updated.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Function
    participant E as E2ERunner
    participant B as Bitcoin RPC Client
    T->>E: GetBtcKeypair()
    E-->>T: (Address, PrivateKey)
    T->>E: ListUTXOs()
    E-->>T: UTXO List
    T->>E: SendToTSSFromWithMemo(amount, UTXOs, memo)
    E->>B: Construct & Sign Transaction
    B-->>E: Transaction Hash
    E-->>T: Transaction Hash
Loading

Possibly related PRs

Suggested labels

improvement, chain:bitcoin, UPGRADE_TESTS

Suggested reviewers

  • lumtis

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@gartnera gartnera force-pushed the bitcoin-localsign branch 2 times, most recently from 7aabf11 to 38151a5 Compare March 26, 2025 18:23
@gartnera gartnera force-pushed the bitcoin-localsign branch from 38151a5 to 76f3f56 Compare March 26, 2025 18:29
@gartnera gartnera requested a review from ws4charlie March 26, 2025 20:25
@gartnera gartnera marked this pull request as ready for review March 26, 2025 20:25
@gartnera gartnera requested a review from a team as a code owner March 26, 2025 20:25
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 (6)
e2e/e2etests/test_bitcoin_deposit_invalid_memo_revert.go (1)

44-45: Consider refactoring repetitive test cases.

The test structure shows three very similar test cases with only the memo parameter changing. Consider refactoring to a table-driven test approach to improve maintainability and reduce code duplication.

func TestBitcoinDepositInvalidMemoRevert(r *runner.E2ERunner, args []string) {
	require.Len(r, args, 0)

	// mine blocks at normal speed
	stop := r.MineBlocksIfLocalBitcoin()
	defer stop()

+	testCases := []struct {
+		name string
+		memo []byte
+	}{
+		{
+			name: "deposit without memo",
+			memo: nil,
+		},
+		{
+			name: "deposit empty memo",
+			memo: []byte{},
+		},
+		{
+			name: "deposit invalid memo",
+			memo: []byte("invalid memo"),
+		},
+	}
+
+	for _, tc := range testCases {
+		utxos := r.ListUTXOs()
+		txHash, err := r.SendToTSSFromWithMemo(0.1, utxos[:1], tc.memo)
+		require.NoError(r, err)
+
+		// wait for the cctx to be mined
+		cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
+		r.Logger.CCTX(*cctx, tc.name)
+		utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted)
+		require.EqualValues(r, crosschaintypes.InboundStatus_INVALID_MEMO, cctx.InboundParams.Status)
+	}
-	// CASE 1
-	// make a deposit without memo output
-	utxos := r.ListUTXOs()
-	txHash, err := r.SendToTSSFromWithMemo(0.1, utxos[:1], nil)
-	require.NoError(r, err)
-
-	// wait for the cctx to be mined
-	cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
-	r.Logger.CCTX(*cctx, "deposit without memo")
-	utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted)
-	require.EqualValues(r, crosschaintypes.InboundStatus_INVALID_MEMO, cctx.InboundParams.Status)
-
-	// CASE 2
-	// make a deposit with a empty memo
-	utxos = r.ListUTXOs()
-	txHash, err = r.SendToTSSFromWithMemo(0.1, utxos[:1], []byte{})
-	require.NoError(r, err)
-
-	// wait for the cctx to be mined
-	cctx = utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
-	r.Logger.CCTX(*cctx, "deposit empty memo")
-	utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted)
-	require.EqualValues(r, crosschaintypes.InboundStatus_INVALID_MEMO, cctx.InboundParams.Status)
-
-	// CASE 3
-	// make a deposit with an invalid memo
-	utxos = r.ListUTXOs()
-	txHash, err = r.SendToTSSFromWithMemo(0.1, utxos[:1], []byte("invalid memo"))
-	require.NoError(r, err)
-
-	// wait for the cctx to be mined
-	cctx = utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
-	r.Logger.CCTX(*cctx, "deposit invalid memo")
-	utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted)
-	require.EqualValues(r, crosschaintypes.InboundStatus_INVALID_MEMO, cctx.InboundParams.Status)
}
e2e/runner/setup_bitcoin.go (1)

69-73: Incorrect function comment for GetBtcAddress.

The function comment states "GetBtcKeypair returns..." but should be "GetBtcAddress returns..." to accurately reflect the function's purpose.

-// GetBtcKeypair returns the BTC address of the runner account
+// GetBtcAddress returns the BTC address of the runner account
 func (r *E2ERunner) GetBtcAddress() *btcutil.AddressWitnessPubKeyHash {
 	address, _ := r.GetBtcKeypair()
 	return address
 }
e2e/runner/balances.go (1)

171-171: Consider handling unused private key more explicitly.

The function now retrieves both the address and private key using GetBtcKeypair() but discards the private key with _. While this is a common pattern, explicitly commenting on the intentional discard of the private key would improve code clarity, especially given the security implications.

-address, _ := r.GetBtcKeypair()
+// We only need the address for balance checking, not the private key
+address, _ := r.GetBtcKeypair()
e2e/runner/bitcoin.go (3)

206-248: Refactored transaction creation for local signing.

The transaction creation logic has been completely rewritten to create and sign transactions locally instead of using the node's wallet RPCs. This is a key implementation of the PR's objective to eliminate the need for loading private keys into the Bitcoin node.

However, there are a few aspects that could be improved:

  1. There's no explicit fee calculation based on transaction size
  2. No handling for different script types (assuming all inputs are P2WPKH)
  3. No verification that inputs haven't been spent elsewhere

These issues might be acceptable in a test environment but should be considered for production use.

Consider adding more robust fee calculation based on transaction size and weight, and adding support for different script types.


249-251: Consider clarifying the purpose of rearranging outputs.

The code swaps TxOut elements to move the memo output to the second position, but it's not immediately clear why this is necessary or what convention it's following.

 // Move memo output to second position
+// Bitcoin convention is to have recipient output first, memo second, and change last
 tx.TxOut[1], tx.TxOut[2] = tx.TxOut[2], tx.TxOut[1]

260-284: Implemented local transaction signing.

The transaction signing process now happens locally instead of relying on the Bitcoin node's wallet. This implements the core objective of the PR to sign Bitcoin transactions locally.

The code correctly constructs the witness data for P2WPKH inputs using the WitnessSignature function, but assumes all inputs are of the same type.

For more robust transaction signing, consider adding support for different script types by checking the script format before choosing the signing method.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d575d3d and 63285c4.

📒 Files selected for processing (25)
  • cmd/zetae2e/bitcoin_address.go (1 hunks)
  • cmd/zetae2e/local/bitcoin.go (3 hunks)
  • cmd/zetae2e/run.go (0 hunks)
  • e2e/e2etests/e2etests.go (1 hunks)
  • e2e/e2etests/helpers.go (2 hunks)
  • e2e/e2etests/test_bitcoin_deposit.go (2 hunks)
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert.go (2 hunks)
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go (2 hunks)
  • e2e/e2etests/test_bitcoin_deposit_and_withdraw_with_dust.go (1 hunks)
  • e2e/e2etests/test_bitcoin_deposit_call.go (3 hunks)
  • e2e/e2etests/test_bitcoin_deposit_invalid_memo_revert.go (3 hunks)
  • e2e/e2etests/test_bitcoin_donation.go (1 hunks)
  • e2e/e2etests/test_bitcoin_std_deposit_and_call.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)
  • e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go (1 hunks)
  • e2e/e2etests/test_bitcoin_withdraw_segwit.go (1 hunks)
  • e2e/e2etests/test_crosschain_swap.go (4 hunks)
  • e2e/e2etests/test_stress_btc_withdraw.go (1 hunks)
  • e2e/runner/balances.go (2 hunks)
  • e2e/runner/bitcoin.go (13 hunks)
  • e2e/runner/runner.go (0 hunks)
  • e2e/runner/setup_bitcoin.go (5 hunks)
  • zetaclient/chains/bitcoin/client/commands.go (0 hunks)
  • zetaclient/chains/bitcoin/client/mockgen.go (0 hunks)
💤 Files with no reviewable changes (4)
  • cmd/zetae2e/run.go
  • e2e/runner/runner.go
  • zetaclient/chains/bitcoin/client/commands.go
  • zetaclient/chains/bitcoin/client/mockgen.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

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

  • e2e/e2etests/test_bitcoin_withdraw_segwit.go
  • e2e/e2etests/test_bitcoin_std_deposit_and_call.go
  • e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go
  • e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_other_address.go
  • cmd/zetae2e/bitcoin_address.go
  • cmd/zetae2e/local/bitcoin.go
  • e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go
  • e2e/e2etests/e2etests.go
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go
  • e2e/e2etests/test_stress_btc_withdraw.go
  • e2e/e2etests/test_bitcoin_donation.go
  • e2e/e2etests/helpers.go
  • e2e/e2etests/test_bitcoin_deposit_call.go
  • e2e/e2etests/test_bitcoin_deposit_and_withdraw_with_dust.go
  • e2e/e2etests/test_bitcoin_deposit_and_call_revert.go
  • e2e/runner/balances.go
  • e2e/e2etests/test_bitcoin_deposit.go
  • e2e/runner/setup_bitcoin.go
  • e2e/e2etests/test_bitcoin_deposit_invalid_memo_revert.go
  • e2e/e2etests/test_crosschain_swap.go
  • e2e/runner/bitcoin.go
🧠 Learnings (2)
cmd/zetae2e/bitcoin_address.go (1)
Learnt from: gartnera
PR: zeta-chain/node#3105
File: e2e/runner/setup_bitcoin.go:51-69
Timestamp: 2025-03-26T19:42:34.108Z
Learning: In test code (`e2e/runner/setup_bitcoin.go`), adding security measures for private key handling in the `GetBtcAddress` method is not required.
e2e/runner/setup_bitcoin.go (1)
Learnt from: gartnera
PR: zeta-chain/node#3105
File: e2e/runner/setup_bitcoin.go:51-69
Timestamp: 2025-03-26T19:42:34.108Z
Learning: In test code (`e2e/runner/setup_bitcoin.go`), adding security measures for private key handling in the `GetBtcAddress` method is not required.
🧬 Code Definitions (5)
e2e/e2etests/test_bitcoin_std_deposit_and_call.go (1)
zetaclient/chains/bitcoin/common/tx_script.go (1)
  • EncodeAddress (238-242)
e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_other_address.go (1)
testutil/sample/crosschain.go (1)
  • InboundParams (176-191)
cmd/zetae2e/local/bitcoin.go (1)
e2e/e2etests/e2etests.go (1)
  • TestBitcoinDepositName (105-105)
e2e/e2etests/test_bitcoin_deposit_call.go (1)
zetaclient/chains/bitcoin/common/tx_script.go (1)
  • EncodeAddress (238-242)
e2e/runner/bitcoin.go (1)
e2e/runner/runner.go (1)
  • E2ERunner (80-204)
🔇 Additional comments (40)
e2e/e2etests/test_bitcoin_deposit_invalid_memo_revert.go (2)

20-21: Method signature change aligns with PR objectives.

The change from deployer-specific UTXO listing (ListDeployerUTXOs) to a more generalized approach (ListUTXOs) aligns with the PR's goal of removing deployer account references from test routines. This modification enhances test isolation and reduces potential race conditions as mentioned in the PR objectives.


32-33: Consistent refactoring approach.

The method signature changes to ListUTXOs() and SendToTSSFromWithMemo() maintain consistency with earlier changes in the file. This systematic approach to refactoring supports the PR's goal of enabling local Bitcoin transaction signing.

e2e/e2etests/helpers.go (1)

31-41: Excellent addition of balance validation to prevent unclear errors.

The new balance check ensures that withdrawals only proceed when sufficient funds are available, preventing cryptic "execution reverted" errors. This is a thoughtful improvement that aligns with the PR objectives and enhances the robustness of the test suite.

e2e/runner/setup_bitcoin.go (4)

24-27: Good refactoring to eliminate deployer-specific dependencies.

The change to use r.GetBtcKeypair() instead of r.BTCDeployerAddress aligns with the PR objectives to remove references to the deployer account and make each test routine operate independently.


48-67: Well-structured keypair retrieval function.

The implementation of GetBtcKeypair() is clean and follows good practices for Bitcoin address derivation from private keys.


90-90: Significant change in wallet creation properties.

Changing disable_private_keys from false to true is a significant modification that aligns with the PR objective of signing Bitcoin transactions locally rather than in the node. Ensure this has been thoroughly tested.


109-112: Good addition of address import for proper UTXO tracking.

Adding the address import ensures proper indexing of UTXOs and transactions, which is essential for subsequent transaction operations.

e2e/e2etests/test_stress_btc_withdraw.go (1)

38-38: Appropriate refactoring to use the new address retrieval method.

This change correctly replaces the direct use of deployer address with the new generalized method, which aligns with the PR's objective of removing references to the deployer account.

e2e/e2etests/test_bitcoin_withdraw_segwit.go (1)

15-15: Consistent refactoring of address retrieval.

The change maintains consistency with the overall approach of eliminating deployer-specific references across the codebase.

e2e/e2etests/test_bitcoin_std_deposit_and_call.go (1)

53-53: Method reference updated to use generalized GetBtcAddress

The change from using BTCDeployerAddress.EncodeAddress() to GetBtcAddress().EncodeAddress() is appropriate and aligns with the PR objective of removing deployer-specific references to prevent race conditions.

cmd/zetae2e/bitcoin_address.go (1)

65-65: Method renamed to better reflect return values

The rename from GetBtcAddress() to GetBtcKeypair() is semantically accurate as the method returns both an address and a private key. This change supports the PR objective of enabling local transaction signing.

Let's verify that this method is used consistently across the codebase:

#!/bin/bash
# Check if there are any remaining references to the old GetBtcAddress method
rg "GetBtcAddress\(\)" --type go
e2e/e2etests/e2etests.go (1)

825-825:

Details

✅ Verification successful

Increased default Bitcoin deposit amount

The default Bitcoin amount for the deposit test has been increased from 0.001 BTC to 1.0 BTC, which is a 1000x increase. This supports the PR objective of using the bitcoin_deposit test to fund withdraw tests.

Before approving this change, verify that this substantial amount increase is necessary and won't consume excessive resources in the test environment:


🏁 Script executed:

#!/bin/bash
# Check how the deposit amount is used in withdrawal tests
rg "TestBitcoinDepositName" --type go -A 5 -B 5

Length of output: 3014


Verified: Increased Bitcoin deposit amount is appropriate for funding withdrawal tests

The updated default value of 1.0 BTC for the TestBitcoinDepositName test has been confirmed as necessary. Our investigation shows that:

  • The deposit test with a default value of 1.0 BTC is explicitly used to fund subsequent withdrawal tests in cmd/zetae2e/local/bitcoin.go.
  • This change aligns with the PR's objective of ensuring sufficient funds for withdrawals.
  • There is no evidence that this increased amount will cause excessive resource usage in the test environment.
e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go (1)

44-44: Updated address reference for revert transaction verification

The test now correctly uses GetBtcAddress().EncodeAddress() instead of BTCDeployerAddress.EncodeAddress() when verifying the receiver of revert transactions. This change is consistent with the PR objective of removing deployer-specific references.

e2e/e2etests/test_bitcoin_std_deposit_and_call_revert_other_address.go (1)

50-50: Appropriate transition from deployer-specific to generalized address retrieval.

The change from r.BTCDeployerAddress.EncodeAddress() to r.GetBtcAddress().EncodeAddress() aligns with the PR objective to remove deployer-specific references. This promotes test routine independence and helps prevent race conditions by retrieving the Bitcoin address dynamically instead of relying on a static deployer address.

e2e/e2etests/test_bitcoin_std_memo_inscribed_deposit_and_call.go (1)

43-43: Method renaming improves code generalization.

The method update from InscribeToTSSFromDeployerWithMemo to InscribeToTSSWithMemo effectively removes the deployer-specific context, making the code more flexible and aligning with the PR's goal of eliminating deployer references. The parameters and functionality remain unchanged, preserving the test's behavior.

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

48-50: Good addition of bitcoin_deposit test as a dependency for withdraw tests.

Adding the e2etests.TestBitcoinDepositName to the withdraw tests ensures proper funding for withdrawals, consistent with the PR objective to use the bitcoin_deposit test to fund withdraw tests. This mirrors the approach taken on the Ethereum side as mentioned in the PR description.


118-119: Refactored reward generation to use deployer runner.

The change to use deployerRunner.GetBtcAddress() instead of a hardcoded address for generating Bitcoin rewards eliminates deployer-specific references and makes the code more flexible. This supports the local transaction signing approach described in the PR objectives.


122-123: Simplified donation process.

Replacing the combined method DonateBTCAndDepositToTSS() with the more focused DonateBTC() streamlines the initialization process and aligns with the PR's goal of making test routines more independent.


154-162: Well-structured initialization for local transaction signing.

This block properly implements the local transaction signing approach by retrieving a Bitcoin keypair, ensuring the address is imported into the RPC client, and generating rewards to that address. The error handling is appropriate, and the sequence of operations is logical for establishing a funded address for testing.

e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go (2)

31-31: Generalized UTXO listing method.

Replacing r.ListDeployerUTXOs() with r.ListUTXOs() removes the deployer-specific reference, making the test more flexible and independent. This aligns with the PR objective to remove all references to the deployer account from each test routine.


40-41: Transaction sending method updated for consistency.

The change from r.SendToTSSFromDeployerWithMemo to r.SendToTSSFromWithMemo generalizes the transaction sending function, removing the deployer context. This supports the PR's goal of locally signing Bitcoin transactions and eliminating deployer dependencies.

e2e/e2etests/test_bitcoin_donation.go (2)

22-22: Improved UTXO retrieval with generalized method.

The change from ListDeployerUTXOs() to ListUTXOs() removes the dependency on a deployer-specific account, which aligns with the objective of making test routines operate independently to prevent race conditions.


27-27: Generalized transaction sending method implementation.

The change from SendToTSSFromDeployerWithMemo() to SendToTSSFromWithMemo() correctly eliminates the deployer-specific context in the transaction sending process, creating a more flexible and reusable approach.

e2e/e2etests/test_bitcoin_deposit.go (3)

16-18: Clear documentation and accurate Bitcoin amount handling.

The added comment and calculation for ZRC20 BTC amounts with 8 decimals improves code clarity and provides essential context for understanding Bitcoin amount handling.


19-20: Proper balance validation implementation.

Retrieving the starting balance before the operation establishes a baseline for post-transaction validation, which is a necessary practice for comprehensive testing.


29-36:

Details

✅ Verification successful

Comprehensive transaction validation with precise assertions.

The added assertions verify that:

  1. The inbound amount matches the expected value
  2. The balance increases by the expected amount after the deposit

This ensures the deposit functionality works correctly with appropriate tolerance checks.


🏁 Script executed:

#!/bin/bash
# Verify the bigSub function used for balance difference calculation exists
rg "func bigSub" --type go

Length of output: 99


Validated Deposit Test Assertions
The assertions in e2e/e2etests/test_bitcoin_deposit.go correctly verify that the inbound deposit amount matches the expected value and that the account balance increases as anticipated. Additionally, the verification confirms that the supporting bigSub function exists (located in e2e/e2etests/helpers.go), which ensures that balance difference calculations are performed accurately. The implementation meets the necessary production-grade standards.

e2e/e2etests/test_bitcoin_deposit_and_withdraw_with_dust.go (2)

35-35: Improved UTXO retrieval with generalized method.

The change from ListDeployerUTXOs() to ListUTXOs() properly removes the deployer-specific context, which aligns with the objective of making test routines operate independently.


39-39: Generalized transaction sending method implementation.

The change from SendToTSSFromDeployerWithMemo() to SendToTSSFromWithMemo() appropriately eliminates the deployer-specific context, creating a more flexible transaction sending approach that can work with any address.

e2e/e2etests/test_bitcoin_deposit_and_call_revert.go (3)

23-23: Improved UTXO retrieval with generalized method.

The change from ListDeployerUTXOs() to ListUTXOs() properly removes the deployer-specific dependency, making the test more isolated and less prone to race conditions.


30-30: Generalized transaction sending method implementation.

The change from SendToTSSFromDeployerWithMemo() to SendToTSSFromWithMemo() correctly eliminates the deployer-specific context in the transaction sending process, creating a more flexible approach.


40-40: Improved address retrieval with generalized method.

The change from directly referencing r.BTCDeployerAddress.EncodeAddress() to using the method call r.GetBtcAddress().EncodeAddress() provides a more encapsulated approach to address handling, which aligns with the objective of removing deployer-specific references and enabling local Bitcoin transaction signing.

e2e/e2etests/test_bitcoin_deposit_call.go (3)

22-22: Modified UTXO retrieval to use generalized method.

The function now uses ListUTXOs() instead of the previous deployer-specific method, aligning with the PR's goal of eliminating deployer-specific functions to prevent race conditions in tests.


33-33: Updated transaction sending to use generalized method.

This change removes the deployer-specific context from the transaction sending process, which is consistent with the PR objective of ensuring each test routine operates independently.


48-48: Updated Bitcoin address retrieval method.

The code now uses GetBtcAddress() instead of directly accessing the deployer address, providing more flexibility and aligning with the local signing approach.

e2e/runner/balances.go (1)

189-189:

Details

❓ Verification inconclusive

Removed spendability check from balance calculation.

The function now adds all unspent outputs to the total balance, regardless of their spendability status. This simplifies the logic but could potentially lead to reporting balances that aren't actually available for spending.

Verify that removing the spendability check doesn't impact test reliability by potentially reporting misleading balances. If this change was intentional as part of the refactoring, consider adding a comment explaining why spendability is no longer checked.


🏁 Script executed:

#!/bin/bash
# Check for any other usages of spendability in UTXO handling
rg --type go "Spendable" -A 3 -B 3

Length of output: 21664


Action: Confirm intentional removal of the spendability check in e2e balance calculations.

It appears that the change in e2e/runner/balances.go (line 189) removes the conditional check for spendability, so that all unspent outputs are summed regardless of whether they are actually available for spending. Our search shows that elsewhere in the codebase—especially in the simulation logic—the spendability is explicitly assessed via calls to methods like SpendableCoins. This suggests that the removal is intentional for the e2e runner, likely to simplify reporting.

Recommendations:

  • Clarification: If this behavior is deliberate, please add an inline comment explaining why the spendability check has been removed in this context. This will help avoid confusion, as the simulation code explicitly checks spendability.
  • Consistency Check: Ensure that the reported balance (which includes all unspent outputs) is acceptable for the intended e2e use and that the difference from simulation behavior is clearly documented or justified.
  • Documentation: Update any relevant tests or external documentation to reflect that the e2e balance computation does not filter out non-spendable outputs.
e2e/e2etests/test_crosschain_swap.go (3)

76-76: Updated Bitcoin address encoding retrieval.

Similar to changes in other files, this modification replaces the direct access to the deployer address with a more flexible approach using GetBtcAddress().


101-101: Replaced deployer-specific UTXO listing with generalized method.

These changes use the new ListUTXOs() method instead of ListDeployerUTXOs(), which aligns with the PR objective of removing all references to the deployer account from each test routine.

Also applies to: 141-141


112-112: Updated transaction sending to use generalized method.

The code now uses SendToTSSFromWithMemo() instead of the deployer-specific method, maintaining consistency with changes throughout the codebase.

Also applies to: 142-143

e2e/runner/bitcoin.go (2)

35-38: Renamed and updated UTXO listing method.

The function has been renamed from ListDeployerUTXOs to ListUTXOs and now retrieves the Bitcoin address dynamically using GetBtcKeypair(), enhancing flexibility and aligning with the PR's goal of local transaction signing.


53-53:

Details

❓ Verification inconclusive

Simplified UTXO filtering logic.

The conditional check for spendability has been removed, with filtering now only based on the amount being greater than or equal to 1.0 BTC. This simplification could potentially affect the selection of UTXOs for tests.

Verify that removing the spendability check doesn't impact test reliability. If this was intentional, consider adding a comment explaining the rationale.


🏁 Script executed:

#!/bin/bash
# Check if there are any tests that might rely on spendability filtering
rg -A 3 -B 3 "Spendable" "e2e/e2etests/*.go"

Length of output: 102


Review Assurance: UTXO Filtering Simplification Evaluation

The change now filters UTXOs solely based on an amount ≥ 1.0 BTC, completely removing the previous spendability check. Our initial attempt to search for tests referencing “Spendable” under e2e/e2etests/*.go returned an error (directory not found). To further confirm that no tests depend on the removed spendability logic, please run additional verifications—such as a broader repository search (e.g., rg -i "spendab" .)—or manually inspect any relevant tests.

If, after manual review, you determine that the removal is intentional, please add an inline comment documenting the rationale behind simplifying the UTXO filtering. This will help maintain clarity for future reviewers and maintainers.

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.

overall looks good.

@gartnera gartnera enabled auto-merge March 27, 2025 16:24
@gartnera gartnera added this pull request to the merge queue Mar 27, 2025
Merged via the queue into develop with commit 81cd423 Mar 27, 2025
46 checks passed
@gartnera gartnera deleted the bitcoin-localsign branch March 27, 2025 16:49
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.

3 participants