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

refactor: Replace testify with gotest.tools in e2e/authz #14502

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
20 changes: 0 additions & 20 deletions tests/e2e/authz/cli_test.go

This file was deleted.

102 changes: 60 additions & 42 deletions tests/e2e/authz/grpc.go → tests/e2e/authz/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package authz

Copy link
Member

@julienrbrt julienrbrt Jan 9, 2023

Choose a reason for hiding this comment

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

We should add the e2e build tag, in each file, now that cli_test.go is deleted.

import (
"fmt"
"strings"
"testing"
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -11,11 +13,16 @@ import (
"github.com/cosmos/cosmos-sdk/x/authz/client/cli"
authzclitestutil "github.com/cosmos/cosmos-sdk/x/authz/client/testutil"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"gotest.tools/v3/assert"
)

func (s *E2ETestSuite) TestQueryGrantGRPC() {
val := s.network.Validators[0]
grantee := s.grantee[1]
func TestQueryGrantGRPC(t *testing.T) {
t.Parallel()
f := initFixture(t)
defer f.TearDownSuite(t)

val := f.network.Validators[0]
grantee := f.grantee[1]
grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s&msg_type_url=%s"
testCases := []struct {
name string
Expand Down Expand Up @@ -62,28 +69,31 @@ func (s *E2ETestSuite) TestQueryGrantGRPC() {
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
t.Run(tc.name, func(t *testing.T) {
resp, _ := testutil.GetRequest(tc.url)
require := s.Require()
if tc.expectErr {
require.Contains(string(resp), tc.errorMsg)
assert.Equal(t, strings.Contains(string(resp), tc.errorMsg), true)
} else {
var g authz.QueryGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &g)
require.NoError(err)
require.Len(g.Grants, 1)
assert.NilError(t, err, "")
assert.Equal(t, len(g.Grants), 1)
g.Grants[0].UnpackInterfaces(val.ClientCtx.InterfaceRegistry)
auth, err := g.Grants[0].GetAuthorization()
require.NoError(err)
require.Equal(auth.MsgTypeURL(), banktypes.SendAuthorization{}.MsgTypeURL())
assert.NilError(t, err, "")
assert.Equal(t, auth.MsgTypeURL(), banktypes.SendAuthorization{}.MsgTypeURL())
}
})
}
}

func (s *E2ETestSuite) TestQueryGrantsGRPC() {
val := s.network.Validators[0]
grantee := s.grantee[1]
func TestQueryGrantsGRPC(t *testing.T) {
t.Parallel()
f := initFixture(t)
defer f.TearDownSuite(t)

val := f.network.Validators[0]
grantee := f.grantee[1]
grantsURL := val.APIAddress + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s"
testCases := []struct {
name string
Expand All @@ -100,7 +110,7 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
"",
func() {},
func(g *authz.QueryGrantsResponse) {
s.Require().Len(g.Grants, 1)
assert.Equal(t, len(g.Grants), 1)
},
},
{
Expand All @@ -119,11 +129,12 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
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)
s.Require().NoError(s.network.WaitForNextBlock())
assert.NilError(t, err)
assert.NilError(t, f.network.WaitForNextBlock())
},

func(g *authz.QueryGrantsResponse) {
s.Require().Len(g.Grants, 2)
assert.Equal(t, len(g.Grants), 2)
},
},
{
Expand All @@ -133,7 +144,8 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
"",
func() {},
func(g *authz.QueryGrantsResponse) {
s.Require().Len(g.Grants, 1)
assert.Equal(t, len(g.Grants), 1)

},
},
{
Expand All @@ -143,33 +155,37 @@ func (s *E2ETestSuite) TestQueryGrantsGRPC() {
"",
func() {},
func(g *authz.QueryGrantsResponse) {
s.Require().Len(g.Grants, 2)
assert.Equal(t, len(g.Grants), 2)

},
},
}
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
t.Run(tc.name, func(t *testing.T) {
tc.preRun()
resp, err := testutil.GetRequest(tc.url)
s.Require().NoError(err)
assert.NilError(t, err)

if tc.expectErr {
s.Require().Contains(string(resp), tc.errMsg)
assert.Equal(t, strings.Contains(string(resp), tc.errMsg), true)
} else {
var authorizations authz.QueryGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations)
s.Require().NoError(err)
assert.NilError(t, err)
tc.postRun(&authorizations)
}
})
}
}

func (s *E2ETestSuite) TestQueryGranterGrantsGRPC() {
val := s.network.Validators[0]
grantee := s.grantee[1]
require := s.Require()
func TestQueryGranterGrantsGRPC(t *testing.T) {
t.Parallel()
f := initFixture(t)
defer f.TearDownSuite(t)

val := f.network.Validators[0]
grantee := f.grantee[1]

testCases := []struct {
name string
Expand Down Expand Up @@ -197,30 +213,32 @@ func (s *E2ETestSuite) TestQueryGranterGrantsGRPC() {
fmt.Sprintf("%s/cosmos/authz/v1beta1/grants/granter/%s", val.APIAddress, val.Address.String()),
false,
"",
8,
3,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
t.Run(tc.name, func(t *testing.T) {
resp, err := testutil.GetRequest(tc.url)
require.NoError(err)
assert.NilError(t, err)

if tc.expectErr {
require.Contains(string(resp), tc.errMsg)
assert.Equal(t, strings.Contains(string(resp), tc.errMsg), true)
} else {
var authorizations authz.QueryGranterGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations)
require.NoError(err)
require.Len(authorizations.Grants, tc.numItems)
assert.NilError(t, err)
assert.Equal(t, len(authorizations.Grants), tc.numItems)
}
})
}
}

func (s *E2ETestSuite) TestQueryGranteeGrantsGRPC() {
val := s.network.Validators[0]
grantee := s.grantee[1]
require := s.Require()
func TestQueryGranteeGrantsGRPC(t *testing.T) {
t.Parallel()
f := initFixture(t)
defer f.TearDownSuite(t)
val := f.network.Validators[0]
grantee := f.grantee[1]

testCases := []struct {
name string
Expand Down Expand Up @@ -252,17 +270,17 @@ func (s *E2ETestSuite) TestQueryGranteeGrantsGRPC() {
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
t.Run(tc.name, func(t *testing.T) {
resp, err := testutil.GetRequest(tc.url)
require.NoError(err)
assert.NilError(t, err)

if tc.expectErr {
require.Contains(string(resp), tc.errMsg)
assert.Equal(t, strings.Contains(string(resp), tc.errMsg), true)
} else {
var authorizations authz.QueryGranteeGrantsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &authorizations)
require.NoError(err)
require.Len(authorizations.Grants, tc.numItems)
assert.NilError(t, err)
assert.Equal(t, len(authorizations.Grants), tc.numItems)
}
})
}
Expand Down
Loading