-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Description Closes: #10082 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) (cherry picked from commit 623d084) # Conflicts: # go.mod # go.sum # x/authz/client/testutil/grpc.go # x/group/go.mod # x/group/go.sum
- Loading branch information
Showing
8 changed files
with
1,387 additions
and
6 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/testutil/rest" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/authz" | ||
"github.com/cosmos/cosmos-sdk/x/authz/client/cli" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
) | ||
|
||
func (s *IntegrationTestSuite) TestQueryGrantGRPC() { | ||
val := s.network.Validators[0] | ||
grantee := s.grantee[1] | ||
grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s&msg_type_url=%s" | ||
testCases := []struct { | ||
name string | ||
url string | ||
expectErr bool | ||
errorMsg string | ||
}{ | ||
{ | ||
"fail invalid granter address", | ||
fmt.Sprintf(grantsURL, "invalid_granter", grantee.String(), typeMsgSend), | ||
true, | ||
"decoding bech32 failed: invalid separator index -1: invalid request", | ||
}, | ||
{ | ||
"fail invalid grantee address", | ||
fmt.Sprintf(grantsURL, val.Address.String(), "invalid_grantee", typeMsgSend), | ||
true, | ||
"decoding bech32 failed: invalid separator index -1: invalid request", | ||
}, | ||
{ | ||
"fail with empty granter", | ||
fmt.Sprintf(grantsURL, "", grantee.String(), typeMsgSend), | ||
true, | ||
"empty address string is not allowed: invalid request", | ||
}, | ||
{ | ||
"fail with empty grantee", | ||
fmt.Sprintf(grantsURL, val.Address.String(), "", typeMsgSend), | ||
true, | ||
"empty address string is not allowed: invalid request", | ||
}, | ||
{ | ||
"fail invalid msg-type", | ||
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String(), "invalidMsg"), | ||
true, | ||
"rpc error: code = NotFound desc = no authorization found for invalidMsg type: key not found", | ||
}, | ||
{ | ||
"valid query", | ||
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String(), typeMsgSend), | ||
false, | ||
"", | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
tc := tc | ||
s.Run(tc.name, func() { | ||
resp, _ := rest.GetRequest(tc.url) | ||
require := s.Require() | ||
if tc.expectErr { | ||
require.Contains(string(resp), tc.errorMsg) | ||
} else { | ||
var g authz.QueryGrantsResponse | ||
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &g) | ||
require.NoError(err) | ||
require.Len(g.Grants, 1) | ||
g.Grants[0].UnpackInterfaces(val.ClientCtx.InterfaceRegistry) | ||
auth := g.Grants[0].GetAuthorization() | ||
require.Equal(auth.MsgTypeURL(), banktypes.SendAuthorization{}.MsgTypeURL()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestQueryGrantsGRPC() { | ||
val := s.network.Validators[0] | ||
grantee := s.grantee[1] | ||
grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s" | ||
testCases := []struct { | ||
name string | ||
url string | ||
expectErr bool | ||
errMsg string | ||
preRun func() | ||
postRun func(*authz.QueryGrantsResponse) | ||
}{ | ||
{ | ||
"valid query: expect single grant", | ||
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String()), | ||
false, | ||
"", | ||
func() {}, | ||
func(g *authz.QueryGrantsResponse) { | ||
s.Require().Len(g.Grants, 1) | ||
}, | ||
}, | ||
{ | ||
"valid query: expect two grants", | ||
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String()), | ||
false, | ||
"", | ||
func() { | ||
_, err := ExecGrant(val, []string{ | ||
grantee.String(), | ||
"generic", | ||
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), | ||
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote), | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()), | ||
fmt.Sprintf("--%s=%d", cli.FlagExpiration, time.Now().Add(time.Minute*time.Duration(120)).Unix()), | ||
}) | ||
s.Require().NoError(err) | ||
}, | ||
func(g *authz.QueryGrantsResponse) { | ||
s.Require().Len(g.Grants, 2) | ||
}, | ||
}, | ||
{ | ||
"valid query: expect single grant with pagination", | ||
fmt.Sprintf(grantsURL+"&pagination.limit=1", val.Address.String(), grantee.String()), | ||
false, | ||
"", | ||
func() {}, | ||
func(g *authz.QueryGrantsResponse) { | ||
s.Require().Len(g.Grants, 1) | ||
}, | ||
}, | ||
{ | ||
"valid query: expect two grants with pagination", | ||
fmt.Sprintf(grantsURL+"&pagination.limit=2", val.Address.String(), grantee.String()), | ||
false, | ||
"", | ||
func() {}, | ||
func(g *authz.QueryGrantsResponse) { | ||
s.Require().Len(g.Grants, 2) | ||
}, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
tc := tc | ||
s.Run(tc.name, func() { | ||
tc.preRun() | ||
resp, _ := rest.GetRequest(tc.url) | ||
if tc.expectErr { | ||
s.Require().Contains(string(resp), tc.errMsg) | ||
} else { | ||
var authorizations authz.QueryGrantsResponse | ||
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations) | ||
s.Require().NoError(err) | ||
tc.postRun(&authorizations) | ||
} | ||
|
||
}) | ||
} | ||
} |
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,84 @@ | ||
go 1.17 | ||
|
||
module github.com/cosmos/cosmos-sdk/x/group | ||
|
||
require ( | ||
github.com/cockroachdb/apd/v2 v2.0.2 | ||
github.com/cosmos/cosmos-sdk v0.44.0 | ||
github.com/gogo/protobuf v1.3.3 | ||
github.com/regen-network/cosmos-proto v0.3.1 | ||
github.com/stretchr/testify v1.7.0 | ||
google.golang.org/grpc v1.40.0 | ||
google.golang.org/protobuf v1.27.1 | ||
pgregory.net/rapid v0.4.7 | ||
) | ||
|
||
require ( | ||
github.com/DataDog/zstd v1.4.5 // indirect | ||
github.com/armon/go-metrics v0.3.9 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/btcsuite/btcd v0.22.0-beta // indirect | ||
github.com/cespare/xxhash v1.1.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.1 // indirect | ||
github.com/confio/ics23/go v0.6.6 // indirect | ||
github.com/cosmos/btcutil v1.0.4 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect | ||
github.com/dgraph-io/ristretto v0.0.3 // indirect | ||
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect | ||
github.com/dustin/go-humanize v1.0.0 // indirect | ||
github.com/fsnotify/fsnotify v1.4.9 // indirect | ||
github.com/go-kit/kit v0.10.0 // indirect | ||
github.com/go-logfmt/logfmt v0.5.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect | ||
github.com/google/btree v1.0.0 // indirect | ||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect | ||
github.com/gtank/merlin v0.1.1 // indirect | ||
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect | ||
github.com/hashicorp/golang-lru v0.5.4 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/jmhodges/levigo v1.0.0 // indirect | ||
github.com/libp2p/go-buffer-pool v0.0.2 // indirect | ||
github.com/magiconair/properties v1.8.5 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect | ||
github.com/mitchellh/mapstructure v1.4.1 // indirect | ||
github.com/pelletier/go-toml v1.9.3 // indirect | ||
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/prometheus/client_golang v1.11.0 // indirect | ||
github.com/prometheus/client_model v0.2.0 // indirect | ||
github.com/prometheus/common v0.30.0 // indirect | ||
github.com/prometheus/procfs v0.6.0 // indirect | ||
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect | ||
github.com/spf13/afero v1.6.0 // indirect | ||
github.com/spf13/cast v1.4.1 // indirect | ||
github.com/spf13/cobra v1.2.1 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.8.1 // indirect | ||
github.com/subosito/gotenv v1.2.0 // indirect | ||
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect | ||
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect | ||
github.com/tendermint/go-amino v0.16.0 // indirect | ||
github.com/tendermint/tendermint v0.34.13 // indirect | ||
github.com/tendermint/tm-db v0.6.4 // indirect | ||
go.etcd.io/bbolt v1.3.5 // indirect | ||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect | ||
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect | ||
golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect | ||
golang.org/x/text v0.3.6 // indirect | ||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect | ||
gopkg.in/ini.v1 v1.62.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) | ||
|
||
replace google.golang.org/grpc => google.golang.org/grpc v1.33.2 | ||
|
||
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 | ||
|
||
replace github.com/cosmos/cosmos-sdk => ../../ |
Oops, something went wrong.