mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
211d9bc0b9
* fix build from source * clean up * update again * change everything * workaround for now * fix versioning * all passing now * fix build issues * clean up * revert use of MulVerify * gaz * stub * Apply suggestions from code review Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * fix all * fix test * todo * fix stub * revert back * make deep source happy * Update shared/bls/herumi/public_key.go * Update shared/bls/blst/signature.go * Update shared/bls/blst/signature_test.go * imports * move iface to common, export errors * rm iface build Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/bls"
|
|
"github.com/prysmaticlabs/prysm/shared/interop"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func Test_genesisStateFromJSONValidators(t *testing.T) {
|
|
jsonData, depositDataList := createGenesisDepositData(t)
|
|
jsonInput, err := json.Marshal(jsonData)
|
|
require.NoError(t, err)
|
|
genesisState, err := genesisStateFromJSONValidators(
|
|
bytes.NewReader(jsonInput), 0, /* genesis time defaults to time.Now() */
|
|
)
|
|
require.NoError(t, err)
|
|
for i, val := range genesisState.Validators {
|
|
assert.DeepEqual(t, val.PublicKey, depositDataList[i].PublicKey)
|
|
}
|
|
}
|
|
|
|
func createGenesisDepositData(t *testing.T) ([]*GenesisValidator, []*ethpb.Deposit_Data) {
|
|
numKeys := 5
|
|
pubKeys := make([]bls.PublicKey, numKeys)
|
|
privKeys := make([]bls.SecretKey, numKeys)
|
|
for i := 0; i < numKeys; i++ {
|
|
randKey, err := bls.RandKey()
|
|
require.NoError(t, err)
|
|
privKeys[i] = randKey
|
|
pubKeys[i] = randKey.PublicKey()
|
|
}
|
|
dataList, _, err := interop.DepositDataFromKeys(privKeys, pubKeys)
|
|
require.NoError(t, err)
|
|
jsonData := make([]*GenesisValidator, numKeys)
|
|
for i := 0; i < numKeys; i++ {
|
|
data := dataList[i]
|
|
enc, err := data.MarshalSSZ()
|
|
require.NoError(t, err)
|
|
jsonData[i] = &GenesisValidator{
|
|
DepositData: fmt.Sprintf("%#x", enc),
|
|
}
|
|
}
|
|
return jsonData, dataList
|
|
}
|