-
Notifications
You must be signed in to change notification settings - Fork 173
test: E2E test for the Bitcoin RBF transaction #3417
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
Merged
Merged
Changes from all commits
Commits
Show all changes
96 commits
Select commit
Hold shift + click to select a range
8fae53a
minimum code refactor for bitcoin RBF
ws4charlie 2481654
add changelog entry
ws4charlie 111d703
add unit test for FeeRateToSatPerByte
ws4charlie 37f4ebb
make changelog descriptive; rename specialHandleFeeRate as GetFeeRate…
ws4charlie e3f2bc6
renaming sample function; make switch case in PostGasPrice to estimat…
ws4charlie 28bd97c
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 009b55b
remove redundant variable description
ws4charlie 09fb0ac
make AddWithdrawTxOutputs a one-line call
ws4charlie aeceb26
implementation of Bitcoin RBF transaction
ws4charlie 6c8f9f4
switch to bitcoin-core image with mempool RPCs enabled
ws4charlie e193580
bitcoin RBF E2E test
ws4charlie a80bd91
add changelog entry
ws4charlie 6803a7c
add changelog entry
ws4charlie fc6f9a4
update changelog
ws4charlie c2a52c0
improve RBF test waiting mechanism
ws4charlie c501cf2
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 1d2afef
rename sample function BTCAddressP2WPKH
ws4charlie 1033a91
remove unused test and comment
ws4charlie bccf7e9
Merge branch 'develop' into feat-bitcoin-RBF-zetaclient-refactor-minimum
ws4charlie 25cdfc7
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 199bf2e
use 1.5 as multiplier to send outbound txs so that we slightly make p…
ws4charlie c156321
Merge branch 'develop' into feat-bitcoin-RBF-zetaclient-implementation
ws4charlie 209e270
disable RBF test by default; it require one-line code change
ws4charlie f4ab7a2
Merge branch 'develop' into feat-bitcoin-RBF-zetaclient-refactor-minimum
ws4charlie 3f5087b
include coin type to error message; make code cleaner
ws4charlie c31020b
return error if failed to get signer address; add BTCPayToAddrScript …
ws4charlie 58fd340
Update zetaclient/chains/bitcoin/signer/signer.go
ws4charlie 0f0b9aa
remove redundant test functions; use testlog for unit test
ws4charlie 54bb4de
create observer in test suite; use testlog package
ws4charlie 93b3a38
add description to fee estimation formula
ws4charlie 4f83fdb
use structured logs
ws4charlie 6fd51dd
make AddTxInputs independent method
ws4charlie a69d58b
add comments to explain function arguments; improve error wrapping; c…
ws4charlie 5c09d39
replace ifs with switch case; return original err without overwriting
ws4charlie c19fa2b
seems safe to remove panic recovery in FetchUTXOs
ws4charlie 0d41413
move Telemetry update to the line before acquiring observer lock
ws4charlie c0a2a23
use testlog package
ws4charlie 8644a33
use retry package for Bitcoin tx broadcasting; let SaveBroadcastedTx …
ws4charlie bf9b4c4
use named return values to make GetEstimatedFeeRate more readable
ws4charlie 9600442
move utxo unit tests to utxos.go and improved unit tests
ws4charlie 8040ac1
wrap RPC error in LoadLastBlockScanned
ws4charlie a64f738
move last scanned block to log field; use Opt function for test suite
ws4charlie bb95935
move values to log fields
ws4charlie 84f4b5c
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 13efedc
add unit test for FetchUTXOs
ws4charlie 416bd03
add unit for SignWithdrawTx; use structured log
ws4charlie 1b369ca
Merge branch 'develop' into feat-bitcoin-RBF-zetaclient-refactor-minimum
ws4charlie 79db16e
avoid creating log field map and add log fields right on the logger
ws4charlie 0349246
fix client.GetEstimatedFeeRate
swift1337 6e8f900
Fix loadBroadcastedTxMap
swift1337 8cddb38
Fix SelectedUTXOs
swift1337 01e50df
Fix log naming
swift1337 d556b7e
fix e2e logging
swift1337 4c6b5bb
Fix setPendingNonce
swift1337 ed986e0
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 1df7b53
Merge branch 'feat-bitcoin-RBF-zetaclient-refactor-minimum' of https:…
ws4charlie 3ab710e
don't use GasPriorityFee as it's always empty
ws4charlie f7e72cc
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 3925b6e
Merge branch 'feat-bitcoin-RBF-zetaclient-refactor-minimum' of https:…
ws4charlie f3cfdb6
Merge branch 'develop' into feat-bitcoin-RBF-zetaclient-implementation
ws4charlie 03d366c
check if fee rate is bumped or not in zetaclient
ws4charlie 277bd1c
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie f952848
revert a few renamings because we will continue to use one single BTC…
ws4charlie a50132e
remove the method OutboundFeeRateFromCCTXRate; add additional field i…
ws4charlie 83c78d3
adjust fee bumper to use new fee rate fed by zetacore
ws4charlie 5d8d57e
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 1627f03
adjust SignRBFTx to work with local E2E test
ws4charlie 3776e30
code clean up; improve comments
ws4charlie 43cb65a
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 592d93e
handle invalid gas priority fee explicitly
ws4charlie 50f70ff
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie 0b4a632
fix withdraw failure and unit tests
ws4charlie 7e4cd78
rename GetLastStuckOutbound -> LastStuckOutbound; unexport SetLastStu…
ws4charlie ccd6533
remove IncreaseIntByPercent and use IncreaseUintByPercent instead
ws4charlie f94d6ae
use same signer package for unit tests
ws4charlie 6f57fb5
unexport FetchFeeBumpInfo
ws4charlie 851a53e
have GetTotalMempoolParentsSizeNFees return a struct; add function Is…
ws4charlie da87ab5
move timeout handling into context
ws4charlie 3843eb8
have BumpTxFee return a result struct BumpResult
ws4charlie 1b77a0d
unexport fee bumper fields
ws4charlie b6a4426
remove Live prefix from live tests as we already have the env flag to…
ws4charlie bbea857
wrap live tests function into test runners so IDE can identify the tests
ws4charlie 30251f4
Merge branch 'feat-bitcoin-RBF-zetaclient-implementation' of https://…
ws4charlie a1b7761
add comment to the disabled Bitcoin RBF E2E test for clarity
ws4charlie 75343be
Merge branch 'develop' of https://github.com/zeta-chain/node into E2E…
ws4charlie 073181a
Merge branch 'develop' of https://github.com/zeta-chain/node into E2E…
ws4charlie 1441ee2
disable Bitcoin rbf test
ws4charlie fc88b12
keep the new line for better indentation
ws4charlie c549770
sync changelog file
ws4charlie 63eea64
add explanation why RBF test is disabled by default
ws4charlie f1a1ca5
improve naming; add more description to the RBF e2e test; make 'appro…
ws4charlie 4f31236
add dependency to E2E test structure; inject dependency for Bitcoin R…
ws4charlie 142e0a4
move helper func BTCWithdraw to a bitcoin runner method
ws4charlie 4ed0e89
Merge branch 'develop' into E2E-test-bitcoin-RBF
ws4charlie 42dea6e
Merge branch 'develop' into E2E-test-bitcoin-RBF
ws4charlie 8de2a68
fix upgrade test failure in CI
ws4charlie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package e2etests | ||
|
|
||
| import ( | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/btcsuite/btcd/chaincfg/chainhash" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/zeta-chain/node/e2e/runner" | ||
| "github.com/zeta-chain/node/e2e/utils" | ||
| crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
| ) | ||
|
|
||
| // TestBitcoinWithdrawRBF tests the RBF (Replace-By-Fee) feature in Zetaclient. | ||
| // It needs block mining to be stopped and runs as the last test in the suite. | ||
| // | ||
| // IMPORTANT: the test requires to simulate a stuck tx in the Bitcoin regnet. | ||
| // The challenge to simulate a stuck tx is to create overwhelming traffic in the local mempool. | ||
| // | ||
| // To work around this: | ||
| // 1. change the 'minTxConfirmations' to 1 to not include outbound tx right away (production should use 0) | ||
| // here: https://github.com/zeta-chain/node/blob/5c2a8ffbc702130fd9538b1cd7640d0e04d3e4f6/zetaclient/chains/bitcoin/observer/outbound.go#L27 | ||
| // 2. stop block mining to let the pending tx sit in the mempool for longer time | ||
| func TestBitcoinWithdrawRBF(r *runner.E2ERunner, args []string) { | ||
| require.Len(r, args, 2) | ||
|
|
||
| // parse arguments | ||
| defaultReceiver := r.GetBtcAddress().EncodeAddress() | ||
| to, amount := utils.ParseBitcoinWithdrawArgs(r, args, defaultReceiver, r.GetBitcoinChainID()) | ||
|
|
||
| // initiate a withdraw CCTX | ||
| receipt := r.WithdrawBTC(to, amount, true) | ||
| cctx := utils.GetCCTXByInboundHash(r.Ctx, r.CctxClient, receipt.TxHash.Hex()) | ||
|
|
||
| // wait for the 1st outbound tracker hash to come in | ||
| nonce := cctx.GetCurrentOutboundParam().TssNonce | ||
| hashes := utils.WaitOutboundTracker(r.Ctx, r.CctxClient, r.GetBitcoinChainID(), nonce, 1, r.Logger, 3*time.Minute) | ||
| txHash, err := chainhash.NewHashFromStr(hashes[0]) | ||
| r.Logger.Info("got 1st tracker hash: %s", txHash) | ||
|
|
||
| // get original tx | ||
| require.NoError(r, err) | ||
| txResult, err := r.BtcRPCClient.GetTransaction(r.Ctx, txHash) | ||
| require.NoError(r, err) | ||
| require.Zero(r, txResult.Confirmations) | ||
|
|
||
| // wait for RBF tx to kick in | ||
| hashes = utils.WaitOutboundTracker(r.Ctx, r.CctxClient, r.GetBitcoinChainID(), nonce, 2, r.Logger, 3*time.Minute) | ||
| txHashRBF, err := chainhash.NewHashFromStr(hashes[1]) | ||
| require.NoError(r, err) | ||
| r.Logger.Info("got 2nd tracker hash: %s", txHashRBF) | ||
|
|
||
| // resume block mining | ||
| stop := r.MineBlocksIfLocalBitcoin() | ||
| defer stop() | ||
|
|
||
| // waiting for CCTX to be mined | ||
| cctx = utils.WaitCctxMinedByInboundHash(r.Ctx, receipt.TxHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
| utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) | ||
|
|
||
| // ensure the original tx is dropped | ||
| utils.MustHaveDroppedBitcoinTx(r.Ctx, r.BtcRPCClient, txHash) | ||
|
|
||
| // ensure the RBF tx is mined | ||
| rawResult := utils.MustHaveMinedBitcoinTx(r.Ctx, r.BtcRPCClient, txHashRBF) | ||
|
|
||
| // ensure RBF fee rate > old rate | ||
| params := cctx.GetCurrentOutboundParam() | ||
| oldRate, err := strconv.ParseInt(params.GasPrice, 10, 64) | ||
| require.NoError(r, err) | ||
|
|
||
| _, newRate, err := r.BtcRPCClient.GetTransactionFeeAndRate(r.Ctx, rawResult) | ||
| require.NoError(r, err) | ||
| require.Greater(r, newRate, oldRate, "RBF fee rate should be higher than the original tx") | ||
ws4charlie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.