-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow BTC revert with dust amount v22 (#3140)
* add deposit and call with dust test
- Loading branch information
1 parent
43f947b
commit f6079fc
Showing
5 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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
54 changes: 54 additions & 0 deletions
54
e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go
This file contains 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,54 @@ | ||
package e2etests | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
"github.com/zeta-chain/node/pkg/constant" | ||
"github.com/zeta-chain/node/testutil/sample" | ||
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
zetabitcoin "github.com/zeta-chain/node/zetaclient/chains/bitcoin" | ||
) | ||
|
||
// TestBitcoinDepositAndCallRevertWithDust sends a Bitcoin deposit that reverts with a dust amount in the revert outbound. | ||
func TestBitcoinDepositAndCallRevertWithDust(r *runner.E2ERunner, args []string) { | ||
// ARRANGE | ||
// Given BTC address | ||
r.SetBtcAddress(r.Name, false) | ||
|
||
require.Len(r, args, 0) | ||
|
||
// Given "Live" BTC network | ||
stop := r.MineBlocksIfLocalBitcoin() | ||
defer stop() | ||
|
||
// 0.002 BTC is consumed in a deposit and revert, the dust is set to 1000 satoshis in the protocol | ||
// Therefore the deposit amount should be 0.002 + 0.000001 = 0.00200100 should trigger the condition | ||
// As only 100 satoshis are left after the deposit | ||
|
||
amount := 0.00200100 | ||
amount += zetabitcoin.DefaultDepositorFee | ||
|
||
// Given a list of UTXOs | ||
utxos, err := r.ListDeployerUTXOs() | ||
require.NoError(r, err) | ||
require.NotEmpty(r, utxos) | ||
|
||
// ACT | ||
// Send BTC to TSS address with a dummy memo | ||
// zetacore should revert cctx if call is made on a non-existing address | ||
nonExistReceiver := sample.EthAddress() | ||
badMemo := append(nonExistReceiver.Bytes(), []byte("gibberish-memo")...) | ||
txHash, err := r.SendToTSSFromDeployerWithMemo(amount, utxos, badMemo) | ||
require.NoError(r, err) | ||
require.NotEmpty(r, txHash) | ||
|
||
// 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_and_revert") | ||
utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted) | ||
|
||
// check the test was effective: the revert outbound amount is less than the dust amount | ||
require.Less(r, cctx.GetCurrentOutboundParam().Amount.Uint64(), uint64(constant.BTCWithdrawalDustAmount)) | ||
} |
This file contains 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 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