use of tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator 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.interop.MockStartDepositGenerator in project teku by ConsenSys.
the class MockStartBeaconStateGeneratorTest method shouldCreateInitialBeaconChainState.
@Test
public void shouldCreateInitialBeaconChainState() {
final UInt64 genesisTime = UInt64.valueOf(498294294824924924L);
final int validatorCount = 10;
final List<BLSKeyPair> validatorKeyPairs = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, validatorCount);
final List<DepositData> deposits = new MockStartDepositGenerator(spec).createDeposits(validatorKeyPairs);
final BeaconState initialBeaconState = new MockStartBeaconStateGenerator(spec).createInitialBeaconState(genesisTime, deposits, Optional.empty());
assertEquals(validatorCount, initialBeaconState.getValidators().size());
assertEquals(validatorCount, initialBeaconState.getEth1_data().getDeposit_count().longValue());
final List<BLSPublicKey> actualValidatorPublicKeys = initialBeaconState.getValidators().stream().map(Validator::getPubkeyBytes).map(BLSPublicKey::fromBytesCompressed).collect(Collectors.toList());
final List<BLSPublicKey> expectedValidatorPublicKeys = validatorKeyPairs.stream().map(BLSKeyPair::getPublicKey).collect(Collectors.toList());
assertEquals(expectedValidatorPublicKeys, actualValidatorPublicKeys);
}
use of tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator 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.interop.MockStartDepositGenerator 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