mirror of https://github.com/status-im/go-waku.git
test: utils (#95)
This commit is contained in:
parent
68fe29c56f
commit
b1284d367d
|
@ -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)
|
||||
}
|
|
@ -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"))
|
||||
}
|
Loading…
Reference in New Issue