-
Notifications
You must be signed in to change notification settings - Fork 122
/
interchain_builder.go
141 lines (114 loc) · 3.63 KB
/
interchain_builder.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
package interchaintest
import (
"context"
"testing"
"github.com/docker/docker/client"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/relayer"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
)
type codecRegistry func(registry codectypes.InterfaceRegistry)
// RegisterInterfaces registers the interfaces for the input codec register functions.
func RegisterInterfaces(codecIR ...codecRegistry) *testutil.TestEncodingConfig {
cfg := cosmos.DefaultEncoding()
for _, r := range codecIR {
r(cfg.InterfaceRegistry)
}
return &cfg
}
// CreateChainWithConfig builds a single chain from the given ibc config.
func CreateChainWithConfig(t *testing.T, numVals, numFull int, name, version string, config ibc.ChainConfig) []ibc.Chain {
t.Helper()
if version == "" {
if len(config.Images) == 0 {
version = "latest"
t.Logf("no image version specified in config, using %s", version)
} else {
version = config.Images[0].Version
}
}
cf := NewBuiltinChainFactory(zaptest.NewLogger(t), []*ChainSpec{
{
Name: name,
ChainName: name,
Version: version,
ChainConfig: config,
NumValidators: &numVals,
NumFullNodes: &numFull,
},
})
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
return chains
}
// CreateChainsWithChainSpecs builds multiple chains from the given chain specs.
func CreateChainsWithChainSpecs(t *testing.T, chainSpecs []*ChainSpec) []ibc.Chain {
t.Helper()
cf := NewBuiltinChainFactory(zaptest.NewLogger(t), chainSpecs)
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
return chains
}
func BuildInitialChainWithRelayer(
t *testing.T,
chains []ibc.Chain,
enableBlockDB bool,
rly ibc.RelayerImplementation,
relayerFlags []string,
links []InterchainLink,
skipPathCreations bool,
) (context.Context, *Interchain, ibc.Relayer, *testreporter.Reporter, *testreporter.RelayerExecReporter, *client.Client, string) {
t.Helper()
ctx := context.Background()
rep := testreporter.NewNopReporter()
eRep := rep.RelayerExecReporter(t)
client, network := DockerSetup(t)
ic := NewInterchain()
for _, chain := range chains {
ic = ic.AddChain(chain)
}
var r ibc.Relayer
if links != nil {
r = NewBuiltinRelayerFactory(
rly,
zaptest.NewLogger(t),
relayer.StartupFlags(relayerFlags...),
).Build(t, client, network)
ic.AddRelayer(r, "relayer")
for _, link := range links {
link.Relayer = r
ic = ic.AddLink(link)
}
}
opt := InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
SkipPathCreation: skipPathCreations,
}
if enableBlockDB {
// This can be used to write to the block database which will index all block data e.g. txs, msgs, events, etc.
opt.BlockDatabaseFile = DefaultBlockDatabaseFilepath()
}
err := ic.Build(ctx, eRep, opt)
require.NoError(t, err)
t.Cleanup(func() {
_ = ic.Close()
if r != nil {
if err := r.StopRelayer(ctx, eRep); err != nil {
t.Logf("an error occurred while stopping the relayer: %s", err)
}
}
})
return ctx, ic, r, rep, eRep, client, network
}
func BuildInitialChain(t *testing.T, chains []ibc.Chain, enableBlockDB bool) (context.Context, *Interchain, *client.Client, string) {
t.Helper()
ctx, ic, _, _, _, client, network := BuildInitialChainWithRelayer(t, chains, enableBlockDB, 0, nil, nil, true)
return ctx, ic, client, network
}