Skip to content

Commit 94cd6ed

Browse files
committed
test(client): refactor relay peer multiaddr usage in tests
1 parent a052b13 commit 94cd6ed

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

client_additional_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12+
const testRelayPeerMultiaddr = "/ip4/127.0.0.1/tcp/4001/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N"
13+
1214
func TestNewClientWithCustomRelayPeers(t *testing.T) {
1315
tests := []struct {
1416
name string
@@ -18,7 +20,7 @@ func TestNewClientWithCustomRelayPeers(t *testing.T) {
1820
{
1921
name: "single relay peer",
2022
relayPeers: []string{
21-
"/ip4/127.0.0.1/tcp/4001/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N",
23+
testRelayPeerMultiaddr,
2224
},
2325
wantErr: false,
2426
},
@@ -66,7 +68,7 @@ func TestConfigureRelayPeersWithValidPeers(t *testing.T) {
6668

6769
// Valid relay peer
6870
relayPeersConfig := []string{
69-
"/ip4/127.0.0.1/tcp/4001/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N",
71+
testRelayPeerMultiaddr,
7072
}
7173

7274
relayPeers := configureRelayPeers(relayPeersConfig, bootstrapPeers, logger)
@@ -80,7 +82,7 @@ func TestConfigureRelayPeersWithMixedValidity(t *testing.T) {
8082

8183
// Mix of valid and invalid
8284
relayPeersConfig := []string{
83-
"/ip4/127.0.0.1/tcp/4001/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N",
85+
testRelayPeerMultiaddr,
8486
"invalid-peer",
8587
}
8688

client_edge_cases_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12+
const testMessagingTopic = "messaging-test"
13+
1214
func TestClientTwoWayMessaging(t *testing.T) {
1315
// Create two clients
1416
privKey1, err := GeneratePrivateKey()
@@ -42,16 +44,16 @@ func TestClientTwoWayMessaging(t *testing.T) {
4244
}()
4345

4446
// Subscribe to same topic
45-
msgChan1 := cl1.Subscribe("messaging-test")
46-
msgChan2 := cl2.Subscribe("messaging-test")
47+
msgChan1 := cl1.Subscribe(testMessagingTopic)
48+
msgChan2 := cl2.Subscribe(testMessagingTopic)
4749

4850
// Give time for subscriptions and discovery
4951
time.Sleep(3 * time.Second)
5052

5153
// Publish from client1
5254
ctx := context.Background()
5355
testData := []byte("Hello from client1")
54-
err = cl1.Publish(ctx, "messaging-test", testData)
56+
err = cl1.Publish(ctx, testMessagingTopic, testData)
5557
require.NoError(t, err)
5658

5759
// Try to receive on both clients (one should get it, the sender filters itself)

client_helpers_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/stretchr/testify/require"
1313
)
1414

15+
const testLocalMultiaddr = "/ip4/127.0.0.1/tcp/4001"
16+
1517
func TestParseMultiaddrs(t *testing.T) {
1618
tests := []struct {
1719
name string
@@ -21,7 +23,7 @@ func TestParseMultiaddrs(t *testing.T) {
2123
}{
2224
{
2325
name: "valid multiaddrs",
24-
addrs: []string{"/ip4/127.0.0.1/tcp/4001", "/ip6/::1/tcp/4001"},
26+
addrs: []string{testLocalMultiaddr, "/ip6/::1/tcp/4001"},
2527
expectedCount: 2,
2628
description: "valid multiaddrs should be parsed successfully",
2729
},
@@ -51,7 +53,7 @@ func TestParseMultiaddrs(t *testing.T) {
5153
},
5254
{
5355
name: "mixed valid and invalid",
54-
addrs: []string{"/ip4/127.0.0.1/tcp/4001", "invalid", "/ip6/::1/tcp/4001"},
56+
addrs: []string{testLocalMultiaddr, "invalid", "/ip6/::1/tcp/4001"},
5557
expectedCount: 2,
5658
description: "only valid multiaddrs should be included",
5759
},
@@ -105,7 +107,7 @@ func TestConnectToCachedPeers(t *testing.T) {
105107
{
106108
ID: "invalid-peer-id",
107109
Name: "test",
108-
Addrs: []string{"/ip4/127.0.0.1/tcp/4001"},
110+
Addrs: []string{testLocalMultiaddr},
109111
},
110112
}
111113
},

0 commit comments

Comments
 (0)