@@ -132,6 +132,103 @@ func TestInstallFilters(t *testing.T) {
132
132
}
133
133
}
134
134
135
+ func TestInstallSymKeyGeneratesHash (t * testing.T ) {
136
+ InitSingleTest ()
137
+
138
+ w := New (& Config {})
139
+ filters := NewFilters (w )
140
+ filter , _ := generateFilter (t , true )
141
+
142
+ // save the current SymKeyHash for comparison
143
+ initialSymKeyHash := filter .SymKeyHash
144
+
145
+ // ensure the SymKeyHash is invalid, for Install to recreate it
146
+ var invalid common.Hash
147
+ filter .SymKeyHash = invalid
148
+
149
+ _ , err := filters .Install (filter )
150
+
151
+ if err != nil {
152
+ t .Fatalf ("Error installing the filter: %s" , err )
153
+ }
154
+
155
+ for i , b := range filter .SymKeyHash {
156
+ if b != initialSymKeyHash [i ] {
157
+ t .Fatalf ("The filter's symmetric key hash was not properly generated by Install" )
158
+ }
159
+ }
160
+ }
161
+
162
+ func TestInstallIdenticalFilters (t * testing.T ) {
163
+ InitSingleTest ()
164
+
165
+ w := New (& Config {})
166
+ filters := NewFilters (w )
167
+ filter1 , _ := generateFilter (t , true )
168
+
169
+ // Copy the first filter since some of its fields
170
+ // are randomly gnerated.
171
+ filter2 := & Filter {
172
+ KeySym : filter1 .KeySym ,
173
+ Topics : filter1 .Topics ,
174
+ PoW : filter1 .PoW ,
175
+ AllowP2P : filter1 .AllowP2P ,
176
+ Messages : make (map [common.Hash ]* ReceivedMessage ),
177
+ }
178
+
179
+ _ , err := filters .Install (filter1 )
180
+
181
+ if err != nil {
182
+ t .Fatalf ("Error installing the first filter with seed %d: %s" , seed , err )
183
+ }
184
+
185
+ _ , err = filters .Install (filter2 )
186
+
187
+ if err != nil {
188
+ t .Fatalf ("Error installing the second filter with seed %d: %s" , seed , err )
189
+ }
190
+
191
+ params , err := generateMessageParams ()
192
+ if err != nil {
193
+ t .Fatalf ("Error generating message parameters with seed %d: %s" , seed , err )
194
+ }
195
+
196
+ params .KeySym = filter1 .KeySym
197
+ params .Topic = BytesToTopic (filter1 .Topics [0 ])
198
+
199
+ filter1 .Src = & params .Src .PublicKey
200
+ filter2 .Src = & params .Src .PublicKey
201
+
202
+ sentMessage , err := NewSentMessage (params )
203
+ if err != nil {
204
+ t .Fatalf ("failed to create new message with seed %d: %s." , seed , err )
205
+ }
206
+ env , err := sentMessage .Wrap (params )
207
+ if err != nil {
208
+ t .Fatalf ("failed Wrap with seed %d: %s." , seed , err )
209
+ }
210
+ msg := env .Open (filter1 )
211
+ if msg == nil {
212
+ t .Fatalf ("failed to Open with filter1" )
213
+ }
214
+
215
+ if ! filter1 .MatchEnvelope (env ) {
216
+ t .Fatalf ("failed matching with the first filter" )
217
+ }
218
+
219
+ if ! filter2 .MatchEnvelope (env ) {
220
+ t .Fatalf ("failed matching with the first filter" )
221
+ }
222
+
223
+ if ! filter1 .MatchMessage (msg ) {
224
+ t .Fatalf ("failed matching with the second filter" )
225
+ }
226
+
227
+ if ! filter2 .MatchMessage (msg ) {
228
+ t .Fatalf ("failed matching with the second filter" )
229
+ }
230
+ }
231
+
135
232
func TestComparePubKey (t * testing.T ) {
136
233
InitSingleTest ()
137
234
@@ -345,11 +442,6 @@ func TestMatchMessageSym(t *testing.T) {
345
442
t .Fatalf ("failed Open with seed %d." , seed )
346
443
}
347
444
348
- // Src mismatch
349
- if f .MatchMessage (msg ) {
350
- t .Fatalf ("failed MatchMessage(src mismatch) with seed %d." , seed )
351
- }
352
-
353
445
// Src: match
354
446
* f .Src .X = * params .Src .PublicKey .X
355
447
* f .Src .Y = * params .Src .PublicKey .Y
@@ -443,11 +535,6 @@ func TestMatchMessageAsym(t *testing.T) {
443
535
t .Fatalf ("failed to open with seed %d." , seed )
444
536
}
445
537
446
- // Src mismatch
447
- if f .MatchMessage (msg ) {
448
- t .Fatalf ("failed MatchMessage(src mismatch) with seed %d." , seed )
449
- }
450
-
451
538
// Src: match
452
539
* f .Src .X = * params .Src .PublicKey .X
453
540
* f .Src .Y = * params .Src .PublicKey .Y
0 commit comments