Skip to content

Commit

Permalink
test(systemtests): fix gRPC tests for v1 & v2 (backport #22774) (#22788)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
mergify[bot] and julienrbrt authored Dec 6, 2024
1 parent b37887e commit 7f5ff06
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 179 deletions.
142 changes: 71 additions & 71 deletions tests/systemtests/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,78 +682,78 @@ func TestAuthzGRPCQueries(t *testing.T) {

grantTestCases := []systest.RestTestCase{
{
"invalid granter address",
fmt.Sprintf(grantURL, "invalid_granter", grantee1Addr, msgSendTypeURL),
http.StatusInternalServerError,
bech32FailOutput,
Name: "invalid granter address",
Url: fmt.Sprintf(grantURL, "invalid_granter", grantee1Addr, msgSendTypeURL),
ExpCodeGTE: http.StatusBadRequest,
ExpOut: bech32FailOutput,
},
{
"invalid grantee address",
fmt.Sprintf(grantURL, granterAddr, "invalid_grantee", msgSendTypeURL),
http.StatusInternalServerError,
bech32FailOutput,
Name: "invalid grantee address",
Url: fmt.Sprintf(grantURL, granterAddr, "invalid_grantee", msgSendTypeURL),
ExpCodeGTE: http.StatusBadRequest,
ExpOut: bech32FailOutput,
},
{
"with empty granter",
fmt.Sprintf(grantURL, "", grantee1Addr, msgSendTypeURL),
http.StatusInternalServerError,
emptyStrOutput,
Name: "with empty granter",
Url: fmt.Sprintf(grantURL, "", grantee1Addr, msgSendTypeURL),
ExpCodeGTE: http.StatusBadRequest,
ExpOut: emptyStrOutput,
},
{
"with empty grantee",
fmt.Sprintf(grantURL, granterAddr, "", msgSendTypeURL),
http.StatusInternalServerError,
emptyStrOutput,
Name: "with empty grantee",
Url: fmt.Sprintf(grantURL, granterAddr, "", msgSendTypeURL),
ExpCodeGTE: http.StatusBadRequest,
ExpOut: emptyStrOutput,
},
{
"invalid msg-type",
fmt.Sprintf(grantURL, granterAddr, grantee1Addr, "invalidMsg"),
http.StatusInternalServerError,
invalidMsgTypeOutput,
Name: "invalid msg-type",
Url: fmt.Sprintf(grantURL, granterAddr, grantee1Addr, "invalidMsg"),
ExpCode: http.StatusInternalServerError,
ExpOut: invalidMsgTypeOutput,
},
{
"valid grant query",
fmt.Sprintf(grantURL, granterAddr, grantee1Addr, msgSendTypeURL),
http.StatusOK,
expGrantOutput,
Name: "valid grant query",
Url: fmt.Sprintf(grantURL, granterAddr, grantee1Addr, msgSendTypeURL),
ExpCode: http.StatusOK,
ExpOut: expGrantOutput,
},
}

systest.RunRestQueries(t, grantTestCases...)
systest.RunRestQueriesIgnoreNumbers(t, grantTestCases...)

// test query grants grpc endpoint
grantsURL := baseurl + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s"

grantsTestCases := []systest.RestTestCase{
{
"expect single grant",
fmt.Sprintf(grantsURL, granterAddr, grantee1Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"1"}}`, grant1),
Name: "expect single grant",
Url: fmt.Sprintf(grantsURL, granterAddr, grantee1Addr),
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"1"}}`, grant1),
},
{
"expect two grants",
fmt.Sprintf(grantsURL, granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"2"}}`, grant2, grant3),
Name: "expect two grants",
Url: fmt.Sprintf(grantsURL, granterAddr, grantee2Addr),
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"2"}}`, grant2, grant3),
},
{
"expect single grant with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=1", granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":"L2Nvc21vcy5nb3YudjEuTXNnVm90ZQ==","total":"0"}}`, grant2),
Name: "expect single grant with pagination",
Url: fmt.Sprintf(grantsURL+"&pagination.limit=1", granterAddr, grantee2Addr),
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":"L2Nvc21vcy5nb3YudjEuTXNnVm90ZQ==","total":"0"}}`, grant2),
},
{
"expect single grant with pagination limit and offset",
fmt.Sprintf(grantsURL+"&pagination.limit=1&pagination.offset=1", granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant3),
Name: "expect single grant with pagination limit and offset",
Url: fmt.Sprintf(grantsURL+"&pagination.limit=1&pagination.offset=1", granterAddr, grantee2Addr),
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant3),
},
{
"expect two grants with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=2", granterAddr, grantee2Addr),
http.StatusOK,
fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant2, grant3),
Name: "expect two grants with pagination",
Url: fmt.Sprintf(grantsURL+"&pagination.limit=2", granterAddr, grantee2Addr),
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant2, grant3),
},
}

