forked from libp2p/go-libp2p-pubsub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,761 additions
and
1,436 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
syntax = "proto2"; | ||
|
||
package compat.pb; | ||
|
||
message Message { | ||
optional bytes from = 1; | ||
optional bytes data = 2; | ||
optional bytes seqno = 3; | ||
repeated string topicIDs = 4; | ||
optional bytes signature = 5; | ||
optional bytes key = 6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package pubsub | ||
|
||
import ( | ||
"testing" | ||
|
||
compat_pb "github.com/libp2p/go-libp2p-pubsub/compat" | ||
pb "github.com/libp2p/go-libp2p-pubsub/pb" | ||
) | ||
|
||
func TestMultitopicMessageCompatibility(t *testing.T) { | ||
topic1 := "topic1" | ||
topic2 := "topic2" | ||
|
||
newMessage1 := &pb.Message{ | ||
From: []byte("A"), | ||
Data: []byte("blah"), | ||
Seqno: []byte("123"), | ||
Topic: &topic1, | ||
Signature: []byte("a-signature"), | ||
Key: []byte("a-key"), | ||
} | ||
oldMessage1 := &compat_pb.Message{ | ||
From: []byte("A"), | ||
Data: []byte("blah"), | ||
Seqno: []byte("123"), | ||
TopicIDs: []string{topic1}, | ||
Signature: []byte("a-signature"), | ||
Key: []byte("a-key"), | ||
} | ||
oldMessage2 := &compat_pb.Message{ | ||
From: []byte("A"), | ||
Data: []byte("blah"), | ||
Seqno: []byte("123"), | ||
TopicIDs: []string{topic1, topic2}, | ||
Signature: []byte("a-signature"), | ||
Key: []byte("a-key"), | ||
} | ||
|
||
newMessage1b, err := newMessage1.Marshal() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
oldMessage1b, err := oldMessage1.Marshal() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
oldMessage2b, err := oldMessage2.Marshal() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
newMessage := new(pb.Message) | ||
oldMessage := new(compat_pb.Message) | ||
|
||
err = newMessage.Unmarshal(oldMessage1b) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if newMessage.GetTopic() != topic1 { | ||
t.Fatalf("bad topic: expected %s, got %s", topic1, newMessage.GetTopic()) | ||
} | ||
|
||
newMessage.Reset() | ||
err = newMessage.Unmarshal(oldMessage2b) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if newMessage.GetTopic() != topic2 { | ||
t.Fatalf("bad topic: expected %s, got %s", topic2, newMessage.GetTopic()) | ||
} | ||
|
||
err = oldMessage.Unmarshal(newMessage1b) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
topics := oldMessage.GetTopicIDs() | ||
if len(topics) != 1 { | ||
t.Fatalf("expected 1 topic, got %d", len(topics)) | ||
} | ||
if topics[0] != topic1 { | ||
t.Fatalf("bad topic: expected %s, got %s", topic1, topics[0]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.