diff --git a/www/zmq/topic.go b/www/zmq/topic.go index 65af50513..5a8b22521 100644 --- a/www/zmq/topic.go +++ b/www/zmq/topic.go @@ -42,5 +42,5 @@ func TopicFromBytes(b []byte) Topic { return 0 } - return Topic(binary.BigEndian.Uint16(b[:2])) + return Topic(binary.BigEndian.Uint16(b)) } diff --git a/www/zmq/topic_test.go b/www/zmq/topic_test.go new file mode 100644 index 000000000..c9e9ec81c --- /dev/null +++ b/www/zmq/topic_test.go @@ -0,0 +1,18 @@ +package zmq + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestTopicFromBytes(t *testing.T) { + validRawTopic := TopicRawTransaction.Bytes() + invalidRawTopic := make([]byte, 0) + + topic := TopicFromBytes(validRawTopic) + require.Equal(t, TopicRawTransaction, topic) + + topic = TopicFromBytes(invalidRawTopic) + require.Equal(t, 0, int(topic)) + +}