Expand All @@ -768,53 +768,53 @@ func TestAuthzGRPCQueries(t *testing.T) {

granterTestCases := []systest.RestTestCase{
{
"invalid granter account address",
fmt.Sprintf(grantsByGranterURL, "invalid address"),
http.StatusInternalServerError,
decodingFailedOutput,
Name: "invalid granter account address",
Url: fmt.Sprintf(grantsByGranterURL, "invalid address"),
ExpCodeGTE: http.StatusBadRequest,
ExpOut: decodingFailedOutput,
},
{
"no authorizations found from granter",
fmt.Sprintf(grantsByGranterURL, grantee2Addr),
http.StatusOK,
noAuthorizationsOutput,
Name: "no authorizations found from granter",
Url: fmt.Sprintf(grantsByGranterURL, grantee2Addr),
ExpCode: http.StatusOK,
ExpOut: noAuthorizationsOutput,
},
{
"valid granter query",
fmt.Sprintf(grantsByGranterURL, grantee1Addr),
http.StatusOK,
granterQueryOutput,
Name: "valid granter query",
Url: fmt.Sprintf(grantsByGranterURL, grantee1Addr),
ExpCode: http.StatusOK,
ExpOut: granterQueryOutput,
},
}

systest.RunRestQueries(t, granterTestCases...)
systest.RunRestQueriesIgnoreNumbers(t, granterTestCases...)

// test query grants by grantee grpc endpoint
grantsByGranteeURL := baseurl + "/cosmos/authz/v1beta1/grants/grantee/%s"
grantee1GrantsOutput := fmt.Sprintf(`{"grants":[{"granter":"%s","grantee":"%s",%s}],"pagination":{"next_key":null,"total":"1"}}`, granterAddr, grantee1Addr, grant1)

granteeTestCases := []systest.RestTestCase{
{
"invalid grantee account address",
fmt.Sprintf(grantsByGranteeURL, "invalid address"),
http.StatusInternalServerError,
decodingFailedOutput,
Name: "invalid grantee account address",
Url: fmt.Sprintf(grantsByGranteeURL, "invalid address"),
ExpCodeGTE: http.StatusBadRequest,
ExpOut: decodingFailedOutput,
},
{
"no authorizations found from grantee",
fmt.Sprintf(grantsByGranteeURL, granterAddr),
http.StatusOK,
noAuthorizationsOutput,
Name: "no authorizations found from grantee",
Url: fmt.Sprintf(grantsByGranteeURL, granterAddr),
ExpCode: http.StatusOK,
ExpOut: noAuthorizationsOutput,
},
{
"valid grantee query",
fmt.Sprintf(grantsByGranteeURL, grantee1Addr),
http.StatusOK,
grantee1GrantsOutput,
Name: "valid grantee query",
Url: fmt.Sprintf(grantsByGranteeURL, grantee1Addr),
ExpCode: http.StatusOK,
ExpOut: grantee1GrantsOutput,
},
}

systest.RunRestQueries(t, granteeTestCases...)
systest.RunRestQueriesIgnoreNumbers(t, granteeTestCases...)
}

