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

Fix instantiate2 proposal cli command #1934

Merged
merged 2 commits into from
Jul 17, 2024
Merged
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
70 changes: 47 additions & 23 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"bytes"
"encoding/hex"
"fmt"
"net/url"
"strconv"
Expand Down Expand Up @@ -75,12 +76,12 @@
return errors.New("authority address is required")
}

src, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
storeCodeMsg, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())

Check warning on line 79 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L79

Added line #L79 was not covered by tests
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&storeCodeMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)

Check warning on line 84 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L84

Added line #L84 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -165,12 +166,12 @@
return errors.New("authority address is required")
}

src, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())
instantiateMsg, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())

Check warning on line 169 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L169

Added line #L169 was not covered by tests
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{instantiateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)

Check warning on line 174 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L174

Added line #L174 was not covered by tests
if err != nil {
return err
}
Expand All @@ -190,16 +191,25 @@
}

func ProposalInstantiateContract2Cmd() *cobra.Command {
decoder := newArgDecoder(hex.DecodeString)

Check warning on line 194 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L194

Added line #L194 was not covered by tests
cmd := &cobra.Command{
Use: "instantiate-contract-2 [code_id_int64] [json_encoded_init_args] --authority [address] --label [text] --title [text] --summary [text] --admin [address,optional] --amount [coins,optional]",
Use: "instantiate-contract-2 [code_id_int64] [json_encoded_init_args] [salt] --authority [address] --label [text] --title [text] " +
Copy link
Member

Choose a reason for hiding this comment

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

In build-address this is called [salt-hex-encoded]. Not sure if that is an elegant way to name those arguments but I think it's important for the user to know the encoding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But hex is only the default here. You can change the encoding using the --ascii, --b64 and --hex flags.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. Then let's keep it as is

"--summary [text] --admin [address,optional] --amount [coins,optional] --fix-msg [bool,optional]",

Check warning on line 197 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L196-L197

Added lines #L196 - L197 were not covered by tests
Short: "Submit an instantiate wasm contract proposal with predictable address",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, proposalTitle, summary, deposit, expedite, err := getProposalInfo(cmd)
if err != nil {
return err
}

salt, err := decoder.DecodeString(args[2])
if err != nil {
return fmt.Errorf("salt: %w", err)

Check warning on line 207 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L205-L207

Added lines #L205 - L207 were not covered by tests
}
fixMsg, err := cmd.Flags().GetBool(flagFixMsg)
if err != nil {
return fmt.Errorf("fix msg: %w", err)

Check warning on line 211 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L209-L211

Added lines #L209 - L211 were not covered by tests
}
authority, err := cmd.Flags().GetString(flagAuthority)
if err != nil {
return fmt.Errorf("authority: %s", err)
Expand All @@ -209,12 +219,22 @@
return errors.New("authority address is required")
}

src, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())
data, err := parseInstantiateArgs(args[0], args[1], clientCtx.Keyring, authority, cmd.Flags())

Check warning on line 222 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L222

Added line #L222 was not covered by tests
if err != nil {
return err
}
instantiateMsg := &types.MsgInstantiateContract2{
Sender: data.Sender,
Admin: data.Admin,
CodeID: data.CodeID,
Label: data.Label,
Msg: data.Msg,
Funds: data.Funds,
Salt: salt,
FixMsg: fixMsg,

Check warning on line 234 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L226-L234

Added lines #L226 - L234 were not covered by tests
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{instantiateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)

Check warning on line 237 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L237

Added line #L237 was not covered by tests
if err != nil {
return err
}
Expand All @@ -228,6 +248,8 @@
cmd.Flags().String(flagLabel, "", "A human-readable name for this contract in lists")
cmd.Flags().String(flagAdmin, "", "Address of an admin")
cmd.Flags().Bool(flagNoAdmin, false, "You must set this explicitly if you don't want an admin")
cmd.Flags().Bool(flagFixMsg, false, "An optional flag to include the json_encoded_init_args for the predictable address generation mode")
decoder.RegisterFlags(cmd.PersistentFlags(), "salt")

Check warning on line 252 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L251-L252

Added lines #L251 - L252 were not covered by tests

// proposal flags
addCommonProposalFlags(cmd)
Expand Down Expand Up @@ -255,7 +277,8 @@
return errors.New("authority address is required")
}

src, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
// Variable storeCodeMsg is not really used. But this allows us to reuse parseStoreCodeArgs.
storeCodeMsg, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())

