mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
|
"github.com/prysmaticlabs/prysm/v3/runtime/interop"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func Test_genesisStateFromJSONValidators(t *testing.T) {
|
|
numKeys := 5
|
|
jsonData := createGenesisDepositData(t, numKeys)
|
|
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, fmt.Sprintf("%#x", val.PublicKey), jsonData[i].PubKey)
|
|
}
|
|
}
|
|
|
|
func createGenesisDepositData(t *testing.T, numKeys int) []*DepositDataJSON {
|
|
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([]*DepositDataJSON, numKeys)
|
|
for i := 0; i < numKeys; i++ {
|
|
dataRoot, err := dataList[i].HashTreeRoot()
|
|
require.NoError(t, err)
|
|
jsonData[i] = &DepositDataJSON{
|
|
PubKey: fmt.Sprintf("%#x", dataList[i].PublicKey),
|
|
Amount: dataList[i].Amount,
|
|
WithdrawalCredentials: fmt.Sprintf("%#x", dataList[i].WithdrawalCredentials),
|
|
DepositDataRoot: fmt.Sprintf("%#x", dataRoot),
|
|
Signature: fmt.Sprintf("%#x", dataList[i].Signature),
|
|
}
|
|
}
|
|
return jsonData
|
|
}
|