github.com/Finschia/finschia-sdk@v0.49.1/x/mint/client/testutil/suite.go (about) 1 package testutil 2 3 import ( 4 "fmt" 5 "strings" 6 7 ostcli "github.com/Finschia/ostracon/libs/cli" 8 "github.com/stretchr/testify/suite" 9 10 "github.com/Finschia/finschia-sdk/client/flags" 11 clitestutil "github.com/Finschia/finschia-sdk/testutil/cli" 12 "github.com/Finschia/finschia-sdk/testutil/network" 13 sdk "github.com/Finschia/finschia-sdk/types" 14 "github.com/Finschia/finschia-sdk/x/mint/client/cli" 15 minttypes "github.com/Finschia/finschia-sdk/x/mint/types" 16 ) 17 18 type IntegrationTestSuite struct { 19 suite.Suite 20 21 cfg network.Config 22 network *network.Network 23 } 24 25 func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite { 26 return &IntegrationTestSuite{cfg: cfg} 27 } 28 29 func (s *IntegrationTestSuite) SetupSuite() { 30 s.T().Log("setting up integration test suite") 31 32 genesisState := s.cfg.GenesisState 33 34 var mintData minttypes.GenesisState 35 s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) 36 37 inflation := sdk.MustNewDecFromStr("1.0") 38 mintData.Minter.Inflation = inflation 39 mintData.Params.InflationMin = inflation 40 mintData.Params.InflationMax = inflation 41 42 mintDataBz, err := s.cfg.Codec.MarshalJSON(&mintData) 43 s.Require().NoError(err) 44 genesisState[minttypes.ModuleName] = mintDataBz 45 s.cfg.GenesisState = genesisState 46 47 s.network = network.New(s.T(), s.cfg) 48 49 _, err = s.network.WaitForHeight(1) 50 s.Require().NoError(err) 51 } 52 53 func (s *IntegrationTestSuite) TearDownSuite() { 54 s.T().Log("tearing down integration test suite") 55 s.network.Cleanup() 56 } 57 58 func (s *IntegrationTestSuite) TestGetCmdQueryParams() { 59 val := s.network.Validators[0] 60 61 testCases := []struct { 62 name string 63 args []string 64 expectedOutput string 65 }{ 66 { 67 "json output", 68 []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", ostcli.OutputFlag)}, 69 `{"mint_denom":"stake","inflation_rate_change":"0.130000000000000000","inflation_max":"1.000000000000000000","inflation_min":"1.000000000000000000","goal_bonded":"0.670000000000000000","blocks_per_year":"6311520"}`, 70 }, 71 { 72 "text output", 73 []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", ostcli.OutputFlag)}, 74 `blocks_per_year: "6311520" 75 goal_bonded: "0.670000000000000000" 76 inflation_max: "1.000000000000000000" 77 inflation_min: "1.000000000000000000" 78 inflation_rate_change: "0.130000000000000000" 79 mint_denom: stake`, 80 }, 81 } 82 83 for _, tc := range testCases { 84 s.Run(tc.name, func() { 85 cmd := cli.GetCmdQueryParams() 86 clientCtx := val.ClientCtx 87 88 out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) 89 s.Require().NoError(err) 90 s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String())) 91 }) 92 } 93 } 94 95 func (s *IntegrationTestSuite) TestGetCmdQueryInflation() { 96 val := s.network.Validators[0] 97 98 testCases := []struct { 99 name string 100 args []string 101 expectedOutput string 102 }{ 103 { 104 "json output", 105 []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", ostcli.OutputFlag)}, 106 `1.000000000000000000`, 107 }, 108 { 109 "text output", 110 []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", ostcli.OutputFlag)}, 111 `1.000000000000000000`, 112 }, 113 } 114 115 for _, tc := range testCases { 116 s.Run(tc.name, func() { 117 cmd := cli.GetCmdQueryInflation() 118 clientCtx := val.ClientCtx 119 120 out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) 121 s.Require().NoError(err) 122 s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String())) 123 }) 124 } 125 } 126 127 func (s *IntegrationTestSuite) TestGetCmdQueryAnnualProvisions() { 128 val := s.network.Validators[0] 129 130 testCases := []struct { 131 name string 132 args []string 133 expectedOutput string 134 }{ 135 { 136 "json output", 137 []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=json", ostcli.OutputFlag)}, 138 `500000000.000000000000000000`, 139 }, 140 { 141 "text output", 142 []string{fmt.Sprintf("--%s=1", flags.FlagHeight), fmt.Sprintf("--%s=text", ostcli.OutputFlag)}, 143 `500000000.000000000000000000`, 144 }, 145 } 146 147 for _, tc := range testCases { 148 s.Run(tc.name, func() { 149 cmd := cli.GetCmdQueryAnnualProvisions() 150 clientCtx := val.ClientCtx 151 152 out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) 153 s.Require().NoError(err) 154 s.Require().Equal(tc.expectedOutput, strings.TrimSpace(out.String())) 155 }) 156 } 157 }