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

Add UpdateInstantiateConfig command #1121

Merged
merged 5 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 {
alpe marked this conversation as resolved.
Show resolved Hide resolved
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)
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good test