Skip to content

Commit 216fc26

Browse files
committed
p2p: fix local/remote cap/protocol mixup
1 parent d84638b commit 216fc26

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

p2p/peer_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -199,68 +199,68 @@ func TestNewPeer(t *testing.T) {
199199

200200
func TestMatchProtocols(t *testing.T) {
201201
tests := []struct {
202-
Local []Cap
203-
Remote []Protocol
202+
Remote []Cap
203+
Local []Protocol
204204
Match map[string]protoRW
205205
}{
206206
{
207-
// No remote protocols
208-
Local: []Cap{{Name: "a"}},
207+
// No remote capabilities
208+
Local: []Protocol{{Name: "a"}},
209209
},
210210
{
211-
// No local capabilities
212-
Remote: []Protocol{{Name: "a"}},
211+
// No local protocols
212+
Remote: []Cap{{Name: "a"}},
213213
},
214214
{
215215
// No mutual protocols
216-
Local: []Cap{{Name: "a"}},
217-
Remote: []Protocol{{Name: "b"}},
216+
Remote: []Cap{{Name: "a"}},
217+
Local: []Protocol{{Name: "b"}},
218218
},
219219
{
220220
// Some matches, some differences
221-
Local: []Cap{{Name: "local"}, {Name: "match1"}, {Name: "match2"}},
222-
Remote: []Protocol{{Name: "match1"}, {Name: "match2"}, {Name: "remote"}},
221+
Remote: []Cap{{Name: "local"}, {Name: "match1"}, {Name: "match2"}},
222+
Local: []Protocol{{Name: "match1"}, {Name: "match2"}, {Name: "remote"}},
223223
Match: map[string]protoRW{"match1": {Protocol: Protocol{Name: "match1"}}, "match2": {Protocol: Protocol{Name: "match2"}}},
224224
},
225225
{
226226
// Various alphabetical ordering
227-
Local: []Cap{{Name: "aa"}, {Name: "ab"}, {Name: "bb"}, {Name: "ba"}},
228-
Remote: []Protocol{{Name: "ba"}, {Name: "bb"}, {Name: "ab"}, {Name: "aa"}},
227+
Remote: []Cap{{Name: "aa"}, {Name: "ab"}, {Name: "bb"}, {Name: "ba"}},
228+
Local: []Protocol{{Name: "ba"}, {Name: "bb"}, {Name: "ab"}, {Name: "aa"}},
229229
Match: map[string]protoRW{"aa": {Protocol: Protocol{Name: "aa"}}, "ab": {Protocol: Protocol{Name: "ab"}}, "ba": {Protocol: Protocol{Name: "ba"}}, "bb": {Protocol: Protocol{Name: "bb"}}},
230230
},
231231
{
232232
// No mutual versions
233-
Local: []Cap{{Version: 1}},
234-
Remote: []Protocol{{Version: 2}},
233+
Remote: []Cap{{Version: 1}},
234+
Local: []Protocol{{Version: 2}},
235235
},
236236
{
237237
// Multiple versions, single common
238-
Local: []Cap{{Version: 1}, {Version: 2}},
239-
Remote: []Protocol{{Version: 2}, {Version: 3}},
238+
Remote: []Cap{{Version: 1}, {Version: 2}},
239+
Local: []Protocol{{Version: 2}, {Version: 3}},
240240
Match: map[string]protoRW{"": {Protocol: Protocol{Version: 2}}},
241241
},
242242
{
243243
// Multiple versions, multiple common
244-
Local: []Cap{{Version: 1}, {Version: 2}, {Version: 3}, {Version: 4}},
245-
Remote: []Protocol{{Version: 2}, {Version: 3}},
244+
Remote: []Cap{{Version: 1}, {Version: 2}, {Version: 3}, {Version: 4}},
245+
Local: []Protocol{{Version: 2}, {Version: 3}},
246246
Match: map[string]protoRW{"": {Protocol: Protocol{Version: 3}}},
247247
},
248248
{
249249
// Various version orderings
250-
Local: []Cap{{Version: 4}, {Version: 1}, {Version: 3}, {Version: 2}},
251-
Remote: []Protocol{{Version: 2}, {Version: 3}, {Version: 1}},
250+
Remote: []Cap{{Version: 4}, {Version: 1}, {Version: 3}, {Version: 2}},
251+
Local: []Protocol{{Version: 2}, {Version: 3}, {Version: 1}},
252252
Match: map[string]protoRW{"": {Protocol: Protocol{Version: 3}}},
253253
},
254254
{
255255
// Versions overriding sub-protocol lengths
256-
Local: []Cap{{Version: 1}, {Version: 2}, {Version: 3}, {Name: "a"}},
257-
Remote: []Protocol{{Version: 1, Length: 1}, {Version: 2, Length: 2}, {Version: 3, Length: 3}, {Name: "a"}},
256+
Remote: []Cap{{Version: 1}, {Version: 2}, {Version: 3}, {Name: "a"}},
257+
Local: []Protocol{{Version: 1, Length: 1}, {Version: 2, Length: 2}, {Version: 3, Length: 3}, {Name: "a"}},
258258
Match: map[string]protoRW{"": {Protocol: Protocol{Version: 3}}, "a": {Protocol: Protocol{Name: "a"}, offset: 3}},
259259
},
260260
}
261261

262262
for i, tt := range tests {
263-
result := matchProtocols(tt.Remote, tt.Local, nil)
263+
result := matchProtocols(tt.Local, tt.Remote, nil)
264264
if len(result) != len(tt.Match) {
265265
t.Errorf("test %d: negotiation mismatch: have %v, want %v", i, len(result), len(tt.Match))
266266
continue

0 commit comments

Comments
 (0)