Skip to content

Commit

Permalink
Add test for successfully setting WhitelistedHooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jcompagni10 committed Jul 2, 2024
1 parent ff4b977 commit 2083c19
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
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
67 changes: 67 additions & 0 deletions x/tokenfactory/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,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)
}
})
}
}

0 comments on commit 2083c19

Please sign in to comment.