Skip to content

Commit

Permalink
Document and test RoundToBytes (#750)
Browse files Browse the repository at this point in the history
* Test TestRoundToBytes

* Improve docs of RoundToBytes
  • Loading branch information
webmaster128 committed Sep 14, 2020
1 parent 578d716 commit 8c2ee78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chain/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Cursor interface {
Last() *Beacon
}

// RoundToBytes provides a byte serialized form of a round number
// RoundToBytes serializes a round number to bytes (8 bytes fixed length big-endian).
func RoundToBytes(r uint64) []byte {
var buff bytes.Buffer
_ = binary.Write(&buff, binary.BigEndian, r)
Expand Down
14 changes: 14 additions & 0 deletions chain/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chain

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestRoundToBytes(t *testing.T) {
require.Equal(t, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, RoundToBytes(0))
require.Equal(t, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, RoundToBytes(1))
require.Equal(t, []byte{0x00, 0x00, 0x00, 0x2a, 0xec, 0x04, 0x83, 0xff}, RoundToBytes(184348345343))
require.Equal(t, []byte{0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0xA7, 0xB8}, RoundToBytes(0xA1B2C3D4E5F6A7B8))
}

0 comments on commit 8c2ee78

Please sign in to comment.