Skip to content

Commit 4a0b1d9

Browse files
committed
Finally Fix All Tests
1 parent d3ca607 commit 4a0b1d9

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

beacon-chain/p2p/dial_relay_node_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"testing"
77

8-
bh "github.com/libp2p/go-libp2p/p2p/host/blank"
9-
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
8+
"github.com/libp2p/go-libp2p"
9+
"github.com/libp2p/go-libp2p/core/network"
1010
"github.com/prysmaticlabs/prysm/v5/testing/assert"
1111
"github.com/prysmaticlabs/prysm/v5/testing/require"
1212
)
@@ -29,8 +29,10 @@ func TestDialRelayNode_InvalidPeerString(t *testing.T) {
2929

3030
func TestDialRelayNode_OK(t *testing.T) {
3131
ctx := context.Background()
32-
relay := bh.NewBlankHost(swarmt.GenSwarm(t))
33-
host := bh.NewBlankHost(swarmt.GenSwarm(t))
32+
relay, err := libp2p.New(libp2p.ResourceManager(&network.NullResourceManager{}))
33+
require.NoError(t, err)
34+
host, err := libp2p.New(libp2p.ResourceManager(&network.NullResourceManager{}))
35+
require.NoError(t, err)
3436
relayAddr := fmt.Sprintf("%s/p2p/%s", relay.Addrs()[0], relay.ID().String())
3537

3638
assert.NoError(t, dialRelayNode(ctx, host, relayAddr), "Unexpected error when dialing relay node")

beacon-chain/p2p/testing/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ go_library(
2222
"//beacon-chain/p2p/peers/scorers:go_default_library",
2323
"//proto/prysm/v1alpha1:go_default_library",
2424
"//proto/prysm/v1alpha1/metadata:go_default_library",
25+
"//testing/require:go_default_library",
2526
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
2627
"@com_github_ethereum_go_ethereum//p2p/enode:go_default_library",
2728
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
29+
"@com_github_libp2p_go_libp2p//:go_default_library",
2830
"@com_github_libp2p_go_libp2p//core:go_default_library",
2931
"@com_github_libp2p_go_libp2p//core/connmgr:go_default_library",
3032
"@com_github_libp2p_go_libp2p//core/control:go_default_library",

beacon-chain/p2p/testing/p2p.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import (
1111
"time"
1212

1313
"github.com/ethereum/go-ethereum/p2p/enr"
14+
"github.com/libp2p/go-libp2p"
1415
pubsub "github.com/libp2p/go-libp2p-pubsub"
1516
core "github.com/libp2p/go-libp2p/core"
1617
"github.com/libp2p/go-libp2p/core/control"
1718
"github.com/libp2p/go-libp2p/core/host"
1819
"github.com/libp2p/go-libp2p/core/network"
1920
"github.com/libp2p/go-libp2p/core/peer"
2021
"github.com/libp2p/go-libp2p/core/protocol"
21-
bhost "github.com/libp2p/go-libp2p/p2p/host/blank"
22-
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
2322
"github.com/multiformats/go-multiaddr"
2423
ssz "github.com/prysmaticlabs/fastssz"
2524
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/encoder"
2625
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers"
2726
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/peers/scorers"
2827
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
2928
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/metadata"
29+
"github.com/prysmaticlabs/prysm/v5/testing/require"
3030
"github.com/sirupsen/logrus"
3131
"google.golang.org/protobuf/proto"
3232
)
@@ -52,7 +52,8 @@ type TestP2P struct {
5252
// NewTestP2P initializes a new p2p test service.
5353
func NewTestP2P(t *testing.T) *TestP2P {
5454
ctx := context.Background()
55-
h := bhost.NewBlankHost(swarmt.GenSwarm(t, swarmt.OptDisableQUIC))
55+
h, err := libp2p.New(libp2p.ResourceManager(&network.NullResourceManager{}))
56+
require.NoError(t, err)
5657
ps, err := pubsub.NewFloodSub(ctx, h,
5758
pubsub.WithMessageSigning(false),
5859
pubsub.WithStrictSignatureVerification(false),
@@ -92,7 +93,8 @@ func connect(a, b host.Host) error {
9293

9394
// ReceiveRPC simulates an incoming RPC.
9495
func (p *TestP2P) ReceiveRPC(topic string, msg proto.Message) {
95-
h := bhost.NewBlankHost(swarmt.GenSwarm(p.t))
96+
h, err := libp2p.New(libp2p.ResourceManager(&network.NullResourceManager{}))
97+
require.NoError(p.t, err)
9698
if err := connect(h, p.BHost); err != nil {
9799
p.t.Fatalf("Failed to connect two peers for RPC: %v", err)
98100
}
@@ -122,7 +124,8 @@ func (p *TestP2P) ReceiveRPC(topic string, msg proto.Message) {
122124

123125
// ReceivePubSub simulates an incoming message over pubsub on a given topic.
124126
func (p *TestP2P) ReceivePubSub(topic string, msg proto.Message) {
125-
h := bhost.NewBlankHost(swarmt.GenSwarm(p.t))
127+
h, err := libp2p.New(libp2p.ResourceManager(&network.NullResourceManager{}))
128+
require.NoError(p.t, err)
126129
ps, err := pubsub.NewFloodSub(context.Background(), h,
127130
pubsub.WithMessageSigning(false),
128131
pubsub.WithStrictSignatureVerification(false),
@@ -136,7 +139,7 @@ func (p *TestP2P) ReceivePubSub(topic string, msg proto.Message) {
136139

137140
// PubSub requires some delay after connecting for the (*PubSub).processLoop method to
138141
// pick up the newly connected peer.
139-
time.Sleep(time.Millisecond * 100)
142+
time.Sleep(time.Millisecond * 1000)
140143

141144
castedMsg, ok := msg.(ssz.Marshaler)
142145
if !ok {

beacon-chain/sync/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ go_test(
254254
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
255255
"@com_github_ethereum_go_ethereum//p2p/enr:go_default_library",
256256
"@com_github_golang_snappy//:go_default_library",
257+
"@com_github_ipfs_go_log_v2//:go_default_library",
257258
"@com_github_libp2p_go_libp2p//core:go_default_library",
258259
"@com_github_libp2p_go_libp2p//core/network:go_default_library",
259260
"@com_github_libp2p_go_libp2p//core/peer:go_default_library",

beacon-chain/sync/subscriber_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,11 @@ func TestSubscribe_HandlesPanic(t *testing.T) {
264264
panic("bad")
265265
}, p.Digest)
266266
r.markForChainStart()
267+
t.Logf("%v", r.cfg.p2p.PubSub().GetTopics())
267268
p.ReceivePubSub(topic, &pb.SignedVoluntaryExit{Exit: &pb.VoluntaryExit{Epoch: 55}, Signature: make([]byte, fieldparams.BLSSignatureLength)})
268269

269270
if util.WaitTimeout(&wg, time.Second) {
270-
t.Fatal("Did not receive PubSub in 1 second")
271+
t.Fatalf("Did not receive PubSub in 1 second: %v", r.cfg.p2p.PubSub().ListPeers(topic))
271272
}
272273
}
273274

0 commit comments

Comments
 (0)