forked from strangelove-ventures/interchaintest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relayerfactory.go
109 lines (97 loc) · 3.14 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
package interchaintest
import (
"fmt"
"testing"
"github.com/docker/docker/client"
"github.com/strangelove-ventures/interchaintest/v6/ibc"
"github.com/strangelove-ventures/interchaintest/v6/label"
"github.com/strangelove-ventures/interchaintest/v6/relayer"
"github.com/strangelove-ventures/interchaintest/v6/relayer/rly"
"go.uber.org/zap"
)
// RelayerFactory describes how to start a Relayer.
type RelayerFactory interface {
// Build returns a Relayer associated with the given arguments.
Build(
t *testing.T,
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
// Labels are reported to allow simple filtering of tests depending on this Relayer.
// While the Name should be fully descriptive,
// the Labels are intended to be short and fixed.
//
// Most relayers will probably only have one label indicative of its name,
// but we allow multiple labels for future compatibility.
Labels() []label.Relayer
// 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.RelayerOptions
}
func NewBuiltinRelayerFactory(impl ibc.RelayerImplementation, logger *zap.Logger, options ...relayer.RelayerOption) RelayerFactory {
return builtinRelayerFactory{impl: impl, log: logger, options: options}
}
// Build returns a relayer chosen depending on f.impl.
func (f builtinRelayerFactory) Build(
t *testing.T,
cli *client.Client,
networkID string,
) ibc.Relayer {
switch f.impl {
case ibc.CosmosRly:
return rly.NewCosmosRelayer(
f.log,
t.Name(),
cli,
networkID,
f.options...,
)
default:
panic(fmt.Errorf("RelayerImplementation %v unknown", f.impl))
}
}
func (f builtinRelayerFactory) Name() string {
switch f.impl {
case ibc.CosmosRly:
// This is using the string "rly" instead of rly.ContainerImage
// so that the slashes in the image repository don't add ambiguity
// to subtest paths, when the factory name is used in calls to t.Run.
for _, opt := range f.options {
switch o := opt.(type) {
case relayer.RelayerOptionDockerImage:
return "rly@" + o.DockerImage.Version
}
}
return "rly@" + rly.DefaultContainerVersion
default:
panic(fmt.Errorf("RelayerImplementation %v unknown", f.impl))
}
}
func (f builtinRelayerFactory) Labels() []label.Relayer {
switch f.impl {
case ibc.CosmosRly:
return []label.Relayer{label.Rly}
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()
default:
panic(fmt.Errorf("RelayerImplementation %v unknown", f.impl))
}
}