-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathdocker_test.go
More file actions
271 lines (229 loc) · 8.85 KB
/
Copy pathdocker_test.go
File metadata and controls
271 lines (229 loc) · 8.85 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//go:build docker_e2e
package docker_e2e
import (
"context"
"encoding/hex"
"fmt"
"os"
"strings"
"testing"
"cosmossdk.io/math"
"github.com/celestiaorg/go-square/v2/share"
tastoradocker "github.com/celestiaorg/tastora/framework/docker"
"github.com/celestiaorg/tastora/framework/docker/container"
"github.com/celestiaorg/tastora/framework/testutil/sdkacc"
tastoratypes "github.com/celestiaorg/tastora/framework/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
dockerclient "github.com/moby/moby/client"
"github.com/stretchr/testify/suite"
"go.uber.org/zap/zaptest"
)
const (
// testChainID is the chain ID used for testing.
// it must be the string "test" as it is handled explicitly in app/node.
testChainID = "test"
// celestiaAppVersion specifies the tag of the celestia-app image to deploy in tests.
celestiaAppVersion = "v5.0.2"
)
func init() {
sdkConf := sdk.GetConfig()
sdkConf.SetBech32PrefixForAccount("celestia", "celestiapub")
sdkConf.Seal()
}
func TestDockerSuite(t *testing.T) {
if testing.Short() {
t.Skip("skipping due to short mode")
}
suite.Run(t, new(DockerTestSuite))
}
type DockerTestSuite struct {
suite.Suite
provider tastoratypes.Provider
celestia tastoratypes.Chain
daNetwork tastoratypes.DataAvailabilityNetwork
evNodeChain tastoratypes.RollkitChain
dockerClient *dockerclient.Client
dockerNetworkID string
}
// ConfigOption is a function type for modifying tastoradocker.Config
type ConfigOption func(*tastoradocker.Config)
// CreateDockerProvider creates a new tastoratypes.Provider with optional configuration modifications
func (s *DockerTestSuite) CreateDockerProvider(opts ...ConfigOption) tastoratypes.Provider {
t := s.T()
client, network := tastoradocker.DockerSetup(t)
// Store client and network ID in the suite for later use
s.dockerClient = client
s.dockerNetworkID = network
cfg := tastoradocker.Config{
Logger: zaptest.NewLogger(t),
DockerClient: client,
DockerNetworkID: network,
DataAvailabilityNetworkConfig: &tastoradocker.DataAvailabilityNetworkConfig{
BridgeNodeCount: 1,
Image: container.NewImage("ghcr.io/celestiaorg/celestia-node", "v0.25.2-mocha", "10001:10001"),
},
RollkitChainConfig: &tastoradocker.RollkitChainConfig{
ChainID: "rollkit-test",
Bin: "testapp",
AggregatorPassphrase: "12345678",
NumNodes: 1,
Image: getEvNodeImage(),
},
}
for _, opt := range opts {
opt(&cfg)
}
return tastoradocker.NewProvider(cfg, t)
}
// getGenesisHash returns the genesis hash of the given chain node.
func (s *DockerTestSuite) getGenesisHash(ctx context.Context) string {
node := s.celestia.GetNodes()[0]
c, err := node.GetRPCClient()
s.Require().NoError(err, "failed to get node client")
first := int64(1)
block, err := c.Block(ctx, &first)
s.Require().NoError(err, "failed to get block")
genesisHash := block.Block.Header.Hash().String()
s.Require().NotEmpty(genesisHash, "genesis hash is empty")
return genesisHash
}
// SetupDockerResources creates a new provider and chain using the given configuration options.
// none of the resources are started.
func (s *DockerTestSuite) SetupDockerResources(opts ...ConfigOption) {
s.provider = s.CreateDockerProvider(opts...)
s.celestia = s.CreateChain()
s.daNetwork = s.CreateDANetwork()
s.evNodeChain = s.CreateEvolveChain()
}
// CreateChain creates a chain using the ChainBuilder pattern.
func (s *DockerTestSuite) CreateChain() tastoratypes.Chain {
ctx := context.Background()
t := s.T()
encConfig := testutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{})
// Create chain using ChainBuilder pattern
chain, err := tastoradocker.NewChainBuilder(t).
WithName("celestia").
WithChainID(testChainID).
WithBinaryName("celestia-appd").
WithBech32Prefix("celestia").
WithDenom("utia").
WithCoinType("118").
WithGasPrices("0.025utia").
WithGasAdjustment(1.3).
WithEncodingConfig(&encConfig).
WithImage(container.NewImage("ghcr.io/celestiaorg/celestia-app", celestiaAppVersion, "10001:10001")).
WithAdditionalStartArgs(
"--force-no-bbr",
"--grpc.enable",
"--grpc.address",
"0.0.0.0:9090",
"--rpc.grpc_laddr=tcp://0.0.0.0:9098",
"--timeout-commit", "1s",
).
WithDockerClient(s.dockerClient).
WithDockerNetworkID(s.dockerNetworkID).
WithNode(tastoradocker.NewChainNodeConfigBuilder().
WithNodeType(tastoratypes.NodeTypeValidator).
Build()).
Build(ctx)
s.Require().NoError(err)
return chain
}
// CreateDANetwork creates a DA network using the provider
func (s *DockerTestSuite) CreateDANetwork() tastoratypes.DataAvailabilityNetwork {
ctx := context.Background()
daNetwork, err := s.provider.GetDataAvailabilityNetwork(ctx)
s.Require().NoError(err)
return daNetwork
}
// CreateEvolveChain creates a Rollkit chain using the provider
func (s *DockerTestSuite) CreateEvolveChain() tastoratypes.RollkitChain {
ctx := context.Background()
rollkitChain, err := s.provider.GetRollkitChain(ctx)
s.Require().NoError(err)
return rollkitChain
}
// StartBridgeNode initializes and starts a bridge node within the data availability network using the given parameters.
func (s *DockerTestSuite) StartBridgeNode(ctx context.Context, bridgeNode tastoratypes.DANode, chainID string, genesisHash string, celestiaNodeHostname string) {
s.Require().Equal(tastoratypes.BridgeNode, bridgeNode.GetType())
err := bridgeNode.Start(ctx,
tastoratypes.WithChainID(chainID),
tastoratypes.WithAdditionalStartArguments("--p2p.network", chainID, "--core.ip", celestiaNodeHostname, "--rpc.addr", "0.0.0.0"),
tastoratypes.WithEnvironmentVariables(
map[string]string{
"CELESTIA_CUSTOM": tastoratypes.BuildCelestiaCustomEnvVar(chainID, genesisHash, ""),
"P2P_NETWORK": chainID,
},
),
)
s.Require().NoError(err)
}
// FundWallet transfers the specified amount of utia from the faucet wallet to the target wallet.
func (s *DockerTestSuite) FundWallet(ctx context.Context, wallet tastoratypes.Wallet, amount int64) {
fromAddress, err := sdkacc.AddressFromWallet(s.celestia.GetFaucetWallet())
s.Require().NoError(err)
toAddress, err := sdk.AccAddressFromBech32(wallet.GetFormattedAddress())
s.Require().NoError(err)
bankSend := banktypes.NewMsgSend(fromAddress, toAddress, sdk.NewCoins(sdk.NewCoin("utia", math.NewInt(amount))))
_, err = s.celestia.BroadcastMessages(ctx, s.celestia.GetFaucetWallet(), bankSend)
s.Require().NoError(err)
}
// StartEvNode initializes and starts an Ev node.
func (s *DockerTestSuite) StartEvNode(ctx context.Context, bridgeNode tastoratypes.DANode, evNode tastoratypes.RollkitNode) {
err := evNode.Init(ctx)
s.Require().NoError(err)
bridgeNodeHostName, err := bridgeNode.GetInternalHostName()
s.Require().NoError(err)
authToken, err := bridgeNode.GetAuthToken()
s.Require().NoError(err)
daAddress := fmt.Sprintf("http://%s:26658", bridgeNodeHostName)
err = evNode.Start(ctx,
"--rollkit.da.address", daAddress,
"--rollkit.da.gas_price", "0.025",
"--rollkit.da.auth_token", authToken,
"--rollkit.rpc.address", "0.0.0.0:7331", // bind to 0.0.0.0 so rpc is reachable from test host.
"--rollkit.da.namespace", generateValidNamespaceHex(),
"--kv-endpoint", "0.0.0.0:8080",
)
s.Require().NoError(err)
}
// StartRollkitNodeWithNamespace initializes and starts a Rollkit node with a specific namespace.
func (s *DockerTestSuite) StartRollkitNodeWithNamespace(ctx context.Context, bridgeNode tastoratypes.DANode, rollkitNode tastoratypes.RollkitNode, namespace string) {
err := rollkitNode.Init(ctx)
s.Require().NoError(err)
bridgeNodeHostName, err := bridgeNode.GetInternalHostName()
s.Require().NoError(err)
authToken, err := bridgeNode.GetAuthToken()
s.Require().NoError(err)
daAddress := fmt.Sprintf("http://%s:26658", bridgeNodeHostName)
err = rollkitNode.Start(ctx,
"--rollkit.da.address", daAddress,
"--rollkit.da.gas_price", "0.025",
"--rollkit.da.auth_token", authToken,
"--rollkit.rpc.address", "0.0.0.0:7331", // bind to 0.0.0.0 so rpc is reachable from test host.
"--rollkit.da.namespace", namespace,
"--kv-endpoint", "0.0.0.0:8080",
)
s.Require().NoError(err)
}
// getEvNodeImage returns the Docker image configuration for Rollkit
// Uses EV_NODE_IMAGE_REPO and EV_NODE_IMAGE_TAG environment variables if set
// Defaults to locally built image using a unique tag to avoid registry conflicts
func getEvNodeImage() container.Image {
repo := strings.TrimSpace(os.Getenv("EV_NODE_IMAGE_REPO"))
if repo == "" {
repo = "evstack"
}
tag := strings.TrimSpace(os.Getenv("EV_NODE_IMAGE_TAG"))
if tag == "" {
tag = "local-dev"
}
return container.NewImage(repo, tag, "10001:10001")
}
func generateValidNamespaceHex() string {
return hex.EncodeToString(share.RandomBlobNamespace().Bytes())
}