mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 04:00:05 +00:00
83179376d4
* Clean testutil, change tool names to Deterministic * Cleanup errors * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into clean-testutil * Fix bug with generating deposits * Fix a few tests * Fix most tests * Clean up some tests * Remove err pt. 1 * Remove err pt. 2 * Change tests to use genesis state util * Remove err from deposits * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Remove circular dependency * Remove uncompressed signature test * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' into clean-testutil * Goimports * gazelle * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Add back error handling * New attestation pool (#4185) * New pool * Better namings * Fmt * Gazelle * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into define-pool * Raul's feedback * Raul's feedback * Log peer conected log for incoming connections (#4173) * Log peer conected log for incoming connections * Merge branch 'master' into peerconnected * Merge branch 'master' into peerconnected * Update handshake.go * Update handshake.go * Merge branch 'master' into peerconnected * Merge branch 'master' into peerconnected * Attestation pool to use go-cache (#4187) * Update EthereumAPIs (#4186) * include new patch targeting latest ethapis master * ensure project builds * Merge branch 'master' into update-all-api * fix up committees * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * include latest eth apis * Merge branch 'master' into update-all-api * update block tests * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * Merge branch 'master' into update-all-api * add todos * Implement GetValidator RPC Endpoint (#4188) * include new patch targeting latest ethapis master * ensure project builds * Merge branch 'master' into update-all-api * fix up committees * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * include latest eth apis * Merge branch 'master' into update-all-api * update block tests * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * Merge branch 'master' into update-all-api * add todos * implement get validator rpc * add test for get validator * table driven test * fix up test * fix confs * tests for more cases * fix up tests and add out of range * Slasher optimization (#4172) * size * batching and concurrency improvements * gaz * merge fixes * fix comment * fix test * fix test * fix build * ethpb * ethpb * fix test * fix comment * add benchmark * fix benchmark * Handle error for all testutil uses * Fix errors * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Revert error handling Revert "Fix errors" This reverts commit db081f5486f62c854e7a34e792f5e380cfa922e7. Revert "Handle error for all testutil uses" This reverts commit bdabef230632dd184491c2dad63c7d3e74a3861b. Revert "Add back error handling" This reverts commit da7e3d2020cd906f45f452d4e441b566f2d5c8aa. * Change genesis state func to use testing.T * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Fix conflict * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' into clean-testutil * Merge branch 'master' into clean-testutil * Captialize other logs * Merge branch 'clean-testutil' of https://github.com/0xKiwi/Prysm into clean-testutil * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' into clean-testutil
121 lines
3.3 KiB
Go
121 lines
3.3 KiB
Go
package endtoend
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"math/big"
|
|
"os"
|
|
"os/exec"
|
|
"path"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
)
|
|
|
|
type validatorClientInfo struct {
|
|
processID int
|
|
monitorPort uint64
|
|
}
|
|
|
|
// initializeValidators sends the deposits to the eth1 chain and starts the validator clients.
|
|
func initializeValidators(
|
|
t *testing.T,
|
|
config *end2EndConfig,
|
|
keystorePath string,
|
|
beaconNodes []*beaconNodeInfo,
|
|
) []*validatorClientInfo {
|
|
binaryPath, found := bazel.FindBinary("validator", "validator")
|
|
if !found {
|
|
t.Fatal("validator binary not found")
|
|
}
|
|
|
|
tmpPath := config.tmpPath
|
|
validatorNum := config.numValidators
|
|
beaconNodeNum := config.numBeaconNodes
|
|
if validatorNum%beaconNodeNum != 0 {
|
|
t.Fatal("Validator count is not easily divisible by beacon node count.")
|
|
}
|
|
|
|
valClients := make([]*validatorClientInfo, beaconNodeNum)
|
|
validatorsPerNode := validatorNum / beaconNodeNum
|
|
for n := uint64(0); n < beaconNodeNum; n++ {
|
|
file, err := os.Create(path.Join(tmpPath, fmt.Sprintf("vals-%d.log", n)))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
args := []string{
|
|
fmt.Sprintf("--interop-num-validators=%d", validatorsPerNode),
|
|
fmt.Sprintf("--interop-start-index=%d", validatorsPerNode*n),
|
|
fmt.Sprintf("--monitoring-port=%d", 9080+n),
|
|
fmt.Sprintf("--beacon-rpc-provider=localhost:%d", 4000+n),
|
|
}
|
|
cmd := exec.Command(binaryPath, args...)
|
|
cmd.Stdout = file
|
|
cmd.Stderr = file
|
|
t.Logf("Starting validator client with flags %s", strings.Join(args, " "))
|
|
if err := cmd.Start(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
valClients[n] = &validatorClientInfo{
|
|
processID: cmd.Process.Pid,
|
|
monitorPort: 9080 + n,
|
|
}
|
|
}
|
|
|
|
client, err := rpc.DialHTTP("http://127.0.0.1:8545")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
web3 := ethclient.NewClient(client)
|
|
|
|
jsonBytes, err := ioutil.ReadFile(keystorePath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
txOps, err := bind.NewTransactor(bytes.NewReader(jsonBytes), "" /*password*/)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
depositInGwei := big.NewInt(int64(params.BeaconConfig().MaxEffectiveBalance))
|
|
txOps.Value = depositInGwei.Mul(depositInGwei, big.NewInt(int64(params.BeaconConfig().GweiPerEth)))
|
|
txOps.GasLimit = 4000000
|
|
|
|
contract, err := contracts.NewDepositContract(config.contractAddr, web3)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
deposits, _, _ := testutil.DeterministicDepositsAndKeys(validatorNum)
|
|
_, roots, err := testutil.DeterministicDepositTrie(len(deposits))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for index, dd := range deposits {
|
|
_, err = contract.Deposit(txOps, dd.Data.PublicKey, dd.Data.WithdrawalCredentials, dd.Data.Signature, roots[index])
|
|
if err != nil {
|
|
t.Error("unable to send transaction to contract")
|
|
}
|
|
}
|
|
|
|
keystore, err := keystore.DecryptKey(jsonBytes, "" /*password*/)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Picked 20 for this as a "safe" number of blocks to mine so the deposits
|
|
// are detected.
|
|
if err := mineBlocks(web3, keystore, 20); err != nil {
|
|
t.Fatalf("failed to mine blocks %v", err)
|
|
}
|
|
|
|
return valClients
|
|
}
|