diff --git a/testutil/tokenfactory/keeper/tokenfactory.go b/testutil/tokenfactory/keeper/tokenfactory.go index 55bbabced..d122324c1 100644 --- a/testutil/tokenfactory/keeper/tokenfactory.go +++ b/testutil/tokenfactory/keeper/tokenfactory.go @@ -14,6 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/neutron-org/neutron/v4/testutil" "github.com/neutron-org/neutron/v4/x/tokenfactory/keeper" "github.com/neutron-org/neutron/v4/x/tokenfactory/types" ) @@ -43,7 +44,7 @@ func TokenFactoryKeeper( accountKeeper, bankKeeper, contractKeeper, - "authority", + testutil.TestOwnerAddress, ) ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) diff --git a/x/tokenfactory/keeper/msg_server_test.go b/x/tokenfactory/keeper/msg_server_test.go index 5130f266b..30edda04c 100644 --- a/x/tokenfactory/keeper/msg_server_test.go +++ b/x/tokenfactory/keeper/msg_server_test.go @@ -869,24 +869,36 @@ func TestMsgUpdateParamsValidate(t *testing.T) { "authority is invalid", }, { - "empty fee_collector_address", + "empty fee_collector_address with denom_creation_fee", types.MsgUpdateParams{ Authority: testutil.TestOwnerAddress, Params: types.Params{ FeeCollectorAddress: "", + DenomCreationFee: sdktypes.NewCoins(sdktypes.NewCoin("untrn", math.OneInt())), }, }, - "fee_collector_address is invalid", + "DenomCreationFee and FeeCollectorAddr must be both set or both unset", + }, + { + "fee_collector_address empty denom_creation_fee", + types.MsgUpdateParams{ + Authority: testutil.TestOwnerAddress, + Params: types.Params{ + FeeCollectorAddress: testAddress, + }, + }, + "DenomCreationFee and FeeCollectorAddr must be both set or both unset", }, { "invalid fee_collector_address", types.MsgUpdateParams{ Authority: testutil.TestOwnerAddress, Params: types.Params{ + DenomCreationFee: sdktypes.NewCoins(sdktypes.NewCoin("untrn", math.OneInt())), FeeCollectorAddress: "invalid fee_collector_address", }, }, - "fee_collector_address is invalid", + "failed to validate FeeCollectorAddress", }, } @@ -899,3 +911,70 @@ func TestMsgUpdateParamsValidate(t *testing.T) { }) } } + +func TestMsgUpdateParamsWhitelistedHooks(t *testing.T) { + k, ctx := testkeeper.TokenFactoryKeeper(t, nil, nil, nil) + + tests := []struct { + name string + params types.Params + error string + }{ + { + "success", + types.Params{ + WhitelistedHooks: []*types.WhitelistedHook{{DenomCreator: testAddress, CodeID: 1}}, + }, + "", + }, + { + "success multiple ", + types.Params{ + WhitelistedHooks: []*types.WhitelistedHook{ + {DenomCreator: testAddress, CodeID: 1}, + {DenomCreator: testAddress, CodeID: 2}, + }, + }, + "", + }, + { + "invalid denom creator", + types.Params{ + WhitelistedHooks: []*types.WhitelistedHook{ + {DenomCreator: "bad_address", CodeID: 1}, + }, + }, + "invalid denom creator", + }, + { + "duplicate hooks", + types.Params{ + WhitelistedHooks: []*types.WhitelistedHook{ + {DenomCreator: testAddress, CodeID: 1}, + {DenomCreator: testAddress, CodeID: 1}, + }, + }, + "duplicate whitelisted hook", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + msg := &types.MsgUpdateParams{ + Authority: testutil.TestOwnerAddress, + Params: tt.params, + } + resp, err := k.UpdateParams(ctx, msg) + if len(tt.error) > 0 { + require.ErrorContains(t, err, tt.error) + require.Nil(t, resp) + + } else { + require.NoError(t, err) + newParams := k.GetParams(ctx) + require.Equal(t, tt.params, newParams) + } + }) + } +} diff --git a/x/tokenfactory/types/tx.go b/x/tokenfactory/types/tx.go index 8b908d852..3925b0b5a 100644 --- a/x/tokenfactory/types/tx.go +++ b/x/tokenfactory/types/tx.go @@ -32,11 +32,5 @@ func (msg *MsgUpdateParams) Validate() error { return errorsmod.Wrap(err, "authority is invalid") } - // TODO: This is inconsistent. Per Params.Validate() an empty creator address is valid as long as - // DenomCreationFee is nil. But This check fails if FeeCollectorAddress is unset. - if _, err := sdk.AccAddressFromBech32(msg.Params.FeeCollectorAddress); err != nil { - return errorsmod.Wrap(err, "fee_collector_address is invalid") - } - return msg.Params.Validate() }