mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
588dea83b7
* test coverage and updates to config twiddlers * LoadChainConfigFile error if SetActive conflicts * lint * wip working around test issues * more fixes, mass test updates * lint * linting * thanks deepsource! * fix undeclared vars * fixing more undefined * fix a bug, make a bug, repeat * gaz * use stock mainnet in case fork schedule matters * remove unused KnownConfigs * post-merge cleanup * eliminating OverrideBeaconConfig outside tests * more cleanup of OverrideBeaconConfig outside tests * config for interop w/ genesis gen support * improve var name * API on package instead of exported value * cleanup remainders of "registry" naming * Nishant feedback * add ropstein to configset * lint * lint #2 * ✂️ * revert accidental commented line * check if active is nil (replace called on empty) * Nishant feedback * replace OverrideBeaconConfig call * update interop instructions w/ new flag * don't let interop replace config set via cli flags Co-authored-by: kasey <kasey@users.noreply.github.com>
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package p2p
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"net"
|
|
"os"
|
|
"testing"
|
|
|
|
gethCrypto "github.com/ethereum/go-ethereum/crypto"
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
|
"github.com/libp2p/go-libp2p-core/crypto"
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
)
|
|
|
|
func TestPrivateKeyLoading(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
file, err := os.CreateTemp(t.TempDir(), "key")
|
|
require.NoError(t, err)
|
|
key, _, err := crypto.GenerateSecp256k1Key(rand.Reader)
|
|
require.NoError(t, err, "Could not generate key")
|
|
raw, err := key.Raw()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
out := hex.EncodeToString(raw)
|
|
|
|
err = os.WriteFile(file.Name(), []byte(out), params.BeaconIoConfig().ReadWritePermissions)
|
|
require.NoError(t, err, "Could not write key to file")
|
|
log.WithField("file", file.Name()).WithField("key", out).Info("Wrote key to file")
|
|
cfg := &Config{
|
|
PrivateKey: file.Name(),
|
|
}
|
|
pKey, err := privKey(cfg)
|
|
require.NoError(t, err, "Could not apply option")
|
|
newPkey := convertToInterfacePrivkey(pKey)
|
|
rawBytes, err := key.Raw()
|
|
require.NoError(t, err)
|
|
newRaw, err := newPkey.Raw()
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, rawBytes, newRaw, "Private keys do not match")
|
|
}
|
|
|
|
func TestIPV6Support(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
key, err := gethCrypto.GenerateKey()
|
|
require.NoError(t, err)
|
|
db, err := enode.OpenDB("")
|
|
if err != nil {
|
|
log.Error("could not open node's peer database")
|
|
}
|
|
lNode := enode.NewLocalNode(db, key)
|
|
mockIPV6 := net.IP{0xff, 0x02, 0xAA, 0, 0x1F, 0, 0x2E, 0, 0, 0x36, 0x45, 0, 0, 0, 0, 0x02}
|
|
lNode.Set(enr.IP(mockIPV6))
|
|
ma, err := convertToSingleMultiAddr(lNode.Node())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ipv6Exists := false
|
|
for _, p := range ma.Protocols() {
|
|
if p.Name == "ip4" {
|
|
t.Error("Got ip4 address instead of ip6")
|
|
}
|
|
if p.Name == "ip6" {
|
|
ipv6Exists = true
|
|
}
|
|
}
|
|
if !ipv6Exists {
|
|
t.Error("Multiaddress did not have ipv6 protocol")
|
|
}
|
|
}
|