mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Apply testutils assertions: final cleanup (#7003)
* slasher/beaconclient tests * slasher/db/kv tests * Merge branch 'master' into apply-testutils-assertions-to-slasher * fix build * slasher/detection tests * rest of the tests * misc tests * tools tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * agg tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * updates aggregated_test * beacon-chain/operations/attestations/kv/* tests updated * beacon-chain/operations/attestations tests updated * beacon-chain/operations/slashings tests updated * Merge branch 'master' into apply-testutils-assertions-misc * gazelle * beacon-chain/core tests updated * fixes test * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/rpc tests updated * beacon-chain/sync/initial-sync tests * misc tests * optimizes error message parsing in testutils * Merge branch 'assertutils-optimize-processing' into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * endtoend tests * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * beacon-chain/blockchain tests updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/state/stategen tests updated * beacon-chain all left-over tests are done * Merge refs/heads/master into apply-testutils-assertions-misc * validator tests updated * slasher tests * Merge branch 'master' into apply-testutils-assertions-misc * gofmt * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * shared upd * end2end tests deps fixed * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * misc * all tests are updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -13,13 +15,21 @@ import (
|
||||
"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()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
privKey := extractPrivateKey()
|
||||
cfg := discover.Config{
|
||||
PrivateKey: privKey,
|
||||
@@ -29,9 +39,7 @@ func TestBootnode_OK(t *testing.T) {
|
||||
|
||||
cfg.PrivateKey = extractPrivateKey()
|
||||
bootNode, err := enode.Parse(enode.ValidSchemes, listener.Self().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
cfg.Bootnodes = []*enode.Node{bootNode}
|
||||
listener2 := createListener(ipAddr, 4001, cfg)
|
||||
defer listener2.Close()
|
||||
@@ -43,34 +51,20 @@ func TestBootnode_OK(t *testing.T) {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
nodes := listener.Lookup(listenerNode2.ID())
|
||||
if len(nodes) == 0 {
|
||||
t.Fatalf("Length of nodes stored in table is not expected. Wanted to be more than %d but got %d", 0, len(nodes))
|
||||
|
||||
}
|
||||
if nodes[0].ID() != listenerNode2.ID() {
|
||||
t.Errorf("Wanted node ID of %s but got %s", listenerNode2.ID(), nodes[1].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())
|
||||
if len(nodes) == 0 {
|
||||
t.Errorf("Length of nodes stored in table is not expected. Wanted to be more than %d but got %d", 0, len(nodes))
|
||||
|
||||
}
|
||||
if nodes[0].ID() != listenerNode.ID() {
|
||||
t.Errorf("Wanted node ID of %s but got %s", listenerNode.ID(), nodes[1].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)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
pk, err := privKey.Raw()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
*privateKey = fmt.Sprintf("%x", pk)
|
||||
|
||||
extractedKey := extractPrivateKey()
|
||||
@@ -78,13 +72,9 @@ func TestPrivateKey_ParsesCorrectly(t *testing.T) {
|
||||
rawKey := (*ecdsa.PrivateKey)((*btcec.PrivateKey)(privKey.(*crypto.Secp256k1PrivateKey)))
|
||||
|
||||
r, s, err := ecdsa.Sign(rand.Reader, extractedKey, []byte{'t', 'e', 's', 't'})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
isVerified := ecdsa.Verify(&rawKey.PublicKey, []byte{'t', 'e', 's', 't'}, r, s)
|
||||
if !isVerified {
|
||||
t.Error("Unmarshalled key is not the same as the key that was given to the function")
|
||||
}
|
||||
assert.Equal(t, true, isVerified, "Unmarshalled key is not the same as the key that was given to the function")
|
||||
*privateKey = ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user