private GenesisConfigFile configWithProperty(final String key, final String value) { return GenesisConfigFile.fromConfig("{\"" + key + "\":\"" + value + "\"}"); }
private GenesisConfigOptions fromConfigOptions(final Map<String, Object> options) { return GenesisConfigFile.fromConfig(new JsonObject(Collections.singletonMap("config", options))) .getConfigOptions(); } }
private CliqueConfigOptions fromConfigOptions(final Map<String, Object> cliqueConfigOptions) { return GenesisConfigFile.fromConfig( new JsonObject(singletonMap("config", singletonMap("clique", cliqueConfigOptions)))) .getConfigOptions() .getCliqueConfigOptions(); } }
private IbftConfigOptions fromConfigOptions(final Map<String, Object> ibftConfigOptions) { return GenesisConfigFile.fromConfig( new JsonObject(singletonMap("config", singletonMap("ibft", ibftConfigOptions)))) .getConfigOptions() .getIbftConfigOptions(); } }
@Test public void shouldSupportEmptyGenesisConfig() { final GenesisConfigOptions config = GenesisConfigFile.fromConfig("{}").getConfigOptions(); assertThat(config.isEthHash()).isFalse(); assertThat(config.isIbft()).isFalse(); assertThat(config.isClique()).isFalse(); assertThat(config.getHomesteadBlockNumber()).isEmpty(); }
public PantheonController<?> build() throws IOException { // instantiate a controller with mainnet config if no genesis file is defined // otherwise use the indicated genesis file final KeyPair nodeKeys = loadKeyPair(nodePrivateKeyFile); final StorageProvider storageProvider = RocksDbStorageProvider.create(homePath.resolve(DATABASE_PATH), metricsSystem); final GenesisConfigFile genesisConfigFile; if (devMode) { genesisConfigFile = GenesisConfigFile.development(); } else { final String genesisConfig = ethNetworkConfig.getGenesisConfig(); genesisConfigFile = GenesisConfigFile.fromConfig(genesisConfig); } return PantheonController.fromConfig( genesisConfigFile, synchronizerConfiguration, storageProvider, syncWithOttoman, ethNetworkConfig.getNetworkId(), miningParameters, nodeKeys, metricsSystem, privacyParameters); } }
private int cliqueBlockPeriod(final PantheonNode node) { final String config = node.genesisConfigProvider().createGenesisConfig(emptyList()).get(); final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(config); final CliqueConfigOptions cliqueConfigOptions = genesisConfigFile.getConfigOptions().getCliqueConfigOptions(); return cliqueConfigOptions.getBlockPeriodSeconds(); }
@Test public void shouldOnlyUseFrontierWhenEmptyJsonConfigIsUsed() { final JsonObject json = new JsonObject("{}"); final ProtocolSchedule<Void> sched = MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), PrivacyParameters.noPrivacy()); Assertions.assertThat(sched.getByBlockNumber(1L).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()).isEqualTo("Frontier"); }
@Test public void predefinedNetworkIdsMustBeEqualToChainIds() { // check the network id against the one in mainnet genesis config // it implies that EthNetworkConfig.mainnet().getNetworkId() returns a value equals to the chain // id // in this network genesis file. GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(EthNetworkConfig.getNetworkConfig(MAINNET).getGenesisConfig()); assertThat(genesisConfigFile.getConfigOptions().getChainId().isPresent()).isTrue(); assertThat(genesisConfigFile.getConfigOptions().getChainId().getAsInt()) .isEqualTo(EthNetworkConfig.getNetworkConfig(MAINNET).getNetworkId()); }
@Test public void shouldCreateRopstenConfig() throws Exception { final ProtocolSchedule<Void> sched = MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig( Resources.toString( Resources.getResource("ropsten.json"), StandardCharsets.UTF_8)) .getConfigOptions(), PrivacyParameters.noPrivacy()); Assertions.assertThat(sched.getByBlockNumber(0).getName()).isEqualTo("TangerineWhistle"); Assertions.assertThat(sched.getByBlockNumber(1).getName()).isEqualTo("TangerineWhistle"); Assertions.assertThat(sched.getByBlockNumber(10).getName()).isEqualTo("SpuriousDragon"); Assertions.assertThat(sched.getByBlockNumber(1700000).getName()).isEqualTo("Byzantium"); Assertions.assertThat(sched.getByBlockNumber(4230000).getName()).isEqualTo("Constantinople"); Assertions.assertThat(sched.getByBlockNumber(4939394).getName()).isEqualTo("ConstantinopleFix"); Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()) .isEqualTo("ConstantinopleFix"); } }
@Test public void createFromConfigWithSettings() { final JsonObject json = new JsonObject( "{\"config\": {\"homesteadBlock\": 2, \"daoForkBlock\": 3, \"eip150Block\": 14, \"eip158Block\": 15, \"byzantiumBlock\": 16, \"constantinopleBlock\": 18, \"constantinopleFixBlock\": 19, \"chainId\":1234}}"); final ProtocolSchedule<Void> sched = MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), PrivacyParameters.noPrivacy()); Assertions.assertThat(sched.getByBlockNumber(1).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockNumber(2).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockNumber(3).getName()).isEqualTo("DaoRecoveryInit"); Assertions.assertThat(sched.getByBlockNumber(4).getName()).isEqualTo("DaoRecoveryTransition"); Assertions.assertThat(sched.getByBlockNumber(13).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockNumber(14).getName()).isEqualTo("TangerineWhistle"); Assertions.assertThat(sched.getByBlockNumber(15).getName()).isEqualTo("SpuriousDragon"); Assertions.assertThat(sched.getByBlockNumber(16).getName()).isEqualTo("Byzantium"); Assertions.assertThat(sched.getByBlockNumber(18).getName()).isEqualTo("Constantinople"); Assertions.assertThat(sched.getByBlockNumber(19).getName()).isEqualTo("ConstantinopleFix"); }
@Test public void protocolSpecsAreCreatedAtBlockDefinedInJson() { final String jsonInput = "{\"config\": " + "{\"chainId\": 4,\n" + "\"homesteadBlock\": 1,\n" + "\"eip150Block\": 2,\n" + "\"eip155Block\": 3,\n" + "\"eip158Block\": 3,\n" + "\"byzantiumBlock\": 1035301}" + "}"; final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions(); final ProtocolSchedule<CliqueContext> protocolSchedule = CliqueProtocolSchedule.create(config, NODE_KEYS); final ProtocolSpec<CliqueContext> homesteadSpec = protocolSchedule.getByBlockNumber(1); final ProtocolSpec<CliqueContext> tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2); final ProtocolSpec<CliqueContext> spuriousDragonSpec = protocolSchedule.getByBlockNumber(3); final ProtocolSpec<CliqueContext> byzantiumSpec = protocolSchedule.getByBlockNumber(1035301); assertThat(homesteadSpec.equals(tangerineWhistleSpec)).isFalse(); assertThat(tangerineWhistleSpec.equals(spuriousDragonSpec)).isFalse(); assertThat(spuriousDragonSpec.equals(byzantiumSpec)).isFalse(); }
@Test public void shouldGetAllocations() { final GenesisConfigFile config = GenesisConfigFile.fromConfig( "{" + " \"alloc\": {" + " \"fe3b557e8fb62b89f4916b721be55ceb828dbd73\": {" + " \"balance\": \"0xad78ebc5ac6200000\"" + " }," + " \"627306090abaB3A6e1400e9345bC60c78a8BEf57\": {" + " \"balance\": \"1000\"" + " }," + " \"f17f52151EbEF6C7334FAD080c5704D77216b732\": {" + " \"balance\": \"90000000000000000000000\"" + " }" + " }" + "}"); final Map<String, String> allocations = config .getAllocations() .collect( Collectors.toMap(GenesisAllocation::getAddress, GenesisAllocation::getBalance)); assertThat(allocations) .containsOnly( entry("fe3b557e8fb62b89f4916b721be55ceb828dbd73", "0xad78ebc5ac6200000"), entry("627306090abab3a6e1400e9345bc60c78a8bef57", "1000"), entry("f17f52151ebef6c7334fad080c5704d77216b732", "90000000000000000000000")); }
@Test public void outOfOrderForksFails() { final JsonObject json = new JsonObject( "{\"config\": {\"homesteadBlock\": 2, \"daoForkBlock\": 3, \"eip150Block\": 14, \"eip158Block\": 15, \"byzantiumBlock\": 16, \"constantinopleBlock\": 18, \"constantinopleFixBlock\": 17, \"chainId\":1234}}"); Assertions.assertThatExceptionOfType(RuntimeException.class) .describedAs( "Genesis Config Error: 'ConstantinopleFix' is scheduled for block 17 but it must be on or after block 18.") .isThrownBy( () -> MainnetProtocolSchedule.fromConfig( GenesisConfigFile.fromConfig(json).getConfigOptions(), PrivacyParameters.noPrivacy())); }
GenesisConfigFile.fromConfig(config), SynchronizerConfiguration.builder().build(), new InMemoryStorageProvider(),
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisConfig()); builder.setNetworkId( genesisConfigFile
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}") .getConfigOptions()); final ProtocolContext<IbftContext> protContext =
GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}") .getConfigOptions()); final ProtocolContext<IbftContext> protContext =