Skip to content

Commit

Permalink
Add custom testnet flags for exits
Browse files Browse the repository at this point in the history
  • Loading branch information
KaloyanTanev committed Oct 3, 2024
1 parent 23790b5 commit 1c9d402
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/createcluster_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,12 @@ func TestClusterCLI(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := newCreateCmd(newCreateClusterCmd(runCreateCluster))
charonDir := testutil.CreateTempCharonDir(t)
clusterDirArg := "--cluster-dir=" + charonDir
if test.threshold != "" {
cmd.SetArgs([]string{"cluster", test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators, test.threshold})
cmd.SetArgs([]string{"cluster", clusterDirArg, test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators, test.threshold})
} else {
cmd.SetArgs([]string{"cluster", test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators})
cmd.SetArgs([]string{"cluster", clusterDirArg, test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators})
}

err := cmd.Execute()
Expand Down
27 changes: 27 additions & 0 deletions cmd/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/eth2wrap"
"github.com/obolnetwork/charon/app/log"
"github.com/obolnetwork/charon/eth2util"
"github.com/obolnetwork/charon/eth2util/signing"
"github.com/obolnetwork/charon/tbls"
)
Expand All @@ -36,6 +37,7 @@ type exitConfig struct {
ExitFromFileDir string
Log log.Config
All bool
testnetConfig eth2util.Network
}

func newExitCmd(cmds ...*cobra.Command) *cobra.Command {
Expand Down Expand Up @@ -67,6 +69,11 @@ const (
publishTimeout
validatorIndex
all
testnetName
testnetForkVersion
testnetChainID
testnetGenesisTimestamp
testnetCapellaHardFork
)

func (ef exitFlag) String() string {
Expand Down Expand Up @@ -99,6 +106,16 @@ func (ef exitFlag) String() string {
return "validator-index"
case all:
return "all"
case testnetName:
return "testnet-name"
case testnetForkVersion:
return "testnet-fork-version"
case testnetChainID:
return "testnet-chain-id"
case testnetGenesisTimestamp:
return "testnet-genesis-timestamp"
case testnetCapellaHardFork:
return "testnet-capella-hard-fork"

Check warning on line 118 in cmd/exit.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit.go#L109-L118

Added lines #L109 - L118 were not covered by tests
default:
return "unknown"
}
Expand Down Expand Up @@ -150,6 +167,16 @@ func bindExitFlags(cmd *cobra.Command, config *exitConfig, flags []exitCLIFlag)
cmd.Flags().Uint64Var(&config.ValidatorIndex, validatorIndex.String(), 0, "Validator index of the validator to exit, the associated public key must be present in the cluster lock manifest. If --validator-public-key is also provided, validator existence won't be checked on the beacon chain.")
case all:
cmd.Flags().BoolVar(&config.All, all.String(), false, "Exit all currently active validators in the cluster.")
case testnetName:
cmd.Flags().StringVar(&config.testnetConfig.Name, testnetName.String(), "", "Name of the custom test network.")
case testnetForkVersion:
cmd.Flags().StringVar(&config.testnetConfig.GenesisForkVersionHex, testnetForkVersion.String(), "", "Genesis fork version of the custom test network (in hex).")
case testnetChainID:
cmd.Flags().Uint64Var(&config.testnetConfig.ChainID, "testnet-chain-id", 0, "Chain ID of the custom test network.")
case testnetGenesisTimestamp:
cmd.Flags().Int64Var(&config.testnetConfig.GenesisTimestamp, "testnet-genesis-timestamp", 0, "Genesis timestamp of the custom test network.")
case testnetCapellaHardFork:
cmd.Flags().StringVar(&config.testnetConfig.CapellaHardFork, "testnet-capella-hard-fork", "", "Capella hard fork version of the custom test network.")

Check warning on line 179 in cmd/exit.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit.go#L170-L179

Added lines #L170 - L179 were not covered by tests
}

if f.required {
Expand Down
13 changes: 13 additions & 0 deletions cmd/exit_broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/obolnetwork/charon/app/z"
manifestpb "github.com/obolnetwork/charon/cluster/manifestpb/v1"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/eth2util"
"github.com/obolnetwork/charon/eth2util/keystore"
"github.com/obolnetwork/charon/tbls"
"github.com/obolnetwork/charon/tbls/tblsconv"
Expand Down Expand Up @@ -62,6 +63,12 @@ func newBcastFullExitCmd(runFunc func(context.Context, exitConfig) error) *cobra
{exitFromDir, false},
{beaconNodeTimeout, false},
{publishTimeout, false},
{all, false},
{testnetName, false},
{testnetForkVersion, false},
{testnetChainID, false},
{testnetGenesisTimestamp, false},
{testnetCapellaHardFork, false},

Check warning on line 71 in cmd/exit_broadcast.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_broadcast.go#L66-L71

Added lines #L66 - L71 were not covered by tests
})

bindLogFlags(cmd.Flags(), &config.Log)
Expand Down Expand Up @@ -98,6 +105,12 @@ func newBcastFullExitCmd(runFunc func(context.Context, exitConfig) error) *cobra
}

