-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: proper subscribe to shards.test fleet (#49)
* fix: proper subscribe to shards.test fleet * test: waku initialization test * test: fleets * test: parseEnrProtocols * test: watch transport connection status
- Loading branch information
1 parent
bd52c08
commit df9939c
Showing
6 changed files
with
248 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package transport | ||
|
||
import ( | ||
"github.com/waku-org/go-waku/waku/v2/protocol" | ||
"github.com/waku-org/go-waku/waku/v2/protocol/relay" | ||
) | ||
|
||
type FleetName string | ||
|
||
const ( | ||
ShardsStaging FleetName = "shards.staging" | ||
ShardsTest FleetName = "shards.test" | ||
WakuSandbox FleetName = "waku.sandbox" | ||
WakuTest FleetName = "waku.test" | ||
) | ||
|
||
const ( | ||
DefaultClusterID = 16 | ||
DefaultShardID = 64 | ||
) | ||
|
||
var fleets = map[FleetName]string{ | ||
WakuSandbox: "enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im", | ||
ShardsTest: "enrtree://AMOJVZX4V6EXP7NTJPMAYJYST2QP6AJXYW76IU6VGJS7UVSNDYZG4@boot.test.shards.nodes.status.im", | ||
} | ||
|
||
func FleetENRTree(fleet FleetName) (string, bool) { | ||
enr, ok := fleets[fleet] | ||
return enr, ok | ||
} | ||
|
||
func (f FleetName) IsSharded() bool { | ||
return f == ShardsStaging || f == ShardsTest | ||
} | ||
|
||
func (f FleetName) DefaultPubsubTopic() string { | ||
if f.IsSharded() { | ||
return protocol.NewStaticShardingPubsubTopic(DefaultClusterID, DefaultShardID).String() | ||
} | ||
|
||
return relay.DefaultWakuTopic | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package transport | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/brianvoe/gofakeit/v6" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFleets(t *testing.T) { | ||
enr, ok := FleetENRTree(WakuSandbox) | ||
require.True(t, ok) | ||
require.Equal(t, fleets[WakuSandbox], enr) | ||
|
||
enr, ok = FleetENRTree(ShardsTest) | ||
require.True(t, ok) | ||
require.Equal(t, fleets[ShardsTest], enr) | ||
|
||
_, ok = FleetENRTree(WakuTest) | ||
require.False(t, ok) // We know this fleet, but it's not supported | ||
} | ||
|
||
func TestFleetSharded(t *testing.T) { | ||
require.True(t, ShardsTest.IsSharded()) | ||
require.True(t, ShardsStaging.IsSharded()) | ||
require.False(t, WakuSandbox.IsSharded()) | ||
require.False(t, WakuTest.IsSharded()) | ||
require.False(t, FleetName(gofakeit.LetterN(5)).IsSharded()) | ||
} | ||
|
||
func TestFleetDefaultPubsubTopic(t *testing.T) { | ||
require.Equal(t, "/waku/2/default-waku/proto", WakuSandbox.DefaultPubsubTopic()) | ||
require.Equal(t, "/waku/2/rs/16/64", ShardsTest.DefaultPubsubTopic()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package transport | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/brianvoe/gofakeit/v6" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/waku-org/go-waku/waku/v2/node" | ||
wakuenr "github.com/waku-org/go-waku/waku/v2/protocol/enr" | ||
"go.uber.org/zap" | ||
|
||
"github.com/six78/2-story-points-cli/internal/testcommon" | ||
pp "github.com/six78/2-story-points-cli/pkg/protocol" | ||
) | ||
|
||
func TestWakuSuite(t *testing.T) { | ||
suite.Run(t, new(WakuSuite)) | ||
} | ||
|
||
type WakuSuite struct { | ||
testcommon.Suite | ||
node *Node | ||
cancel func() | ||
} | ||
|
||
func (s *WakuSuite) SetupSuite() { | ||
var ctx context.Context | ||
ctx, s.cancel = context.WithCancel(context.Background()) | ||
|
||
logger, err := zap.NewDevelopment() | ||
s.Require().NoError(err) | ||
|
||
// Skip initialization, for this test we only need roomCache and logger | ||
s.node = NewNode(ctx, logger) | ||
} | ||
|
||
func (s *WakuSuite) TearDownSuite() { | ||
s.cancel() | ||
} | ||
|
||
func (s *WakuSuite) TestPublicEncryption() { | ||
room, err := pp.NewRoom() | ||
s.Require().NoError(err) | ||
|
||
payload := make([]byte, 100) | ||
gofakeit.Slice(payload) | ||
|
||
message, err := s.node.buildWakuMessage(room, payload) | ||
s.Require().NoError(err) | ||
|
||
err = s.node.encryptPublicPayload(room, message) | ||
s.Require().NoError(err) | ||
|
||
decryptedPayload, err := decryptMessage(room, message) | ||
s.Require().NoError(err) | ||
|
||
s.Require().Equal(payload, decryptedPayload) | ||
} | ||
|
||
func (s *WakuSuite) TestWakuInitialize() { | ||
err := s.node.Initialize() | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *WakuSuite) TestParseEnrProtocols() { | ||
p := parseEnrProtocols(wakuenr.WakuEnrBitfield(0b00000000)) | ||
s.Require().Empty(p) | ||
|
||
p = parseEnrProtocols(wakuenr.WakuEnrBitfield(0b00000001)) | ||
s.Require().Equal("relay", p) | ||
|
||
p = parseEnrProtocols(wakuenr.WakuEnrBitfield(0b00000010)) | ||
s.Require().Equal("store", p) | ||
|
||
p = parseEnrProtocols(wakuenr.WakuEnrBitfield(0b00000011)) | ||
s.Require().Equal("store,relay", p) | ||
|
||
p = parseEnrProtocols(wakuenr.WakuEnrBitfield(0b00000100)) | ||
s.Require().Equal("filter", p) | ||
|
||
p = parseEnrProtocols(wakuenr.WakuEnrBitfield(0b00001000)) | ||
s.Require().Equal("lightpush", p) | ||
|
||
p = parseEnrProtocols(wakuenr.WakuEnrBitfield(0b00001111)) | ||
s.Require().Equal("lightpush,filter,store,relay", p) | ||
} | ||
|
||
func (s *WakuSuite) TestWatchConnectionStatus() { | ||
err := s.node.Initialize() | ||
s.Require().NoError(err) | ||
|
||
sub := s.node.SubscribeToConnectionStatus() | ||
|
||
finished := make(chan struct{}) | ||
|
||
go func() { | ||
s.node.watchConnectionStatus() | ||
close(finished) | ||
}() | ||
|
||
sent := node.ConnStatus{} | ||
err = gofakeit.Struct(&sent) | ||
s.Require().NoError(err) | ||
|
||
s.node.wakuConnectionStatus <- sent | ||
|
||
select { | ||
case received := <-sub: | ||
s.Require().Equal(sent.IsOnline, received.IsOnline) | ||
s.Require().Equal(sent.HasHistory, received.HasHistory) | ||
s.Require().Equal(len(sent.Peers), received.PeersCount) | ||
s.Require().True(reflect.DeepEqual(received, s.node.ConnectionStatus())) | ||
case <-time.After(500 * time.Millisecond): | ||
s.Require().Fail("timeout waiting for connection status") | ||
} | ||
|
||
close(s.node.wakuConnectionStatus) | ||
|
||
select { | ||
case <-finished: | ||
break | ||
case <-time.After(500 * time.Millisecond): | ||
s.Require().Fail("timeout waiting for connection status watch finish") | ||
} | ||
} |