test: migrate e2e/mint to system tests (#22294)

This commit is contained in:
Akhil Kumar P 2024-10-17 18:45:56 +05:30 committed by GitHub
parent c905c5ee9b
commit 29ea9c8a5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 98 additions and 134 deletions

View File

@ -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))
}

View File

@ -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())
})
}
}

View File

@ -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()
}

View File

@ -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)
}