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 16 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
218 changes: 6 additions & 212 deletions tests/e2e/feegrant/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/suite"

// without this import amino json encoding will fail when resolving any types
_ "cosmossdk.io/api/cosmos/feegrant/v1beta1"
"cosmossdk.io/x/feegrant"
"cosmossdk.io/x/feegrant/client/cli"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -112,205 +110,6 @@ func (s *E2ETestSuite) TearDownSuite() {
s.network.Cleanup()
}

func (s *E2ETestSuite) TestCmdGetFeeGrant() {
val := s.network.Validators[0]
granter := val.Address
grantee := s.addedGrantee
clientCtx := val.ClientCtx

testCases := []struct {
name string
args []string
expectErrMsg string
expectErr bool
respType *feegrant.Grant
resp *feegrant.Grant
}{
{
"wrong granter",
[]string{
"wrong_granter",
grantee.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
"decoding bech32 failed",
true, nil, nil,
},
{
"wrong grantee",
[]string{
granter.String(),
"wrong_grantee",
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
"decoding bech32 failed",
true, nil, nil,
},
{
"non existed grant",
[]string{
"cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl",
grantee.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
"fee-grant not found",
true, nil, nil,
},
{
"valid req",
[]string{
granter.String(),
grantee.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
"",
false,
&feegrant.Grant{},
&s.addedGrant,
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryFeeGrant(codecaddress.NewBech32Codec("cosmos"))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

if tc.expectErr {
s.Require().Error(err)
s.Require().Contains(err.Error(), tc.expectErrMsg)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
s.Require().Equal(tc.respType.Grantee, tc.respType.Grantee)
s.Require().Equal(tc.respType.Granter, tc.respType.Granter)
grant, err := tc.respType.GetGrant()
s.Require().NoError(err)
grant1, err1 := tc.resp.GetGrant()
s.Require().NoError(err1)
s.Require().Equal(
grant.(*feegrant.BasicAllowance).SpendLimit,
grant1.(*feegrant.BasicAllowance).SpendLimit,
)
}
})
}
}

func (s *E2ETestSuite) TestCmdGetFeeGrantsByGrantee() {
val := s.network.Validators[0]
grantee := s.addedGrantee
clientCtx := val.ClientCtx

testCases := []struct {
name string
args []string
expectErr bool
resp *feegrant.QueryAllowancesResponse
expectLength int
}{
{
"wrong grantee",
[]string{
"wrong_grantee",
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
true, nil, 0,
},
{
"non existent grantee",
[]string{
"cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl",
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
false, &feegrant.QueryAllowancesResponse{}, 0,
},
{
"valid req",
[]string{
grantee.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
false, &feegrant.QueryAllowancesResponse{}, 1,
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryFeeGrantsByGrantee(codecaddress.NewBech32Codec("cosmos"))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.resp), out.String())

s.Require().Len(tc.resp.Allowances, tc.expectLength)
}
})
}
}

func (s *E2ETestSuite) TestCmdGetFeeGrantsByGranter() {
val := s.network.Validators[0]
granter := s.addedGranter
clientCtx := val.ClientCtx

testCases := []struct {
name string
args []string
expectErr bool
resp *feegrant.QueryAllowancesByGranterResponse
expectLength int
}{
{
"wrong grantee",
[]string{
"wrong_grantee",
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
true, nil, 0,
},
{
"non existent grantee",
[]string{
"cosmos1nph3cfzk6trsmfxkeu943nvach5qw4vwstnvkl",
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
false, &feegrant.QueryAllowancesByGranterResponse{}, 0,
},
{
"valid req",
[]string{
granter.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
},
false, &feegrant.QueryAllowancesByGranterResponse{}, 1,
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryFeeGrantsByGranter(codecaddress.NewBech32Codec("cosmos"))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.resp), out.String())
s.Require().Len(tc.resp.Allowances, tc.expectLength)
}
})
}
}

func (s *E2ETestSuite) TestNewCmdFeeGrant() {
val := s.network.Validators[0]
granter := val.Address
Expand Down Expand Up @@ -897,20 +696,15 @@ func (s *E2ETestSuite) TestFilteredFeeAllowance() {
})
}

args := []string{
granter.String(),
grantee.String(),
fmt.Sprintf("--%s=json", flags.FlagOutput),
}

// get filtered fee allowance and check info
cmd := cli.GetCmdQueryFeeGrant(codecaddress.NewBech32Codec("cosmos"))
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
grantAllowneceURL := val.APIAddress + "/cosmos/feegrant/v1beta1/allowance/%s/%s"
uri := fmt.Sprintf(grantAllowneceURL, granter.String(), grantee.String())
respBytes, err := testutil.GetRequest(uri)
s.Require().NoError(err)

resp := &feegrant.Grant{}

s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), resp), out.String())
respAllow := &feegrant.QueryAllowanceResponse{}
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(respBytes, respAllow), string(respBytes))
resp := respAllow.GetAllowance()
s.Require().Equal(resp.Grantee, resp.Grantee)
s.Require().Equal(resp.Granter, resp.Granter)

Expand Down
Loading