prysm-pulse/beacon-chain/node/registration/p2p_test.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

69 lines
2.3 KiB
Go

package registration
import (
"flag"
"os"
"testing"
"github.com/prysmaticlabs/prysm/v3/cmd"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/testing/assert"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/urfave/cli/v2"
)
func TestP2PPreregistration_DefaultDataDir(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(cmd.DataDirFlag.Name, "", "")
ctx := cli.NewContext(&app, set, nil)
_, dataDir, err := P2PPreregistration(ctx)
require.NoError(t, err)
assert.Equal(t, cmd.DefaultDataDir(), dataDir)
}
func TestP2PPreregistration(t *testing.T) {
sampleNode := "- enr:-TESTNODE"
testDataDir := "testDataDir"
file, err := os.CreateTemp(t.TempDir(), "bootstrapFile*.yaml")
require.NoError(t, err)
err = os.WriteFile(file.Name(), []byte(sampleNode), 0644)
require.NoError(t, err, "Error in WriteFile call")
params.SetupTestConfigCleanup(t)
config := params.BeaconNetworkConfig()
config.BootstrapNodes = []string{file.Name()}
params.OverrideBeaconNetworkConfig(config)
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(cmd.DataDirFlag.Name, testDataDir, "")
ctx := cli.NewContext(&app, set, nil)
bootstrapNodeAddrs, dataDir, err := P2PPreregistration(ctx)
require.NoError(t, err)
require.Equal(t, 1, len(bootstrapNodeAddrs))
assert.Equal(t, sampleNode[2:], bootstrapNodeAddrs[0])
assert.Equal(t, testDataDir, dataDir)
}
func TestBootStrapNodeFile(t *testing.T) {
file, err := os.CreateTemp(t.TempDir(), "bootstrapFile")
require.NoError(t, err)
sampleNode0 := "- enr:-Ku4QMKVC_MowDsmEa20d5uGjrChI0h8_KsKXDmgVQbIbngZV0i" +
"dV6_RL7fEtZGo-kTNZ5o7_EJI_vCPJ6scrhwX0Z4Bh2F0dG5ldHOIAAAAAAAAAACEZXRoMpD" +
"1pf1CAAAAAP__________gmlkgnY0gmlwhBLf22SJc2VjcDI1NmsxoQJxCnE6v_x2ekgY_uo" +
"E1rtwzvGy40mq9eD66XfHPBWgIIN1ZHCCD6A"
sampleNode1 := "- enr:-TESTNODE2"
sampleNode2 := "- enr:-TESTNODE3"
err = os.WriteFile(file.Name(), []byte(sampleNode0+"\n"+sampleNode1+"\n"+sampleNode2), 0644)
require.NoError(t, err, "Error in WriteFile call")
nodeList, err := readbootNodes(file.Name())
require.NoError(t, err, "Error in readbootNodes call")
assert.Equal(t, sampleNode0[2:], nodeList[0], "Unexpected nodes")
assert.Equal(t, sampleNode1[2:], nodeList[1], "Unexpected nodes")
assert.Equal(t, sampleNode2[2:], nodeList[2], "Unexpected nodes")
}