forked from strangelove-ventures/interchaintest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chainspec_test.go
179 lines (143 loc) · 4.27 KB
/
chainspec_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package interchaintest_test
import (
"regexp"
"testing"
"github.com/google/go-cmp/cmp"
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)
func TestChainSpec_Config(t *testing.T) {
t.Run("valid", func(t *testing.T) {
s := interchaintest.ChainSpec{
Name: "gaia",
Version: "v7.0.1",
}
_, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)
})
t.Run("missing UidGid", func(t *testing.T) {
s := interchaintest.ChainSpec{
Name: "gaia",
Version: "v7.0.1",
ChainConfig: ibc.ChainConfig{
Type: "cosmos",
// Skip Name, as that is intended to be inherited from ChainName.
ChainID: "mychain-123",
Images: []ibc.DockerImage{
{Repository: "docker.example.com", Version: "latest"},
},
Bin: "/bin/true",
Bech32Prefix: "foo",
Denom: "bar",
GasPrices: "1bar",
GasAdjustment: 2,
TrustingPeriod: "24h",
},
}
_, err := s.Config(zaptest.NewLogger(t))
require.Error(t, err)
})
t.Run("omit name when all other fields provided", func(t *testing.T) {
s := interchaintest.ChainSpec{
ChainName: "mychain",
ChainConfig: ibc.ChainConfig{
Type: "cosmos",
// Skip Name, as that is intended to be inherited from ChainName.
ChainID: "mychain-123",
Images: []ibc.DockerImage{
{Repository: "docker.example.com", Version: "latest", UidGid: "1:1"},
},
Bin: "/bin/true",
Bech32Prefix: "foo",
Denom: "bar",
GasPrices: "1bar",
GasAdjustment: 2,
TrustingPeriod: "24h",
},
}
_, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)
})
t.Run("consistently generated config", func(t *testing.T) {
s := interchaintest.ChainSpec{
Name: "gaia",
Version: "v7.0.1",
}
cfg1, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)
cfg2, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)
diff := cmp.Diff(cfg1, cfg2)
require.Empty(t, diff, "diff when generating config multiple times")
})
t.Run("name and chain ID generation", func(t *testing.T) {
t.Run("same name and chain ID generated when ChainName and ChainID omitted", func(t *testing.T) {
s := interchaintest.ChainSpec{
Name: "gaia",
Version: "v7.0.1",
}
cfg, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^gaia-\d+$`), cfg.Name)
require.Equal(t, cfg.Name, cfg.ChainID)
})
t.Run("chain ID generated from ChainName, when ChainName provided", func(t *testing.T) {
s := interchaintest.ChainSpec{
Name: "gaia",
ChainName: "mychain",
Version: "v7.0.1",
}
cfg, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)
require.Equal(t, "mychain", cfg.Name)
require.Regexp(t, regexp.MustCompile(`^mychain-\d+$`), cfg.ChainID)
})
})
t.Run("overrides", func(t *testing.T) {
baseSpec := &interchaintest.ChainSpec{
Name: "gaia",
Version: "v7.0.1",
ChainName: "g",
ChainConfig: ibc.ChainConfig{
ChainID: "g-0000",
},
}
baseCfg, err := baseSpec.Config(zaptest.NewLogger(t))
require.NoError(t, err)
t.Run("NoHostMount", func(t *testing.T) {
m := true
require.NotEqual(t, baseCfg.NoHostMount, m)
s := baseSpec
s.NoHostMount = &m
cfg, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)
require.Equal(t, m, cfg.NoHostMount)
})
})
t.Run("error cases", func(t *testing.T) {
t.Run("version required", func(t *testing.T) {
s := interchaintest.ChainSpec{
Name: "gaia",
}
_, err := s.Config(zaptest.NewLogger(t))
require.EqualError(t, err, "ChainSpec.Version must not be empty")
})
t.Run("name required", func(t *testing.T) {
s := interchaintest.ChainSpec{
Version: "v1.2.3",
}
_, err := s.Config(zaptest.NewLogger(t))
require.EqualError(t, err, "ChainSpec.Name required when not all config fields are set")
})
t.Run("name invalid", func(t *testing.T) {
s := interchaintest.ChainSpec{
Name: "invalid_chain",
Version: "v1.2.3",
}
_, err := s.Config(zaptest.NewLogger(t))
require.ErrorContains(t, err, "no chain configuration for invalid_chain (available chains are:")
})
})
}