Skip to content

Commit

Permalink
allow gov and proposer to delete invalid output root (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Nov 15, 2024
1 parent 3965ef4 commit 0cbcfed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions x/ophost/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ func (ms MsgServer) DeleteOutput(ctx context.Context, req *types.MsgDeleteOutput
return nil, err
}

// permission check
if bridgeConfig.Challenger != challenger {
return nil, errors.ErrUnauthorized.Wrap("invalid challenger")
// gov, current propoer or current challenger can delete output.
if ms.authority != challenger && bridgeConfig.Proposer != challenger && bridgeConfig.Challenger != challenger {
return nil, errors.ErrUnauthorized.Wrapf("invalid challenger; expected %s, %s or %s, got %s", ms.authority, bridgeConfig.Proposer, bridgeConfig.Challenger, challenger)
}

nextOutputIndex, err := ms.GetNextOutputIndex(ctx, bridgeId)
Expand Down
16 changes: 14 additions & 2 deletions x/ophost/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func Test_DeleteOutput(t *testing.T) {
require.NoError(t, err)

// unauthorized
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[0], 1, 1))
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[2], 1, 1))
require.Error(t, err)

// valid
// valid by challenger
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[1], 1, 1))
require.NoError(t, err)

Expand All @@ -140,6 +140,18 @@ func Test_DeleteOutput(t *testing.T) {
// invalid output index: nextoutputindex is 2 now
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[1], 1, 2))
require.Error(t, err)

// valid delete by gov
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(input.OPHostKeeper.GetAuthority(), 1, 1))
require.NoError(t, err)

// should be able to resubmit the same output
_, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[0], 1, 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)

// valid delete by proposer
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[0], 1, 1))
require.NoError(t, err)
}

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

0 comments on commit 0cbcfed

Please sign in to comment.