add tests for beaconcha baseURL (#13308)

* 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>
This commit is contained in:
Joel Rousseau 2024-02-13 22:44:51 +09:00 committed by GitHub
parent 9aa55b47f3
commit f2f10e7381
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 13 deletions

View File

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

View File

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