diff --git a/ignite/templates/module/create/files/base/x/{{moduleName}}/client/cli/suite_test.go.plush b/ignite/templates/module/create/files/base/x/{{moduleName}}/client/cli/suite_test.go.plush index 135caf8045..1cbe9641c2 100644 --- a/ignite/templates/module/create/files/base/x/{{moduleName}}/client/cli/suite_test.go.plush +++ b/ignite/templates/module/create/files/base/x/{{moduleName}}/client/cli/suite_test.go.plush @@ -3,46 +3,38 @@ package cli_test import ( "testing" + "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" "<%= modulePath %>/testutil/network" + "<%= modulePath %>/x/<%= moduleName %>/types" ) type IntegrationTestSuite struct { suite.Suite - - locked bool - net *network.Network - cfg network.Config -} - -func (s *IntegrationTestSuite) network() *network.Network { - s.net = network.New(s.T(), s.cfg) - s.locked = true - return s.net } -func (s *IntegrationTestSuite) waitForNextBlock() { - s.T().Log("wait for next block") - s.Require().NoError(s.net.WaitForNextBlock()) +func (s *IntegrationTestSuite) network(state proto.Message) *network.Network { + s.T().Helper() + cfg := network.DefaultConfig() + if state != nil { + buf, err := cfg.Codec.MarshalJSON(state) + s.Require().NoError(err) + cfg.GenesisState[types.ModuleName] = buf + } + return network.New(s.T(), cfg) } func (s *IntegrationTestSuite) SetupTest() { s.T().Log("setting up test") - s.cfg = network.DefaultConfig() } func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") - s.cfg = network.DefaultConfig() } func (s *IntegrationTestSuite) TearDownTest() { s.T().Log("tearing down test") - if s.net != nil && s.locked { - s.net.Cleanup() - s.locked = false - } } func (s *IntegrationTestSuite) TearDownSuite() { diff --git a/ignite/templates/typed/list/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush b/ignite/templates/typed/list/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush index bc13818958..884949c3b3 100644 --- a/ignite/templates/typed/list/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush +++ b/ignite/templates/typed/list/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush @@ -11,12 +11,13 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "<%= ModulePath %>/testutil/network" "<%= ModulePath %>/testutil/nullify" "<%= ModulePath %>/x/<%= ModuleName %>/client/cli" "<%= ModulePath %>/x/<%= ModuleName %>/types" ) -func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Objects(n int) []types.<%= TypeName.UpperCamel %> { +func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Objects(n int) (*network.Network, []types.<%= TypeName.UpperCamel %>) { s.T().Helper() state := types.GenesisState{<%= if (IsIBC) { %>PortId: types.PortID<% } %>} for i := 0; i < n; i++ { @@ -26,21 +27,18 @@ func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Objects(n in nullify.Fill(&<%= TypeName.LowerCamel %>) state.<%= TypeName.UpperCamel %>List = append(state.<%= TypeName.UpperCamel %>List, <%= TypeName.LowerCamel %>) } - buf, err := s.cfg.Codec.MarshalJSON(&state) - s.Require().NoError(err) - s.cfg.GenesisState[types.ModuleName] = buf - return state.<%= TypeName.UpperCamel %>List + return s.network(&state), state.<%= TypeName.UpperCamel %>List } func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { var ( - objs = s.networkWith<%= TypeName.UpperCamel %>Objects(2) - net = s.network() - ctx = net.Validators[0].ClientCtx - common = []string{ + net, objs = s.networkWith<%= TypeName.UpperCamel %>Objects(2) + ctx = net.Validators[0].ClientCtx + common = []string{ fmt.Sprintf("--%s=json", tmcli.OutputFlag), } ) + defer net.Cleanup() tests := []struct { desc string id string @@ -73,7 +71,7 @@ func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { } require.NoError(t, err) var resp types.QueryGet<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NotNil(t, resp.<%= TypeName.UpperCamel %>) require.Equal(t, nullify.Fill(&tc.obj), @@ -85,10 +83,10 @@ func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { var ( - objs = s.networkWith<%= TypeName.UpperCamel %>Objects(5) - net = s.network() - ctx = net.Validators[0].ClientCtx + net, objs = s.networkWith<%= TypeName.UpperCamel %>Objects(5) + ctx = net.Validators[0].ClientCtx ) + defer net.Cleanup() request := func(next []byte, offset, limit uint64, total bool) []string { args := []string{ fmt.Sprintf("--%s=json", tmcli.OutputFlag), @@ -111,7 +109,7 @@ func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdList<%= TypeName.UpperCamel %>(), args) require.NoError(t, err) var resp types.QueryAll<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.LessOrEqual(t, len(resp.<%= TypeName.UpperCamel %>), step) require.Subset(t, nullify.Fill(objs), @@ -127,7 +125,7 @@ func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdList<%= TypeName.UpperCamel %>(), args) require.NoError(t, err) var resp types.QueryAll<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.LessOrEqual(t, len(resp.<%= TypeName.UpperCamel %>), step) require.Subset(t, nullify.Fill(objs), @@ -141,7 +139,7 @@ func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdList<%= TypeName.UpperCamel %>(), args) require.NoError(t, err) var resp types.QueryAll<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NoError(t, err) require.Equal(t, len(objs), int(resp.Pagination.Total)) require.ElementsMatch(t, diff --git a/ignite/templates/typed/list/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush b/ignite/templates/typed/list/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush index 608a4fc742..34f19cb871 100644 --- a/ignite/templates/typed/list/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush +++ b/ignite/templates/typed/list/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush @@ -17,12 +17,12 @@ import ( func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + defer net.Cleanup() tests := []struct { desc string args []string @@ -35,7 +35,7 @@ func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), }, }, } @@ -59,23 +59,23 @@ func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestUpdate<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + common = []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), + } + args = append([]string{}, fields...) ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), - } - args := append([]string{}, fields...) - args = append(args, common...) + args = append(args, common...) + defer net.Cleanup() _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreate<%= TypeName.UpperCamel %>(), args) s.Require().NoError(err) - s.waitForNextBlock() + s.Require().NoError(net.WaitForNextBlock()) tests := []struct { desc string @@ -121,23 +121,23 @@ func (s *IntegrationTestSuite) TestUpdate<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestDelete<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + common = []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), + } + args = append([]string{}, fields...) ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), - } - args := append([]string{}, fields...) - args = append(args, common...) + args = append(args, common...) + defer net.Cleanup() _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreate<%= TypeName.UpperCamel %>(), args) s.Require().NoError(err) - s.waitForNextBlock() + s.Require().NoError(net.WaitForNextBlock()) tests := []struct { desc string diff --git a/ignite/templates/typed/map/files/tests/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush b/ignite/templates/typed/map/files/tests/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush index 9a5499ffa2..258c6c3ca8 100644 --- a/ignite/templates/typed/map/files/tests/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush +++ b/ignite/templates/typed/map/files/tests/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush @@ -12,6 +12,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "<%= ModulePath %>/testutil/network" "<%= ModulePath %>/testutil/nullify" "<%= ModulePath %>/x/<%= ModuleName %>/client/cli" "<%= ModulePath %>/x/<%= ModuleName %>/types" @@ -20,7 +21,7 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize -func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Objects(n int) []types.<%= TypeName.UpperCamel %> { +func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Objects(n int) (*network.Network, []types.<%= TypeName.UpperCamel %>) { s.T().Helper() state := types.GenesisState{<%= if (IsIBC) { %>PortId: types.PortID<% } %>} for i := 0; i < n; i++ { @@ -31,21 +32,18 @@ func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Objects(n in nullify.Fill(&<%= TypeName.LowerCamel %>) state.<%= TypeName.UpperCamel %>List = append(state.<%= TypeName.UpperCamel %>List, <%= TypeName.LowerCamel %>) } - buf, err := s.cfg.Codec.MarshalJSON(&state) - s.Require().NoError(err) - s.cfg.GenesisState[types.ModuleName] = buf - return state.<%= TypeName.UpperCamel %>List + return s.network(&state), state.<%= TypeName.UpperCamel %>List } func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { var ( - objs = s.networkWith<%= TypeName.UpperCamel %>Objects(2) - net = s.network() - ctx = net.Validators[0].ClientCtx - common = []string{ + net, objs = s.networkWith<%= TypeName.UpperCamel %>Objects(2) + ctx = net.Validators[0].ClientCtx + common = []string{ fmt.Sprintf("--%s=json", tmcli.OutputFlag), } ) + defer net.Cleanup() tests := []struct { desc string <%= for (i, index) in Indexes { %>id<%= index.Name.UpperCamel %> <%= index.DataType() %> @@ -85,7 +83,7 @@ func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { } require.NoError(t, err) var resp types.QueryGet<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NotNil(t, resp.<%= TypeName.UpperCamel %>) require.Equal(t, nullify.Fill(&tc.obj), @@ -97,10 +95,10 @@ func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { var ( - objs = s.networkWith<%= TypeName.UpperCamel %>Objects(5) - net = s.network() - ctx = net.Validators[0].ClientCtx + net, objs = s.networkWith<%= TypeName.UpperCamel %>Objects(5) + ctx = net.Validators[0].ClientCtx ) + defer net.Cleanup() request := func(next []byte, offset, limit uint64, total bool) []string { args := []string{ fmt.Sprintf("--%s=json", tmcli.OutputFlag), @@ -123,7 +121,7 @@ func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdList<%= TypeName.UpperCamel %>(), args) require.NoError(t, err) var resp types.QueryAll<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.LessOrEqual(t, len(resp.<%= TypeName.UpperCamel %>), step) require.Subset(t, nullify.Fill(objs), @@ -139,7 +137,7 @@ func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdList<%= TypeName.UpperCamel %>(), args) require.NoError(t, err) var resp types.QueryAll<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.LessOrEqual(t, len(resp.<%= TypeName.UpperCamel %>), step) require.Subset(t, nullify.Fill(objs), @@ -153,7 +151,7 @@ func (s *IntegrationTestSuite) TestList<%= TypeName.UpperCamel %>() { out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdList<%= TypeName.UpperCamel %>(), args) require.NoError(t, err) var resp types.QueryAll<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NoError(t, err) require.Equal(t, len(objs), int(resp.Pagination.Total)) require.ElementsMatch(t, diff --git a/ignite/templates/typed/map/files/tests/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush b/ignite/templates/typed/map/files/tests/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush index 479169b9c2..094226e34a 100644 --- a/ignite/templates/typed/map/files/tests/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush +++ b/ignite/templates/typed/map/files/tests/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush @@ -20,12 +20,12 @@ var _ = strconv.IntSize func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + defer net.Cleanup() tests := []struct { desc string <%= for (i, index) in Indexes { %>id<%= index.Name.UpperCamel %> <%= index.DataType() %> @@ -42,7 +42,7 @@ func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), }, }, } @@ -70,27 +70,27 @@ func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestUpdate<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + common = []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), + } + args = []string{ + <%= for (i, index) in Indexes { %>"0", + <% } %> + } ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), - } - args := []string{ - <%= for (i, index) in Indexes { %>"0", - <% } %> - } - args = append(args, fields...) - args = append(args, common...) + args = append(args, fields...) + args = append(args, common...) + defer net.Cleanup() _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreate<%= TypeName.UpperCamel %>(), args) s.Require().NoError(err) - s.waitForNextBlock() + s.Require().NoError(net.WaitForNextBlock()) tests := []struct { desc string @@ -138,27 +138,27 @@ func (s *IntegrationTestSuite) TestUpdate<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestDelete<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + common = []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), + } + args = []string{ + <%= for (i, index) in Indexes { %>"0", + <% } %> + } ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), - } - args := []string{ - <%= for (i, index) in Indexes { %>"0", - <% } %> - } - args = append(args, fields...) - args = append(args, common...) + args = append(args, fields...) + args = append(args, common...) + defer net.Cleanup() _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreate<%= TypeName.UpperCamel %>(), args) s.Require().NoError(err) - s.waitForNextBlock() + s.Require().NoError(net.WaitForNextBlock()) tests := []struct { desc string diff --git a/ignite/templates/typed/singleton/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush b/ignite/templates/typed/singleton/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush index e106924ce4..b92b6886f7 100644 --- a/ignite/templates/typed/singleton/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush +++ b/ignite/templates/typed/singleton/files/component/x/{{moduleName}}/client/cli/query_{{typeName}}_test.go.plush @@ -9,32 +9,30 @@ import ( tmcli "github.com/cometbft/cometbft/libs/cli" "google.golang.org/grpc/status" + "<%= ModulePath %>/testutil/network" "<%= ModulePath %>/testutil/nullify" "<%= ModulePath %>/x/<%= ModuleName %>/client/cli" "<%= ModulePath %>/x/<%= ModuleName %>/types" ) -func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Objects() (types.<%= TypeName.UpperCamel %>) { +func (s *IntegrationTestSuite) networkWith<%= TypeName.UpperCamel %>Object() (*network.Network, types.<%= TypeName.UpperCamel %>) { s.T().Helper() state := types.GenesisState{<%= if (IsIBC) { %>PortId: types.PortID<% } %>} <%= TypeName.LowerCamel %> := &types.<%= TypeName.UpperCamel %>{} nullify.Fill(&<%= TypeName.LowerCamel %>) state.<%= TypeName.UpperCamel %> = <%= TypeName.LowerCamel %> - buf, err := s.cfg.Codec.MarshalJSON(&state) - s.Require().NoError(err) - s.cfg.GenesisState[types.ModuleName] = buf - return *state.<%= TypeName.UpperCamel %> + return s.network(&state), *state.<%= TypeName.UpperCamel %> } func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { var ( - obj = s.networkWith<%= TypeName.UpperCamel %>Objects() - net = s.network() - ctx = net.Validators[0].ClientCtx - common = []string{ + net, obj = s.networkWith<%= TypeName.UpperCamel %>Object() + ctx = net.Validators[0].ClientCtx + common = []string{ fmt.Sprintf("--%s=json", tmcli.OutputFlag), } ) + defer net.Cleanup() tests := []struct { desc string args []string @@ -59,7 +57,7 @@ func (s *IntegrationTestSuite) TestShow<%= TypeName.UpperCamel %>() { } require.NoError(t, err) var resp types.QueryGet<%= TypeName.UpperCamel %>Response - require.NoError(t, s.cfg.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) require.NotNil(t, resp.<%= TypeName.UpperCamel %>) require.Equal(t, nullify.Fill(&tc.obj), diff --git a/ignite/templates/typed/singleton/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush b/ignite/templates/typed/singleton/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush index 6d63845b90..2fb83a8cf6 100644 --- a/ignite/templates/typed/singleton/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush +++ b/ignite/templates/typed/singleton/files/messages/x/{{moduleName}}/client/cli/tx_{{typeName}}_test.go.plush @@ -15,12 +15,12 @@ import ( func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + defer net.Cleanup() tests := []struct { desc string args []string @@ -33,7 +33,7 @@ func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), }, }, } @@ -57,23 +57,23 @@ func (s *IntegrationTestSuite) TestCreate<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestUpdate<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + common = []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), + } + args = append([]string{}, fields...) ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), - } - args := append([]string{}, fields...) - args = append(args, common...) + args = append(args, common...) + defer net.Cleanup() _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreate<%= TypeName.UpperCamel %>(), args) s.Require().NoError(err) - s.waitForNextBlock() + s.Require().NoError(net.WaitForNextBlock()) tests := []struct { desc string @@ -106,23 +106,23 @@ func (s *IntegrationTestSuite) TestUpdate<%= TypeName.UpperCamel %>() { func (s *IntegrationTestSuite) TestDelete<%= TypeName.UpperCamel %>() { var ( - net = s.network() + net = s.network(nil) val = net.Validators[0] ctx = val.ClientCtx + fields = []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} + common = []string{ + fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()), + } + args = append([]string{}, fields...) ) - - fields := []string{<%= for (field) in Fields { %> "<%= field.DefaultTestValue() %>", <% } %>} - common := []string{ - fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), - } - args := append([]string{}, fields...) - args = append(args, common...) + args = append(args, common...) + defer net.Cleanup() _, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreate<%= TypeName.UpperCamel %>(), args) s.Require().NoError(err) - s.waitForNextBlock() + s.Require().NoError(net.WaitForNextBlock()) tests := []struct { desc string