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

Allow FeeCollectorAddress to be valid when setting Tokenfactory params #610

Merged
merged 2 commits into from
Jul 3, 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
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()
}
Loading