Skip to content

Commit

Permalink
fix: add ENR shard info comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
romanzac committed Apr 8, 2024
1 parent 72be483 commit 9693bed
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions waku/v2/node/wakunode2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
wenr "github.com/waku-org/go-waku/waku/v2/protocol/enr"
"math/big"
"net"
"sync"
Expand Down Expand Up @@ -419,6 +420,8 @@ func TestStaticShardingLimits(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 140*time.Second)
defer cancel()

testClusterID := uint16(21)

// Node1 with Relay
hostAddr1, err := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
require.NoError(t, err)
Expand All @@ -427,7 +430,7 @@ func TestStaticShardingLimits(t *testing.T) {
wakuNode1, err := New(
WithHostAddress(hostAddr1),
WithWakuRelay(),
WithClusterID(uint16(21)),
WithClusterID(testClusterID),
WithDiscoveryV5(uint(discv5UDPPort1), nil, true),
)
require.NoError(t, err)
Expand All @@ -443,7 +446,7 @@ func TestStaticShardingLimits(t *testing.T) {
wakuNode2, err := New(
WithHostAddress(hostAddr2),
WithWakuRelay(),
WithClusterID(uint16(21)),
WithClusterID(testClusterID),
WithDiscoveryV5(uint(discv5UDPPort2), []*enode.Node{wakuNode1.localNode.Node()}, true),
)
require.NoError(t, err)
Expand All @@ -463,9 +466,14 @@ func TestStaticShardingLimits(t *testing.T) {

r1 := wakuNode1.Relay()

var shardedPubSubTopics []string
var (
shardedPubSubTopics []string
expectedShardIDs []uint16
)

for i := 0; i < 1024; i++ {
shardedPubSubTopics = append(shardedPubSubTopics, fmt.Sprintf("/waku/2/rs/21/%d", i))
shardedPubSubTopics = append(shardedPubSubTopics, fmt.Sprintf("/waku/2/rs/%d/%d", testClusterID, i))
expectedShardIDs = append(expectedShardIDs, uint16(i))

Check failure on line 476 in waku/v2/node/wakunode2_test.go

View workflow job for this annotation

GitHub Actions / lint

SA4010: this result of append is never used, except maybe in other appends (staticcheck)
}

// Subscribe topics related to static sharding
Expand All @@ -475,5 +483,12 @@ func TestStaticShardingLimits(t *testing.T) {
time.Sleep(10 * time.Millisecond)
}

// Check ENR value after 1024 subscriptions
shardsENR, err := wenr.RelaySharding(wakuNode1.ENR().Record())
require.NoError(t, err)
require.Equal(t, testClusterID, shardsENR.ClusterID)
require.Equal(t, 1024, len(shardsENR.ShardIDs))

time.Sleep(1 * time.Second)

}

0 comments on commit 9693bed

Please sign in to comment.