Skip to content

Commit

Permalink
cmd: charon alpha test skeleton (#3008)
Browse files Browse the repository at this point in the history
Add the skeleton framework for the charon alpha test command. Prepare all the necessities required to start building different test suites. Set the first 3 envisioned categories - peers, beacon node and validator client.

To try it out:
```
make charon
./charon alpha test peers --enrs="test" --output-toml="peers.toml" --timeout="3s"
./charon alpha test beacon --endpoints="test" --output-toml="beacon.toml" --timeout="3s"
./charon alpha test validator --output-toml="validator.toml" --timeout="3s"
```
From all the flags above, only `enrs` and `endpoints` are mandatory.

N.B.: Implementation of peers, beacon node and validator client tests are out of the scope of this PR.

~~Edit: Unit tests are not yet of this PR, keep in mind when reviewing~~

category: feature
ticket: #2995
  • Loading branch information
KaloyanTanev authored Apr 8, 2024
1 parent 3d05771 commit 5cf0827
Show file tree
Hide file tree
Showing 13 changed files with 2,133 additions and 2 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ linters:
- gochecknoglobals
- gocognit
- gocyclo
- godot
- godox
- goerr113
- golint
Expand Down
80 changes: 80 additions & 0 deletions cmd/ascii.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright © 2022-2024 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1

package cmd

func peersASCII() []string {
return []string{
" ____ ",
" | __ \\ ",
" | |__) |___ ___ _ __ ___ ",
" | ___// _ \\ / _ \\| '__|/ __| ",
" | | | __/| __/| | \\__ \\ ",
" |_| \\___| \\___||_| |___/ ",
}
}

func beaconASCII() []string {
return []string{
" ____ ",
" | _ \\ ",
" | |_) | ___ __ _ ___ ___ _ __ ",
" | _ < / _ \\ / _` | / __|/ _ \\ | '_ \\ ",
" | |_) || __/| (_| || (__| (_) || | | | ",
" |____/ \\___| \\__,_| \\___|\\___/ |_| |_| ",
}
}

func validatorASCII() []string {
return []string{
" __ __ _ _ _ _ ",
" \\ \\ / / | |(_, | | | | ",
" \\ \\ / /__ _ | | _ __| | __ _ | |_ ___ _ __ ",
" \\ \\/ // _` || || | / _` | / _` || __|/ _ \\ | '__| ",
" \\ /| (_| || || || (_| || (_| || |_| (_) || | ",
" \\/ \\__,_||_||_| \\__,_| \\__,_| \\__|\\___/ |_| ",
}
}

func categoryDefaultASCII() []string {
return []string{
" ",
" ",
" ",
" ",
" ",
" ",
}
}

func scoreAASCII() []string {
return []string{
" ",
" /\\ ",
" / \\ ",
" / /\\ \\ ",
" / ____ \\ ",
"/_/ \\_\\",
}
}

func scoreBASCII() []string {
return []string{
" ____ ",
"| _ \\ ",
"| |_) | ",
"| _ < ",
"| |_) | ",
"|____/ ",
}
}

func scoreCASCII() []string {
return []string{
" ____ ",
" / ____| ",
"| | ",
"| | ",
"| |____ ",
" \\_____| ",
}
}
5 changes: 5 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func New() *cobra.Command {
),
newCombineCmd(newCombineFunc),
newAlphaCmd(
newTestCmd(
newTestPeersCmd(runTestPeers),
newTestBeaconCmd(runTestBeacon),
newTestValidatorCmd(runTestValidator),
),
newAddValidatorsCmd(runAddValidatorsSolo),
newViewClusterManifestCmd(runViewClusterManifest),
),
Expand Down
67 changes: 67 additions & 0 deletions cmd/duration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright © 2022-2024 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1

package cmd

import (
"encoding/json"
"strconv"
"time"

"github.com/obolnetwork/charon/app/errors"
)

type Duration struct {
time.Duration
}

func (d Duration) MarshalJSON() ([]byte, error) {
res, err := json.Marshal(d.String())
if err != nil {
return nil, errors.Wrap(err, "marshal json duration")
}

return res, nil
}

func (d *Duration) UnmarshalJSON(b []byte) error {
var v any
err := json.Unmarshal(b, &v)
if err != nil {
return errors.Wrap(err, "unmarshal json duration")
}
switch value := v.(type) {
case float64:
d.Duration = time.Duration(value)
case string:
d.Duration, err = time.ParseDuration(value)
if err != nil {
return errors.Wrap(err, "parse string time to duration")
}
default:
return errors.New("invalid json duration")
}

return nil
}

func (d Duration) MarshalText() ([]byte, error) {
return []byte(d.String()), nil
}

func (d *Duration) UnmarshalText(b []byte) error {
strTime := string(b)
intTime, err := strconv.ParseInt(strTime, 10, 64)
switch {
case err == nil:
d.Duration = time.Duration(intTime)
case errors.Is(err, strconv.ErrSyntax):
d.Duration, err = time.ParseDuration(strTime)
if err != nil {
return errors.Wrap(err, "parse string time to duration")
}
default:
return errors.Wrap(err, "invalid text duration")
}

return nil
}
Loading

0 comments on commit 5cf0827

Please sign in to comment.