Search in sources :

Example 1 with MockStartDepositGenerator

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);
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) IntStream(java.util.stream.IntStream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) SpecVersion(tech.pegasys.teku.spec.SpecVersion) ArrayList(java.util.ArrayList) ExecutionPayloadHeader(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) Assertions(org.assertj.core.api.Assertions) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) BeaconStateBellatrix(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.bellatrix.BeaconStateBellatrix) BLSSignature(tech.pegasys.teku.bls.BLSSignature) GENESIS_EPOCH(tech.pegasys.teku.spec.config.SpecConfig.GENESIS_EPOCH) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) Collections(java.util.Collections) BLSKeyGenerator(tech.pegasys.teku.bls.BLSKeyGenerator) DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with MockStartDepositGenerator

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);
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MockStartBeaconStateGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartBeaconStateGenerator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) MockStartValidatorKeyPairFactory(tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) Test(org.junit.jupiter.api.Test)

Example 3 with MockStartDepositGenerator

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));
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) ArrayList(java.util.ArrayList) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 4 with MockStartDepositGenerator

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;
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) MockStartBeaconStateGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartBeaconStateGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

MockStartDepositGenerator (tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator)4 DepositData (tech.pegasys.teku.spec.datastructures.operations.DepositData)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)4 DepositGenerator (tech.pegasys.teku.spec.datastructures.util.DepositGenerator)3 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 MockStartBeaconStateGenerator (tech.pegasys.teku.spec.datastructures.interop.MockStartBeaconStateGenerator)2 DepositWithIndex (tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex)2 Validator (tech.pegasys.teku.spec.datastructures.state.Validator)2 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1