Skip to content

Commit

Permalink
add tests for beaconcha baseURL (#13308)
Browse files Browse the repository at this point in the history
* add tests for different environments

* sort import

* remove goerli for prater

* clean

---------

Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com>
Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent 9aa55b4 commit f2f10e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
30 changes: 17 additions & 13 deletions validator/accounts/accounts_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,7 @@ func displayExitInfo(rawExitedKeys [][]byte, trimmedExitedKeys []string) {
if len(rawExitedKeys) > 0 {
urlFormattedPubKeys := make([]string, len(rawExitedKeys))
for i, key := range rawExitedKeys {
var baseUrl string
switch params.BeaconConfig().ConfigName {
case params.PraterName, params.GoerliName:
baseUrl = "https://goerli.beaconcha.in/validator/"
case params.HoleskyName:
baseUrl = "https://holesky.beaconcha.in/validator/"
case params.SepoliaName:
baseUrl = "https://sepolia.beaconcha.in/validator/"
default:
baseUrl = "https://beaconcha.in/validator/"
}
// Remove '0x' prefix
urlFormattedPubKeys[i] = baseUrl + hexutil.Encode(key)[2:]
urlFormattedPubKeys[i] = formatBeaconChaURL(key)
}

ifaceKeys := make([]interface{}, len(urlFormattedPubKeys))
Expand All @@ -182,6 +170,22 @@ func displayExitInfo(rawExitedKeys [][]byte, trimmedExitedKeys []string) {
}
}

func formatBeaconChaURL(key []byte) string {
baseURL := "https://%sbeaconcha.in/validator/%s"
keyWithout0x := hexutil.Encode(key)[2:]

switch env := params.BeaconConfig().ConfigName; env {
case params.PraterName, params.GoerliName:
return fmt.Sprintf(baseURL, "prater.", keyWithout0x)
case params.HoleskyName:
return fmt.Sprintf(baseURL, "holesky.", keyWithout0x)
case params.SepoliaName:
return fmt.Sprintf(baseURL, "sepolia.", keyWithout0x)
default:
return fmt.Sprintf(baseURL, "", keyWithout0x)
}
}

func writeSignedVoluntaryExitJSON(sve *eth.SignedVoluntaryExit, outputDirectory string) error {
if err := file.MkdirAll(outputDirectory); err != nil {
return err
Expand Down
17 changes: 17 additions & 0 deletions validator/accounts/accounts_exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/v4/api/server/structs"
"github.com/prysmaticlabs/prysm/v4/build/bazel"
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
"github.com/prysmaticlabs/prysm/v4/config/params"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v4/io/file"
eth "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
Expand All @@ -22,6 +23,22 @@ func TestDisplayExitInfo(t *testing.T) {
key := []byte("0x123456")
displayExitInfo([][]byte{key}, []string{string(key)})
assert.LogsContain(t, logHook, "https://beaconcha.in/validator/3078313233343536")

params.BeaconConfig().ConfigName = params.GoerliName
displayExitInfo([][]byte{key}, []string{string(key)})
assert.LogsContain(t, logHook, "https://prater.beaconcha.in/validator/3078313233343536")

params.BeaconConfig().ConfigName = params.PraterName
displayExitInfo([][]byte{key}, []string{string(key)})
assert.LogsContain(t, logHook, "https://prater.beaconcha.in/validator/3078313233343536")

params.BeaconConfig().ConfigName = params.HoleskyName
displayExitInfo([][]byte{key}, []string{string(key)})
assert.LogsContain(t, logHook, "https://holesky.beaconcha.in/validator/3078313233343536")

params.BeaconConfig().ConfigName = params.SepoliaName
displayExitInfo([][]byte{key}, []string{string(key)})
assert.LogsContain(t, logHook, "https://sepolia.beaconcha.in/validator/3078313233343536")
}

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

0 comments on commit f2f10e7

Please sign in to comment.