4
4
package antithesis
5
5
6
6
import (
7
+ "encoding/base64"
7
8
"encoding/json"
8
9
"errors"
9
10
"fmt"
@@ -27,17 +28,23 @@ const (
27
28
imageTagEnvName = "IMAGE_TAG"
28
29
)
29
30
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
+
30
41
var (
31
42
errTargetPathEnvVarNotSet = errors .New (targetPathEnvName + " environment variable not set" )
32
43
errImageTagEnvVarNotSet = errors .New (imageTagEnvName + " environment variable not set" )
33
44
errAvalancheGoEvVarNotSet = errors .New (tmpnet .AvalancheGoPathEnvName + " environment variable not set" )
34
45
errPluginDirEnvVarNotSet = errors .New (tmpnet .AvalancheGoPluginDirEnvName + " environment variable not set" )
35
46
)
36
47
37
- type cChainConfig struct {
38
- LogJSONFormat bool `json:"log-json-format"`
39
- }
40
-
41
48
// Creates docker compose configuration for an antithesis test setup. Configuration is via env vars to
42
49
// simplify usage by main entrypoints. If the provided network includes a subnet, the initial DB state for
43
50
// the subnet will be created and written to the target path.
@@ -129,18 +136,6 @@ func initComposeConfig(
129
136
if err := os .MkdirAll (volumePath , perms .ReadWriteExecute ); err != nil {
130
137
return fmt .Errorf ("failed to create volume path %q: %w" , volumePath , err )
131
138
}
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
- }
144
139
}
145
140
}
146
141
return nil
@@ -158,6 +153,9 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
158
153
bootstrapIP string
159
154
bootstrapIDs string
160
155
)
156
+
157
+ chainConfigB64 , _ := encodeChainConfig ()
158
+
161
159
for i , node := range network .Nodes {
162
160
address := fmt .Sprintf ("%s.%d" , baseNetworkAddress , 3 + i )
163
161
@@ -177,6 +175,10 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
177
175
config .StakingSignerKeyContentKey : signerKey ,
178
176
}
179
177
178
+ if chainConfigB64 != "" {
179
+ env [config .ChainConfigContentKey ] = chainConfigB64
180
+ }
181
+
180
182
// Apply configuration appropriate to a test network
181
183
for k , v := range tmpnet .DefaultTmpnetFlags () {
182
184
env [k ] = v
@@ -190,11 +192,6 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
190
192
Source : fmt .Sprintf ("./volumes/%s/logs" , serviceName ),
191
193
Target : "/root/.avalanchego/logs" ,
192
194
},
193
- {
194
- Type : types .VolumeTypeBind ,
195
- Source : fmt .Sprintf ("./volumes/%s/configs/chains/C" , serviceName ),
196
- Target : "/root/.avalanchego/configs/chains/C" ,
197
- },
198
195
}
199
196
200
197
trackSubnets := node .Flags [config .TrackSubnetsKey ]
@@ -305,10 +302,20 @@ func getServiceName(index int) string {
305
302
return fmt .Sprintf ("%s-node-%d" , baseName , index )
306
303
}
307
304
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
314
321
}
0 commit comments