2019-10-04 22:46:49 +00:00
|
|
|
package interop_test
|
2019-09-14 14:46:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
"github.com/go-yaml/yaml"
|
2019-10-04 22:46:49 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/interop"
|
2019-09-14 14:46:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type TestCase struct {
|
|
|
|
Privkey string `yaml:"privkey"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type KeyTest struct {
|
|
|
|
TestCases []*TestCase `yaml:"test_cases"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestKeyGenerator(t *testing.T) {
|
|
|
|
path, err := bazel.Runfile("keygen_test_vector.yaml")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
file, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
testCases := &KeyTest{}
|
|
|
|
if err := yaml.Unmarshal(file, testCases); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-10-04 22:46:49 +00:00
|
|
|
priv, _, err := interop.DeterministicallyGenerateKeys(0, 1000)
|
2019-09-14 14:46:38 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
// cross-check with the first 1000 keys generated from the python spec
|
|
|
|
for i, key := range priv {
|
|
|
|
hexKey := testCases.TestCases[i].Privkey
|
|
|
|
nKey, err := hexutil.Decode("0x" + hexKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !bytes.Equal(key.Marshal(), nKey) {
|
|
|
|
t.Errorf("key for index %d failed, wanted %v but got %v", i, nKey, key.Marshal())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|