2019-06-25 16:57:47 +00:00
|
|
|
package spectest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2019-09-08 19:41:52 +00:00
|
|
|
"encoding/hex"
|
|
|
|
"path"
|
2019-06-25 16:57:47 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
2019-09-08 19:41:52 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
2019-06-25 16:57:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPrivToPubYaml(t *testing.T) {
|
2019-09-08 19:41:52 +00:00
|
|
|
testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/priv_to_pub/small")
|
2019-06-25 16:57:47 +00:00
|
|
|
|
2019-09-08 19:41:52 +00:00
|
|
|
for _, folder := range testFolders {
|
|
|
|
t.Run(folder.Name(), func(t *testing.T) {
|
|
|
|
file, err := testutil.BazelFileBytes(path.Join(testFolderPath, folder.Name(), "data.yaml"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to read file: %v", err)
|
|
|
|
}
|
|
|
|
test := &PrivToPubTest{}
|
|
|
|
if err := yaml.Unmarshal(file, test); err != nil {
|
|
|
|
t.Fatalf("Failed to unmarshal: %v", err)
|
|
|
|
}
|
2019-06-25 16:57:47 +00:00
|
|
|
|
2019-09-08 19:41:52 +00:00
|
|
|
pkBytes, err := hex.DecodeString(test.Input[2:])
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot decode string to bytes: %v", err)
|
|
|
|
}
|
|
|
|
sk, err := bls.SecretKeyFromBytes(pkBytes)
|
2019-06-25 16:57:47 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot unmarshal input to secret key: %v", err)
|
|
|
|
}
|
2019-09-08 19:41:52 +00:00
|
|
|
|
|
|
|
outputBytes, err := hex.DecodeString(test.Output[2:])
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot decode string to bytes: %v", err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(outputBytes, sk.PublicKey().Marshal()) {
|
2019-12-03 20:29:05 +00:00
|
|
|
t.Fatalf("Output does not marshaled public key bytes wanted %#x but got %#x", outputBytes, sk.PublicKey().Marshal())
|
2019-06-25 16:57:47 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|