From 12b8df82044b27c04f040dc4d2509f0abf272229 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 3 Jul 2020 15:03:40 +0200 Subject: [PATCH] Update pseudo tests --- x/upgrade/keeper/grpc_query_test.go | 137 ++++------------------------ 1 file changed, 19 insertions(+), 118 deletions(-) diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 64a6741f5498..2d3331314832 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -2,130 +2,31 @@ package keeper_test import ( gocontext "context" + "testing" - "github.com/cosmos/cosmos-sdk/types/query" - - "github.com/cosmos/cosmos-sdk/baseapp" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/stretchr/testify/require" ) -func (suite *IntegrationTestSuite) TestQueryBalance() { - app, ctx := suite.app, suite.ctx - _, _, addr := authtypes.KeyTestPubAddr() - - queryHelper := baseapp.NewQueryServerTestHelper(ctx) - types.RegisterQueryServer(queryHelper, app.BankKeeper) - queryClient := types.NewQueryClient(queryHelper) - - _, err := queryClient.Balance(gocontext.Background(), &types.QueryBalanceRequest{}) - suite.Require().Error(err) - - _, err = queryClient.Balance(gocontext.Background(), &types.QueryBalanceRequest{Address: addr}) - suite.Require().Error(err) - - req := types.NewQueryBalanceRequest(addr, fooDenom) - res, err := queryClient.Balance(gocontext.Background(), req) - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.True(res.Balance.IsZero()) - - origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30)) - acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr) - - app.AccountKeeper.SetAccount(ctx, acc) - suite.Require().NoError(app.BankKeeper.SetBalances(ctx, acc.GetAddress(), origCoins)) - - res, err = queryClient.Balance(gocontext.Background(), req) - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.True(res.Balance.IsEqual(newFooCoin(50))) -} - -func (suite *IntegrationTestSuite) TestQueryAllBalances() { - app, ctx := suite.app, suite.ctx - _, _, addr := authtypes.KeyTestPubAddr() - - queryHelper := baseapp.NewQueryServerTestHelper(ctx) - types.RegisterQueryServer(queryHelper, app.BankKeeper) - queryClient := types.NewQueryClient(queryHelper) - - _, err := queryClient.AllBalances(gocontext.Background(), &types.QueryAllBalancesRequest{}) - suite.Require().Error(err) - - pageReq := &query.PageRequest{ - Key: nil, - Limit: 1, - CountTotal: false, - } - req := types.NewQueryAllBalancesRequest(addr, pageReq) - res, err := queryClient.AllBalances(gocontext.Background(), req) - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.True(res.Balances.IsZero()) - - fooCoins := newFooCoin(50) - barCoins := newBarCoin(30) - - origCoins := sdk.NewCoins(fooCoins, barCoins) - acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr) - - app.AccountKeeper.SetAccount(ctx, acc) - suite.Require().NoError(app.BankKeeper.SetBalances(ctx, acc.GetAddress(), origCoins)) - - res, err = queryClient.AllBalances(gocontext.Background(), req) - suite.Require().NoError(err) - suite.Require().NotNil(res) - suite.Equal(res.Balances.Len(), 1) - suite.NotNil(res.Res.NextKey) - - suite.T().Log("query second page with nextkey") - pageReq = &query.PageRequest{ - Key: res.Res.NextKey, - Limit: 1, - CountTotal: true, - } - req = types.NewQueryAllBalancesRequest(addr, pageReq) - res, err = queryClient.AllBalances(gocontext.Background(), req) - suite.Equal(res.Balances.Len(), 1) - suite.Nil(res.Res.NextKey) -} - -func (suite *IntegrationTestSuite) TestQueryTotalSupply() { - app, ctx := suite.app, suite.ctx - expectedTotalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin("test", 400000000))) - app.BankKeeper.SetSupply(ctx, expectedTotalSupply) - - queryHelper := baseapp.NewQueryServerTestHelper(ctx) - types.RegisterQueryServer(queryHelper, app.BankKeeper) - queryClient := types.NewQueryClient(queryHelper) - - res, err := queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{}) - suite.Require().NoError(err) - suite.Require().NotNil(res) - - suite.Require().Equal(expectedTotalSupply.Total, res.Supply) -} - -func (suite *IntegrationTestSuite) TestQueryTotalSupplyOf() { - app, ctx := suite.app, suite.ctx - - test1Supply := sdk.NewInt64Coin("test1", 4000000) - test2Supply := sdk.NewInt64Coin("test2", 700000000) - expectedTotalSupply := types.NewSupply(sdk.NewCoins(test1Supply, test2Supply)) - app.BankKeeper.SetSupply(ctx, expectedTotalSupply) +func TestGRPCQueryParams(t *testing.T) { + // TODO Setup tests - create queryClient - queryHelper := baseapp.NewQueryServerTestHelper(ctx) - types.RegisterQueryServer(queryHelper, app.BankKeeper) - queryClient := types.NewQueryClient(queryHelper) + // No current plan + res, err := queryClient.Parameters(gocontext.Background(), &types.QueryCurrentPlanRequest{}) + require.NoError(t, err) + require.Nil(t, res.Plan) - _, err := queryClient.SupplyOf(gocontext.Background(), &types.QuerySupplyOfRequest{}) - suite.Require().Error(err) + // TODO Create upgrade plan. Does it need to go through gov & upgrade proposal? + res, err := queryClient.Parameters(gocontext.Background(), &types.QueryCurrentPlanRequest{}) + require.NoError(t, err) + require.Equal(t, res.Plan, plan) - res, err := queryClient.SupplyOf(gocontext.Background(), &types.QuerySupplyOfRequest{Denom: test1Supply.Denom}) - suite.Require().NoError(err) - suite.Require().NotNil(res) + // TODO Wait for plan to be applied. Possible to advance N blocks programmatically in test so that plan gets applied? + res, err := queryClient.Parameters(gocontext.Background(), &types.QueryCurrentPlanRequest{}) + require.NoError(t, err) + require.Nil(t, res.Plan) - suite.Require().Equal(test1Supply, res.Amount) + res, err := queryClient.Parameters(gocontext.Background(), &types.QueryAppliedPlanRequest{Name: "test-plan"}) + require.NoError(t, err) + require.Equal(t, res.Height, 1234) }