forked from ethersphere/swarm
-
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
13 changed files
with
104 additions
and
76 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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 |
---|---|---|
@@ -1,28 +1,45 @@ | ||
package message_test | ||
|
||
import ( | ||
"fmt" | ||
"encoding/json" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/epiclabs-io/ut" | ||
"github.com/ethersphere/swarm/pss/message" | ||
) | ||
|
||
// test that topic conversion functions give predictable results | ||
var someTopics = []string{"These", "are", "some", "topics", "A topic can be very long as well, longer than TopicLength"} | ||
var fixtureTopicHash = []string{`"0x91273d49"`, `"0xba78973d"`, `"0xa6b46dd0"`, `"0xf013aa4b"`, `"0x26f57386"`} | ||
var fixtureTopicStringer = []string{"0x91273d49", "0xba78973d", "0xa6b46dd0", "0xf013aa4b", "0x26f57386"} | ||
|
||
func TestTopic(tx *testing.T) { | ||
t := ut.BeginTest(tx, false) // set to true to generate test results | ||
defer t.FinishTest() | ||
func TestTopic(t *testing.T) { | ||
|
||
for i, topicString := range someTopics { | ||
topic := message.NewTopic([]byte(topicString)) | ||
|
||
// Test marshalling and unmarshalling the topic as JSON: | ||
t.TestJSONMarshaller(fmt.Sprintf("topic%d.json", i), topic) | ||
jsonBytes, err := json.Marshal(topic) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
expected := fixtureTopicHash[i] | ||
actual := string(jsonBytes) | ||
if expected != actual { | ||
t.Fatalf("Expected JSON serialization to return %s, got %s", expected, actual) | ||
} | ||
|
||
var topic2 message.Topic | ||
err = json.Unmarshal(jsonBytes, &topic2) | ||
if !reflect.DeepEqual(topic, topic2) { | ||
t.Fatalf("Expected JSON decoding to return the same object, got %v", topic2) | ||
} | ||
|
||
// test Stringer: | ||
s := topic.String() | ||
t.EqualsKey(fmt.Sprintf("topic%d", i), s) | ||
expected = fixtureTopicStringer[i] | ||
actual = topic.String() | ||
if expected != actual { | ||
t.Fatalf("Expected topic stringer to return %s, got %s", expected, actual) | ||
} | ||
} | ||
} |