Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add check for pending status
Browse files Browse the repository at this point in the history
kingpinXD committed Nov 27, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 601488d commit 9a7cd75
Showing 3 changed files with 51 additions and 4 deletions.
5 changes: 1 addition & 4 deletions x/crosschain/keeper/msg_server_abort_stuck_cctx.go
Original file line number Diff line number Diff line change
@@ -36,10 +36,7 @@ func (k msgServer) AbortStuckCCTX(
}

// check if the cctx is pending
isPending := cctx.CctxStatus.Status == types.CctxStatus_PendingOutbound ||
cctx.CctxStatus.Status == types.CctxStatus_PendingInbound ||
cctx.CctxStatus.Status == types.CctxStatus_PendingRevert
if !isPending {
if !cctx.CctxStatus.Status.IsPendingStatus() {
return nil, types.ErrStatusNotPending
}

8 changes: 8 additions & 0 deletions x/crosschain/types/status.go
Original file line number Diff line number Diff line change
@@ -86,3 +86,11 @@ func stateTransitionMap() map[CctxStatus][]CctxStatus {
}
return stateTransitionMap
}

func (c CctxStatus) IsTerminalStatus() bool {
return c == CctxStatus_Aborted || c == CctxStatus_Reverted || c == CctxStatus_OutboundMined
}

func (c CctxStatus) IsPendingStatus() bool {
return c == CctxStatus_PendingInbound || c == CctxStatus_PendingOutbound || c == CctxStatus_PendingRevert
}
42 changes: 42 additions & 0 deletions x/crosschain/types/status_test.go
Original file line number Diff line number Diff line change
@@ -174,3 +174,45 @@ func TestStatus_ChangeStatus(t *testing.T) {
)
})
}

func TestCctxStatus_IsTerminalStatus(t *testing.T) {
tests := []struct {
name string
status types.CctxStatus
expected bool
}{
{"PendingInbound", types.CctxStatus_PendingInbound, false},
{"PendingOutbound", types.CctxStatus_PendingOutbound, false},
{"OutboundMined", types.CctxStatus_OutboundMined, true},
{"Reverted", types.CctxStatus_Reverted, true},
{"Aborted", types.CctxStatus_Aborted, true},
{"PendingRevert", types.CctxStatus_PendingRevert, false},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expected, tc.status.IsTerminalStatus())
})
}
}

func TestCctxStatus_IsPendingStatus(t *testing.T) {
tests := []struct {
name string
status types.CctxStatus
expected bool
}{
{"PendingInbound", types.CctxStatus_PendingInbound, true},
{"PendingOutbound", types.CctxStatus_PendingOutbound, true},
{"OutboundMined", types.CctxStatus_OutboundMined, false},
{"Reverted", types.CctxStatus_Reverted, false},
{"Aborted", types.CctxStatus_Aborted, false},
{"PendingRevert", types.CctxStatus_PendingRevert, true},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expected, tc.status.IsPendingStatus())
})
}
}

0 comments on commit 9a7cd75

Please sign in to comment.