laconicd-deprecated/x/bond/client/testutil/grpc_gateway_test.go
Sai Kumar d28ef888ff
dxns bond module test (#4)
* WIP : added bond module tx and query cli commands

* added bond module invariant

* update the go.mod

* addressed the pr changes

* update to proto files

* refactor: move the proto package version from `v1` to `v1beta1` for vulcanize modules

* WIP : addin the unit test scripts to bond module

* refactor: refactored the test cases for bond module

* refactor: refactored the bond module test cases
1. refactored grpc gateway  endpoints of bond module
2. added test cases to cli query , cli tx and grpc end points

* addressed the pr comments
1. changed query-by-owner to by-owner in cli cmd
2. changed bonds-by-owner route to by-owner in bond module
2021-09-29 18:18:30 +05:30

226 lines
4.8 KiB
Go

package testutil
import (
"fmt"
"github.com/cosmos/cosmos-sdk/testutil"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/cosmos/cosmos-sdk/types/rest"
bondtypes "github.com/tharsis/ethermint/x/bond/types"
)
func (s *IntegrationTestSuite) TestGetBondsGRPC() {
val := s.network.Validators[0]
sr := s.Require()
testCases := []struct {
name string
url string
headers map[string]string
noOfBonds int
expErr bool
}{
{
"invalid request with headers",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/bonds", val.APIAddress),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
0,
true,
},
{
"valid request",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/bonds", val.APIAddress),
map[string]string{},
0,
false,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
sr.NoError(err)
var bonds bondtypes.QueryGetBondsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bonds)
if tc.expErr {
sr.Empty(bonds.GetBonds())
} else {
sr.NoError(err)
sr.Len(bonds.GetBonds(), tc.noOfBonds)
}
})
}
}
func (s *IntegrationTestSuite) TestGetParamsGRPC() {
val := s.network.Validators[0]
sr := s.Require()
testCases := []struct {
name string
url string
headers map[string]string
noOfBonds int
expErr bool
}{
{
"valid request",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/params", val.APIAddress),
map[string]string{},
0,
false,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
resp, err := rest.GetRequest(tc.url)
s.Require().NoError(err)
var params bondtypes.QueryParamsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &params)
if tc.expErr {
sr.Empty(params.GetParams())
} else {
sr.NoError(err)
sr.Equal(params.GetParams().MaxBondAmount, bondtypes.DefaultParams().MaxBondAmount)
}
})
}
}
func (s *IntegrationTestSuite) TestGetBondsByOwnerGRPC() {
val := s.network.Validators[0]
sr := s.Require()
testCases := []struct {
name string
url string
headers map[string]string
noOfBonds int
expErr bool
}{
{
"invalid request with headers",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/by-owner", val.APIAddress),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
0,
true,
},
{
"valid request",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/by-owner/%s,", val.APIAddress, val.Address.String()),
map[string]string{},
0,
false,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
sr.NoError(err)
var bonds bondtypes.QueryGetBondsByOwnerResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bonds)
if tc.expErr {
sr.Empty(bonds.GetBonds())
} else {
sr.NoError(err)
sr.Len(bonds.GetBonds(), tc.noOfBonds)
}
})
}
}
func (s *IntegrationTestSuite) TestGetBondByIdGRPC() {
val := s.network.Validators[0]
sr := s.Require()
testCases := []struct {
name string
url string
headers map[string]string
noOfBonds int
expErr bool
}{
{
"invalid request with headers",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/bonds/%s", val.APIAddress, "asdadad"),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
0,
true,
},
{
"valid request",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/bonds/%s,", val.APIAddress, "asdadad"),
map[string]string{},
0,
false,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
sr.NoError(err)
var bonds bondtypes.QueryGetBondByIdResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bonds)
if tc.expErr {
sr.Empty(bonds.GetBond().GetId())
} else {
sr.NoError(err)
sr.Len(bonds.GetBond().GetId(), tc.noOfBonds)
}
})
}
}
func (s *IntegrationTestSuite) TestGetBondModuleBalanceGRPC() {
val := s.network.Validators[0]
sr := s.Require()
testCases := []struct {
name string
url string
headers map[string]string
noOfBonds int
expErr bool
}{
{
"invalid request with headers",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/balance", val.APIAddress),
map[string]string{
grpctypes.GRPCBlockHeightHeader: "1",
},
0,
true,
},
{
"valid request",
fmt.Sprintf("%s/vulcanize/bond/v1beta1/balance", val.APIAddress),
map[string]string{},
0,
false,
},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers)
sr.NoError(err)
var bonds bondtypes.QueryGetBondModuleBalanceResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bonds)
if tc.expErr {
sr.Empty(bonds.GetBalance())
} else {
sr.NoError(err)
sr.True(bonds.GetBalance().IsZero())
}
})
}
}