2019-10-04 22:46:49 +00:00
|
|
|
package interop_test
|
2019-09-14 14:46:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
2020-07-19 21:08:29 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
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")
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-09-14 14:46:38 +00:00
|
|
|
file, err := ioutil.ReadFile(path)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-09-14 14:46:38 +00:00
|
|
|
testCases := &KeyTest{}
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, yaml.Unmarshal(file, testCases))
|
2019-10-04 22:46:49 +00:00
|
|
|
priv, _, err := interop.DeterministicallyGenerateKeys(0, 1000)
|
2020-07-19 21:08:29 +00:00
|
|
|
require.NoError(t, err)
|
2019-09-14 14:46:38 +00:00
|
|
|
// 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
|
|
|
|
}
|
2020-07-19 21:08:29 +00:00
|
|
|
assert.DeepEqual(t, key.Marshal(), nKey)
|
2019-09-14 14:46:38 +00:00
|
|
|
}
|
|
|
|
}
|