-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register
x/mint
gRPC gateway routes (#7214)
* Add grpc-gateway mint module test script * Add grpc-gateway mint module test script * Add grpc inflation test-case * Fix `x/mint` grpc test-case * review changes Co-authored-by: aleem1314 <aleem.rgukt123@gmail.com> Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
- Loading branch information
1 parent
c1b975e
commit 18ac096
Showing
2 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package rest_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
) | ||
|
||
type IntegrationTestSuite struct { | ||
suite.Suite | ||
cfg network.Config | ||
network *network.Network | ||
} | ||
|
||
func (s *IntegrationTestSuite) SetupSuite() { | ||
s.T().Log("setting up integration test suite") | ||
|
||
cfg := network.DefaultConfig() | ||
|
||
genesisState := cfg.GenesisState | ||
cfg.NumValidators = 1 | ||
|
||
var mintData minttypes.GenesisState | ||
s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) | ||
|
||
inflation := sdk.MustNewDecFromStr("1.0") | ||
mintData.Minter.Inflation = inflation | ||
mintData.Params.InflationMin = inflation | ||
mintData.Params.InflationMax = inflation | ||
|
||
mintDataBz, err := cfg.Codec.MarshalJSON(&mintData) | ||
s.Require().NoError(err) | ||
genesisState[minttypes.ModuleName] = mintDataBz | ||
cfg.GenesisState = genesisState | ||
|
||
s.cfg = cfg | ||
s.network = network.New(s.T(), cfg) | ||
|
||
_, err = s.network.WaitForHeight(1) | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TearDownSuite() { | ||
s.T().Log("tearing down integration test suite") | ||
s.network.Cleanup() | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestQueryGRPC() { | ||
val := s.network.Validators[0] | ||
baseURL := val.APIAddress | ||
testCases := []struct { | ||
name string | ||
url string | ||
headers map[string]string | ||
respType proto.Message | ||
expected proto.Message | ||
}{ | ||
{ | ||
"gRPC request params", | ||
fmt.Sprintf("%s/cosmos/mint/v1beta1/params", baseURL), | ||
map[string]string{}, | ||
&minttypes.QueryParamsResponse{}, | ||
&minttypes.QueryParamsResponse{ | ||
Params: minttypes.NewParams("stake", sdk.NewDecWithPrec(13, 2), sdk.NewDecWithPrec(100, 2), | ||
sdk.NewDec(1), sdk.NewDecWithPrec(67, 2), (60 * 60 * 8766 / 5)), | ||
}, | ||
}, | ||
{ | ||
"gRPC request inflation", | ||
fmt.Sprintf("%s/cosmos/mint/v1beta1/inflation", baseURL), | ||
map[string]string{}, | ||
&minttypes.QueryInflationResponse{}, | ||
&minttypes.QueryInflationResponse{ | ||
Inflation: sdk.NewDec(1), | ||
}, | ||
}, | ||
{ | ||
"gRPC request annual provisions", | ||
fmt.Sprintf("%s/cosmos/mint/v1beta1/annual_provisions", baseURL), | ||
map[string]string{ | ||
grpctypes.GRPCBlockHeightHeader: "1", | ||
}, | ||
&minttypes.QueryAnnualProvisionsResponse{}, | ||
&minttypes.QueryAnnualProvisionsResponse{ | ||
AnnualProvisions: sdk.NewDec(500000000), | ||
}, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) | ||
s.Run(tc.name, func() { | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.JSONMarshaler.UnmarshalJSON(resp, tc.respType)) | ||
s.Require().Equal(tc.expected.String(), tc.respType.String()) | ||
}) | ||
} | ||
} | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters