2020-06-27 15:48:36 +00:00
|
|
|
package v1_test
|
2020-01-04 03:51:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
2020-07-22 19:42:43 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-06-27 15:48:36 +00:00
|
|
|
keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v1"
|
2020-01-04 03:51:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInteropListValidatingKeysZero(t *testing.T) {
|
2020-01-24 17:21:31 +00:00
|
|
|
_, _, err := keymanager.NewInterop("")
|
2020-07-22 19:42:43 +00:00
|
|
|
assert.ErrorContains(t, "unexpected end of JSON input", err)
|
2020-01-24 17:21:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInteropListValidatingKeysEmptyJSON(t *testing.T) {
|
|
|
|
_, _, err := keymanager.NewInterop("{}")
|
2020-07-22 19:42:43 +00:00
|
|
|
assert.ErrorContains(t, "input length must be greater than 0", err)
|
2020-01-04 03:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInteropListValidatingKeysSingle(t *testing.T) {
|
2020-01-24 17:21:31 +00:00
|
|
|
direct, _, err := keymanager.NewInterop(`{"keys":1}`)
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-04 03:51:53 +00:00
|
|
|
keys, err := direct.FetchValidatingKeys()
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(keys), "Incorrect number of keys returned")
|
2020-01-04 03:51:53 +00:00
|
|
|
|
|
|
|
pkBytes, err := hex.DecodeString("25295f0d1d592a90b333e26e85149708208e9f8e8bc18f6c77bd62f8ad7a6866")
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-04 03:51:53 +00:00
|
|
|
privateKey, err := bls.SecretKeyFromBytes(pkBytes)
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.DeepEqual(t, privateKey.PublicKey().Marshal(), keys[0][:], "Public k 0 incorrect")
|
2020-01-04 03:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestInteropListValidatingKeysOffset(t *testing.T) {
|
2020-01-24 17:21:31 +00:00
|
|
|
direct, _, err := keymanager.NewInterop(`{"keys":1,"offset":9}`)
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-04 03:51:53 +00:00
|
|
|
keys, err := direct.FetchValidatingKeys()
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(keys), "Incorrect number of keys returned")
|
2020-01-04 03:51:53 +00:00
|
|
|
|
|
|
|
pkBytes, err := hex.DecodeString("2b3b88a041168a1c4cd04bdd8de7964fd35238f95442dc678514f9dadb81ec34")
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
2020-01-04 03:51:53 +00:00
|
|
|
privateKey, err := bls.SecretKeyFromBytes(pkBytes)
|
2020-07-22 19:42:43 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, privateKey.PublicKey().Marshal(), keys[0][:], "Public k 0 incorrect")
|
2020-01-04 03:51:53 +00:00
|
|
|
}
|