-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd: charon alpha test skeleton (#3008)
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
1 parent
3d05771
commit 5cf0827
Showing
13 changed files
with
2,133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,7 @@ linters: | |
- gochecknoglobals | ||
- gocognit | ||
- gocyclo | ||
- godot | ||
- godox | ||
- goerr113 | ||
- golint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ | ||
" ____ ", | ||
" / ____| ", | ||
"| | ", | ||
"| | ", | ||
"| |____ ", | ||
" \\_____| ", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.