Skip to content

Commit

Permalink
bug fix checking if output index is less than next output index (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha authored May 23, 2024
1 parent fa4d466 commit e5ffbd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions x/ophost/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func (ms MsgServer) DeleteOutput(ctx context.Context, req *types.MsgDeleteOutput
return nil, err
}

if outputIndex >= nextOutputIndex {
return nil, types.ErrInvalidOutputIndex
}

// delete output proposals in [outputIndex, nextOutputIndex) range
for i := outputIndex; i < nextOutputIndex; i++ {
if err := ms.DeleteOutputProposal(ctx, bridgeId, i); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion x/ophost/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,14 @@ func Test_DeleteOutput(t *testing.T) {
_, err = input.OPHostKeeper.GetOutputProposal(ctx, 1, 1)
require.Error(t, err)

// should able to resubmit the same output
// should be able to resubmit the same output
proposeRes, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[0], 1, 100, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}))
require.NoError(t, err)
require.Equal(t, uint64(1), proposeRes.OutputIndex)

// invalid output index: nextoutputindex is 2 now
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[1], 1, 2))
require.Error(t, err)
}

func Test_InitiateTokenDeposit(t *testing.T) {
Expand Down

0 comments on commit e5ffbd9

Please sign in to comment.