Skip to content

Commit

Permalink
add deposit and call with dust test
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Nov 11, 2024
1 parent 43f947b commit 12b5606
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 41 deletions.
83 changes: 42 additions & 41 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,65 +268,66 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
if !skipRegular {
// defines all tests, if light is enabled, only the most basic tests are run and advanced are skipped
erc20Tests := []string{
e2etests.TestERC20WithdrawName,
e2etests.TestMultipleERC20WithdrawsName,
e2etests.TestERC20DepositAndCallRefundName,
e2etests.TestZRC20SwapName,
//e2etests.TestERC20WithdrawName,
//e2etests.TestMultipleERC20WithdrawsName,
//e2etests.TestERC20DepositAndCallRefundName,
//e2etests.TestZRC20SwapName,
}
erc20AdvancedTests := []string{
e2etests.TestERC20DepositRestrictedName,
//e2etests.TestERC20DepositRestrictedName,
}
zetaTests := []string{
e2etests.TestZetaWithdrawName,
e2etests.TestMessagePassingExternalChainsName,
e2etests.TestMessagePassingRevertFailExternalChainsName,
e2etests.TestMessagePassingRevertSuccessExternalChainsName,
//e2etests.TestZetaWithdrawName,
//e2etests.TestMessagePassingExternalChainsName,
//e2etests.TestMessagePassingRevertFailExternalChainsName,
//e2etests.TestMessagePassingRevertSuccessExternalChainsName,
}
zetaAdvancedTests := []string{
e2etests.TestZetaDepositRestrictedName,
e2etests.TestZetaDepositName,
e2etests.TestZetaDepositNewAddressName,
//e2etests.TestZetaDepositRestrictedName,
//e2etests.TestZetaDepositName,
//e2etests.TestZetaDepositNewAddressName,
}
zevmMPTests := []string{}
zevmMPAdvancedTests := []string{
e2etests.TestMessagePassingZEVMToEVMName,
e2etests.TestMessagePassingEVMtoZEVMName,
e2etests.TestMessagePassingEVMtoZEVMRevertName,
e2etests.TestMessagePassingZEVMtoEVMRevertName,
e2etests.TestMessagePassingZEVMtoEVMRevertFailName,
e2etests.TestMessagePassingEVMtoZEVMRevertFailName,
//e2etests.TestMessagePassingZEVMToEVMName,
//e2etests.TestMessagePassingEVMtoZEVMName,
//e2etests.TestMessagePassingEVMtoZEVMRevertName,
//e2etests.TestMessagePassingZEVMtoEVMRevertName,
//e2etests.TestMessagePassingZEVMtoEVMRevertFailName,
//e2etests.TestMessagePassingEVMtoZEVMRevertFailName,
}

bitcoinTests := []string{
e2etests.TestBitcoinDonationName,
e2etests.TestBitcoinDepositName,
e2etests.TestBitcoinDepositAndCallName,
e2etests.TestBitcoinDepositAndCallRevertName,
e2etests.TestBitcoinWithdrawSegWitName,
e2etests.TestBitcoinWithdrawInvalidAddressName,
e2etests.TestZetaWithdrawBTCRevertName,
e2etests.TestCrosschainSwapName,
//e2etests.TestBitcoinDonationName,
//e2etests.TestBitcoinDepositName,
//e2etests.TestBitcoinDepositAndCallName,
//e2etests.TestBitcoinDepositAndCallRevertName,
e2etests.TestBitcoinDepositAndCallRevertWithDustName,
//e2etests.TestBitcoinWithdrawSegWitName,
//e2etests.TestBitcoinWithdrawInvalidAddressName,
//e2etests.TestZetaWithdrawBTCRevertName,
//e2etests.TestCrosschainSwapName,
}
bitcoinAdvancedTests := []string{
e2etests.TestBitcoinWithdrawTaprootName,
e2etests.TestBitcoinWithdrawLegacyName,
e2etests.TestBitcoinWithdrawMultipleName,
e2etests.TestBitcoinWithdrawP2SHName,
e2etests.TestBitcoinWithdrawP2WSHName,
e2etests.TestBitcoinWithdrawRestrictedName,
e2etests.TestBitcoinStdMemoDepositName,
e2etests.TestBitcoinStdMemoDepositAndCallName,
e2etests.TestBitcoinStdMemoDepositAndCallRevertName,
e2etests.TestBitcoinStdMemoDepositAndCallRevertOtherAddressName,
//e2etests.TestBitcoinWithdrawTaprootName,
//e2etests.TestBitcoinWithdrawLegacyName,
//e2etests.TestBitcoinWithdrawMultipleName,
//e2etests.TestBitcoinWithdrawP2SHName,
//e2etests.TestBitcoinWithdrawP2WSHName,
//e2etests.TestBitcoinWithdrawRestrictedName,
//e2etests.TestBitcoinStdMemoDepositName,
//e2etests.TestBitcoinStdMemoDepositAndCallName,
//e2etests.TestBitcoinStdMemoDepositAndCallRevertName,
//e2etests.TestBitcoinStdMemoDepositAndCallRevertOtherAddressName,
}
ethereumTests := []string{
e2etests.TestEtherWithdrawName,
e2etests.TestContextUpgradeName,
e2etests.TestEtherDepositAndCallName,
e2etests.TestEtherDepositAndCallRefundName,
//e2etests.TestEtherWithdrawName,
//e2etests.TestContextUpgradeName,
//e2etests.TestEtherDepositAndCallName,
//e2etests.TestEtherDepositAndCallRefundName,
}
ethereumAdvancedTests := []string{
e2etests.TestEtherWithdrawRestrictedName,
//e2etests.TestEtherWithdrawRestrictedName,
}
precompiledContractTests := []string{}

Expand Down
6 changes: 6 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const (
TestBitcoinDepositName = "bitcoin_deposit"
TestBitcoinDepositAndCallName = "bitcoin_deposit_and_call"
TestBitcoinDepositAndCallRevertName = "bitcoin_deposit_and_call_revert"
TestBitcoinDepositAndCallRevertWithDustName = "bitcoin_deposit_and_call_revert_with_dust"
TestBitcoinDonationName = "bitcoin_donation"
TestBitcoinStdMemoDepositName = "bitcoin_std_memo_deposit"
TestBitcoinStdMemoDepositAndCallName = "bitcoin_std_memo_deposit_and_call"
Expand Down Expand Up @@ -508,6 +509,11 @@ var AllE2ETests = []runner.E2ETest{
},
TestBitcoinDepositAndCallRevert,
),
runner.NewE2ETest(
TestBitcoinDepositAndCallRevertWithDustName,
"deposit Bitcoin into ZEVM; revert with dust amount that aborts the CCTX", []runner.ArgDefinition{},
TestBitcoinDepositAndCallRevertWithDust,
),
runner.NewE2ETest(
TestBitcoinStdMemoDepositName,
"deposit Bitcoin into ZEVM with standard memo",
Expand Down
6 changes: 6 additions & 0 deletions e2e/e2etests/test_bitcoin_deposit_and_call_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func TestBitcoinDepositAndCallRevert(r *runner.E2ERunner, args []string) {
amount := parseFloat(r, args[0])
amount += zetabitcoin.DefaultDepositorFee

r.Logger.Print("BITCOIN: Amount to send: %s", args[0])

// Given a list of UTXOs
utxos, err := r.ListDeployerUTXOs()
require.NoError(r, err)
Expand All @@ -47,5 +49,9 @@ func TestBitcoinDepositAndCallRevert(r *runner.E2ERunner, args []string) {
assert.Equal(r, r.BTCDeployerAddress.EncodeAddress(), receiver)
assert.Positive(r, value)

r.Logger.Print("BITCOIN: Amount received: %d", value)

// 0.002

r.Logger.Info("Sent %f BTC to TSS with invalid memo, got refund of %d satoshis", amount, value)
}
56 changes: 56 additions & 0 deletions e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package e2etests

import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
"github.com/zeta-chain/node/testutil/sample"
)

// TestBitcoinDepositAndCallRevertWithDust sends a Bitcoin deposit that reverts with a dust amount in the revert outbound.
// Given the dust is too smart, the CCTX should revert
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.000005 = 0.00200500 should trigger the condition
// As only 500 satoshis are left after the deposit

amount := 0.00200500

// 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)

// ASSERT
// Now we want to make sure refund TX is completed.
cctx := utils.WaitCctxRevertedByInboundHash(r.Ctx, r, txHash.String(), r.CctxClient)

// Check revert tx receiver address and amount
receiver, value := r.QueryOutboundReceiverAndAmount(cctx.OutboundParams[1].Hash)
assert.Equal(r, r.BTCDeployerAddress.EncodeAddress(), receiver)
assert.Positive(r, value)

r.Logger.Print("BITCOIN: Amount received: %d", value)
r.Logger.Info("Sent %f BTC to TSS with invalid memo, got refund of %d satoshis", amount, value)
}

0 comments on commit 12b5606

Please sign in to comment.