Skip to content

Commit

Permalink
Follow spec for ConfigureMinter, ConfigureMinterController, and Remov…
Browse files Browse the repository at this point in the history
…eMinter (#88)
  • Loading branch information
jtieri authored Feb 8, 2023
1 parent 08af7e3 commit 9cb79bd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions interchaintest/ibctest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,16 @@ func TestNobleChain(t *testing.T) {
_, err = nobleValidator.ExecTx(ctx, masterMinterKeyName,
"tokenfactory", "configure-minter-controller", roles.MinterController.Address, roles.User.Address,
)
require.NoError(t, err, "failed to execute configure minter controller tx")
require.NoError(t, err, "tx to configure minter controller should still succeed even though in paused state")

_, _, err = nobleValidator.ExecQuery(ctx, "tokenfactory", "show-minters", roles.User.Address)
require.Error(t, err, "'user' should not have been able to become a minter while chain is paused")

_, err = nobleValidator.ExecTx(ctx, minterControllerKeyName, "tokenfactory", "remove-minter", roles.Minter.Address)
require.NoError(t, err, "failed to send remove minter tx")
require.NoError(t, err, "minters should be able to be removed while in paused state")

_, _, err = nobleValidator.ExecQuery(ctx, "tokenfactory", "show-minters", roles.Minter.Address)
require.Error(t, err, "minter should have been removed, even while chain is puased")
require.Error(t, err, "minter should not have been added so remove should be a no-op and this should fail")

_, err = nobleValidator.ExecTx(ctx, pauserKeyName,
"tokenfactory", "unpause",
Expand Down
12 changes: 12 additions & 0 deletions x/tokenfactory/keeper/msg_server_configure_minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
func (k msgServer) ConfigureMinter(goCtx context.Context, msg *types.MsgConfigureMinter) (*types.MsgConfigureMinterResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if k.GetPaused(ctx).Paused {
return nil, sdkerrors.Wrap(types.ErrPaused, "minters cannot be configured while the tokenfactory is paused")
}

mintingDenom := k.GetMintingDenom(ctx)

if msg.Allowance.Denom != mintingDenom.Denom {
Expand All @@ -27,6 +31,14 @@ func (k msgServer) ConfigureMinter(goCtx context.Context, msg *types.MsgConfigur
return nil, sdkerrors.Wrapf(types.ErrUnauthorized, "you are not a controller of this minter")
}

if msg.Address != minterController.Minter {
return nil, sdkerrors.Wrapf(
types.ErrUnauthorized,
"minter address ≠ minter controller's minter address, (%s≠%s)",
msg.Address, minterController.Minter,
)
}

k.SetMinters(ctx, types.Minters{
Address: msg.Address,
Allowance: msg.Allowance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
func (k msgServer) ConfigureMinterController(goCtx context.Context, msg *types.MsgConfigureMinterController) (*types.MsgConfigureMinterControllerResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if k.GetPaused(ctx).Paused {
return nil, sdkerrors.Wrap(types.ErrPaused, "minter controllers cannot be configured while the tokenfactory is paused")
}

masterMinter, found := k.GetMasterMinter(ctx)
if !found {
return nil, sdkerrors.Wrapf(types.ErrUserNotFound, "master minter is not set")
Expand Down
8 changes: 8 additions & 0 deletions x/tokenfactory/keeper/msg_server_remove_minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ func (k msgServer) RemoveMinter(goCtx context.Context, msg *types.MsgRemoveMinte
return nil, sdkerrors.Wrapf(types.ErrUnauthorized, "you are not a controller of this minter")
}

if msg.Address != minterController.Minter {
return nil, sdkerrors.Wrapf(
types.ErrUnauthorized,
"minter address ≠ minter controller's minter address, (%s≠%s)",
msg.Address, minterController.Minter,
)
}

minter, found := k.GetMinters(ctx, msg.Address)
if !found {
return nil, sdkerrors.Wrapf(types.ErrUserNotFound, "a minter with a given address doesn't exist")
Expand Down

0 comments on commit 9cb79bd

Please sign in to comment.