Check warning on line 281 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L281

Added line #L281 was not covered by tests
if err != nil {
return err
}
Expand All @@ -265,7 +288,7 @@
return err
}

source, builder, codeHash, err := parseVerificationFlags(src.WASMByteCode, cmd.Flags())
source, builder, codeHash, err := parseVerificationFlags(storeCodeMsg.WASMByteCode, cmd.Flags())

Check warning on line 291 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L291

Added line #L291 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -319,10 +342,10 @@
}
}

msg := types.MsgStoreAndInstantiateContract{
storeAndInstantiateMsg := types.MsgStoreAndInstantiateContract{

Check warning on line 345 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L345

Added line #L345 was not covered by tests
Authority: authority,
WASMByteCode: src.WASMByteCode,
InstantiatePermission: src.InstantiatePermission,
WASMByteCode: storeCodeMsg.WASMByteCode,
InstantiatePermission: storeCodeMsg.InstantiatePermission,

Check warning on line 348 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L347-L348

Added lines #L347 - L348 were not covered by tests
UnpinCode: unpinCode,
Source: source,
Builder: builder,
Expand All @@ -332,11 +355,11 @@
Msg: []byte(args[1]),
Funds: amount,
}
if err = msg.ValidateBasic(); err != nil {
if err = storeAndInstantiateMsg.ValidateBasic(); err != nil {

Check warning on line 358 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L358

Added line #L358 was not covered by tests
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&msg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&storeAndInstantiateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)

Check warning on line 362 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L362

Added line #L362 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -380,12 +403,12 @@
return errors.New("authority address is required")
}

src, err := parseMigrateContractArgs(args, authority)
migrateMsg, err := parseMigrateContractArgs(args, authority)

Check warning on line 406 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L406

Added line #L406 was not covered by tests
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&migrateMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)

Check warning on line 411 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L411

Added line #L411 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -519,12 +542,12 @@
return errors.New("authority address is required")
}

src, err := parseUpdateContractAdminArgs(args, authority)
upgradeAdminMsg, err := parseUpdateContractAdminArgs(args, authority)

Check warning on line 545 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L545

Added line #L545 was not covered by tests
if err != nil {
return err
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&src}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)
proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&upgradeAdminMsg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary, expedite)

Check warning on line 550 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L550

Added line #L550 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -747,7 +770,7 @@
Long: strings.TrimSpace(
fmt.Sprintf(`Submit an update instantiate config proposal for multiple code ids.

Example:
Example:

Check warning on line 773 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L773

Added line #L773 was not covered by tests
$ %s tx gov submit-proposal update-instantiate-config 1:nobody 2:everybody 3:%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm,%s1vx8knpllrj7n963p9ttd80w47kpacrhuts497x
`, version.AppName, bech32Prefix, bech32Prefix)),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -939,15 +962,16 @@
return errors.New("authority address is required")
}

src, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())
// Variable storeCodeMsg is not really used. But this allows us to reuse parseStoreCodeArgs.
storeCodeMsg, err := parseStoreCodeArgs(args[0], authority, cmd.Flags())

Check warning on line 966 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L966

Added line #L966 was not covered by tests
if err != nil {
return err
}

msg := types.MsgStoreAndMigrateContract{
Authority: authority,
WASMByteCode: src.WASMByteCode,
InstantiatePermission: src.InstantiatePermission,
WASMByteCode: storeCodeMsg.WASMByteCode,
InstantiatePermission: storeCodeMsg.InstantiatePermission,

Check warning on line 974 in x/wasm/client/cli/gov_tx.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/gov_tx.go#L973-L974

Added lines #L973 - L974 were not covered by tests
Msg: []byte(args[2]),
Contract: args[1],
}
Expand Down