diff --git a/testutil/compose/compose/main.go b/testutil/compose/compose/main.go index 758e91397..3ce694abe 100644 --- a/testutil/compose/compose/main.go +++ b/testutil/compose/compose/main.go @@ -17,7 +17,7 @@ // using docker-compose. // // It consists of three steps: -// - compose define: Creates charon-compose.yml (and p2pkeys) that defines a desired cluster including keygen. +// - compose define: Creates config.json (and p2pkeys) and a docker-compose.yml to create a cluster definition file. // - compose lock: Creates docker-compose.yml to generates keys and cluster lock file. // - compose run: Creates docker-compose.yml that runs the cluster. package main @@ -57,7 +57,7 @@ func newRootCmd() *cobra.Command { func newRunCmd() *cobra.Command { cmd := &cobra.Command{ Use: "run", - Short: "Create a docker-compose.yml from charon-compose.yml to run the cluster.", + Short: "Creates docker-compose.yml that runs the cluster.", } up := addUpFlag(cmd.Flags()) @@ -81,7 +81,7 @@ func newRunCmd() *cobra.Command { func newLockCmd() *cobra.Command { cmd := &cobra.Command{ Use: "lock", - Short: "Create a docker-compose.yml for generating keys and a cluster lock file.", + Short: "Creates docker-compose.yml to generates keys and cluster lock file.", } up := addUpFlag(cmd.Flags()) @@ -105,7 +105,7 @@ func newLockCmd() *cobra.Command { func newDefineCmd() *cobra.Command { cmd := &cobra.Command{ Use: "define", - Short: "Create a charon-compose.yml definition and a docker-compose.yml for generating a cluster definition file", + Short: "Creates config.json (and p2pkeys) and a docker-compose.yml to create a cluster definition file", } conf := compose.NewDefaultConfig() diff --git a/testutil/compose/config.go b/testutil/compose/config.go index 39845c618..21f909d0e 100644 --- a/testutil/compose/config.go +++ b/testutil/compose/config.go @@ -18,7 +18,7 @@ package compose const ( version = "obol/charon/compose/1.0.0" - composeFile = "charon-compose.yml" + configFile = "config.json" defaultImageTag = "latest" defaultBeaconNode = "mock" defaultKeyGen = keyGenCreate @@ -64,6 +64,9 @@ type Config struct { // Version defines the compose config version. Version string `json:"version"` + // Step defines the current completed compose step. + Step step `json:"step"` + // NumNodes is the number of charon nodes in the cluster. NumNodes int `json:"num_nodes"` @@ -76,16 +79,14 @@ type Config struct { // ImageTag defines the charon docker image tag: ghcr.io/obolnetwork/charon:{ImageTag}. ImageTag string `json:"image_tag"` - // VCs define the types of validator clients to use. - VCs []vcType `json:"validator_clients"` - // KeyGen defines the key generation process. KeyGen KeyGen `json:"key_gen"` // BeaconNode url endpoint or "mock" for simnet. BeaconNode string `json:"beacon_node"` - Step step `json:"step"` + // VCs define the types of validator clients to use. + VCs []vcType `json:"validator_clients"` } // NewDefaultConfig returns a new default config. diff --git a/testutil/compose/define.go b/testutil/compose/define.go index 1ae6c539e..9f88e7cb6 100644 --- a/testutil/compose/define.go +++ b/testutil/compose/define.go @@ -29,7 +29,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enr" - "github.com/goccy/go-yaml" "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/log" @@ -125,7 +124,7 @@ func Define(ctx context.Context, dir string, seed int, conf Config) error { } } - log.Info(ctx, "Creating charon-compose.yml") + log.Info(ctx, "Creating config.json") if err := writeConfig(dir, conf); err != nil { return err @@ -225,12 +224,7 @@ func writeConfig(dir string, conf Config) error { return errors.Wrap(err, "marshal config") } - b, err = yaml.JSONToYAML(b) - if err != nil { - return errors.Wrap(err, "yaml config") - } - - err = os.WriteFile(path.Join(dir, composeFile), b, 0o755) //nolint:gosec + err = os.WriteFile(path.Join(dir, configFile), b, 0o755) //nolint:gosec if err != nil { return errors.Wrap(err, "write config") } diff --git a/testutil/compose/define_test.go b/testutil/compose/define_test.go index 6c6862cc3..4c84a26a4 100644 --- a/testutil/compose/define_test.go +++ b/testutil/compose/define_test.go @@ -35,7 +35,7 @@ func TestDefineCompose(t *testing.T) { err = compose.Define(context.Background(), dir, 1, compose.NewDefaultConfig()) require.NoError(t, err) - conf, err := os.ReadFile(path.Join(dir, "charon-compose.yml")) + conf, err := os.ReadFile(path.Join(dir, "config.json")) require.NoError(t, err) testutil.RequireGoldenBytes(t, conf) diff --git a/testutil/compose/lock.go b/testutil/compose/lock.go index f6fa1459f..3aa67cec6 100644 --- a/testutil/compose/lock.go +++ b/testutil/compose/lock.go @@ -23,8 +23,6 @@ import ( "os" "path" - "github.com/goccy/go-yaml" - "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/log" ) @@ -112,16 +110,11 @@ func newNodeEnvs(index int, validatorMock, beaconMock bool) []kv { // loadConfig returns the config loaded from disk. func loadConfig(dir string) (Config, error) { - b, err := os.ReadFile(path.Join(dir, composeFile)) + b, err := os.ReadFile(path.Join(dir, configFile)) if err != nil { return Config{}, errors.Wrap(err, "load config") } - b, err = yaml.YAMLToJSON(b) - if err != nil { - return Config{}, errors.Wrap(err, "yaml config") - } - var resp Config if err := json.Unmarshal(b, &resp); err != nil { return Config{}, errors.Wrap(err, "unmarshal Config") diff --git a/testutil/compose/run.go b/testutil/compose/run.go index 3c2b1a3f2..dd8cf3850 100644 --- a/testutil/compose/run.go +++ b/testutil/compose/run.go @@ -23,7 +23,7 @@ import ( "github.com/obolnetwork/charon/app/log" ) -// Run creates a docker-compose.yml from charon-compose.yml to run the cluster. +// Run creates a docker-compose.yml from config.json to run the cluster. func Run(ctx context.Context, dir string) error { ctx = log.WithTopic(ctx, "run") diff --git a/testutil/compose/testdata/TestDefineCompose.golden b/testutil/compose/testdata/TestDefineCompose.golden index ed0f7b80f..5d37b32fb 100644 --- a/testutil/compose/testdata/TestDefineCompose.golden +++ b/testutil/compose/testdata/TestDefineCompose.golden @@ -1,12 +1,15 @@ -version: obol/charon/compose/1.0.0 -num_nodes: 4 -threshold: 3 -num_validators: 1 -image_tag: latest -validator_clients: -- teku -- lighthouse -- mock -key_gen: create -beacon_node: mock -step: defined +{ + "version": "obol/charon/compose/1.0.0", + "step": "defined", + "num_nodes": 4, + "threshold": 3, + "num_validators": 1, + "image_tag": "latest", + "key_gen": "create", + "beacon_node": "mock", + "validator_clients": [ + "teku", + "lighthouse", + "mock" + ] +} \ No newline at end of file