aboutsummaryrefslogtreecommitdiffstats
path: root/whisper
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-04-22 23:17:07 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-04-28 15:49:05 +0800
commit2b9fd6b40a759078d1dcc1c7edcfafd4ccf38af3 (patch)
tree814e1801fe53208cd9e34ba077e71d788cf9a97d /whisper
parent406e74e2afdce374fd227873f4eb96a0ba99bd23 (diff)
downloadgo-tangerine-2b9fd6b40a759078d1dcc1c7edcfafd4ccf38af3.tar.gz
go-tangerine-2b9fd6b40a759078d1dcc1c7edcfafd4ccf38af3.tar.zst
go-tangerine-2b9fd6b40a759078d1dcc1c7edcfafd4ccf38af3.zip
whisper: add full filter test suite
Diffstat (limited to 'whisper')
-rw-r--r--whisper/filter_test.go50
-rw-r--r--whisper/peer.go3
2 files changed, 51 insertions, 2 deletions
diff --git a/whisper/filter_test.go b/whisper/filter_test.go
index ac0ebaba7..ca28fd83c 100644
--- a/whisper/filter_test.go
+++ b/whisper/filter_test.go
@@ -147,3 +147,53 @@ func TestFilterTopicsCreation(t *testing.T) {
}
}
}
+
+var filterCompareTests = []struct {
+ matcher filterer
+ message filterer
+ match bool
+}{
+ { // Wild-card filter matching anything
+ matcher: filterer{to: "", from: "", matcher: newTopicMatcher()},
+ message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ match: true,
+ },
+ { // Filter matching the to field
+ matcher: filterer{to: "to", from: "", matcher: newTopicMatcher()},
+ message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ match: true,
+ },
+ { // Filter rejecting the to field
+ matcher: filterer{to: "to", from: "", matcher: newTopicMatcher()},
+ message: filterer{to: "", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ match: false,
+ },
+ { // Filter matching the from field
+ matcher: filterer{to: "", from: "from", matcher: newTopicMatcher()},
+ message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ match: true,
+ },
+ { // Filter rejecting the from field
+ matcher: filterer{to: "", from: "from", matcher: newTopicMatcher()},
+ message: filterer{to: "to", from: "", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ match: false,
+ },
+ { // Filter matching the topic field
+ matcher: filterer{to: "", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ message: filterer{to: "to", from: "from", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ match: true,
+ },
+ { // Filter rejecting the topic field
+ matcher: filterer{to: "", from: "", matcher: newTopicMatcher(NewFilterTopicsFromStringsFlat("topic")...)},
+ message: filterer{to: "to", from: "from", matcher: newTopicMatcher()},
+ match: false,
+ },
+}
+
+func TestFilterCompare(t *testing.T) {
+ for i, tt := range filterCompareTests {
+ if match := tt.matcher.Compare(tt.message); match != tt.match {
+ t.Errorf("test %d: match mismatch: have %v, want %v", i, match, tt.match)
+ }
+ }
+}
diff --git a/whisper/peer.go b/whisper/peer.go
index 77e09bece..9fdc28434 100644
--- a/whisper/peer.go
+++ b/whisper/peer.go
@@ -21,8 +21,7 @@ type peer struct {
quit chan struct{}
}
-// newPeer creates and initializes a new whisper peer connection, returning either
-// the newly constructed link or a failure reason.
+// newPeer creates a new whisper peer object, but does not run the handshake itself.
func newPeer(host *Whisper, remote *p2p.Peer, rw p2p.MsgReadWriter) *peer {
return &peer{
host: host,