From ae784d82d65ae9c0478058c3f8a667cfd7936461 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 21 Nov 2024 19:51:54 -0500 Subject: [PATCH] match pending revert for v21 dtc dust amount withdraw --- ...tcoin_deposit_and_call_revert_with_dust.go | 11 +++++-- e2e/utils/zetacore.go | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go b/e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go index cc5f5451dc..432b20c4d6 100644 --- a/e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go +++ b/e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go @@ -47,7 +47,12 @@ func TestBitcoinDepositAndCallRevertWithDust(r *runner.E2ERunner, args []string) // ASSERT // Now we want to make sure the cctx is aborted with expected error message - cctx := utils.WaitCctxAbortedByInboundHash(r.Ctx, r, txHash.String(), r.CctxClient) - require.True(r, cctx.GetCurrentOutboundParam().Amount.Uint64() < constant.BTCWithdrawalDustAmount) - require.True(r, strings.Contains(cctx.CctxStatus.ErrorMessage, crosschaintypes.ErrInvalidWithdrawalAmount.Error())) + + // cctx status would be pending revert if using v21 or before + cctx := utils.WaitCctxByStatusList(r.Ctx, r, txHash.String(), r.CctxClient, []crosschaintypes.CctxStatus{crosschaintypes.CctxStatus_Aborted, crosschaintypes.CctxStatus_PendingRevert}) + + if cctx.CctxStatus.Status == crosschaintypes.CctxStatus_Aborted { + require.True(r, cctx.GetCurrentOutboundParam().Amount.Uint64() < constant.BTCWithdrawalDustAmount) + require.True(r, strings.Contains(cctx.CctxStatus.ErrorMessage, crosschaintypes.ErrInvalidWithdrawalAmount.Error())) + } } diff --git a/e2e/utils/zetacore.go b/e2e/utils/zetacore.go index 34e53e61b0..b004148917 100644 --- a/e2e/utils/zetacore.go +++ b/e2e/utils/zetacore.go @@ -194,6 +194,22 @@ func MatchStatus(s crosschaintypes.CctxStatus) WaitOpts { }) } +// MatchStatusList is the WaitOpts that matches CCTX with the given status. +// It returns as soon as any of the status is matched. +func MatchStatusList(s []crosschaintypes.CctxStatus) WaitOpts { + return Matches(func(tx crosschaintypes.CrossChainTx) bool { + if tx.CctxStatus == nil { + return false + } + for _, s := range s { + if tx.CctxStatus.Status == s { + return true + } + } + return false + }) +} + // MatchReverted is the WaitOpts that matches reverted CCTX. func MatchReverted() WaitOpts { return Matches(func(tx crosschaintypes.CrossChainTx) bool { @@ -227,6 +243,20 @@ func WaitCctxRevertedByInboundHash( return cctxs[0] } +// WaitCctxByStatusList waits until cctx is in one of the given statuses. +func WaitCctxByStatusList( + ctx context.Context, + t require.TestingT, + hash string, + c CCTXClient, + status []crosschaintypes.CctxStatus, +) crosschaintypes.CrossChainTx { + cctx := WaitCctxByInboundHash(ctx, t, hash, c, MatchStatusList(status)) + require.Len(t, cctx, 1) + + return cctx[0] +} + // WaitCctxAbortedByInboundHash waits until cctx is aborted by inbound hash. func WaitCctxAbortedByInboundHash( ctx context.Context,