aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/topic_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-04-13 17:16:51 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-04-13 17:16:51 +0800
commit9a53390f49b9667db162bf2ef487d0af64b3363d (patch)
treeb71d2daee37a56a7872d5d3c1536ed83a39d7bc2 /whisper/topic_test.go
parent7b501906db5b4bed0cf9972a1b103cc343d7f2d2 (diff)
downloadgo-tangerine-9a53390f49b9667db162bf2ef487d0af64b3363d.tar.gz
go-tangerine-9a53390f49b9667db162bf2ef487d0af64b3363d.tar.zst
go-tangerine-9a53390f49b9667db162bf2ef487d0af64b3363d.zip
whisper: clean up and integrate topics
Diffstat (limited to 'whisper/topic_test.go')
-rw-r--r--whisper/topic_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/whisper/topic_test.go b/whisper/topic_test.go
new file mode 100644
index 000000000..4626e2ae5
--- /dev/null
+++ b/whisper/topic_test.go
@@ -0,0 +1,38 @@
+package whisper
+
+import (
+ "bytes"
+ "testing"
+)
+
+var topicCreationTests = []struct {
+ data []byte
+ hash [4]byte
+}{
+ {hash: [4]byte{0xc5, 0xd2, 0x46, 0x01}, data: nil},
+ {hash: [4]byte{0xc5, 0xd2, 0x46, 0x01}, data: []byte{}},
+ {hash: [4]byte{0x8f, 0x9a, 0x2b, 0x7d}, data: []byte("test name")},
+}
+
+func TestTopicCreation(t *testing.T) {
+ for i, tt := range topicCreationTests {
+ topic := NewTopic(tt.data)
+ if bytes.Compare(topic[:], tt.hash[:]) != 0 {
+ t.Errorf("test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash)
+ }
+ }
+}
+
+func TestTopicSetCreation(t *testing.T) {
+ topics := make([]Topic, len(topicCreationTests))
+ for i, tt := range topicCreationTests {
+ topics[i] = NewTopic(tt.data)
+ }
+ set := NewTopicSet(topics)
+ for i, tt := range topicCreationTests {
+ topic := NewTopic(tt.data)
+ if _, ok := set[topic.String()]; !ok {
+ t.Errorf("topic %d: not found in set", i)
+ }
+ }
+}