From b1284d367d4c5ebc75c64adc65b10a5bd43bc946 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 20 Oct 2021 14:43:59 -0400 Subject: [PATCH] test: utils (#95) --- waku/v2/protocol/pb/utils_test.go | 27 +++++++++++++++++++++++++++ waku/v2/protocol/utils_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 waku/v2/protocol/pb/utils_test.go create mode 100644 waku/v2/protocol/utils_test.go diff --git a/waku/v2/protocol/pb/utils_test.go b/waku/v2/protocol/pb/utils_test.go new file mode 100644 index 00000000..7f42bb4b --- /dev/null +++ b/waku/v2/protocol/pb/utils_test.go @@ -0,0 +1,27 @@ +package pb + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestHash(t *testing.T) { + expected := []byte{89, 47, 167, 67, 136, 159, 199, 249, 42, 194, 163, 123, 177, 245, 186, 29, 175, 42, 92, 132, 116, 28, 160, 224, 6, 29, 36, 58, 46, 103, 7, 186} + result := Hash([]byte("Hello World")) + require.Equal(t, expected, result) +} + +func TestEnvelopeHash(t *testing.T) { + msg := new(WakuMessage) + msg.ContentTopic = "Test" + msg.Payload = []byte("Hello World") + msg.Timestamp = float64(123456789123456789) + msg.Version = 1 + + expected := []byte{77, 197, 250, 41, 30, 163, 192, 239, 48, 104, 58, 175, 36, 81, 96, 58, 118, 107, 73, 4, 153, 182, 33, 199, 144, 156, 110, 226, 93, 85, 160, 180} + result, err := msg.Hash() + + require.NoError(t, err) + require.Equal(t, expected, result) +} diff --git a/waku/v2/protocol/utils_test.go b/waku/v2/protocol/utils_test.go new file mode 100644 index 00000000..a6fbec12 --- /dev/null +++ b/waku/v2/protocol/utils_test.go @@ -0,0 +1,25 @@ +package protocol + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestFulltextMatch(t *testing.T) { + expectedProtocol := "/vac/waku/relay/2.0.0" + fn := FulltextMatch(expectedProtocol) + + require.True(t, fn(expectedProtocol)) + require.False(t, fn("/some/random/protocol/1.0.0")) +} + +func TestPrefixTextMatch(t *testing.T) { + expectedPrefix := "/vac/waku/relay/2.0" + fn := PrefixTextMatch(expectedPrefix) + + require.True(t, fn("/vac/waku/relay/2.0.0")) + require.True(t, fn("/vac/waku/relay/2.0.2")) + require.False(t, fn("/vac/waku/relay/2.1.0")) + require.False(t, fn("/some/random/protocol/1.0.0")) +}