Skip to content

Commit

Permalink
Fix review comments and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Dec 13, 2022
1 parent fc7e0b2 commit 0567f4a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 2 additions & 0 deletions x/wasm/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { //nolint:staticcheck
cdc.RegisterConcrete(&MsgMigrateContract{}, "wasm/MsgMigrateContract", nil)
cdc.RegisterConcrete(&MsgUpdateAdmin{}, "wasm/MsgUpdateAdmin", nil)
cdc.RegisterConcrete(&MsgClearAdmin{}, "wasm/MsgClearAdmin", nil)
cdc.RegisterConcrete(&MsgUpdateInstantiateConfig{}, "wasm/MsgUpdateInstantiateConfig", nil)

cdc.RegisterConcrete(&PinCodesProposal{}, "wasm/PinCodesProposal", nil)
cdc.RegisterConcrete(&UnpinCodesProposal{}, "wasm/UnpinCodesProposal", nil)
Expand Down Expand Up @@ -61,6 +62,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&MsgClearAdmin{},
&MsgIBCCloseChannel{},
&MsgIBCSend{},
&MsgUpdateInstantiateConfig{},
)
registry.RegisterImplementations(
(*govtypes.Content)(nil),
Expand Down
10 changes: 9 additions & 1 deletion x/wasm/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,15 @@ func (msg MsgUpdateInstantiateConfig) Type() string {

func (msg MsgUpdateInstantiateConfig) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil {
return err
return sdkerrors.Wrap(err, "sender")
}

if msg.CodeID == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required")
}

if msg.NewInstantiatePermission == nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "instantiate permission is required")
}

if err := msg.NewInstantiatePermission.ValidateBasic(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions x/wasm/types/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,65 @@ func TestMsgJsonSignBytes(t *testing.T) {
})
}
}

func TestMsgUpdateInstantiateConfig(t *testing.T) {
bad, err := sdk.AccAddressFromHex("012345")
require.NoError(t, err)
badAddress := bad.String()
// proper address size
goodAddress := sdk.AccAddress(make([]byte, 20)).String()
anotherGoodAddress := sdk.AccAddress(bytes.Repeat([]byte{0x2}, 20)).String()

specs := map[string]struct {
src MsgUpdateInstantiateConfig
expErr bool
}{
"all good": {
src: MsgUpdateInstantiateConfig{
Sender: goodAddress,
CodeID: 1,
NewInstantiatePermission: &AccessConfig{Permission: AccessTypeOnlyAddress, Address: anotherGoodAddress},
},
},
"bad sender": {
src: MsgUpdateInstantiateConfig{
Sender: badAddress,
CodeID: 1,
NewInstantiatePermission: &AccessConfig{Permission: AccessTypeOnlyAddress, Address: anotherGoodAddress},
},
expErr: true,
},
"invalid NewInstantiatePermission": {
src: MsgUpdateInstantiateConfig{
Sender: goodAddress,
CodeID: 1,
NewInstantiatePermission: &AccessConfig{Permission: AccessTypeOnlyAddress, Address: badAddress},
},
expErr: true,
},
"missing code id": {
src: MsgUpdateInstantiateConfig{
Sender: goodAddress,
NewInstantiatePermission: &AccessConfig{Permission: AccessTypeOnlyAddress, Address: anotherGoodAddress},
},
expErr: true,
},
"missing NewInstantiatePermission": {
src: MsgUpdateInstantiateConfig{
Sender: goodAddress,
CodeID: 1,
},
expErr: true,
},
}
for msg, spec := range specs {
t.Run(msg, func(t *testing.T) {
err := spec.src.ValidateBasic()
if spec.expErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}

0 comments on commit 0567f4a

Please sign in to comment.