From f2f10e7381e361e3074decff7becf78302cf15b3 Mon Sep 17 00:00:00 2001 From: Joel Rousseau Date: Tue, 13 Feb 2024 22:44:51 +0900 Subject: [PATCH] add tests for beaconcha baseURL (#13308) * add tests for different environments * sort import * remove goerli for prater * clean --------- Co-authored-by: Manu NALEPA Co-authored-by: Preston Van Loon --- validator/accounts/accounts_exit.go | 30 ++++++++++++++---------- validator/accounts/accounts_exit_test.go | 17 ++++++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/validator/accounts/accounts_exit.go b/validator/accounts/accounts_exit.go index eb57e425f440..98f1d0d13f9e 100644 --- a/validator/accounts/accounts_exit.go +++ b/validator/accounts/accounts_exit.go @@ -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 diff --git a/validator/accounts/accounts_exit_test.go b/validator/accounts/accounts_exit_test.go index 5c0efd3f3080..fc87b1240580 100644 --- a/validator/accounts/accounts_exit_test.go +++ b/validator/accounts/accounts_exit_test.go @@ -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) {