github.com/Finschia/finschia-sdk@v0.48.1/x/foundation/keeper/internal/grpc_query_test.go (about)

     1  package internal_test
     2  
     3  import (
     4  	gocontext "context"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/suite"
     9  	tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
    10  
    11  	"github.com/Finschia/finschia-sdk/baseapp"
    12  	"github.com/Finschia/finschia-sdk/simapp"
    13  	sdk "github.com/Finschia/finschia-sdk/types"
    14  	authtypes "github.com/Finschia/finschia-sdk/x/auth/types"
    15  	"github.com/Finschia/finschia-sdk/x/foundation"
    16  	"github.com/Finschia/finschia-sdk/x/foundation/keeper"
    17  	"github.com/Finschia/finschia-sdk/x/foundation/keeper/internal"
    18  )
    19  
    20  type FoundationTestSuite struct {
    21  	suite.Suite
    22  
    23  	app         *simapp.SimApp
    24  	ctx         sdk.Context
    25  	queryClient foundation.QueryClient
    26  
    27  	impl internal.Keeper
    28  }
    29  
    30  func (s *FoundationTestSuite) SetupTest() {
    31  	s.app = simapp.Setup(false)
    32  	s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{})
    33  
    34  	queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.app.InterfaceRegistry())
    35  	foundation.RegisterQueryServer(queryHelper, keeper.NewQueryServer(s.app.FoundationKeeper))
    36  	s.queryClient = foundation.NewQueryClient(queryHelper)
    37  
    38  	s.impl = internal.NewKeeper(
    39  		s.app.AppCodec(),
    40  		s.app.GetKey(foundation.ModuleName),
    41  		s.app.MsgServiceRouter(),
    42  		s.app.AccountKeeper,
    43  		s.app.BankKeeper,
    44  		authtypes.FeeCollectorName,
    45  		foundation.DefaultConfig(),
    46  		foundation.DefaultAuthority().String(),
    47  		s.app.GetSubspace(foundation.ModuleName),
    48  	)
    49  }
    50  
    51  func (s *FoundationTestSuite) TestQueryParams() {
    52  	var (
    53  		req         *foundation.QueryParamsRequest
    54  		expResponse foundation.QueryParamsResponse
    55  	)
    56  
    57  	testCases := []struct {
    58  		msg      string
    59  		malleate func()
    60  		expPass  bool
    61  	}{
    62  		{
    63  			"with foundation tax",
    64  			func() {
    65  				params := foundation.Params{
    66  					FoundationTax: sdk.OneDec(),
    67  				}
    68  				s.impl.SetParams(s.ctx, params)
    69  
    70  				req = &foundation.QueryParamsRequest{}
    71  				expResponse = foundation.QueryParamsResponse{Params: params}
    72  			},
    73  			true,
    74  		},
    75  	}
    76  
    77  	for _, tc := range testCases {
    78  		s.Run(fmt.Sprintf("Case %s", tc.msg), func() {
    79  			s.SetupTest() // reset
    80  
    81  			tc.malleate()
    82  
    83  			res, err := s.queryClient.Params(gocontext.Background(), req)
    84  
    85  			if tc.expPass {
    86  				s.Require().NoError(err)
    87  				s.Require().NotNil(res)
    88  				s.Require().Equal(&expResponse, res)
    89  			} else {
    90  				s.Require().Error(err)
    91  			}
    92  		})
    93  	}
    94  }
    95  
    96  func TestFoundationTestSuite(t *testing.T) {
    97  	suite.Run(t, new(FoundationTestSuite))
    98  }