Skip to content

Commit

Permalink
Merge pull request #610 from neutron-org/fix/tf-params-validation
Browse files Browse the repository at this point in the history
Allow FeeCollectorAddress to be valid when setting Tokenfactory params
  • Loading branch information
pr0n00gler authored Jul 3, 2024
2 parents c4a23be + 2083c19 commit 12d95c7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
3 changes: 2 additions & 1 deletion testutil/tokenfactory/keeper/tokenfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func TokenFactoryKeeper(
accountKeeper,
bankKeeper,
contractKeeper,
"authority",
testutil.TestOwnerAddress,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
85 changes: 82 additions & 3 deletions x/tokenfactory/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand All @@ -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)
}
})
}
}
6 changes: 0 additions & 6 deletions x/tokenfactory/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 12d95c7

Please sign in to comment.