From bf939309872f5d810bb93f989c577b8b4700a8ab Mon Sep 17 00:00:00 2001 From: Akhil Kumar P <36399231+akhilkumarpilli@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:45:56 +0530 Subject: [PATCH] test: migrate e2e/mint to system tests (#22294) (cherry picked from commit 29ea9c8a5e985dcbe1e9d44da361ec3bba7dafd2) --- tests/e2e/mint/cli_test.go | 20 ------- tests/e2e/mint/grpc.go | 64 ---------------------- tests/e2e/mint/suite.go | 50 ----------------- tests/systemtests/mint_test.go | 98 ++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 134 deletions(-) delete mode 100644 tests/e2e/mint/cli_test.go delete mode 100644 tests/e2e/mint/grpc.go delete mode 100644 tests/e2e/mint/suite.go create mode 100644 tests/systemtests/mint_test.go diff --git a/tests/e2e/mint/cli_test.go b/tests/e2e/mint/cli_test.go deleted file mode 100644 index 08158c279684..000000000000 --- a/tests/e2e/mint/cli_test.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build e2e -// +build e2e - -package mint - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - "cosmossdk.io/simapp" - - "github.com/cosmos/cosmos-sdk/testutil/network" -) - -func TestE2ETestSuite(t *testing.T) { - cfg := network.DefaultConfig(simapp.NewTestNetworkFixture) - cfg.NumValidators = 1 - suite.Run(t, NewE2ETestSuite(cfg)) -} diff --git a/tests/e2e/mint/grpc.go b/tests/e2e/mint/grpc.go deleted file mode 100644 index 188d641d5d41..000000000000 --- a/tests/e2e/mint/grpc.go +++ /dev/null @@ -1,64 +0,0 @@ -package mint - -import ( - "fmt" - - "github.com/cosmos/gogoproto/proto" - - "cosmossdk.io/math" - minttypes "cosmossdk.io/x/mint/types" - - "github.com/cosmos/cosmos-sdk/testutil" - grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" -) - -func (s *E2ETestSuite) TestQueryGRPC() { - val := s.network.GetValidators()[0] - baseURL := val.GetAPIAddress() - 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", math.LegacyNewDecWithPrec(13, 2), math.LegacyNewDecWithPrec(100, 2), - math.LegacyNewDec(1), math.LegacyNewDecWithPrec(67, 2), (60 * 60 * 8766 / 5), math.ZeroInt()), - }, - }, - { - "gRPC request inflation", - fmt.Sprintf("%s/cosmos/mint/v1beta1/inflation", baseURL), - map[string]string{}, - &minttypes.QueryInflationResponse{}, - &minttypes.QueryInflationResponse{ - Inflation: math.LegacyNewDec(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: math.LegacyNewDec(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.GetClientCtx().Codec.UnmarshalJSON(resp, tc.respType)) - s.Require().Equal(tc.expected.String(), tc.respType.String()) - }) - } -} diff --git a/tests/e2e/mint/suite.go b/tests/e2e/mint/suite.go deleted file mode 100644 index 7f40603246b1..000000000000 --- a/tests/e2e/mint/suite.go +++ /dev/null @@ -1,50 +0,0 @@ -package mint - -import ( - "github.com/stretchr/testify/suite" - - "cosmossdk.io/math" - minttypes "cosmossdk.io/x/mint/types" - - "github.com/cosmos/cosmos-sdk/testutil/network" -) - -type E2ETestSuite struct { - suite.Suite - - cfg network.Config - network network.NetworkI -} - -func NewE2ETestSuite(cfg network.Config) *E2ETestSuite { - return &E2ETestSuite{cfg: cfg} -} - -func (s *E2ETestSuite) SetupSuite() { - s.T().Log("setting up e2e test suite") - - genesisState := s.cfg.GenesisState - - var mintData minttypes.GenesisState - s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) - - inflation := math.LegacyMustNewDecFromStr("1.0") - mintData.Minter.Inflation = inflation - mintData.Params.InflationMin = inflation - mintData.Params.InflationMax = inflation - - mintDataBz, err := s.cfg.Codec.MarshalJSON(&mintData) - s.Require().NoError(err) - genesisState[minttypes.ModuleName] = mintDataBz - s.cfg.GenesisState = genesisState - - s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) - s.Require().NoError(err) - - s.Require().NoError(s.network.WaitForNextBlock()) -} - -func (s *E2ETestSuite) TearDownSuite() { - s.T().Log("tearing down e2e test suite") - s.network.Cleanup() -} diff --git a/tests/systemtests/mint_test.go b/tests/systemtests/mint_test.go new file mode 100644 index 000000000000..c95aaaee1233 --- /dev/null +++ b/tests/systemtests/mint_test.go @@ -0,0 +1,98 @@ +package systemtests + +import ( + "fmt" + "net/http" + "testing" + + "github.com/stretchr/testify/require" + "github.com/tidwall/sjson" +) + +func TestMintQueries(t *testing.T) { + // scenario: test mint grpc queries + // given a running chain + + sut.ResetChain(t) + cli := NewCLIWrapper(t, sut, verbose) + + sut.ModifyGenesisJSON(t, + func(genesis []byte) []byte { + state, err := sjson.Set(string(genesis), "app_state.mint.minter.inflation", "1.00") + require.NoError(t, err) + return []byte(state) + }, + func(genesis []byte) []byte { + state, err := sjson.Set(string(genesis), "app_state.mint.params.inflation_max", "1.00") + require.NoError(t, err) + return []byte(state) + }, + ) + + sut.StartChain(t) + + sut.AwaitNextBlock(t) + + baseurl := sut.APIAddress() + blockHeightHeader := "x-cosmos-block-height" + queryAtHeight := "1" + + // TODO: check why difference in values when querying with height between v1 and v2 + // ref: https://github.com/cosmos/cosmos-sdk/issues/22302 + if isV2() { + queryAtHeight = "2" + } + + paramsResp := `{"params":{"mint_denom":"stake","inflation_rate_change":"0.130000000000000000","inflation_max":"1.000000000000000000","inflation_min":"0.000000000000000000","goal_bonded":"0.670000000000000000","blocks_per_year":"6311520","max_supply":"0"}}` + inflationResp := `{"inflation":"1.000000000000000000"}` + annualProvisionsResp := `{"annual_provisions":"2000000000.000000000000000000"}` + + testCases := []struct { + name string + url string + headers map[string]string + expOut string + }{ + { + "gRPC request params", + fmt.Sprintf("%s/cosmos/mint/v1beta1/params", baseurl), + map[string]string{}, + paramsResp, + }, + { + "gRPC request inflation", + fmt.Sprintf("%s/cosmos/mint/v1beta1/inflation", baseurl), + map[string]string{}, + inflationResp, + }, + { + "gRPC request annual provisions", + fmt.Sprintf("%s/cosmos/mint/v1beta1/annual_provisions", baseurl), + map[string]string{ + blockHeightHeader: queryAtHeight, + }, + annualProvisionsResp, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // TODO: remove below check once grpc gateway is implemented in v2 + if isV2() { + return + } + resp := GetRequestWithHeaders(t, tc.url, tc.headers, http.StatusOK) + require.JSONEq(t, tc.expOut, string(resp)) + }) + } + + // test cli queries + rsp := cli.CustomQuery("q", "mint", "params") + require.JSONEq(t, paramsResp, rsp) + + rsp = cli.CustomQuery("q", "mint", "inflation") + require.JSONEq(t, inflationResp, rsp) + + rsp = cli.CustomQuery("q", "mint", "annual-provisions", "--height="+queryAtHeight) + require.JSONEq(t, annualProvisionsResp, rsp) +}