46 lines
842 B
Go
46 lines
842 B
Go
|
package vectors
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func LoadVector(t *testing.T, f string, out interface{}) {
|
||
|
p := filepath.Join("../../extern/serialization-vectors", f)
|
||
|
fi, err := os.Open(p)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if err := json.NewDecoder(fi).Decode(out); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestBlockHeaderVectors(t *testing.T) {
|
||
|
var headers []HeaderVector
|
||
|
LoadVector(t, "block_headers.json", &headers)
|
||
|
|
||
|
for i, hv := range headers {
|
||
|
if hv.Block.Cid().String() != hv.Cid {
|
||
|
t.Fatalf("CID mismatch in test vector %d", i)
|
||
|
}
|
||
|
|
||
|
data, err := hv.Block.Serialize()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if fmt.Sprintf("%x", data) != hv.CborHex {
|
||
|
t.Fatalf("serialized data mismatched for test vector %d", i)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestMessageSigningVectors(t *testing.T) {
|
||
|
// TODO:
|
||
|
}
|