Skip to content

Commit 6c7ed84

Browse files
added C chain config via env variables
1 parent 993ae10 commit 6c7ed84

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

tests/antithesis/compose.go

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package antithesis
55

66
import (
7+
"encoding/base64"
78
"encoding/json"
89
"errors"
910
"fmt"
@@ -27,17 +28,23 @@ const (
2728
imageTagEnvName = "IMAGE_TAG"
2829
)
2930

31+
type CChainConfig struct {
32+
LogJSONFormat bool `json:"log-json-format"`
33+
}
34+
35+
type ChainConfig struct {
36+
C struct {
37+
Config string `json:"Config"`
38+
} `json:"C"`
39+
}
40+
3041
var (
3142
errTargetPathEnvVarNotSet = errors.New(targetPathEnvName + " environment variable not set")
3243
errImageTagEnvVarNotSet = errors.New(imageTagEnvName + " environment variable not set")
3344
errAvalancheGoEvVarNotSet = errors.New(tmpnet.AvalancheGoPathEnvName + " environment variable not set")
3445
errPluginDirEnvVarNotSet = errors.New(tmpnet.AvalancheGoPluginDirEnvName + " environment variable not set")
3546
)
3647

37-
type cChainConfig struct {
38-
LogJSONFormat bool `json:"log-json-format"`
39-
}
40-
4148
// Creates docker compose configuration for an antithesis test setup. Configuration is via env vars to
4249
// simplify usage by main entrypoints. If the provided network includes a subnet, the initial DB state for
4350
// the subnet will be created and written to the target path.
@@ -129,18 +136,6 @@ func initComposeConfig(
129136
if err := os.MkdirAll(volumePath, perms.ReadWriteExecute); err != nil {
130137
return fmt.Errorf("failed to create volume path %q: %w", volumePath, err)
131138
}
132-
// Write config.json if this is the C-Chain config directory
133-
if isCChainConfigDir(volumePath) {
134-
configFilePath := filepath.Join(volumePath, "config.json")
135-
cfg := cChainConfig{LogJSONFormat: true}
136-
configContent, err := json.MarshalIndent(cfg, "", " ")
137-
if err != nil {
138-
return fmt.Errorf("failed to marshal config.json: %w", err)
139-
}
140-
if err := os.WriteFile(configFilePath, configContent, perms.ReadWrite); err != nil {
141-
return fmt.Errorf("failed to write config.json to %q: %w", configFilePath, err)
142-
}
143-
}
144139
}
145140
}
146141
return nil
@@ -158,6 +153,9 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
158153
bootstrapIP string
159154
bootstrapIDs string
160155
)
156+
157+
chainConfigB64, _ := encodeChainConfig()
158+
161159
for i, node := range network.Nodes {
162160
address := fmt.Sprintf("%s.%d", baseNetworkAddress, 3+i)
163161

@@ -177,6 +175,10 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
177175
config.StakingSignerKeyContentKey: signerKey,
178176
}
179177

178+
if chainConfigB64 != "" {
179+
env[config.ChainConfigContentKey] = chainConfigB64
180+
}
181+
180182
// Apply configuration appropriate to a test network
181183
for k, v := range tmpnet.DefaultTmpnetFlags() {
182184
env[k] = v
@@ -190,11 +192,6 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
190192
Source: fmt.Sprintf("./volumes/%s/logs", serviceName),
191193
Target: "/root/.avalanchego/logs",
192194
},
193-
{
194-
Type: types.VolumeTypeBind,
195-
Source: fmt.Sprintf("./volumes/%s/configs/chains/C", serviceName),
196-
Target: "/root/.avalanchego/configs/chains/C",
197-
},
198195
}
199196

200197
trackSubnets := node.Flags[config.TrackSubnetsKey]
@@ -305,10 +302,20 @@ func getServiceName(index int) string {
305302
return fmt.Sprintf("%s-node-%d", baseName, index)
306303
}
307304

308-
// isCChainConfigDir returns true if the given path matches the expected C-Chain config directory structure:
309-
// .../volumes/<serviceName>/configs/chains/C
310-
func isCChainConfigDir(path string) bool {
311-
return filepath.Base(path) == "C" &&
312-
filepath.Base(filepath.Dir(path)) == "chains" &&
313-
filepath.Base(filepath.Dir(filepath.Dir(path))) == "configs"
305+
func encodeChainConfig() (string, error) {
306+
cchainConfig := CChainConfig{LogJSONFormat: true}
307+
cchainConfigBytes, err := json.Marshal(cchainConfig)
308+
if err != nil {
309+
return "", err
310+
}
311+
cchainConfigB64 := base64.StdEncoding.EncodeToString(cchainConfigBytes)
312+
313+
var chainConfig ChainConfig
314+
chainConfig.C.Config = cchainConfigB64
315+
chainConfigBytes, err := json.Marshal(chainConfig)
316+
if err != nil {
317+
return "", err
318+
}
319+
chainConfigB64 := base64.StdEncoding.EncodeToString(chainConfigBytes)
320+
return chainConfigB64, nil
314321
}

0 commit comments

Comments
 (0)