Skip to content

Commit

Permalink
tests: topic from bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad committed Jan 18, 2025
1 parent db6d2a8 commit b646b3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion www/zmq/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ func TopicFromBytes(b []byte) Topic {
return 0
}

return Topic(binary.BigEndian.Uint16(b[:2]))
return Topic(binary.BigEndian.Uint16(b))
}
18 changes: 18 additions & 0 deletions www/zmq/topic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package zmq

import (
"github.com/stretchr/testify/require"
"testing"
)

func TestTopicFromBytes(t *testing.T) {

Check failure on line 8 in www/zmq/topic_test.go

View workflow job for this annotation

GitHub Actions / linting

empty-lines: extra empty line at the end of a block (revive)

Check failure on line 8 in www/zmq/topic_test.go

View workflow job for this annotation

GitHub Actions / build-linux

empty-lines: extra empty line at the end of a block (revive)
validRawTopic := TopicRawTransaction.Bytes()
invalidRawTopic := make([]byte, 0)

topic := TopicFromBytes(validRawTopic)
require.Equal(t, TopicRawTransaction, topic)

topic = TopicFromBytes(invalidRawTopic)
require.Equal(t, 0, int(topic))

}

Check failure on line 18 in www/zmq/topic_test.go

View workflow job for this annotation

GitHub Actions / linting

unnecessary trailing newline (whitespace)

Check failure on line 18 in www/zmq/topic_test.go

View workflow job for this annotation

GitHub Actions / build-linux

unnecessary trailing newline (whitespace)

0 comments on commit b646b3b

Please sign in to comment.