Skip to content

Commit

Permalink
register aborted CCTX for Bitcoin inbound that carries insufficient d…
Browse files Browse the repository at this point in the history
…eposit fee
  • Loading branch information
ws4charlie committed Jan 16, 2025
1 parent 7eea20e commit deb1fc1
Show file tree
Hide file tree
Showing 34 changed files with 377 additions and 261 deletions.
3 changes: 2 additions & 1 deletion cmd/zetae2e/local/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func bitcoinTestRoutines(
_, err := runnerDeposit.GenerateToAddressIfLocalBitcoin(101, runnerDeposit.BTCDeployerAddress)
require.NoError(runnerDeposit, err)

// send BTC to ZEVM addresses
// donate BTC to TSS and send BTC to ZEVM addresses
runnerDeposit.DonateBTC()
runnerDeposit.DepositBTC(runnerDeposit.EVMAddress())
runnerDeposit.DepositBTC(runnerWithdraw.EVMAddress())
}
Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestBitcoinStdMemoDepositAndCallName,
e2etests.TestBitcoinStdMemoDepositAndCallRevertName,
e2etests.TestBitcoinStdMemoInscribedDepositAndCallName,
e2etests.TestBitcoinDepositAndAbortWithLowDepositFeeName,
e2etests.TestCrosschainSwapName,
}
bitcoinDepositTestsAdvanced := []string{
Expand Down
1 change: 1 addition & 0 deletions docs/spec/crosschain/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ message MsgVoteInbound {
RevertOptions revert_options = 17;
CallOptions call_options = 18;
bool is_cross_chain_call = 19;
string error_message = 20;
}
```

Expand Down
7 changes: 7 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const (
TestBitcoinStdMemoDepositAndCallRevertName = "bitcoin_std_memo_deposit_and_call_revert"
TestBitcoinStdMemoDepositAndCallRevertOtherAddressName = "bitcoin_std_memo_deposit_and_call_revert_other_address"
TestBitcoinStdMemoInscribedDepositAndCallName = "bitcoin_std_memo_inscribed_deposit_and_call"
TestBitcoinDepositAndAbortWithLowDepositFeeName = "bitcoin_deposit_and_abort_with_low_deposit_fee"
TestBitcoinWithdrawSegWitName = "bitcoin_withdraw_segwit"
TestBitcoinWithdrawTaprootName = "bitcoin_withdraw_taproot"
TestBitcoinWithdrawMultipleName = "bitcoin_withdraw_multiple"
Expand Down Expand Up @@ -647,6 +648,12 @@ var AllE2ETests = []runner.E2ETest{
},
TestBitcoinStdMemoInscribedDepositAndCall,
),
runner.NewE2ETest(
TestBitcoinDepositAndAbortWithLowDepositFeeName,
"deposit Bitcoin into ZEVM that aborts due to insufficient deposit fee",
[]runner.ArgDefinition{},
TestBitcoinDepositAndAbortWithLowDepositFee,
),
runner.NewE2ETest(
TestBitcoinWithdrawSegWitName,
"withdraw BTC from ZEVM to a SegWit address",
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_bitcoin_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestBitcoinDeposit(r *runner.E2ERunner, args []string) {

depositAmount := utils.ParseFloat(r, args[0])

txHash := r.DepositBTCWithAmount(depositAmount, nil)
txHash := r.DepositBTCWithAmount(depositAmount, nil, true)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
Expand Down
35 changes: 35 additions & 0 deletions e2e/e2etests/test_bitcoin_deposit_abort_with_low_deposit_fee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package e2etests

import (
"fmt"

"github.com/btcsuite/btcd/btcutil"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
zetabitcoin "github.com/zeta-chain/node/zetaclient/chains/bitcoin/common"
)

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

// Given small amount
depositAmount := zetabitcoin.DefaultDepositorFee - float64(1)/btcutil.SatoshiPerBitcoin

// ACT
txHash := r.DepositBTCWithAmount(depositAmount, nil, false)

// ASSERT
// cctx status should be aborted
cctx := utils.WaitCctxAbortedByInboundHash(r.Ctx, r, txHash.String(), r.CctxClient)
r.Logger.CCTX(cctx, "deposit aborted")

// check cctx details
require.Equal(r, cctx.InboundParams.Amount.Uint64(), uint64(0))
require.Equal(r, cctx.GetCurrentOutboundParam().Amount.Uint64(), uint64(0))

// check cctx error message
expectedError := fmt.Sprintf("deposited amount %v is less than depositor fee", depositAmount)
require.Contains(r, cctx.CctxStatus.ErrorMessage, expectedError)
}
6 changes: 2 additions & 4 deletions e2e/e2etests/test_bitcoin_deposit_and_call_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ func TestBitcoinDepositAndCallRevert(r *runner.E2ERunner, args []string) {
amount += zetabitcoin.DefaultDepositorFee

// Given a list of UTXOs
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
require.NotEmpty(r, utxos)
utxos := r.ListDeployerUTXOs()

// 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)
txHash, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[:1], badMemo)
require.NoError(r, err)
require.NotEmpty(r, txHash)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ func TestBitcoinDepositAndCallRevertWithDust(r *runner.E2ERunner, args []string)
amount := depositAmount + zetabitcoin.DefaultDepositorFee

// Given a list of UTXOs
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
require.NotEmpty(r, utxos)
utxos := r.ListDeployerUTXOs()

// 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()
anyMemo := append(nonExistReceiver.Bytes(), []byte("gibberish-memo")...)
txHash, err := r.SendToTSSFromDeployerWithMemo(amount, utxos, anyMemo)
txHash, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[:1], anyMemo)
require.NoError(r, err)
require.NotEmpty(r, txHash)

Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_bitcoin_deposit_and_withdraw_with_dust.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ func TestBitcoinDepositAndWithdrawWithDust(r *runner.E2ERunner, args []string) {
require.Equal(r, receipt.Status, uint64(1))

// Given a list of UTXOs
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
require.NotEmpty(r, utxos)
utxos := r.ListDeployerUTXOs()

// ACT
// Deposit 0.01 BTC to withdrawer, this is an arbitrary amount, must be greater than dust amount
txHash, err := r.SendToTSSFromDeployerWithMemo(0.01, utxos, withdrawerAddr.Bytes())
txHash, err := r.SendToTSSFromDeployerWithMemo(0.01, utxos[:1], withdrawerAddr.Bytes())
require.NoError(r, err)
require.NotEmpty(r, txHash)

Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_bitcoin_deposit_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func TestBitcoinDepositAndCall(r *runner.E2ERunner, args []string) {
amountTotal := amount + common.DefaultDepositorFee

// Given a list of UTXOs
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
require.NotEmpty(r, utxos)
utxos := r.ListDeployerUTXOs()

// deploy an example contract in ZEVM
contractAddr, _, contract, err := testcontract.DeployExample(r.ZEVMAuth, r.ZEVMClient)
Expand All @@ -36,7 +34,7 @@ func TestBitcoinDepositAndCall(r *runner.E2ERunner, args []string) {
// Send BTC to TSS address with a dummy memo
data := []byte("hello satoshi")
memo := append(contractAddr.Bytes(), data...)
txHash, err := r.SendToTSSFromDeployerWithMemo(amountTotal, utxos, memo)
txHash, err := r.SendToTSSFromDeployerWithMemo(amountTotal, utxos[:1], memo)
require.NoError(r, err)

// wait for the cctx to be mined
Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_bitcoin_donation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ func TestBitcoinDonation(r *runner.E2ERunner, args []string) {
amountTotal := amount + zetabitcoin.DefaultDepositorFee

// Given a list of UTXOs
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
require.NotEmpty(r, utxos)
utxos := r.ListDeployerUTXOs()

// ACT
// Send BTC to TSS address with donation message
memo := []byte(constant.DonationMessage)
txHash, err := r.SendToTSSFromDeployerWithMemo(amountTotal, utxos, memo)
txHash, err := r.SendToTSSFromDeployerWithMemo(amountTotal, utxos[:1], memo)
require.NoError(r, err)

// ASSERT after 4 Zeta blocks
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_bitcoin_std_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestBitcoinStdMemoDeposit(r *runner.E2ERunner, args []string) {
}

// deposit BTC with standard memo
txHash := r.DepositBTCWithAmount(amount, memo)
txHash := r.DepositBTCWithAmount(amount, memo, true)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_bitcoin_std_deposit_and_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestBitcoinStdMemoDepositAndCall(r *runner.E2ERunner, args []string) {
}

// deposit BTC with standard memo
txHash := r.DepositBTCWithAmount(amount, memo)
txHash := r.DepositBTCWithAmount(amount, memo, true)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout)
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_bitcoin_std_deposit_and_call_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestBitcoinStdMemoDepositAndCallRevert(r *runner.E2ERunner, args []string)

// ACT
// Deposit
txHash := r.DepositBTCWithAmount(amount, memo)
txHash := r.DepositBTCWithAmount(amount, memo, true)

// ASSERT
// Now we want to make sure revert TX is completed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestBitcoinStdMemoDepositAndCallRevertOtherAddress(r *runner.E2ERunner, arg

// ACT
// Deposit
txHash := r.DepositBTCWithAmount(amount, memo)
txHash := r.DepositBTCWithAmount(amount, memo, true)

// ASSERT
// Now we want to make sure revert TX is completed.
Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_crosschain_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {

r.Logger.Info("******* Second test: BTC -> ERC20ZRC20")
// list deployer utxos
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
utxos := r.ListDeployerUTXOs()

r.Logger.Info("#utxos %d", len(utxos))
r.Logger.Info("memo address %s", r.ERC20ZRC20Addr)
Expand Down Expand Up @@ -143,8 +142,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) {
r.Logger.Info("memo length %d", len(memo))

amount := 0.1
utxos, err = r.ListDeployerUTXOs()
require.NoError(r, err)
utxos = r.ListDeployerUTXOs()
txid, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[0:1], memo)
require.NoError(r, err)

Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_stress_btc_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestStressBTCDeposit(r *runner.E2ERunner, args []string) {
// send the deposits
for i := 0; i < numDeposits; i++ {
i := i
txHash := r.DepositBTCWithAmount(depositAmount, nil)
txHash := r.DepositBTCWithAmount(depositAmount, nil, true)
r.Logger.Print("index %d: starting deposit, tx hash: %s", i, txHash.String())

eg.Go(func() error { return monitorBTCDeposit(r, txHash, i, time.Now()) })
Expand Down
Loading

0 comments on commit deb1fc1

Please sign in to comment.