diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-04-14 16:12:09 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-04-14 16:12:09 +0800 |
commit | 4af7743663fa3e444668b90878f64d0df4316deb (patch) | |
tree | 0ad5898d8510600fe8cfe230d18f2c72b8cf53ed /whisper/topic_test.go | |
parent | cb707ba50ce8626aa1b0e87d7526416a9592852a (diff) | |
download | dexon-4af7743663fa3e444668b90878f64d0df4316deb.tar.gz dexon-4af7743663fa3e444668b90878f64d0df4316deb.tar.zst dexon-4af7743663fa3e444668b90878f64d0df4316deb.zip |
whisper: add utility functions for creating topics
Diffstat (limited to 'whisper/topic_test.go')
-rw-r--r-- | whisper/topic_test.go | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/whisper/topic_test.go b/whisper/topic_test.go index 4626e2ae5..5f8583987 100644 --- a/whisper/topic_test.go +++ b/whisper/topic_test.go @@ -15,10 +15,39 @@ var topicCreationTests = []struct { } func TestTopicCreation(t *testing.T) { + // Create the topics individually 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) + t.Errorf("binary test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) + } + } + for i, tt := range topicCreationTests { + topic := NewTopicFromString(string(tt.data)) + if bytes.Compare(topic[:], tt.hash[:]) != 0 { + t.Errorf("textual test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) + } + } + // Create the topics in batches + binaryData := make([][]byte, len(topicCreationTests)) + for i, tt := range topicCreationTests { + binaryData[i] = tt.data + } + textualData := make([]string, len(topicCreationTests)) + for i, tt := range topicCreationTests { + textualData[i] = string(tt.data) + } + + topics := NewTopics(binaryData...) + for i, tt := range topicCreationTests { + if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { + t.Errorf("binary batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) + } + } + topics = NewTopicsFromStrings(textualData...) + for i, tt := range topicCreationTests { + if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { + t.Errorf("textual batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) } } } |