package spectest import ( "bytes" "encoding/hex" "path" "testing" "github.com/ghodss/yaml" "github.com/prysmaticlabs/prysm/shared/bls" "github.com/prysmaticlabs/prysm/shared/testutil" ) func TestPrivToPubYaml(t *testing.T) { testFolders, testFolderPath := testutil.TestFolders(t, "general", "bls/priv_to_pub/small") 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) } pkBytes, err := hex.DecodeString(test.Input[2:]) if err != nil { t.Fatalf("Cannot decode string to bytes: %v", err) } sk, err := bls.SecretKeyFromBytes(pkBytes) if err != nil { t.Fatalf("Cannot unmarshal input to secret key: %v", err) } 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()) { t.Fatalf("Output does not marshaled public key bytes wanted %#x but got %#x", outputBytes, sk.PublicKey().Marshal()) } }) } }