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!: remove legacy REST #9594

Merged
merged 36 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
57d94c6
remove rest client from x/*
aleem1314 Jun 28, 2021
a285c72
removed RegisterRESTRoutes from x/*
aleem1314 Jun 29, 2021
59ca884
remove legacy rest wiring
aleem1314 Jun 29, 2021
81a9bbe
make mocks
aleem1314 Jun 29, 2021
307c503
refactor grpc tests
aleem1314 Jun 30, 2021
1997439
remove client/rpc REST
aleem1314 Jun 30, 2021
4fa7c43
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jun 30, 2021
3eb5be7
move types/rest to testutil/rest
aleem1314 Jun 30, 2021
400b188
fix lint errors
aleem1314 Jun 30, 2021
405671c
fix lint errors
aleem1314 Jun 30, 2021
b778852
review changes
aleem1314 Jul 1, 2021
d28daf8
Add DefaultPage doc
aleem1314 Jul 1, 2021
4e5d4be
remove legacy swagger
aleem1314 Jul 1, 2021
2b40c22
WIP review changes
aleem1314 Jul 1, 2021
d2f1a13
fix lint errors
aleem1314 Jul 1, 2021
5e98b22
WIP integration tests refactor
aleem1314 Jul 2, 2021
4b605a2
WIP staking tests refactor
aleem1314 Jul 2, 2021
1318e84
fix tests
aleem1314 Jul 2, 2021
e366149
refactor gov module integration tests
aleem1314 Jul 2, 2021
51c595d
refactor x/bank integration tests
aleem1314 Jul 2, 2021
23e83c4
refactor staking integration tests
aleem1314 Jul 2, 2021
c075bc9
Update CHANGELOG.md
aleem1314 Jul 2, 2021
4292e7a
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 2, 2021
e3c3dc3
update staking integration tests
aleem1314 Jul 3, 2021
d68dd92
fix tests
aleem1314 Jul 3, 2021
a0fd07a
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 3, 2021
2431964
fix tests
aleem1314 Jul 3, 2021
c4a7a30
Update CHANGELOG.md
aleem1314 Jul 5, 2021
d2f2c03
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 5, 2021
665fde3
make update-swagger-docs
aleem1314 Jul 5, 2021
fa2165f
fix imports
aleem1314 Jul 5, 2021
c3fd850
add Deprecated message
aleem1314 Jul 6, 2021
061a8c8
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 6, 2021
215bf26
Add build norace flag
aleem1314 Jul 6, 2021
03e2f3d
Merge branch 'master' into aleem/7517-remove-legacy-rest
aleem1314 Jul 6, 2021
60950ca
Merge branch 'aleem/7517-remove-legacy-rest' of https://github.com/co…
aleem1314 Jul 6, 2021
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
Prev Previous commit
Next Next commit
WIP integration tests refactor
  • Loading branch information
aleem1314 committed Jul 2, 2021
commit 5e98b223624c7730bfe4ec0cfd1afcae8f4975bc
4 changes: 0 additions & 4 deletions x/authz/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}

func TestGRPCQueryTestSuite(t *testing.T) {
suite.Run(t, new(GRPCQueryTestSuite))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,17 @@ import (
"fmt"
"time"

"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/testutil/network"
"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"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

type GRPCQueryTestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
grantee sdk.AccAddress
}

func (s *GRPCQueryTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

cfg := network.DefaultConfig()
cfg.NumValidators = 1
s.cfg = cfg

var err error
s.network, err = network.New(s.T(), s.T().TempDir(), cfg)
s.Require().NoError(err)

val := s.network.Validators[0]
// Create new account in the keyring.
info, _, err := val.ClientCtx.Keyring.NewMnemonic("grantee", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
s.Require().NoError(err)
newAddr := sdk.AccAddress(info.GetPubKey().Address())

// Send some funds to the new account.
out, err := banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
newAddr,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
)
s.Require().NoError(err)
s.Require().Contains(out.String(), `"code":0`)

// grant authorization
out, err = ExecGrant(val, []string{
newAddr.String(),
"send",
fmt.Sprintf("--%s=100steak", cli.FlagSpendLimit),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
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)
s.Require().Contains(out.String(), `"code":0`)

s.grantee = newAddr
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
}

func (s *GRPCQueryTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
s.network.Cleanup()
}

func (s *GRPCQueryTestSuite) TestQueryGrantGRPC() {
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
Expand All @@ -89,7 +24,7 @@ func (s *GRPCQueryTestSuite) TestQueryGrantGRPC() {
}{
{
"fail invalid granter address",
fmt.Sprintf(grantsURL, "invalid_granter", s.grantee.String(), typeMsgSend),
fmt.Sprintf(grantsURL, "invalid_granter", grantee.String(), typeMsgSend),
true,
"decoding bech32 failed: invalid index of 1: invalid request",
},
Expand All @@ -101,7 +36,7 @@ func (s *GRPCQueryTestSuite) TestQueryGrantGRPC() {
},
{
"fail with empty granter",
fmt.Sprintf(grantsURL, "", s.grantee.String(), typeMsgSend),
fmt.Sprintf(grantsURL, "", grantee.String(), typeMsgSend),
true,
"empty address string is not allowed: invalid request",
},
Expand All @@ -113,13 +48,13 @@ func (s *GRPCQueryTestSuite) TestQueryGrantGRPC() {
},
{
"fail invalid msg-type",
fmt.Sprintf(grantsURL, val.Address.String(), s.grantee.String(), "invalidMsg"),
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(), s.grantee.String(), typeMsgSend),
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String(), typeMsgSend),
false,
"",
},
Expand All @@ -144,8 +79,9 @@ func (s *GRPCQueryTestSuite) TestQueryGrantGRPC() {
}
}

func (s *GRPCQueryTestSuite) TestQueryGrantsGRPC() {
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
Expand All @@ -157,7 +93,7 @@ func (s *GRPCQueryTestSuite) TestQueryGrantsGRPC() {
}{
{
"valid query: expect single grant",
fmt.Sprintf(grantsURL, val.Address.String(), s.grantee.String()),
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String()),
false,
"",
func() {},
Expand All @@ -167,12 +103,12 @@ func (s *GRPCQueryTestSuite) TestQueryGrantsGRPC() {
},
{
"valid query: expect two grants",
fmt.Sprintf(grantsURL, val.Address.String(), s.grantee.String()),
fmt.Sprintf(grantsURL, val.Address.String(), grantee.String()),
false,
"",
func() {
_, err := ExecGrant(val, []string{
s.grantee.String(),
grantee.String(),
"generic",
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", cli.FlagMsgType, typeMsgVote),
Expand All @@ -189,7 +125,7 @@ func (s *GRPCQueryTestSuite) TestQueryGrantsGRPC() {
},
{
"valid query: expect single grant with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=1", val.Address.String(), s.grantee.String()),
fmt.Sprintf(grantsURL+"&pagination.limit=1", val.Address.String(), grantee.String()),
false,
"",
func() {},
Expand All @@ -199,7 +135,7 @@ func (s *GRPCQueryTestSuite) TestQueryGrantsGRPC() {
},
{
"valid query: expect two grants with pagination",
fmt.Sprintf(grantsURL+"&pagination.limit=2", val.Address.String(), s.grantee.String()),
fmt.Sprintf(grantsURL+"&pagination.limit=2", val.Address.String(), grantee.String()),
false,
"",
func() {},
Expand Down
4 changes: 2 additions & 2 deletions x/authz/client/testutil/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func (s *IntegrationTestSuite) TestQueryAuthorizations() {
val := s.network.Validators[0]

grantee := s.grantee
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

_, err := ExecGrant(
Expand Down Expand Up @@ -95,7 +95,7 @@ func (s *IntegrationTestSuite) TestQueryAuthorizations() {
func (s *IntegrationTestSuite) TestQueryAuthorization() {
val := s.network.Validators[0]

grantee := s.grantee
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

_, err := ExecGrant(
Expand Down
76 changes: 53 additions & 23 deletions x/authz/client/testutil/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type IntegrationTestSuite struct {

cfg network.Config
network *network.Network
grantee sdk.AccAddress
grantee []sdk.AccAddress
}

func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
Expand All @@ -43,24 +43,12 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.Require().NoError(err)

val := s.network.Validators[0]
s.grantee = make([]sdk.AccAddress, 2)

// Create new account in the keyring.
info, _, err := val.ClientCtx.Keyring.NewMnemonic("grantee", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
s.Require().NoError(err)
newAddr := sdk.AccAddress(info.GetPubKey().Address())

s.grantee[0] = s.createAccount("grantee1")
// Send some funds to the new account.
_, err = banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
newAddr,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
)
s.Require().NoError(err)
s.grantee = newAddr

s.msgSendExec(s.grantee[0])
_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)

Expand All @@ -70,10 +58,52 @@ func (s *IntegrationTestSuite) SetupSuite() {
fmt.Sprintf("--%s=%s", govcli.FlagDeposit, sdk.NewCoin(s.cfg.BondDenom, govtypes.DefaultMinDepositTokens).String()))
s.Require().NoError(err)

// Create new account in the keyring.
s.grantee[1] = s.createAccount("grantee2")
// Send some funds to the new account.
s.msgSendExec(s.grantee[1])

// grant send authorization to grantee2
out, err := ExecGrant(val, []string{
s.grantee[1].String(),
"send",
fmt.Sprintf("--%s=100steak", cli.FlagSpendLimit),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
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)
s.Require().Contains(out.String(), `"code":0`)

_, err = s.network.WaitForHeight(1)
s.Require().NoError(err)
}

func (s *IntegrationTestSuite) createAccount(uid string) sdk.AccAddress {
val := s.network.Validators[0]
// Create new account in the keyring.
info, _, err := val.ClientCtx.Keyring.NewMnemonic(uid, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
s.Require().NoError(err)
return sdk.AccAddress(info.GetPubKey().Address())
}

func (s *IntegrationTestSuite) msgSendExec(grantee sdk.AccAddress) {
val := s.network.Validators[0]
// Send some funds to the new account.
out, err := banktestutil.MsgSendExec(
val.ClientCtx,
val.Address,
grantee,
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
)
s.Require().NoError(err)
s.Require().Contains(out.String(), `"code":0`)
}

func (s *IntegrationTestSuite) TearDownSuite() {
s.T().Log("tearing down integration test suite")
s.network.Cleanup()
Expand All @@ -85,7 +115,7 @@ var typeMsgSubmitProposal = sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{})

func (s *IntegrationTestSuite) TestCLITxGrantAuthorization() {
val := s.network.Validators[0]
grantee := s.grantee
grantee := s.grantee[0]

twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()
pastHour := time.Now().Add(time.Minute * time.Duration(-60)).Unix()
Expand Down Expand Up @@ -308,7 +338,7 @@ func execDelegate(val *network.Validator, args []string) (testutil.BufferWriter,
func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() {
val := s.network.Validators[0]

grantee := s.grantee
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

// send-authorization
Expand Down Expand Up @@ -454,7 +484,7 @@ func (s *IntegrationTestSuite) TestCmdRevokeAuthorizations() {

func (s *IntegrationTestSuite) TestExecAuthorizationWithExpiration() {
val := s.network.Validators[0]
grantee := s.grantee
grantee := s.grantee[0]
tenSeconds := time.Now().Add(time.Second * time.Duration(10)).Unix()

_, err := ExecGrant(
Expand Down Expand Up @@ -494,7 +524,7 @@ func (s *IntegrationTestSuite) TestExecAuthorizationWithExpiration() {

func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() {
val := s.network.Validators[0]
grantee := s.grantee
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

_, err := ExecGrant(
Expand Down Expand Up @@ -596,7 +626,7 @@ func (s *IntegrationTestSuite) TestNewExecGenericAuthorized() {

func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() {
val := s.network.Validators[0]
grantee := s.grantee
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

_, err := ExecGrant(
Expand Down Expand Up @@ -681,7 +711,7 @@ func (s *IntegrationTestSuite) TestNewExecGrantAuthorized() {

func (s *IntegrationTestSuite) TestExecDelegateAuthorization() {
val := s.network.Validators[0]
grantee := s.grantee
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

_, err := ExecGrant(
Expand Down Expand Up @@ -884,7 +914,7 @@ func (s *IntegrationTestSuite) TestExecDelegateAuthorization() {

func (s *IntegrationTestSuite) TestExecUndelegateAuthorization() {
val := s.network.Validators[0]
grantee := s.grantee
grantee := s.grantee[0]
twoHours := time.Now().Add(time.Minute * time.Duration(120)).Unix()

// granting undelegate msg authorization
Expand Down
6 changes: 0 additions & 6 deletions x/mint/client/testutil/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build norace
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved

package testutil

import (
Expand All @@ -15,7 +13,3 @@ func TestIntegrationTestSuite(t *testing.T) {
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}

func TestGRPCQueryTestSuite(t *testing.T) {
suite.Run(t, new(GRPCQueryTestSuite))
}
Loading