Skip to content

Commit

Permalink
deposit and withdraw dust test
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Dec 20, 2024
1 parent 4255a9e commit 6b4e77e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
17 changes: 9 additions & 8 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,19 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
// btc withdraw tests are those that need a Bitcoin node wallet to send UTXOs
bitcoinDepositTests := []string{
e2etests.TestBitcoinDonationName,
e2etests.TestBitcoinDepositName,
e2etests.TestBitcoinDepositAndCallName,
e2etests.TestBitcoinDepositAndCallRevertName,
e2etests.TestBitcoinStdMemoDepositName,
e2etests.TestBitcoinStdMemoDepositAndCallName,
e2etests.TestBitcoinStdMemoDepositAndCallRevertName,
e2etests.TestBitcoinStdMemoInscribedDepositAndCallName,
e2etests.TestCrosschainSwapName,
//e2etests.TestBitcoinDepositName,
//e2etests.TestBitcoinDepositAndCallName,
//e2etests.TestBitcoinDepositAndCallRevertName,
//e2etests.TestBitcoinStdMemoDepositName,
//e2etests.TestBitcoinStdMemoDepositAndCallName,
//e2etests.TestBitcoinStdMemoDepositAndCallRevertName,
//e2etests.TestBitcoinStdMemoInscribedDepositAndCallName,
//e2etests.TestCrosschainSwapName,
}
bitcoinDepositTestsAdvanced := []string{
e2etests.TestBitcoinDepositAndCallRevertWithDustName,
e2etests.TestBitcoinStdMemoDepositAndCallRevertOtherAddressName,
e2etests.TestBitcoinDepositAndWithdrawWithDustName,
}
bitcoinWithdrawTests := []string{
e2etests.TestBitcoinWithdrawSegWitName,
Expand Down
13 changes: 11 additions & 2 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const (
TestBitcoinDepositAndCallName = "bitcoin_deposit_and_call"
TestBitcoinDepositAndCallRevertName = "bitcoin_deposit_and_call_revert"
TestBitcoinDepositAndCallRevertWithDustName = "bitcoin_deposit_and_call_revert_with_dust"
TestBitcoinDepositAndWithdrawWithDustName = "bitcoin_deposit_and_withdraw_with_dust"
TestBitcoinDonationName = "bitcoin_donation"
TestBitcoinStdMemoDepositName = "bitcoin_std_memo_deposit"
TestBitcoinStdMemoDepositAndCallName = "bitcoin_std_memo_deposit_and_call"
Expand Down Expand Up @@ -586,16 +587,24 @@ var AllE2ETests = []runner.E2ETest{
),
runner.NewE2ETest(
TestBitcoinDepositAndCallRevertName,
"deposit Bitcoin into ZEVM; expect refund", []runner.ArgDefinition{
"deposit Bitcoin into ZEVM; expect refund",
[]runner.ArgDefinition{
{Description: "amount in btc", DefaultValue: "0.1"},
},
TestBitcoinDepositAndCallRevert,
),
runner.NewE2ETest(
TestBitcoinDepositAndCallRevertWithDustName,
"deposit Bitcoin into ZEVM; revert with dust amount that aborts the CCTX", []runner.ArgDefinition{},
"deposit Bitcoin into ZEVM; revert with dust amount that aborts the CCTX",
[]runner.ArgDefinition{},
TestBitcoinDepositAndCallRevertWithDust,
),
runner.NewE2ETest(
TestBitcoinDepositAndWithdrawWithDustName,
"deposit Bitcoin into ZEVM and withdraw with dust amount that fails the CCTX",
[]runner.ArgDefinition{},
TestBitcoinDepositAndWithdrawWithDust,

Check failure on line 606 in e2e/e2etests/e2etests.go

View workflow job for this annotation

GitHub Actions / build-and-test

undefined: TestBitcoinDepositAndWithdrawWithDust

Check failure on line 606 in e2e/e2etests/e2etests.go

View workflow job for this annotation

GitHub Actions / build-and-test

undefined: TestBitcoinDepositAndWithdrawWithDust

Check failure on line 606 in e2e/e2etests/e2etests.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TestBitcoinDepositAndWithdrawWithDust (typecheck)

Check failure on line 606 in e2e/e2etests/e2etests.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TestBitcoinDepositAndWithdrawWithDust) (typecheck)

Check failure on line 606 in e2e/e2etests/e2etests.go

View workflow job for this annotation

GitHub Actions / lint

undefined: TestBitcoinDepositAndWithdrawWithDust) (typecheck)
),
runner.NewE2ETest(
TestBitcoinStdMemoDepositName,
"deposit Bitcoin into ZEVM with standard memo",
Expand Down
6 changes: 3 additions & 3 deletions x/crosschain/keeper/evm_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (k Keeper) ProcessZEVMInboundV1(

// If Validation fails, we will not process the event and return and error. This condition means that the event was correct, and emitted from a registered ZRC20 contract
// But the information entered by the user is incorrect. In this case we can return an error and roll back the transaction
if err := k.ValidateZrc20WithdrawEvent(ctx, eventZRC20Withdrawal, coin.ForeignChainId); err != nil {
if err := k.ValidateZRC20WithdrawEvent(ctx, eventZRC20Withdrawal, coin.ForeignChainId); err != nil {
return err
}
// If the event is valid, we will process it and create a new CCTX
Expand Down Expand Up @@ -303,9 +303,9 @@ func (k Keeper) ProcessZetaSentEvent(
return nil
}

// ValidateZrc20WithdrawEvent checks if the ZRC20Withdrawal event is valid
// ValidateZRC20WithdrawEvent checks if the ZRC20Withdrawal event is valid
// It verifies event information for BTC chains and returns an error if the event is invalid
func (k Keeper) ValidateZrc20WithdrawEvent(ctx sdk.Context, event *zrc20.ZRC20Withdrawal, chainID int64) error {
func (k Keeper) ValidateZRC20WithdrawEvent(ctx sdk.Context, event *zrc20.ZRC20Withdrawal, chainID int64) error {
// The event was parsed; that means the user has deposited tokens to the contract.
return k.validateZRC20Withdrawal(ctx, chainID, event.Value, event.To)
}
Expand Down
16 changes: 8 additions & 8 deletions x/crosschain/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestValidateZrc20WithdrawEvent(t *testing.T) {
*sample.ValidZRC20WithdrawToBTCReceipt(t).Logs[3],
)
require.NoError(t, err)
err = k.ValidateZrc20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
err = k.ValidateZRC20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
require.NoError(t, err)
})

Expand All @@ -174,12 +174,12 @@ func TestValidateZrc20WithdrawEvent(t *testing.T) {

// 1000 satoshis is the minimum amount that can be withdrawn
btcMainNetWithdrawalEvent.Value = big.NewInt(constant.BTCWithdrawalDustAmount)
err = k.ValidateZrc20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
err = k.ValidateZRC20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
require.NoError(t, err)

// 999 satoshis cannot be withdrawn
btcMainNetWithdrawalEvent.Value = big.NewInt(constant.BTCWithdrawalDustAmount - 1)
err = k.ValidateZrc20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
err = k.ValidateZRC20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
require.ErrorContains(t, err, "less than dust amount")
})

Expand All @@ -189,7 +189,7 @@ func TestValidateZrc20WithdrawEvent(t *testing.T) {
*sample.ValidZRC20WithdrawToBTCReceipt(t).Logs[3],
)
require.NoError(t, err)
err = k.ValidateZrc20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinTestnet.ChainId)
err = k.ValidateZRC20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinTestnet.ChainId)
require.ErrorContains(t, err, "invalid address")
})

