Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: charon alpha test skeleton #3008

Merged
merged 19 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
KaloyanTanev marked this conversation as resolved.
Show resolved Hide resolved
- 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{
" ",
" ",
" ",
" ",
" ",
" ",
}

Check warning on line 46 in cmd/ascii.go

View check run for this annotation

Codecov / codecov/patch

cmd/ascii.go#L38-L46

Added lines #L38 - L46 were not covered by tests
}

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

Check warning on line 57 in cmd/ascii.go

View check run for this annotation

Codecov / codecov/patch

cmd/ascii.go#L49-L57

Added lines #L49 - L57 were not covered by tests
}

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

Check warning on line 68 in cmd/ascii.go

View check run for this annotation

Codecov / codecov/patch

cmd/ascii.go#L60-L68

Added lines #L60 - L68 were not covered by tests
}

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 @@
),
newCombineCmd(newCombineFunc),
newAlphaCmd(
newTestCmd(
newTestPeersCmd(runTestPeers),
newTestBeaconCmd(runTestBeacon),
newTestValidatorCmd(runTestValidator),
),

Check warning on line 52 in cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/cmd.go#L48-L52

Added lines #L48 - L52 were not covered by tests
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
KaloyanTanev marked this conversation as resolved.
Show resolved Hide resolved

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")
}

Check warning on line 21 in cmd/duration.go

View check run for this annotation

Codecov / codecov/patch

cmd/duration.go#L20-L21

Added lines #L20 - L21 were not covered by tests

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")

Check warning on line 41 in cmd/duration.go

View check run for this annotation

Codecov / codecov/patch

cmd/duration.go#L40-L41

Added lines #L40 - L41 were not covered by tests
}

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")

Check warning on line 63 in cmd/duration.go

View check run for this annotation

Codecov / codecov/patch

cmd/duration.go#L62-L63

Added lines #L62 - L63 were not covered by tests
}

return nil
}
Loading
Loading