Skip to content

Commit

Permalink
fix: change node2 to lightpush receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
romanzac committed May 2, 2024
1 parent 12a8923 commit 73a90e0
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions waku/v2/protocol/lightpush/waku_lightpush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ func makeWakuRelay(t *testing.T, pusubTopic string) (*relay.WakuRelay, *relay.Su
return relay, sub[0], host
}

func makeWakuLightPush(t *testing.T, relay *relay.WakuRelay, pm *peermanager.PeerManager) (*WakuLightPush, host.Host) {
port, err := tests.FindFreePort(t, "", 5)
require.NoError(t, err)

host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err)

lightPushNode := NewWakuLightPush(relay, pm, prometheus.DefaultRegisterer, utils.Logger())
lightPushNode.SetHost(host)

return lightPushNode, host
}

// Node1: Relay
// Node2: Relay+Lightpush
// Client that will lightpush a message
Expand Down Expand Up @@ -327,30 +340,16 @@ func TestWakuLightPushWithStaticSharding(t *testing.T) {
defer node1.Stop()
defer sub1.Unsubscribe()

node2, sub2, host2 := makeWakuRelay(t, pubSubTopic)
defer node2.Stop()
defer sub2.Unsubscribe()

lightPushNode2 := NewWakuLightPush(node2, nil, prometheus.DefaultRegisterer, utils.Logger())
lightPushNode2.SetHost(host2)
err := lightPushNode2.Start(ctx)
require.NoError(t, err)
defer lightPushNode2.Stop()
_, host2 := makeWakuLightPush(t, nil, nil)

host2.Peerstore().AddAddr(host1.ID(), tests.GetHostAddress(host1), peerstore.PermanentAddrTTL)
err = host2.Peerstore().AddProtocols(host1.ID(), relay.WakuRelayID_v200)
err := host2.Peerstore().AddProtocols(host1.ID(), relay.WakuRelayID_v200)
require.NoError(t, err)

err = host2.Connect(ctx, host2.Peerstore().PeerInfo(host1.ID()))
require.NoError(t, err)

port, err := tests.FindFreePort(t, "", 5)
require.NoError(t, err)

clientHost, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err)
client := NewWakuLightPush(nil, nil, prometheus.DefaultRegisterer, utils.Logger())
client.SetHost(clientHost)
client, clientHost := makeWakuLightPush(t, nil, nil)

clientHost.Peerstore().AddAddr(host2.ID(), tests.GetHostAddress(host2), peerstore.PermanentAddrTTL)
err = clientHost.Peerstore().AddProtocols(host2.ID(), LightPushID_v20beta1)
Expand Down

0 comments on commit 73a90e0

Please sign in to comment.