Add tool and script for interop testing (#3417)

* add tool and script for interop testing

* identity

* lint

* merge upstream, fix conflict, update script, add comment

* add comma separated support for --peer=

* remove NUM_VALIDATORS, comma fix

* WIP docker image

* use CI builder

* pr feedback

* whatever antoine says

* ignore git in docker

* jobs=auto

* disable remote cache

* try to cache the golang part

* try to cache the golang part

* nvm

* From Antoine with love

* fix
This commit is contained in:
Preston Van Loon
2019-09-09 14:31:19 -07:00
committed by Raul Jordan
parent af07c13730
commit 3708a8f476
12 changed files with 261 additions and 13 deletions

View File

@@ -4,7 +4,9 @@ go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/prysmaticlabs/prysm/tools/unencrypted-keys-gen",
visibility = ["//visibility:private"],
visibility = [
"//tools/interop/convert-keys:__pkg__",
],
deps = [
"//shared/bls:go_default_library",
],

View File

@@ -18,11 +18,13 @@ var (
overwrite = flag.Bool("overwrite", false, "If the key file exists, it will be overwritten")
)
type unencryptedKeysContainer struct {
Keys []*unencryptedKeys `json:"keys"`
// UnencryptedKeysContainer defines the structure of the unecrypted key JSON file.
type UnencryptedKeysContainer struct {
Keys []*UnencryptedKeys `json:"keys"`
}
type unencryptedKeys struct {
// UnencryptedKeys is the inner struct of the JSON file.
type UnencryptedKeys struct {
ValidatorKey []byte `json:"validator_key"`
WithdrawalKey []byte `json:"withdrawal_key"`
}
@@ -53,14 +55,14 @@ func main() {
}()
ctnr := generateUnencryptedKeys(rand.Reader)
if err := saveUnencryptedKeysToFile(file, ctnr); err != nil {
if err := SaveUnencryptedKeysToFile(file, ctnr); err != nil {
log.Fatal(err)
}
}
func generateUnencryptedKeys(r io.Reader) *unencryptedKeysContainer {
ctnr := &unencryptedKeysContainer{
Keys: make([]*unencryptedKeys, *numKeys),
func generateUnencryptedKeys(r io.Reader) *UnencryptedKeysContainer {
ctnr := &UnencryptedKeysContainer{
Keys: make([]*UnencryptedKeys, *numKeys),
}
for i := 0; i < *numKeys; i++ {
signingKey, err := bls.RandKey(r)
@@ -71,7 +73,7 @@ func generateUnencryptedKeys(r io.Reader) *unencryptedKeysContainer {
if err != nil {
log.Fatal(err)
}
ctnr.Keys[i] = &unencryptedKeys{
ctnr.Keys[i] = &UnencryptedKeys{
ValidatorKey: signingKey.Marshal(),
WithdrawalKey: withdrawalKey.Marshal(),
}
@@ -79,7 +81,8 @@ func generateUnencryptedKeys(r io.Reader) *unencryptedKeysContainer {
return ctnr
}
func saveUnencryptedKeysToFile(w io.Writer, ctnr *unencryptedKeysContainer) error {
// SaveUnencryptedKeysToFile JSON encodes the container and writes to the writer.
func SaveUnencryptedKeysToFile(w io.Writer, ctnr *UnencryptedKeysContainer) error {
enc, err := json.Marshal(ctnr)
if err != nil {
log.Fatal(err)

View File

@@ -11,11 +11,11 @@ import (
func TestSavesUnencryptedKeys(t *testing.T) {
ctnr := generateUnencryptedKeys(rand.Reader)
buf := new(bytes.Buffer)
if err := saveUnencryptedKeysToFile(buf, ctnr); err != nil {
if err := SaveUnencryptedKeysToFile(buf, ctnr); err != nil {
t.Fatal(err)
}
enc := buf.Bytes()
dec := &unencryptedKeysContainer{}
dec := &UnencryptedKeysContainer{}
if err := json.Unmarshal(enc, dec); err != nil {
t.Fatal(err)
}