func setupChain(t *testing.T) (*systest.CLIWrapper, string, string) {
Expand Down
52 changes: 26 additions & 26 deletions tests/systemtests/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestBankGRPCQueries(t *testing.T) {
map[string]string{
blockHeightHeader: fmt.Sprintf("%d", blockHeight+5),
},
http.StatusInternalServerError,
http.StatusBadRequest,
"invalid height",
},
{
Expand All @@ -280,7 +280,7 @@ func TestBankGRPCQueries(t *testing.T) {

for _, tc := range supplyTestCases {
t.Run(tc.name, func(t *testing.T) {
resp := systest.GetRequestWithHeaders(t, tc.url, tc.headers, tc.expHttpCode)
resp := systest.GetRequestWithHeadersGreaterThanOrEqual(t, tc.url, tc.headers, tc.expHttpCode)
require.Contains(t, string(resp), tc.expOut)
})
}
Expand All @@ -289,22 +289,22 @@ func TestBankGRPCQueries(t *testing.T) {
denomMetadataUrl := baseurl + "/cosmos/bank/v1beta1/denoms_metadata"
dmTestCases := []systest.RestTestCase{
{
"test GRPC client metadata",
denomMetadataUrl,
http.StatusOK,
fmt.Sprintf(`{"metadatas":%s,"pagination":{"next_key":null,"total":"2"}}`, bankDenomMetadata),
Name: "test GRPC client metadata",
Url: denomMetadataUrl,
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"metadatas":%s,"pagination":{"next_key":null,"total":"2"}}`, bankDenomMetadata),
},
{
"test GRPC client metadata of a specific denom",
denomMetadataUrl + "/uatom",
http.StatusOK,
fmt.Sprintf(`{"metadata":%s}`, atomDenomMetadata),
Name: "test GRPC client metadata of a specific denom",
Url: denomMetadataUrl + "/uatom",
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"metadata":%s}`, atomDenomMetadata),
},
{
"test GRPC client metadata of a bogus denom",
denomMetadataUrl + "/foobar",
http.StatusNotFound,
`{"code":5, "message":"client metadata for denom foobar", "details":[]}`,
Name: "test GRPC client metadata of a bogus denom",
Url: denomMetadataUrl + "/foobar",
ExpCode: http.StatusNotFound,
ExpOut: `{"code":5, "message":"client metadata for denom foobar", "details":[]}`,
},
}

Expand All @@ -316,22 +316,22 @@ func TestBankGRPCQueries(t *testing.T) {

balanceTestCases := []systest.RestTestCase{
{
"test GRPC total account balance",
balanceUrl + account1Addr,
http.StatusOK,
allBalancesOutput,
Name: "test GRPC total account balance",
Url: balanceUrl + account1Addr,
ExpCode: http.StatusOK,
ExpOut: allBalancesOutput,
},
{
"test GRPC account balance of a specific denom",
fmt.Sprintf("%s%s/by_denom?denom=%s", balanceUrl, account1Addr, newDenom),
http.StatusOK,
fmt.Sprintf(`{"balance":%s}`, specificDenomOutput),
Name: "test GRPC account balance of a specific denom",
Url: fmt.Sprintf("%s%s/by_denom?denom=%s", balanceUrl, account1Addr, newDenom),
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"balance":%s}`, specificDenomOutput),
},
{
"test GRPC account balance of a bogus denom",
fmt.Sprintf("%s%s/by_denom?denom=foobar", balanceUrl, account1Addr),
http.StatusOK,
fmt.Sprintf(`{"balance":%s}`, bogusDenomOutput),
Name: "test GRPC account balance of a bogus denom",
Url: fmt.Sprintf("%s%s/by_denom?denom=foobar", balanceUrl, account1Addr),
ExpCode: http.StatusOK,
ExpOut: fmt.Sprintf(`{"balance":%s}`, bogusDenomOutput),
},
}

Expand Down
Loading

0 comments on commit 7f5ff06

Please sign in to comment.