prysm-pulse/testing/bls/hash_to_G2_test.go
Nishant Das 18e1d43360
Update blst to v0.3.5 and add BLS spec tests (#9611)
* add new dep

* add changes so far

* fix all tests

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-09-17 01:32:23 +00:00

45 lines
1.1 KiB
Go

package bls
import (
"bytes"
"encoding/hex"
"strings"
"testing"
"github.com/ghodss/yaml"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/testing/bls/utils"
blst "github.com/supranational/blst/bindings/go"
)
func TestHashToG2(t *testing.T) {
t.Run("blst", testHashToG2)
}
func testHashToG2(t *testing.T) {
t.Skip("Hash To G2 needs co-ordinates exposed")
fNames, fContent := utils.RetrieveFiles("hash_to_G2", t)
for i, file := range fNames {
content := fContent[i]
t.Run(file, func(t *testing.T) {
test := &HashToG2Test{}
require.NoError(t, yaml.Unmarshal(content, test))
msgBytes := []byte(test.Input.Message)
splitX := strings.Split(test.Output.X, ",")
outputX, err := hex.DecodeString(splitX[0][2:])
require.NoError(t, err)
point := blst.HashToG2(msgBytes, nil)
val := point.Compress()
if !bytes.Equal(val, outputX) {
t.Fatalf("Retrieved X value does not match output. "+
"Expected %#v but received %#v for test case %d", outputX, val, i)
}
t.Log("Success")
})
}
}