parser: generalize API for decoding serializable types

This commit is contained in:
George Tankersley
2018-09-14 00:00:00 +00:00
parent c947b00d36
commit 35638b3900
4 changed files with 202 additions and 18 deletions

View File

@@ -6,6 +6,8 @@ import (
"encoding/hex"
"os"
"testing"
"github.com/gtank/ctxd/parser/internal/bytestring"
)
func TestBlockHeader(t *testing.T) {
@@ -26,14 +28,21 @@ func TestBlockHeader(t *testing.T) {
continue
}
// Try to read the header
blockHeader := &BlockHeader{}
err = ReadBlockHeader(blockHeader, decodedBlockData)
s := bytestring.String(decodedBlockData)
startLength := len(s)
dec := NewBlockHeaderDecoder(&s)
blockHeader := BlockHeader{}
err = dec.Decode(&blockHeader)
if err != nil {
t.Error(err)
continue
}
if (startLength - len(s)) != SER_BLOCK_HEADER_SIZE {
t.Error("did not advance underlying bytestring")
}
// Some basic sanity checks
if blockHeader.Version != 4 {
t.Error("Read wrong version in a test block.")
@@ -73,7 +82,7 @@ func TestBlockHeader(t *testing.T) {
break
}
hash := blockHeader.GetBlockHeaderHash()
hash := blockHeader.GetHash()
// This is not necessarily true for anything but our current test cases.
for _, b := range hash[28:] {