mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
3cb32c3792
* add discovery * gaz * add build options * add udpPort * add more changes * refactor private key * added discovery loop * add ttl * add ttl * use ip type instead of string * tests pass * gaz and new test file * add test * add more tests * add one more test * adding multiAddr tests * adding new protocol , listener * fix keys * more fixes * more changes dialing peers works now * gaz * add more changes * add more changes * gaz * add new test helpers * new test * fixed all tests * gaz * reduce sleep * lint * new changes * change formats * fix all this stuff * remove discv5 protocol * remove protocol * remove port condition,too restrictive * preston's feedback * preston's feedback * close all peers * gaz * remove unused func * Update beacon-chain/p2p/service.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * remove build options * refactor tests
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package p2p
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
curve "github.com/ethereum/go-ethereum/crypto"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
)
|
|
|
|
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 := ecdsa.GenerateKey(curve.S256(), rand.Reader)
|
|
if err != nil {
|
|
t.Fatalf("Could not generate key: %v", err)
|
|
}
|
|
keyStr := hex.EncodeToString(curve.FromECDSA(key))
|
|
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")
|
|
cfg := &Config{
|
|
PrivateKey: file.Name(),
|
|
}
|
|
pKey, err := privKey(cfg)
|
|
if err != nil {
|
|
t.Fatalf("Could not apply option: %v", err)
|
|
}
|
|
newEncoded := hex.EncodeToString(curve.FromECDSA(pKey))
|
|
if newEncoded != keyStr {
|
|
t.Error("Private keys do not match")
|
|
}
|
|
}
|