-
Notifications
You must be signed in to change notification settings - Fork 402
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
Introduce new AccessType to allow a set of addresses #974
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -597,27 +597,38 @@ func ProposalUnpinCodesCmd() *cobra.Command { | |
return cmd | ||
} | ||
|
||
func parseAccessConfig(config string) (types.AccessConfig, error) { | ||
switch config { | ||
func parseAccessConfig(raw string) (c types.AccessConfig, err error) { | ||
switch raw { | ||
case "nobody": | ||
return types.AllowNobody, nil | ||
case "everybody": | ||
return types.AllowEverybody, nil | ||
default: | ||
address, err := sdk.AccAddressFromBech32(config) | ||
if err != nil { | ||
return types.AccessConfig{}, fmt.Errorf("unable to parse address %s", config) | ||
parts := strings.Split(raw, ",") | ||
addrs := make([]sdk.AccAddress, len(parts)) | ||
for i, v := range parts { | ||
addr, err := sdk.AccAddressFromBech32(v) | ||
if err != nil { | ||
return types.AccessConfig{}, fmt.Errorf("unable to parse address %q: %s", v, err) | ||
} | ||
addrs[i] = addr | ||
} | ||
return types.AccessTypeOnlyAddress.With(address), nil | ||
defer func() { // convert panic in ".With" to error for better output | ||
if r := recover(); r != nil { | ||
err = r.(error) | ||
} | ||
}() | ||
cfg := types.AccessTypeAnyOfAddresses.With(addrs...) | ||
return cfg, cfg.ValidateBasic() | ||
} | ||
} | ||
|
||
func parseAccessConfigUpdates(args []string) ([]types.AccessConfigUpdate, error) { | ||
updates := make([]types.AccessConfigUpdate, len(args)) | ||
for i, c := range args { | ||
// format: code_id,access_config | ||
// access_config: nobody|everybody|address | ||
parts := strings.Split(c, ",") | ||
// format: code_id:access_config | ||
// access_config: nobody|everybody|address(es) | ||
parts := strings.Split(c, ":") | ||
if len(parts) != 2 { | ||
return nil, fmt.Errorf("invalid format") | ||
} | ||
|
@@ -642,15 +653,15 @@ func parseAccessConfigUpdates(args []string) ([]types.AccessConfigUpdate, error) | |
func ProposalUpdateInstantiateConfigCmd() *cobra.Command { | ||
bech32Prefix := sdk.GetConfig().GetBech32AccountAddrPrefix() | ||
cmd := &cobra.Command{ | ||
Use: "update-instantiate-config [code-id,permission]...", | ||
Use: "update-instantiate-config [code-id:permission]...", | ||
Short: "Submit an update instantiate config proposal.", | ||
Args: cobra.MinimumNArgs(1), | ||
Long: strings.TrimSpace( | ||
fmt.Sprintf(`Submit an update instantiate config proposal for multiple code ids. | ||
|
||
Example: | ||
$ %s tx gov submit-proposal update-instantiate-config 1,nobody 2,everybody 3,%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm | ||
`, version.AppName, bech32Prefix)), | ||
$ %s tx gov submit-proposal update-instantiate-config 1:nobody 2:everybody 3:%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm,%s1vx8knpllrj7n963p9ttd80w47kpacrhuts497x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! I think this should work fine. |
||
`, version.AppName, bech32Prefix, bech32Prefix)), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package cli | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/CosmWasm/wasmd/x/wasm/types" | ||
) | ||
|
||
func TestParseAccessConfigUpdates(t *testing.T) { | ||
specs := map[string]struct { | ||
src []string | ||
exp []types.AccessConfigUpdate | ||
expErr bool | ||
}{ | ||
"nobody": { | ||
src: []string{"1:nobody"}, | ||
exp: []types.AccessConfigUpdate{{ | ||
CodeID: 1, | ||
InstantiatePermission: types.AccessConfig{Permission: types.AccessTypeNobody}, | ||
}}, | ||
}, | ||
"everybody": { | ||
src: []string{"1:everybody"}, | ||
exp: []types.AccessConfigUpdate{{ | ||
CodeID: 1, | ||
InstantiatePermission: types.AccessConfig{Permission: types.AccessTypeEverybody}, | ||
}}, | ||
}, | ||
"any of addresses - single": { | ||
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"}, | ||
exp: []types.AccessConfigUpdate{ | ||
{ | ||
CodeID: 1, | ||
InstantiatePermission: types.AccessConfig{ | ||
Permission: types.AccessTypeAnyOfAddresses, | ||
Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"any of addresses - multiple": { | ||
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"}, | ||
exp: []types.AccessConfigUpdate{ | ||
{ | ||
CodeID: 1, | ||
InstantiatePermission: types.AccessConfig{ | ||
Permission: types.AccessTypeAnyOfAddresses, | ||
Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x", "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"multiple code ids with different permissions": { | ||
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", "2:nobody"}, | ||
exp: []types.AccessConfigUpdate{ | ||
{ | ||
CodeID: 1, | ||
InstantiatePermission: types.AccessConfig{ | ||
Permission: types.AccessTypeAnyOfAddresses, | ||
Addresses: []string{"cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x", "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr"}, | ||
}, | ||
}, { | ||
CodeID: 2, | ||
InstantiatePermission: types.AccessConfig{ | ||
Permission: types.AccessTypeNobody, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"any of addresses - empty list": { | ||
src: []string{"1:"}, | ||
expErr: true, | ||
}, | ||
"any of addresses - invalid address": { | ||
src: []string{"1:foo"}, | ||
expErr: true, | ||
}, | ||
"any of addresses - duplicate address": { | ||
src: []string{"1:cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x,cosmos1vx8knpllrj7n963p9ttd80w47kpacrhuts497x"}, | ||
expErr: true, | ||
}, | ||
} | ||
for name, spec := range specs { | ||
t.Run(name, func(t *testing.T) { | ||
got, gotErr := parseAccessConfigUpdates(spec.src) | ||
if spec.expErr { | ||
require.Error(t, gotErr) | ||
return | ||
} | ||
require.NoError(t, gotErr) | ||
assert.Equal(t, spec.exp, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why deprecate?
I think it is fine to use the simpler version for the cases where it works