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

feat(x/feegrant): feegrant autcli module query #16213

Merged
merged 18 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 2 additions & 2 deletions tests/e2e/feegrant/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ package feegrant
import (
"testing"

"github.com/stretchr/testify/suite"

"cosmossdk.io/simapp"
"github.com/cosmos/cosmos-sdk/testutil/network"

"github.com/stretchr/testify/suite"
)

func TestE2ETestSuite(t *testing.T) {
Expand Down
203 changes: 203 additions & 0 deletions tests/e2e/feegrant/grpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package feegrant

import (
"fmt"

"github.com/cosmos/cosmos-sdk/testutil"
)

func (s *E2ETestSuite) TestGrantGRPCAllowance() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we make them non E2E? and put them here if they do not exist: https://github.com/cosmos/cosmos-sdk/blob/c8ab555174ef5b1f8557b80361d8b83754f62f6a/x/feegrant/keeper/grpc_query_test.go
It would be great to delete the E2E and improve existing grpc tests instead of adding new ones at a different place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that those ones are mocked, but If we don't think is necessary for them to be in e2e I will delete them.

Copy link
Contributor

@likhita-809 likhita-809 Jun 6, 2023

Choose a reason for hiding this comment

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

I think we are already testing them in feegrant's grpc_query_test.go, but the only difference is we are using QueryRequests there and RPC URLs here, maybe we could improve the tests there instead of adding them in E2E tests

val := s.network.Validators[0]
s.createGrant(s.addedGranter, s.addedGrantee)
testCases := []struct {
name string
args struct {
Granter string
Grantee string
}
expectErr bool
errorMsg string
msg string
}{
{
name: "correct grant",
args: struct {
Granter string
Grantee string
}{
Granter: s.addedGranter.String(),
Grantee: s.addedGrantee.String(),
},
expectErr: false,
errorMsg: "",
msg: "\"allowance\":{\"@type\":\"/cosmos.feegrant.v1beta1.BasicAllowance\",\"spend_limit\":[{\"denom\":\"stake\",\"amount\":\"100\"}]",
},
{
name: "invalid grantee",
args: struct {
Granter string
Grantee string
}{
Granter: s.addedGranter.String(),
Grantee: "incorrect_grantee",
},
expectErr: true,
errorMsg: "decoding bech32 failed",
msg: "",
},
{
name: "non existent grant",
args: struct {
Granter string
Grantee string
}{
Granter: "cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl",
Grantee: s.addedGrantee.String(),
},
expectErr: true,
errorMsg: "fee-grant not found",
msg: "",
},
}

grantAllowneceURL := val.APIAddress + "/cosmos/feegrant/v1beta1/allowance/%s/%s"
for _, tc := range testCases {
uri := fmt.Sprintf(grantAllowneceURL, tc.args.Granter, tc.args.Grantee)
s.Run(tc.name, func() {
resp, err := testutil.GetRequest(uri)
if tc.expectErr {
s.Require().Contains(string(resp), tc.errorMsg)
} else {
s.Require().NoError(err)
s.Require().Contains(string(resp), tc.msg)
}
})
}

}

func (s *E2ETestSuite) TestGrantGRPCAllowanceByGrantee() {
val := s.network.Validators[0]
s.createGrant(s.addedGranter, s.addedGrantee)
testCases := []struct {
name string
args struct {
Grantee string
}
expectErr bool
errorMsg string
msg string
}{
{
name: "correct grpc request",
args: struct {
Grantee string
}{
Grantee: s.addedGrantee.String(),
},
expectErr: false,
errorMsg: "",
msg: "\"allowance\":{\"@type\":\"/cosmos.feegrant.v1beta1.BasicAllowance\",\"spend_limit\":[{\"denom\":\"stake\",\"amount\":\"100\"}]",
},
{
name: "invalid grantee",
args: struct {
Grantee string
}{
Grantee: "incorrect_grantee",
},
expectErr: true,
errorMsg: "decoding bech32 failed",
msg: "",
},
{
name: "non existent grant",
args: struct {
Grantee string
}{
Grantee: "cosmos1h6wddg9x0zsusswhchkfhwwtkdg62fehs5ees4",
},
expectErr: false,
errorMsg: "",
msg: "{\"allowances\":[],\"pagination\":{\"next_key\":null,\"total\":\"0\"}}",
},
}

grantAllowneceURL := val.APIAddress + "/cosmos/feegrant/v1beta1/allowances/%s"
for _, tc := range testCases {
uri := fmt.Sprintf(grantAllowneceURL, tc.args.Grantee)
s.Run(tc.name, func() {
resp, err := testutil.GetRequest(uri)
if tc.expectErr {
s.Require().Contains(string(resp), tc.errorMsg)
} else {
s.Require().NoError(err)
s.Require().Contains(string(resp), tc.msg)
}
})
}

}

func (s *E2ETestSuite) TestGrantGRPCAllowanceByGranter() {
val := s.network.Validators[0]
s.createGrant(s.addedGranter, s.addedGrantee)
testCases := []struct {
name string
args struct {
Granter string
}
expectErr bool
errorMsg string
msg string
}{
{
name: "correct grpc request",
args: struct {
Granter string
}{
Granter: s.addedGranter.String(),
},
expectErr: false,
errorMsg: "",
msg: "\"allowance\":{\"@type\":\"/cosmos.feegrant.v1beta1.BasicAllowance\",\"spend_limit\":[{\"denom\":\"stake\",\"amount\":\"100\"}]",
},
{
name: "invalid grantee",
args: struct {
Granter string
}{
Granter: "incorrect_grantee",
},
expectErr: true,
errorMsg: "decoding bech32 failed",
msg: "",
},
{
name: "non existent grant",
args: struct {
Granter string
}{
Granter: "cosmos1h6wddg9x0zsusswhchkfhwwtkdg62fehs5ees4",
},
expectErr: false,
errorMsg: "{\"allowances\":[],\"pagination\":{\"next_key\":null,\"total\":\"0\"}}",
msg: "",
},
}

grantAllowneceURL := val.APIAddress + "/cosmos/feegrant/v1beta1/issued/%s"
for _, tc := range testCases {
uri := fmt.Sprintf(grantAllowneceURL, tc.args.Granter)
s.Run(tc.name, func() {
resp, err := testutil.GetRequest(uri)
if tc.expectErr {
s.Require().Contains(string(resp), tc.errorMsg)
} else {
s.Require().NoError(err)
s.Require().Contains(string(resp), tc.msg)
}
})
}

}
Loading