Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignite
GitHub Repository: ignite/cli
Path: blob/main/integration/app/cmd_app_test.go
1007 views
1
//go:build !relayer
2
3
package app_test
4
5
import (
6
"bytes"
7
"os"
8
"path/filepath"
9
"testing"
10
11
"github.com/stretchr/testify/require"
12
13
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step"
14
"github.com/ignite/cli/v29/ignite/services/chain"
15
envtest "github.com/ignite/cli/v29/integration"
16
)
17
18
// TestGenerateAnApp tests scaffolding a new chain.
19
func TestGenerateAnApp(t *testing.T) {
20
var (
21
env = envtest.New(t)
22
app = env.ScaffoldApp("github.com/test/blog")
23
)
24
25
_, statErr := os.Stat(filepath.Join(app.SourcePath(), "x", "blog"))
26
require.False(t, os.IsNotExist(statErr), "the default module should be scaffolded")
27
28
app.EnsureSteady()
29
}
30
31
// TestGenerateAnAppMinimal tests scaffolding a new minimal chain.
32
func TestGenerateAnAppMinimal(t *testing.T) {
33
var (
34
env = envtest.New(t)
35
app = env.ScaffoldApp("blog", "--minimal")
36
)
37
38
_, statErr := os.Stat(filepath.Join(app.SourcePath(), "x", "blog"))
39
require.False(t, os.IsNotExist(statErr), "the default module should be scaffolded")
40
41
app.EnsureSteady()
42
}
43
44
// TestGenerateAnAppWithName tests scaffolding a new chain using a local name instead of a GitHub URI.
45
func TestGenerateAnAppWithName(t *testing.T) {
46
var (
47
env = envtest.New(t)
48
app = env.ScaffoldApp("blog")
49
)
50
51
_, statErr := os.Stat(filepath.Join(app.SourcePath(), "x", "blog"))
52
require.False(t, os.IsNotExist(statErr), "the default module should be scaffolded")
53
54
app.EnsureSteady()
55
}
56
57
// TestGenerateAnAppWithInvalidName tests scaffolding a new chain using an invalid name.
58
func TestGenerateAnAppWithInvalidName(t *testing.T) {
59
buf := new(bytes.Buffer)
60
61
env := envtest.New(t)
62
env.Must(env.Exec("should prevent creating an app with an invalid name",
63
step.NewSteps(step.New(
64
step.Exec(envtest.IgniteApp, "s", "chain", "blog2"),
65
step.Stdout(buf),
66
step.Stderr(buf),
67
)),
68
envtest.ExecShouldError(),
69
))
70
71
require.Contains(t, buf.String(), "Invalid app name blog2: cannot contain numbers")
72
}
73
74
func TestGenerateAnAppWithNoDefaultModule(t *testing.T) {
75
var (
76
env = envtest.New(t)
77
app = env.ScaffoldApp("github.com/test/blog", "--no-module")
78
)
79
80
_, statErr := os.Stat(filepath.Join(app.SourcePath(), "x", "blog"))
81
require.True(t, os.IsNotExist(statErr), "the default module should not be scaffolded")
82
83
app.EnsureSteady()
84
}
85
86
func TestGenerateAnAppWithNoDefaultModuleAndCreateAModule(t *testing.T) {
87
var (
88
env = envtest.New(t)
89
app = env.ScaffoldApp("github.com/test/blog", "--no-module")
90
)
91
92
defer app.EnsureSteady()
93
94
app.Scaffold(
95
"should scaffold a new module into a chain that never had modules before",
96
false,
97
"module", "first_module",
98
)
99
}
100
101
func TestGenerateAppWithEmptyModule(t *testing.T) {
102
var (
103
env = envtest.New(t)
104
app = env.ScaffoldApp("github.com/test/blog")
105
)
106
107
app.Scaffold(
108
"create a module",
109
false,
110
"module", "example", "--require-registration",
111
)
112
113
app.Scaffold(
114
"should prevent creating an existing module",
115
true,
116
"module", "example", "--require-registration",
117
)
118
119
app.Scaffold(
120
"should prevent creating a module with an invalid name",
121
true,
122
"module", "example1", "--require-registration",
123
)
124
125
app.Scaffold(
126
"should prevent creating a module with a reserved name",
127
true,
128
"module", "tx", "--require-registration",
129
)
130
131
app.Scaffold(
132
"should prevent creating a module with a forbidden prefix",
133
true,
134
"module", "ibcfoo", "--require-registration",
135
)
136
137
app.Scaffold(
138
"should prevent creating a module prefixed with an existing module",
139
true,
140
"module", "examplefoo", "--require-registration",
141
)
142
143
app.Scaffold(
144
"create a module with dependencies",
145
false,
146
"module",
147
"with_dep",
148
"--dep",
149
"auth,bank,staking,slashing,example",
150
"--require-registration",
151
)
152
153
app.Scaffold(
154
"should prevent creating a module with invalid dependencies",
155
true,
156
"module",
157
"with_wrong_dep",
158
"--dep",
159
"dup,dup",
160
"--require-registration",
161
)
162
163
app.Scaffold(
164
"should prevent creating a module with a non registered dependency",
165
true,
166
"module",
167
"with_no_dep",
168
"--dep",
169
"inexistent",
170
"--require-registration",
171
)
172
173
app.EnsureSteady()
174
}
175
176
func TestGenerateAnAppWithAddressPrefix(t *testing.T) {
177
var (
178
env = envtest.New(t)
179
app = env.ScaffoldApp("github.com/test/blog", "--address-prefix=gm", "--coin-type=60")
180
)
181
182
_, statErr := os.Stat(filepath.Join(app.SourcePath(), "x", "blog"))
183
require.False(t, os.IsNotExist(statErr), "the default module should be scaffolded")
184
185
c, err := chain.New(app.SourcePath())
186
require.NoError(t, err, "failed to get new chain")
187
188
bech32Prefix, err := c.Bech32Prefix()
189
require.NoError(t, err)
190
191
require.Equal(t, bech32Prefix, "gm")
192
193
coinType, err := c.CoinType()
194
require.NoError(t, err, "failed to get coin type")
195
require.Equal(t, coinType, uint32(60))
196
197
app.EnsureSteady()
198
}
199
200
func TestGenerateAnAppWithDefaultDenom(t *testing.T) {
201
var (
202
env = envtest.New(t)
203
app = env.ScaffoldApp("github.com/test/blog", "--default-denom=good")
204
)
205
206
_, statErr := os.Stat(filepath.Join(app.SourcePath(), "x", "blog"))
207
require.False(t, os.IsNotExist(statErr), "the default module should be scaffolded")
208
209
c, err := chain.New(app.SourcePath())
210
require.NoError(t, err, "failed to get new chain")
211
212
cfg, err := c.Config()
213
require.NoError(t, err)
214
215
require.Equal(t, cfg.DefaultDenom, "good")
216
217
app.EnsureSteady()
218
}
219
220