Skip to content

Commit ce30e2b

Browse files
author
jeronimoalbi
committed
tests: fix broken network publish integration test
1 parent a953084 commit ce30e2b

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

ignite/chainconfig/config/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ type Host struct {
148148

149149
// BaseConfig defines a struct with the fields that are common to all config versions.
150150
type BaseConfig struct {
151-
Version Version `yaml:"version"`
152-
Build Build `yaml:"build"`
153-
Accounts []Account `yaml:"accounts"`
154-
Faucet Faucet `yaml:"faucet,omitempty"`
155-
Client Client `yaml:"client,omitempty"`
156-
Genesis map[string]interface{} `yaml:"genesis,omitempty"`
151+
Version Version `yaml:"version"`
152+
Build Build `yaml:"build"`
153+
Accounts []Account `yaml:"accounts"`
154+
Faucet Faucet `yaml:"faucet,omitempty"`
155+
Client Client `yaml:"client,omitempty"`
156+
Genesis xyaml.Map `yaml:"genesis,omitempty"`
157157
}
158158

159159
// GetVersion returns the config version.

integration/app/tx_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ func TestSignTxWithDashedAppName(t *testing.T) {
2525
env = envtest.New(t)
2626
appname = "dashed-app-name"
2727
app = env.Scaffold(appname)
28-
host = app.RandomizeServerPorts()
28+
servers = app.RandomizeServerPorts()
2929
ctx, cancel = context.WithCancel(env.Ctx())
3030
)
3131

32-
nodeAddr, err := xurl.TCP(host.RPC)
32+
nodeAddr, err := xurl.TCP(servers.RPC)
3333
if err != nil {
34-
t.Fatalf("cant read nodeAddr from host.RPC %v: %v", host.RPC, err)
34+
t.Fatalf("cant read nodeAddr from host.RPC %v: %v", servers.RPC, err)
3535
}
3636

3737
env.Exec("scaffold a simple list",
@@ -65,13 +65,13 @@ func TestSignTxWithDashedAppName(t *testing.T) {
6565
"output", "json",
6666
),
6767
step.PreExec(func() error {
68-
return env.IsAppServed(ctx, host)
68+
return env.IsAppServed(ctx, servers.API)
6969
}),
7070
),
7171
step.New(
7272
step.Stdout(output),
7373
step.PreExec(func() error {
74-
err := env.IsAppServed(ctx, host)
74+
err := env.IsAppServed(ctx, servers.API)
7575
return err
7676
}),
7777
step.Exec(
@@ -116,7 +116,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
116116
env = envtest.New(t)
117117
appname = randstr.Runes(10)
118118
app = env.Scaffold(fmt.Sprintf("github.com/test/%s", appname))
119-
host = app.RandomizeServerPorts()
119+
servers = app.RandomizeServerPorts()
120120
ctx, cancel = context.WithCancel(env.Ctx())
121121
)
122122

@@ -148,7 +148,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
148148
"output", "json",
149149
),
150150
step.PreExec(func() error {
151-
return env.IsAppServed(ctx, host)
151+
return env.IsAppServed(ctx, servers.API)
152152
}),
153153
),
154154
step.New(
@@ -182,7 +182,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
182182
return errors.New("expected alice and bob accounts to be created")
183183
}
184184

185-
nodeAddr, err := xurl.TCP(host.RPC)
185+
nodeAddr, err := xurl.TCP(servers.RPC)
186186
if err != nil {
187187
return err
188188
}
@@ -219,7 +219,7 @@ func TestGetTxViaGRPCGateway(t *testing.T) {
219219
return err
220220
}
221221

222-
apiAddr, err := xurl.HTTP(host.API)
222+
apiAddr, err := xurl.HTTP(servers.API)
223223
if err != nil {
224224
return err
225225
}

integration/network/network_test.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"os"
77
"path"
8+
"path/filepath"
89
"strings"
910
"testing"
1011

@@ -13,14 +14,16 @@ import (
1314
"github.com/go-git/go-git/v5/plumbing"
1415
"github.com/stretchr/testify/require"
1516

17+
"github.com/ignite/cli/ignite/chainconfig"
1618
"github.com/ignite/cli/ignite/pkg/cmdrunner/step"
1719
"github.com/ignite/cli/ignite/pkg/gomodule"
1820
envtest "github.com/ignite/cli/integration"
1921
)
2022

2123
const (
22-
spnModule = "github.com/tendermint/spn"
23-
spnRepoURL = "https://" + spnModule
24+
spnModule = "github.com/tendermint/spn"
25+
spnRepoURL = "https://" + spnModule
26+
spnConfigFile = "config_2.yml"
2427
)
2528

2629
func cloneSPN(t *testing.T) string {
@@ -66,27 +69,53 @@ func cloneSPN(t *testing.T) string {
6669
return path
6770
}
6871

72+
func migrateSPNConfig(t *testing.T, spnPath string) {
73+
configPath := filepath.Join(spnPath, spnConfigFile)
74+
rawCfg, err := os.ReadFile(configPath)
75+
require.NoError(t, err)
76+
77+
version, err := chainconfig.ReadConfigVersion(bytes.NewReader(rawCfg))
78+
require.NoError(t, err)
79+
if version != chainconfig.LatestVersion {
80+
t.Logf("migrating spn config from v%d to v%d", version, chainconfig.LatestVersion)
81+
82+
file, err := os.OpenFile(configPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755)
83+
require.NoError(t, err)
84+
85+
defer file.Close()
86+
87+
err = chainconfig.MigrateLatest(bytes.NewReader(rawCfg), file)
88+
require.NoError(t, err)
89+
}
90+
}
91+
6992
func TestNetworkPublish(t *testing.T) {
7093
var (
7194
spnPath = cloneSPN(t)
7295
env = envtest.New(t)
7396
spn = env.App(
7497
spnPath,
7598
envtest.AppHomePath(t.TempDir()),
76-
envtest.AppConfigPath(path.Join(spnPath, "config_2.yml")),
99+
envtest.AppConfigPath(path.Join(spnPath, spnConfigFile)),
77100
)
78-
servers = spn.Config().Host
79101
)
80102

81103
var (
82104
ctx, cancel = context.WithTimeout(env.Ctx(), envtest.ServeTimeout)
83105
isBackendAliveErr error
84106
)
85107

108+
// Make sure that the SPN config file is at the latest version
109+
migrateSPNConfig(t, spnPath)
110+
111+
validator := spn.Config().Validators[0]
112+
servers, err := validator.GetServers()
113+
require.NoError(t, err)
114+
86115
go func() {
87116
defer cancel()
88117

89-
if isBackendAliveErr = env.IsAppServed(ctx, servers); isBackendAliveErr != nil {
118+
if isBackendAliveErr = env.IsAppServed(ctx, servers.API.Address); isBackendAliveErr != nil {
90119
return
91120
}
92121
var b bytes.Buffer

0 commit comments

Comments
 (0)