prysm-pulse/beacon-chain/p2p/options_test.go
Nishant Das 3cb32c3792
Implement Discv5 in Prysm (#3211)
* 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
2019-08-21 11:38:30 +05:30

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")
}
}