Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow gov and proposer to delete invalid output root #120

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading