Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignite
GitHub Repository: ignite/cli
Path: blob/main/integration/cosmosgen/cosmosgen_test.go
1007 views
1
package cosmosgen_test
2
3
import (
4
"os"
5
"path/filepath"
6
"testing"
7
8
"github.com/stretchr/testify/assert"
9
"github.com/stretchr/testify/require"
10
11
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step"
12
envtest "github.com/ignite/cli/v29/integration"
13
)
14
15
func TestCosmosGenScaffold(t *testing.T) {
16
if envtest.IsCI {
17
t.Skip("Skipping CosmosGenScaffold test in CI environment")
18
}
19
20
var (
21
env = envtest.New(t)
22
app = env.ScaffoldApp("github.com/test/blog")
23
)
24
25
const (
26
withMsgModuleName = "withmsg"
27
withoutMsgModuleName = "withoutmsg"
28
)
29
30
env.Must(env.Exec("add custom module with message",
31
step.NewSteps(step.New(
32
step.Exec(
33
envtest.IgniteApp,
34
"s",
35
"module",
36
"--yes",
37
withMsgModuleName,
38
),
39
step.Workdir(app.SourcePath()),
40
)),
41
))
42
43
env.Must(env.Exec("create a message",
44
step.NewSteps(step.New(
45
step.Exec(
46
envtest.IgniteApp,
47
"s",
48
"message",
49
"--yes",
50
"mymessage",
51
"myfield1",
52
"myfield2:bool",
53
"--module",
54
withMsgModuleName,
55
),
56
step.Workdir(app.SourcePath()),
57
)),
58
))
59
60
env.Must(env.Exec("add custom module without message",
61
step.NewSteps(step.New(
62
step.Exec(
63
envtest.IgniteApp,
64
"s",
65
"module",
66
"--yes",
67
withoutMsgModuleName,
68
),
69
step.Workdir(app.SourcePath()),
70
)),
71
))
72
73
env.Must(env.Exec("create a type",
74
step.NewSteps(step.New(
75
step.Exec(
76
envtest.IgniteApp,
77
"s",
78
"type",
79
"--yes",
80
"mytype",
81
"mytypefield",
82
"--module",
83
withoutMsgModuleName,
84
),
85
step.Workdir(app.SourcePath()),
86
)),
87
))
88
89
env.Must(env.Exec("create a query",
90
step.NewSteps(step.New(
91
step.Exec(
92
envtest.IgniteApp,
93
"s",
94
"query",
95
"--yes",
96
"myQuery",
97
"mytypefield",
98
"--module",
99
withoutMsgModuleName,
100
),
101
step.Workdir(app.SourcePath()),
102
)),
103
))
104
105
tsDirGenerated := filepath.Join(app.SourcePath(), "ts-client")
106
require.NoError(t, os.RemoveAll(tsDirGenerated))
107
108
env.Must(env.Exec("generate typescript",
109
step.NewSteps(step.New(
110
step.Exec(
111
envtest.IgniteApp,
112
"g",
113
"ts-client",
114
"--yes",
115
"--clear-cache",
116
),
117
step.Workdir(app.SourcePath()),
118
)),
119
))
120
121
expectedModules := []string{
122
"cosmos.auth.v1beta1",
123
"cosmos.authz.v1beta1",
124
"cosmos.bank.v1beta1",
125
"cosmos.base.tendermint.v1beta1",
126
"cosmos.distribution.v1beta1",
127
"cosmos.evidence.v1beta1",
128
"cosmos.feegrant.v1beta1",
129
"cosmos.gov.v1beta1",
130
"cosmos.gov.v1",
131
"cosmos.group.v1",
132
"cosmos.mint.v1beta1",
133
"cosmos.nft.v1beta1",
134
"cosmos.params.v1beta1",
135
"cosmos.slashing.v1beta1",
136
"cosmos.staking.v1beta1",
137
"cosmos.tx.v1beta1",
138
"cosmos.upgrade.v1beta1",
139
"cosmos.vesting.v1beta1",
140
// custom modules
141
"blog.blog.v1",
142
"blog.withmsg.v1",
143
"blog.withoutmsg.v1",
144
}
145
146
for _, mod := range expectedModules {
147
_, err := os.Stat(filepath.Join(tsDirGenerated, mod))
148
if assert.False(t, os.IsNotExist(err), "missing module %q in %s", mod, tsDirGenerated) {
149
assert.NoError(t, err)
150
}
151
}
152
153
if t.Failed() {
154
// list ts-client files
155
tsFiles, err := os.ReadDir(tsDirGenerated)
156
require.NoError(t, err)
157
t.Log("TS files:", len(tsFiles))
158
for _, file := range tsFiles {
159
t.Logf(" - %s", file.Name())
160
}
161
}
162
}
163
164