use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.
the class DataStructureUtil method newDeposits.
public List<DepositWithIndex> newDeposits(int numDeposits) {
List<DepositWithIndex> deposits = new ArrayList<>();
final DepositGenerator depositGenerator = new DepositGenerator(spec);
for (int i = 0; i < numDeposits; i++) {
BLSKeyPair keypair = BLSTestUtil.randomKeyPair(i);
DepositData depositData = depositGenerator.createDepositData(keypair, getMaxEffectiveBalance(), keypair.getPublicKey());
DepositWithIndex deposit = new DepositWithIndex(Deposit.SSZ_SCHEMA.getProofSchema().getDefault(), depositData, UInt64.valueOf(i));
deposits.add(deposit);
}
return deposits;
}
use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.
the class GenesisGeneratorTest method shouldActivateToppedUpValidator.
@Test
public void shouldActivateToppedUpValidator() {
MockStartDepositGenerator mockStartDepositGenerator = new MockStartDepositGenerator(spec, new DepositGenerator(spec, true));
DepositData PARTIAL_DEPOSIT_DATA = mockStartDepositGenerator.createDeposits(VALIDATOR_KEYS.subList(0, 1), UInt64.valueOf(1000000000L)).get(0);
DepositData TOP_UP_DEPOSIT_DATA = mockStartDepositGenerator.createDeposits(VALIDATOR_KEYS.subList(0, 1), UInt64.valueOf(31000000000L)).get(0);
List<DepositData> INITIAL_DEPOSIT_DATA = List.of(PARTIAL_DEPOSIT_DATA, TOP_UP_DEPOSIT_DATA);
List<Deposit> INITIAL_DEPOSITS = IntStream.range(0, INITIAL_DEPOSIT_DATA.size()).mapToObj(index -> {
final DepositData data = INITIAL_DEPOSIT_DATA.get(index);
return new DepositWithIndex(data, UInt64.valueOf(index));
}).collect(toList());
genesisGenerator.updateCandidateState(Bytes32.ZERO, UInt64.ZERO, INITIAL_DEPOSITS);
final BeaconState state = genesisGenerator.getGenesisState();
Assertions.<Integer>assertThat(spec.getActiveValidatorIndices(state, GENESIS_EPOCH)).hasSize(1);
assertThat(genesisGenerator.getActiveValidatorCount()).isEqualTo(1);
}
use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.
the class StateUpgradeTransitionTest method createGenesis.
private BeaconState createGenesis(final Spec spec) {
final List<DepositData> initialDepositData = new MockStartDepositGenerator(spec, new DepositGenerator(spec, true)).createDeposits(VALIDATOR_KEYS, spec.getGenesisSpecConfig().getMaxEffectiveBalance());
final List<DepositWithIndex> deposits = new ArrayList<>();
for (int index = 0; index < initialDepositData.size(); index++) {
final DepositData data = initialDepositData.get(index);
DepositWithIndex deposit = new DepositWithIndex(data, UInt64.valueOf(index));
deposits.add(deposit);
}
final BeaconState initialState = spec.initializeBeaconStateFromEth1(Bytes32.ZERO, UInt64.ZERO, deposits, Optional.empty());
return initialState.updated(state -> state.setGenesis_time(UInt64.ZERO));
}
use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.
the class ChainBuilder method generateGenesis.
public SignedBlockAndState generateGenesis(final UInt64 genesisTime, final boolean signDeposits, final UInt64 depositAmount, final Optional<ExecutionPayloadHeader> payloadHeader) {
checkState(blocks.isEmpty(), "Genesis already created");
// Generate genesis state
final List<DepositData> initialDepositData = new MockStartDepositGenerator(spec, new DepositGenerator(spec, signDeposits)).createDeposits(validatorKeys, depositAmount);
BeaconState genesisState = new MockStartBeaconStateGenerator(spec).createInitialBeaconState(genesisTime, initialDepositData, payloadHeader);
// Generate genesis block
BeaconBlock genesisBlock = BeaconBlock.fromGenesisState(spec, genesisState);
final SignedBeaconBlock signedBlock = SignedBeaconBlock.create(spec, genesisBlock, BLSSignature.empty());
final SignedBlockAndState blockAndState = new SignedBlockAndState(signedBlock, genesisState);
trackBlock(blockAndState);
return blockAndState;
}
Aggregations