func runBcastFullExit(ctx context.Context, config exitConfig) error {
// Check if custom testnet configuration is provided.
if config.testnetConfig.IsNonZero() {
// Add testnet config to supported networks.
eth2util.AddTestNetwork(config.testnetConfig)
}

Check warning on line 112 in cmd/exit_broadcast.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_broadcast.go#L110-L112

Added lines #L110 - L112 were not covered by tests

identityKey, err := k1util.Load(config.PrivateKeyPath)
if err != nil {
return errors.Wrap(err, "could not load identity key")
Expand Down
12 changes: 12 additions & 0 deletions cmd/exit_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/obolnetwork/charon/app/obolapi"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/eth2util"
"github.com/obolnetwork/charon/eth2util/keystore"
)

Expand Down Expand Up @@ -49,6 +50,11 @@ func newFetchExitCmd(runFunc func(context.Context, exitConfig) error) *cobra.Com
{all, false},
{fetchedExitPath, false},
{publishTimeout, false},
{testnetName, false},
{testnetForkVersion, false},
{testnetChainID, false},
{testnetGenesisTimestamp, false},
{testnetCapellaHardFork, false},

Check warning on line 57 in cmd/exit_fetch.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_fetch.go#L53-L57

Added lines #L53 - L57 were not covered by tests
})

bindLogFlags(cmd.Flags(), &config.Log)
Expand All @@ -73,6 +79,12 @@ func newFetchExitCmd(runFunc func(context.Context, exitConfig) error) *cobra.Com
}

func runFetchExit(ctx context.Context, config exitConfig) error {
// Check if custom testnet configuration is provided.
if config.testnetConfig.IsNonZero() {
// Add testnet config to supported networks.
eth2util.AddTestNetwork(config.testnetConfig)
}

Check warning on line 86 in cmd/exit_fetch.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_fetch.go#L84-L86

Added lines #L84 - L86 were not covered by tests

if _, err := os.Stat(config.FetchedExitPath); err != nil {
return errors.Wrap(err, "store exit path")
}
Expand Down
12 changes: 12 additions & 0 deletions cmd/exit_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/eth2util"
)

func newListActiveValidatorsCmd(runFunc func(context.Context, exitConfig) error) *cobra.Command {
Expand Down Expand Up @@ -43,6 +44,11 @@ func newListActiveValidatorsCmd(runFunc func(context.Context, exitConfig) error)
{lockFilePath, false},
{beaconNodeEndpoints, true},
{beaconNodeTimeout, false},
{testnetName, false},
{testnetForkVersion, false},
{testnetChainID, false},
{testnetGenesisTimestamp, false},
{testnetCapellaHardFork, false},

Check warning on line 51 in cmd/exit_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_list.go#L47-L51

Added lines #L47 - L51 were not covered by tests
})

bindLogFlags(cmd.Flags(), &config.Log)
Expand All @@ -51,6 +57,12 @@ func newListActiveValidatorsCmd(runFunc func(context.Context, exitConfig) error)
}

func runListActiveValidatorsCmd(ctx context.Context, config exitConfig) error {
// Check if custom testnet configuration is provided.
if config.testnetConfig.IsNonZero() {
// Add testnet config to supported networks.
eth2util.AddTestNetwork(config.testnetConfig)
}

Check warning on line 64 in cmd/exit_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_list.go#L62-L64

Added lines #L62 - L64 were not covered by tests

valList, err := listActiveVals(ctx, config)
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions cmd/exit_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/obolnetwork/charon/app/obolapi"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/eth2util"
"github.com/obolnetwork/charon/eth2util/keystore"
)

Expand Down Expand Up @@ -54,6 +55,11 @@ func newSubmitPartialExitCmd(runFunc func(context.Context, exitConfig) error) *c
{beaconNodeTimeout, false},
{publishTimeout, false},
{all, false},
{testnetName, false},
{testnetForkVersion, false},
{testnetChainID, false},
{testnetGenesisTimestamp, false},
{testnetCapellaHardFork, false},

Check warning on line 62 in cmd/exit_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_sign.go#L58-L62

Added lines #L58 - L62 were not covered by tests
})

bindLogFlags(cmd.Flags(), &config.Log)
Expand Down Expand Up @@ -82,6 +88,12 @@ func newSubmitPartialExitCmd(runFunc func(context.Context, exitConfig) error) *c
}

func runSignPartialExit(ctx context.Context, config exitConfig) error {
// Check if custom testnet configuration is provided.
if config.testnetConfig.IsNonZero() {
// Add testnet config to supported networks.
eth2util.AddTestNetwork(config.testnetConfig)
}

Check warning on line 95 in cmd/exit_sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/exit_sign.go#L93-L95

Added lines #L93 - L95 were not covered by tests

identityKey, err := k1util.Load(config.PrivateKeyPath)
if err != nil {
return errors.Wrap(err, "could not load identity key")
Expand Down

0 comments on commit 1c9d402

Please sign in to comment.