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 16, 2022
1 parent fc7e0b2 commit 453b63b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ MsgUpdateInstantiateConfig updates instantiate config for a smart contract
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that actor that signed the messages |
| `code_id` | [uint64](#uint64) | | CodeID references the new WASM code |
| `code_id` | [uint64](#uint64) | | CodeID references the stored WASM code |
| `new_instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | NewInstantiatePermission is the new access control |


Expand Down
2 changes: 1 addition & 1 deletion proto/cosmwasm/wasm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ message MsgClearAdminResponse {}
message MsgUpdateInstantiateConfig {
// Sender is the that actor that signed the messages
string sender = 1;
// CodeID references the new WASM code
// CodeID references the stored WASM code
uint64 code_id = 2 [ (gogoproto.customname) = "CodeID" ];
// NewInstantiatePermission is the new access control
AccessConfig new_instantiate_permission = 3;
Expand Down
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 453b63b

Please sign in to comment.