Skip to content

Commit

Permalink
refactor: only owner can unpause
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Apr 30, 2024
1 parent 9d8b170 commit c20460d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
8 changes: 4 additions & 4 deletions x/aura/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func (k msgServer) Pause(ctx context.Context, msg *types.MsgPause) (*types.MsgPa
}

func (k msgServer) Unpause(ctx context.Context, msg *types.MsgUnpause) (*types.MsgUnpauseResponse, error) {
has, err := k.Pausers.Has(ctx, msg.Signer)
owner, err := k.Owner.Get(ctx)
if err != nil {
return nil, sdkerrors.Wrapf(err, "unable to retrieve pauser from state")
return nil, sdkerrors.Wrapf(err, "unable to retrieve owner from state")
}
if !has {
return nil, types.ErrInvalidPauser
if msg.Signer != owner {
return nil, sdkerrors.Wrapf(types.ErrInvalidOwner, "expected %s, got %s", owner, msg.Signer)
}

if paused, _ := k.Paused.Get(ctx); !paused {
Expand Down
24 changes: 16 additions & 8 deletions x/aura/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,30 @@ func TestUnpause(t *testing.T) {

// ARRANGE: Set paused state to true.
require.NoError(t, k.Paused.Set(ctx, true))
// ARRANGE: Set pauser in state.
pauser := utils.TestAccount()
require.NoError(t, k.Pausers.Set(ctx, pauser.Address))

// ACT: Attempt to unpause with no owner set.
_, err := server.Unpause(ctx, &types.MsgUnpause{})
// ASSERT: The action should've failed due to no owner set.
require.ErrorContains(t, err, "unable to retrieve owner from state")
paused, _ := k.Paused.Get(ctx)
require.True(t, paused)

// ARRANGE: Set owner in state.
owner := utils.TestAccount()
require.NoError(t, k.Owner.Set(ctx, owner.Address))

// ACT: Attempt to unpause with invalid signer.
_, err := server.Unpause(ctx, &types.MsgUnpause{
_, err = server.Unpause(ctx, &types.MsgUnpause{
Signer: utils.TestAccount().Address,
})
// ASSERT: The action should've failed due to invalid signer.
require.ErrorContains(t, err, types.ErrInvalidPauser.Error())
paused, _ := k.Paused.Get(ctx)
require.ErrorContains(t, err, types.ErrInvalidOwner.Error())
paused, _ = k.Paused.Get(ctx)
require.True(t, paused)

// ACT: Attempt to unpause.
_, err = server.Unpause(ctx, &types.MsgUnpause{
Signer: pauser.Address,
Signer: owner.Address,
})
// ASSERT: The action should've succeeded.
require.NoError(t, err)
Expand All @@ -174,7 +182,7 @@ func TestUnpause(t *testing.T) {

// ACT: Attempt to unpause again.
_, err = server.Unpause(ctx, &types.MsgUnpause{
Signer: pauser.Address,
Signer: owner.Address,
})
// ASSERT: The action should've failed due to module being unpaused already.
require.ErrorContains(t, err, "module is already unpaused")
Expand Down
7 changes: 4 additions & 3 deletions x/aura/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package types
import "cosmossdk.io/errors"

var (
ErrInvalidBurner = errors.Register(ModuleName, 1, "signer is not a burner")
ErrInvalidMinter = errors.Register(ModuleName, 2, "signer is not a minter")
ErrInvalidPauser = errors.Register(ModuleName, 3, "signer is not a pauser")
ErrInvalidOwner = errors.Register(ModuleName, 1, "signer is not owner")
ErrInvalidBurner = errors.Register(ModuleName, 2, "signer is not a burner")
ErrInvalidMinter = errors.Register(ModuleName, 3, "signer is not a minter")
ErrInvalidPauser = errors.Register(ModuleName, 4, "signer is not a pauser")
)

0 comments on commit c20460d

Please sign in to comment.