forked from strangelove-ventures/interchaintest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relayerfactory.go
121 lines (108 loc) · 3.19 KB
/
relayerfactory.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
package interchaintest
import (
"fmt"
"github.com/docker/docker/client"
"go.uber.org/zap"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"github.com/strangelove-ventures/interchaintest/v7/relayer"
"github.com/strangelove-ventures/interchaintest/v7/relayer/hermes"
"github.com/strangelove-ventures/interchaintest/v7/relayer/hyperspace"
"github.com/strangelove-ventures/interchaintest/v7/relayer/icq"
"github.com/strangelove-ventures/interchaintest/v7/relayer/rly"
)
type TestName interface {
Name() string
}
// RelayerFactory describes how to start a Relayer.
type RelayerFactory interface {
// Build returns a Relayer associated with the given arguments.
Build(
t TestName,
cli *client.Client,
networkID string,
) ibc.Relayer
// Name returns a descriptive name of the factory,
// indicating details of the Relayer that will be built.
Name() string
// Capabilities is an indication of the features this relayer supports.
// Tests for any unsupported features will be skipped rather than failed.
Capabilities() map[relayer.Capability]bool
}
// builtinRelayerFactory is the built-in relayer factory that understands
// how to start the cosmos relayer in a docker container.
type builtinRelayerFactory struct {
impl ibc.RelayerImplementation
log *zap.Logger
options []relayer.RelayerOpt
version string
}
func NewBuiltinRelayerFactory(impl ibc.RelayerImplementation, logger *zap.Logger, options ...relayer.RelayerOpt) RelayerFactory {
return &builtinRelayerFactory{impl: impl, log: logger, options: options}
}
// Build returns a relayer chosen depending on f.impl.
func (f *builtinRelayerFactory) Build(
t TestName,
cli *client.Client,
networkID string,
) ibc.Relayer {
switch f.impl {
case ibc.CosmosRly:
r := rly.NewCosmosRelayer(
f.log,
t.Name(),
cli,
networkID,
f.options...,
)
f.setRelayerVersion(r.ContainerImage())
return r
case ibc.Hyperspace:
return hyperspace.NewHyperspaceRelayer(
f.log,
t.Name(),
cli,
networkID,
f.options...,
)
case ibc.Hermes:
r := hermes.NewHermesRelayer(f.log, t.Name(), cli, networkID, f.options...)
f.setRelayerVersion(r.ContainerImage())
return r
case ibc.Icq:
return icq.NewIcqRelayer(f.log, t.Name(), cli, networkID, f.options...)
default:
panic(fmt.Errorf("RelayerImplementation %v unknown", f.impl))
}
}
func (f *builtinRelayerFactory) setRelayerVersion(di ibc.DockerImage) {
f.version = di.Version
}
func (f *builtinRelayerFactory) Name() string {
switch f.impl {
case ibc.CosmosRly:
if f.version == "" {
return "rly@" + f.version
}
return "rly@" + rly.DefaultContainerVersion
case ibc.Hermes:
if f.version == "" {
return "hermes@" + f.version
}
return "hermes@" + hermes.DefaultContainerVersion
default:
panic(fmt.Errorf("RelayerImplementation %v unknown", f.impl))
}
}
// Capabilities returns the set of capabilities for the
// relayer implementation backing this factory.
func (f builtinRelayerFactory) Capabilities() map[relayer.Capability]bool {
switch f.impl {
case ibc.CosmosRly:
return rly.Capabilities()
case ibc.Hermes:
// TODO: specify capability for hermes.
return rly.Capabilities()
default:
panic(fmt.Errorf("RelayerImplementation %v unknown", f.impl))
}
}