mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
ff1b03ab13
* prysmctl using the same genesis func as e2e * add whitespace to genesis.json for readability * fix typo in fork name * don't require validator count if deposits given * add gosec exception * the other nosec :( * appease deepsource * fix comments on renamed public value/func --------- Co-authored-by: kasey <kasey@users.noreply.github.com>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package testnet
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/crypto/bls"
|
|
"github.com/prysmaticlabs/prysm/v4/runtime/interop"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
)
|
|
|
|
func Test_genesisStateFromJSONValidators(t *testing.T) {
|
|
numKeys := 5
|
|
jsonData := createGenesisDepositData(t, numKeys)
|
|
jsonInput, err := json.Marshal(jsonData)
|
|
require.NoError(t, err)
|
|
_, dds, err := depositEntriesFromJSON(jsonInput)
|
|
require.NoError(t, err)
|
|
for i := range dds {
|
|
assert.DeepEqual(t, fmt.Sprintf("%#x", dds[i].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
|
|
}
|