Expand All @@ -201,7 +201,7 @@ func TestValidateZrc20WithdrawEvent(t *testing.T) {
require.NoError(t, err)
btcMainNetWithdrawalEvent.To = []byte("04b2891ba8cb491828db3ebc8a780d43b169e7b3974114e6e50f9bab6ec" +
"63c2f20f6d31b2025377d05c2a704d3bd799d0d56f3a8543d79a01ab6084a1cb204f260")
err = k.ValidateZrc20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
err = k.ValidateZRC20WithdrawEvent(ctx, btcMainNetWithdrawalEvent, chains.BitcoinMainnet.ChainId)
require.ErrorContains(t, err, "unsupported address")
})

Expand All @@ -213,7 +213,7 @@ func TestValidateZrc20WithdrawEvent(t *testing.T) {
value := big.NewInt(constant.SolanaWalletRentExempt)
solWithdrawalEvent := sample.ZRC20Withdrawal(to, value)

err := k.ValidateZrc20WithdrawEvent(ctx, solWithdrawalEvent, chains.SolanaMainnet.ChainId)
err := k.ValidateZRC20WithdrawEvent(ctx, solWithdrawalEvent, chains.SolanaMainnet.ChainId)
require.ErrorContains(t, err, "invalid address")
})

Expand All @@ -227,12 +227,12 @@ func TestValidateZrc20WithdrawEvent(t *testing.T) {
solWithdrawalEvent := sample.ZRC20Withdrawal(to, value)

// 1000000 lamports can be withdrawn
err := k.ValidateZrc20WithdrawEvent(ctx, solWithdrawalEvent, chainID)
err := k.ValidateZRC20WithdrawEvent(ctx, solWithdrawalEvent, chainID)
require.NoError(t, err)

// 999999 lamports cannot be withdrawn
solWithdrawalEvent.Value = big.NewInt(constant.SolanaWalletRentExempt - 1)
err = k.ValidateZrc20WithdrawEvent(ctx, solWithdrawalEvent, chainID)
err = k.ValidateZRC20WithdrawEvent(ctx, solWithdrawalEvent, chainID)
require.ErrorContains(t, err, "less than rent exempt")
})
}
Expand Down

0 comments on commit 6b4e77e

Please sign in to comment.