-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelayerfactory.go
80 lines (71 loc) · 2.07 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
package rollupe2etesting
import (
"fmt"
"github.com/decentrio/rollup-e2e-testing/ibc"
"github.com/decentrio/rollup-e2e-testing/relayer"
rly "github.com/decentrio/rollup-e2e-testing/relayer/rly"
"github.com/docker/docker/client"
"go.uber.org/zap"
)
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,
relayerName, networkID string,
) ibc.Relayer
// Name returns a descriptive name of the factory,
// indicating details of the Relayer that will be built.
Name() string
}
// 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 TestName,
cli *client.Client,
relayerName, networkID string,
) ibc.Relayer {
switch f.impl {
case ibc.CosmosRly:
return rly.NewCosmosRelayer(
f.log,
t.Name(),
cli,
relayerName,
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))
}
}