use of tech.pegasys.teku.spec.datastructures.operations.DepositData in project teku by ConsenSys.
the class MockStartBeaconStateGenerator method createInitialBeaconState.
public BeaconState createInitialBeaconState(final UInt64 genesisTime, final List<DepositData> initialDepositData, final Optional<ExecutionPayloadHeader> payloadHeader) {
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(BLOCK_HASH, genesisTime, deposits, payloadHeader);
return initialState.updated(state -> state.setGenesis_time(genesisTime));
}
use of tech.pegasys.teku.spec.datastructures.operations.DepositData in project teku by ConsenSys.
the class DataStructureUtil method randomDepositData.
public DepositData randomDepositData() {
BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(nextSeed());
BLSPublicKey pubkey = keyPair.getPublicKey();
Bytes32 withdrawal_credentials = randomBytes32();
DepositMessage proof_of_possession_data = new DepositMessage(pubkey, withdrawal_credentials, getMaxEffectiveBalance());
final Bytes32 domain = computeDomain();
final Bytes signing_root = getSigningRoot(proof_of_possession_data, domain);
BLSSignature proof_of_possession = BLS.sign(keyPair.getSecretKey(), signing_root);
return new DepositData(proof_of_possession_data, proof_of_possession);
}
use of tech.pegasys.teku.spec.datastructures.operations.DepositData 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.operations.DepositData 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.operations.DepositData in project teku by ConsenSys.
the class GenesisGeneratorTest method shouldIgnoreInvalidDeposits.
@Test
public void shouldIgnoreInvalidDeposits() {
List<Deposit> deposits = new ArrayList<>(initialDeposits);
// Add an invalid deposit at the start with the same key as a later, valid deposit
final int expectedIndex = 3;
final DepositData validData = deposits.get(expectedIndex).getData();
final DepositData invalidData = new DepositData(validData.getPubkey(), validData.getWithdrawal_credentials(), validData.getAmount(), BLSSignature.empty());
deposits.add(0, new Deposit(invalidData));
genesisGenerator.updateCandidateState(Bytes32.ZERO, UInt64.ZERO, deposits);
final BeaconState state = genesisGenerator.getGenesisState();
// All deposits were processed
assertThat(state.getEth1_deposit_index()).isEqualTo(UInt64.valueOf(deposits.size()));
// But one didn't result in a new validator
assertThat(state.getValidators()).hasSize(deposits.size() - 1);
assertThat(genesisGenerator.getActiveValidatorCount()).isEqualTo(deposits.size() - 1);
// And the validator with an invalid deposit should wind up at index 3, not 0 because their
// first deposit was completely ignored
final Validator validator = state.getValidators().get(expectedIndex);
assertThat(validator.getPubkeyBytes()).isEqualTo(validData.getPubkey().toBytesCompressed());
assertThat(genesisSpec.predicates().isActiveValidator(validator, GENESIS_EPOCH)).isTrue();
}
Aggregations