mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 05:38:55 +00:00
7cc32c4dda
* remove unused code * remove defer use in loop * Remove unused methods and constants * gofmt and gaz * nilness check * remove unused args * Add TODO for refactoring subscribeWithBase to remove unused arg. It seems too involved to include in this sweeping PR. https://github.com/prysmaticlabs/prysm/issues/7437 * replace empty slice declaration * Remove unnecessary type conversions * remove redundant type declaration * rename receivers to be consistent * Remove bootnode query tool. It is now obsolete by discv5 * Remove relay node. It is no longer used or supported * Revert "Remove relay node. It is no longer used or supported" This reverts commit 4bd7717334dad85ef4766ed9bc4da711fb5fa810. * Delete unused test directory * Delete unsupported gcp startup script * Delete old k8s script * build fixes * fix build * go mod tidy * revert slasher/db/kv/block_header.go * fix build * remove redundant nil check * combine func args Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"crypto/rand"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
"github.com/libp2p/go-libp2p-core/crypto"
|
|
"github.com/prysmaticlabs/prysm/shared/iputils"
|
|
_ "github.com/prysmaticlabs/prysm/shared/maxprocs"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
logrus.SetOutput(ioutil.Discard)
|
|
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestBootnode_OK(t *testing.T) {
|
|
ipAddr, err := iputils.ExternalIPv4()
|
|
require.NoError(t, err)
|
|
privKey := extractPrivateKey()
|
|
cfg := discover.Config{
|
|
PrivateKey: privKey,
|
|
}
|
|
listener := createListener(ipAddr, 4000, cfg)
|
|
defer listener.Close()
|
|
|
|
cfg.PrivateKey = extractPrivateKey()
|
|
bootNode, err := enode.Parse(enode.ValidSchemes, listener.Self().String())
|
|
require.NoError(t, err)
|
|
cfg.Bootnodes = []*enode.Node{bootNode}
|
|
listener2 := createListener(ipAddr, 4001, cfg)
|
|
defer listener2.Close()
|
|
|
|
// test that both the nodes have the other peer stored in their local table.
|
|
listenerNode := listener.Self()
|
|
listenerNode2 := listener2.Self()
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
nodes := listener.Lookup(listenerNode2.ID())
|
|
assert.NotEqual(t, 0, len(nodes), "Length of nodes stored in table is not expected")
|
|
assert.Equal(t, listenerNode2.ID(), nodes[0].ID())
|
|
|
|
nodes = listener2.Lookup(listenerNode.ID())
|
|
assert.NotEqual(t, 0, len(nodes), "Length of nodes stored in table is not expected")
|
|
assert.Equal(t, listenerNode.ID(), nodes[0].ID())
|
|
}
|
|
|
|
func TestPrivateKey_ParsesCorrectly(t *testing.T) {
|
|
privKey, _, err := crypto.GenerateSecp256k1Key(rand.Reader)
|
|
require.NoError(t, err)
|
|
|
|
pk, err := privKey.Raw()
|
|
require.NoError(t, err)
|
|
*privateKey = fmt.Sprintf("%x", pk)
|
|
|
|
extractedKey := extractPrivateKey()
|
|
|
|
rawKey := (*ecdsa.PrivateKey)(privKey.(*crypto.Secp256k1PrivateKey))
|
|
|
|
r, s, err := ecdsa.Sign(rand.Reader, extractedKey, []byte{'t', 'e', 's', 't'})
|
|
require.NoError(t, err)
|
|
|
|
isVerified := ecdsa.Verify(&rawKey.PublicKey, []byte{'t', 'e', 's', 't'}, r, s)
|
|
assert.Equal(t, true, isVerified, "Unmarshalled key is not the same as the key that was given to the function")
|
|
*privateKey = ""
|
|
}
|