Skip to content

Commit

Permalink
Update config types for environment (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary authored Aug 6, 2024
2 parents 6d500c8 + 57afc68 commit b1b9eaf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ EnvVar: `EIGENLAYER_NETWORK`

The Ethereum network to target

*Values:* `local, devnet, holesky, mainnet`
*Values:* `holesky, ethereum`

### `--rpc-url`

Expand Down
26 changes: 9 additions & 17 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ type GlobalConfig struct {
type Environment int

var (
Environment_LOCAL Environment = 0
Environment_DEV Environment = 1
Environment_PRE_PROD Environment = 2
Environment_PROD Environment = 3
Environment_TESTNET Environment = 4
Environment_PRE_PROD Environment = 0
Environment_TESTNET Environment = 1
Environment_MAINNET Environment = 2
)

type UpdaterConfig struct {
Expand Down Expand Up @@ -78,32 +76,26 @@ var validateConfig *ValidateConfig
// parseEnvironment normalizes environment names to an enum value
func parseEnvironment(env string) Environment {
switch env {
case "pre-prod", "preprod":
case "preprod":
return Environment_PRE_PROD
case "prod", "production":
return Environment_PROD
case "local", "localnet":
return Environment_LOCAL
case "testnet":
return Environment_TESTNET
case "mainnet":
return Environment_MAINNET
default:
return Environment_DEV
return Environment_PRE_PROD
}
}

// StringEnvironmentFromEnum gets a string environment value from the enum
func StringEnvironmentFromEnum(env Environment) (string, error) {
switch env {
case Environment_PROD:
return "prod", nil
case Environment_PRE_PROD:
return "preprod", nil
case Environment_TESTNET:
return "testnet", nil
case Environment_DEV:
return "dev", nil
case Environment_LOCAL:
return "local", nil
case Environment_MAINNET:
return "mainnet", nil
}
return "", errors.New(fmt.Sprintf("String env not found for '%d'", env))
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@ func TestKebabToSnakeCase(t *testing.T) {
assert.Equal(t, "some_kebab_string", snakeString)
}

func TestGetEnvNetwork_ValidNetworkProd(t *testing.T) {
envNetwork, err := StringEnvironmentFromEnum(Environment_PROD)
assert.Nil(t, err)
assert.Equal(t, "prod", envNetwork)
}

func TestGetEnvNetwork_ValidNetworkPreProd(t *testing.T) {
envNetwork, err := StringEnvironmentFromEnum(Environment_PRE_PROD)
assert.Nil(t, err)
assert.Equal(t, "preprod", envNetwork)
}

func TestGetEnvNetwork_ValidNetworkPreDev(t *testing.T) {
envNetwork, err := StringEnvironmentFromEnum(Environment_DEV)
func TestGetEnvNetwork_ValidNetworkMainnet(t *testing.T) {
envNetwork, err := StringEnvironmentFromEnum(Environment_MAINNET)
assert.Nil(t, err)
assert.Equal(t, "dev", envNetwork)
assert.Equal(t, "mainnet", envNetwork)
}

func TestGetEnvNetwork_InvalidNetwork(t *testing.T) {
Expand Down

0 comments on commit b1b9eaf

Please sign in to comment.