2019-10-04 22:46:49 +00:00
|
|
|
package interop_test
|
2019-09-14 14:46:38 +00:00
|
|
|
|
|
|
|
import (
|
2022-10-17 21:04:19 +00:00
|
|
|
"fmt"
|
2022-04-18 20:42:07 +00:00
|
|
|
"os"
|
2019-09-14 14:46:38 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
"github.com/go-yaml/yaml"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/runtime/interop"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/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)
|
2022-04-18 20:42:07 +00:00
|
|
|
file, err := os.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))
|
2022-10-17 21:04:19 +00:00
|
|
|
priv, pubkeys, 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)
|
2022-11-19 03:40:32 +00:00
|
|
|
fmt.Printf("pubkey: %s privkey: %s \n", hexutil.Encode(pubkeys[i].Marshal()), hexutil.Encode(key.Marshal()))
|
2019-09-14 14:46:38 +00:00
|
|
|
}
|
|
|
|
}
|