Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignite
GitHub Repository: ignite/cli
Path: blob/main/integration/chain/config_test.go
1007 views
1
//go:build !relayer
2
3
package chain_test
4
5
import (
6
"context"
7
"fmt"
8
"path/filepath"
9
"testing"
10
11
"github.com/stretchr/testify/require"
12
13
chainconfig "github.com/ignite/cli/v29/ignite/config/chain"
14
"github.com/ignite/cli/v29/ignite/pkg/confile"
15
"github.com/ignite/cli/v29/ignite/pkg/randstr"
16
envtest "github.com/ignite/cli/v29/integration"
17
)
18
19
func TestOverwriteSDKConfigsAndChainID(t *testing.T) {
20
var (
21
env = envtest.New(t)
22
appname = randstr.Runes(10)
23
app = env.ScaffoldApp(fmt.Sprintf("github.com/test/%s", appname))
24
servers = app.RandomizeServerPorts()
25
ctx, cancel = context.WithCancel(env.Ctx())
26
isBackendAliveErr error
27
)
28
29
var cfg chainconfig.Config
30
cf := confile.New(confile.DefaultYAMLEncodingCreator, filepath.Join(app.SourcePath(), "config.yml"))
31
require.NoError(t, cf.Load(&cfg))
32
33
cfg.Genesis = map[string]interface{}{"chain_id": "cosmos"}
34
cfg.Validators[0].App["hello"] = "cosmos"
35
cfg.Validators[0].Config["log_format"] = "json"
36
37
require.NoError(t, cf.Save(cfg))
38
39
go func() {
40
defer cancel()
41
isBackendAliveErr = env.IsAppServed(ctx, servers.API)
42
}()
43
44
app.MustServe(ctx)
45
require.NoError(t, isBackendAliveErr, "app cannot get online in time")
46
47
cases := []struct {
48
ec confile.EncodingCreator
49
relpath string
50
key string
51
want interface{}
52
}{
53
{confile.DefaultJSONEncodingCreator, "config/genesis.json", "chain_id", "cosmos"},
54
{confile.DefaultTOMLEncodingCreator, "config/app.toml", "hello", "cosmos"},
55
{confile.DefaultTOMLEncodingCreator, "config/config.toml", "log_format", "json"},
56
}
57
for _, tt := range cases {
58
t.Run("test "+tt.relpath, func(t *testing.T) {
59
var conf map[string]interface{}
60
61
path := filepath.Join(env.AppHome(appname), tt.relpath)
62
c := confile.New(tt.ec, path)
63
64
require.NoError(t, c.Load(&conf))
65
require.Equalf(t, tt.want, conf[tt.key], "unexpected value for %s", tt.relpath)
66
})
67
}
68
}
69
70