2020-03-19 05:53:15 +00:00
|
|
|
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) {
|
2020-04-08 16:48:15 +00:00
|
|
|
t.Skip("we need to regenerate for beacon")
|
2020-03-19 05:53:15 +00:00
|
|
|
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:
|
|
|
|
}
|