Skip to content

Commit

Permalink
Merge pull request #727 from CosmWasm/719-explicitly-no-admin
Browse files Browse the repository at this point in the history
You must explicitly declare --no-admin on cli instantiate if that is what you want
  • Loading branch information
ethanfrey authored Jan 21, 2022
2 parents b4258b9 + 1e78fbc commit 1eb27da
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fixed circleci by removing the golang executor from a docker build
- Go 1.17 provides a much clearer go.mod file [\#679](https://github.com/CosmWasm/wasmd/pull/679) ([faddat](https://github.com/faddat))
- Autopin wasm code uploaded by gov proposal [\#726](https://github.com/CosmWasm/wasmd/pull/726) ([ethanfrey](https://github.com/ethanfrey))
- You must explicitly declare --no-admin on cli instantiate if that is what you want [\#727](https://github.com/CosmWasm/wasmd/pull/727) ([ethanfrey](https://github.com/ethanfrey))


[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.22.0...v0.21.0)
Expand Down
1 change: 1 addition & 0 deletions x/wasm/client/cli/genesis_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func GenesisInstantiateContractCmd(defaultNodeHome string, genesisMutator Genesi
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
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().String(flagRunAs, "", "The address that pays the init funds. It is the creator of the contract.")

cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
Expand Down
60 changes: 60 additions & 0 deletions x/wasm/client/cli/genesis_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expMsgCount: 1,
},
Expand All @@ -157,6 +158,7 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("admin", myWellFundedAccount)
},
expMsgCount: 2,
},
Expand All @@ -175,6 +177,7 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expMsgCount: 2,
},
Expand All @@ -185,6 +188,7 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expError: true,
},
Expand All @@ -202,6 +206,59 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
},
expError: true,
},
"fails if no explicit --no-admin passed": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
},
expError: true,
},
"fails if both --admin and --no-admin passed": {
srcGenesis: types.GenesisState{
Params: types.DefaultParams(),
Codes: []types.Code{
{
CodeID: 1,
CodeInfo: types.CodeInfo{
CodeHash: []byte("a-valid-code-hash"),
Creator: keeper.RandomBech32AccountAddress(t),
InstantiateConfig: types.AccessConfig{
Permission: types.AccessTypeEverybody,
},
},
CodeBytes: wasmIdent,
},
},
},
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{"1", `{}`})
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("no-admin", "true")
flagSet.Set("admin", myWellFundedAccount)
},
expError: true,
},
Expand All @@ -227,6 +284,7 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet := cmd.Flags()
flagSet.Set("label", "testing")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
flagSet.Set("no-admin", "true")
},
expMsgCount: 1,
},
Expand All @@ -253,6 +311,7 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet.Set("label", "testing")
flagSet.Set("run-as", myWellFundedAccount)
flagSet.Set("amount", "100stake")
flagSet.Set("no-admin", "true")
},
expMsgCount: 1,
},
Expand All @@ -279,6 +338,7 @@ func TestInstantiateContractCmd(t *testing.T) {
flagSet.Set("label", "testing")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
flagSet.Set("amount", "10stake")
flagSet.Set("no-admin", "true")
},
expError: true,
},
Expand Down
14 changes: 14 additions & 0 deletions x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
flagAmount = "amount"
flagLabel = "label"
flagAdmin = "admin"
flagNoAdmin = "no-admin"
flagRunAs = "run-as"
flagInstantiateByEverybody = "instantiate-everybody"
flagInstantiateByAddress = "instantiate-only-address"
Expand Down Expand Up @@ -157,6 +158,7 @@ func InstantiateContractCmd() *cobra.Command {
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
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")
flags.AddTxFlagsToCmd(cmd)
return cmd
}
Expand Down Expand Up @@ -187,6 +189,18 @@ func parseInstantiateArgs(rawCodeID, initMsg string, sender sdk.AccAddress, flag
if err != nil {
return types.MsgInstantiateContract{}, fmt.Errorf("admin: %s", err)
}
noAdmin, err := flags.GetBool(flagNoAdmin)
if err != nil {
return types.MsgInstantiateContract{}, fmt.Errorf("no-admin: %s", err)
}

// ensure sensible admin is set (or explicitly immutable)
if adminStr == "" && !noAdmin {
return types.MsgInstantiateContract{}, fmt.Errorf("you must set an admin or explicitly pass --no-admin to make it immutible (wasmd issue #719)")
}
if adminStr != "" && noAdmin {
return types.MsgInstantiateContract{}, fmt.Errorf("you set an admin and passed --no-admin, those cannot both be true")
}

// build and sign the transaction, then broadcast to Tendermint
msg := types.MsgInstantiateContract{
Expand Down

0 comments on commit 1eb27da

Please sign in to comment.