use of tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory 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.MockStartValidatorKeyPairFactory in project teku by ConsenSys.
the class InMemoryStorageSystemBuilder method build.
public StorageSystem build() {
final Database database;
switch(version) {
case LEVELDB_TREE:
database = createLevelDbTreeDatabase();
break;
// Leveldb only varies by db type which doesn't apply to in-memory
case LEVELDB2:
case V6:
database = createV6Database();
break;
// Leveldb only varies by db type which doesn't apply to in-memory
case LEVELDB1:
case V5:
database = createV5Database();
break;
case V4:
database = createV4Database();
break;
default:
throw new UnsupportedOperationException("Unsupported database version: " + version);
}
final List<BLSKeyPair> validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, numberOfValidators);
return StorageSystem.create(database, createRestartSupplier(), storageMode, storeConfig, spec, ChainBuilder.create(spec, validatorKeys));
}
use of tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory in project teku by ConsenSys.
the class GenesisCommand method generate.
@Command(name = "mock", description = "Generate a mock genesis state", mixinStandardHelpOptions = true, showDefaultValues = true, abbreviateSynopsis = true, versionProvider = PicoCliVersionProvider.class, synopsisHeading = "%n", descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", footer = "Teku is licensed under the Apache License 2.0")
public void generate(@Mixin MockGenesisParams genesisParams, @Mixin MinimalEth2NetworkOptions networkOptions) throws IOException {
// Output to stdout if no file is specified
final Spec spec = networkOptions.getSpec();
final boolean outputToFile = genesisParams.outputFile != null && !genesisParams.outputFile.isBlank();
try (final OutputStream fileStream = outputToFile ? new FileOutputStream(genesisParams.outputFile) : System.out) {
if (outputToFile) {
SUB_COMMAND_LOG.generatingMockGenesis(genesisParams.validatorCount, genesisParams.genesisTime);
}
final long genesisTime = genesisParams.genesisTime;
final List<BLSKeyPair> validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, genesisParams.validatorCount);
final BeaconState genesisState = InteropStartupUtil.createMockedStartInitialBeaconState(spec, genesisTime, validatorKeys);
if (outputToFile) {
SUB_COMMAND_LOG.storingGenesis(genesisParams.outputFile, false);
}
fileStream.write(genesisState.sszSerialize().toArrayUnsafe());
if (outputToFile) {
SUB_COMMAND_LOG.storingGenesis(genesisParams.outputFile, true);
}
}
}
Aggregations