Skip to content

Commit

Permalink
match pending revert for v21 dtc dust amount withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Nov 22, 2024
1 parent ffc9b19 commit ae784d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions e2e/e2etests/test_bitcoin_deposit_and_call_revert_with_dust.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}
30 changes: 30 additions & 0 deletions e2e/utils/zetacore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ae784d8

Please sign in to comment.