mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 09:14:28 +00:00
82efca9b6f
* move to deprecated-p2p * fix lint * lint? * fix lint * lint * lint * lint * lint
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package p2p
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
crypto "github.com/libp2p/go-libp2p-crypto"
|
|
"github.com/libp2p/go-libp2p/config"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
)
|
|
|
|
func TestBuildOptions(t *testing.T) {
|
|
opts := buildOptions(&ServerConfig{})
|
|
|
|
_ = opts
|
|
}
|
|
|
|
func TestPrivateKeyLoading(t *testing.T) {
|
|
file, err := ioutil.TempFile(testutil.TempDir(), "key")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer os.Remove(file.Name())
|
|
key, _, err := crypto.GenerateKeyPair(crypto.RSA, 2048)
|
|
if err != nil {
|
|
t.Fatalf("Could not generate key: %v", err)
|
|
}
|
|
marshaled, err := crypto.MarshalPrivateKey(key)
|
|
if err != nil {
|
|
t.Fatalf("Could not marshal key: %v", err)
|
|
}
|
|
keyStr := crypto.ConfigEncodeKey(marshaled)
|
|
|
|
err = ioutil.WriteFile(file.Name(), []byte(keyStr), 0600)
|
|
if err != nil {
|
|
t.Fatalf("Could not write key to file: %v", err)
|
|
}
|
|
log.WithField("file", file.Name()).WithField("key", keyStr).Info("Wrote key to file")
|
|
|
|
var cfg config.Config
|
|
err = cfg.Apply(privKey(file.Name()))
|
|
if err != nil {
|
|
t.Fatalf("Could not apply option: %v", err)
|
|
}
|
|
newMarshaled, _ := crypto.MarshalPrivateKey(cfg.PeerKey)
|
|
newEncoded := crypto.ConfigEncodeKey(newMarshaled)
|
|
if newEncoded != keyStr {
|
|
t.Error("Private keys do not match")
|
|
}
|
|
}
|