private GenesisConfigOptions fromConfigOptions(final Map<String, Object> options) { return GenesisConfigFile.fromConfig(new JsonObject(Collections.singletonMap("config", options))) .getConfigOptions(); } }
private IbftConfigOptions fromConfigOptions(final Map<String, Object> ibftConfigOptions) { return GenesisConfigFile.fromConfig( new JsonObject(singletonMap("config", singletonMap("ibft", ibftConfigOptions)))) .getConfigOptions() .getIbftConfigOptions(); } }
private CliqueConfigOptions fromConfigOptions(final Map<String, Object> cliqueConfigOptions) { return GenesisConfigFile.fromConfig( new JsonObject(singletonMap("config", singletonMap("clique", cliqueConfigOptions)))) .getConfigOptions() .getCliqueConfigOptions(); } }
@Test public void shouldLoadDevelopmentConfigFile() { final GenesisConfigFile config = GenesisConfigFile.development(); // Sanity check some basic properties to confirm this is the dev file. assertThat(config.getConfigOptions().isEthHash()).isTrue(); assertThat(config.getConfigOptions().getChainId()).hasValue(DEVELOPMENT_CHAIN_ID); assertThat(config.getAllocations().map(GenesisAllocation::getAddress)) .contains( "fe3b557e8fb62b89f4916b721be55ceb828dbd73", "627306090abab3a6e1400e9345bc60c78a8bef57", "f17f52151ebef6c7334fad080c5704d77216b732"); }
@Test public void shouldLoadMainnetConfigFile() { final GenesisConfigFile config = GenesisConfigFile.mainnet(); // Sanity check some basic properties to confirm this is the mainnet file. assertThat(config.getConfigOptions().isEthHash()).isTrue(); assertThat(config.getConfigOptions().getChainId()).hasValue(MAINNET_CHAIN_ID); assertThat(config.getAllocations().map(GenesisAllocation::getAddress)) .contains( "000d836201318ec6899a67540690382780743280", "001762430ea9c3a26e5749afdb70da5f78ddbb8c", "001d14804b399c6ef80e64576f657660804fec0b"); }
@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 shouldSupportEmptyGenesisConfig() { final GenesisConfigOptions config = GenesisConfigFile.fromConfig("{}").getConfigOptions(); assertThat(config.isEthHash()).isFalse(); assertThat(config.isIbft()).isFalse(); assertThat(config.isClique()).isFalse(); assertThat(config.getHomesteadBlockNumber()).isEmpty(); }
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 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 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())); }
@Test public void parametersAlignWithMainnetWithAdjustments() { final ProtocolSpec<CliqueContext> homestead = CliqueProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), NODE_KEYS) .getByBlockNumber(0); assertThat(homestead.getName()).isEqualTo("Frontier"); assertThat(homestead.getBlockReward()).isEqualTo(Wei.ZERO); assertThat(homestead.getDifficultyCalculator()).isInstanceOf(CliqueDifficultyCalculator.class); } }
@Test public void blockHeadersRoundTrip() throws IOException { final List<BlockHeader> headers = new ArrayList<>(); final ByteBuffer buffer = ByteBuffer.wrap(Resources.toByteArray(Resources.getResource("50.blocks"))); for (int i = 0; i < 50; ++i) { final int blockSize = RLP.calculateSize(BytesValue.wrapBuffer(buffer)); final byte[] block = new byte[blockSize]; buffer.get(block); buffer.compact().position(0); final RLPInput oneBlock = new BytesValueRLPInput(BytesValue.wrap(block), false); oneBlock.enterList(); headers.add(BlockHeader.readFrom(oneBlock, MainnetBlockHashFunction::createHash)); // We don't care about the bodies, just the headers oneBlock.skipNext(); oneBlock.skipNext(); } final MessageData initialMessage = BlockHeadersMessage.create(headers); final MessageData raw = new RawMessage(EthPV62.BLOCK_HEADERS, initialMessage.getData()); final BlockHeadersMessage message = BlockHeadersMessage.readFrom(raw); final Iterator<BlockHeader> readHeaders = message.getHeaders( FixedDifficultyProtocolSchedule.create( GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy())); for (int i = 0; i < 50; ++i) { Assertions.assertThat(readHeaders.next()).isEqualTo(headers.get(i)); } } }
.bodies( FixedDifficultyProtocolSchedule.create( GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy())) .iterator();
builder.setNetworkId( genesisConfigFile .getConfigOptions() .getChainId() .orElse(EthNetworkConfig.getNetworkConfig(MAINNET).getNetworkId()));
final ProtocolSchedule<Void> protocolSchedule = FixedDifficultyProtocolSchedule.create( GenesisConfigFile.development().getConfigOptions(), PrivacyParameters.noPrivacy()); final Blockchain blockchain = new TestBlockchain(); final TransactionProcessor transactionProcessor =
@Before public void setup() { protocolSchedule = CliqueProtocolSchedule.create( GenesisConfigFile.DEFAULT.getConfigOptions(), proposerKeyPair); final Address otherAddress = Util.publicKeyToAddress(otherKeyPair.getPublicKey()); validatorList.add(otherAddress); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAfterBlock(any())).thenReturn(new VoteTally(validatorList)); voteProposer = new VoteProposer(); final CliqueContext cliqueContext = new CliqueContext(voteTallyCache, voteProposer, null); final Block genesis = GenesisState.fromConfig(GenesisConfigFile.mainnet(), protocolSchedule).getBlock(); blockchain = createInMemoryBlockchain(genesis); protocolContext = new ProtocolContext<>(blockchain, stateArchive, cliqueContext); // Add a block above the genesis final BlockHeaderTestFixture headerTestFixture = new BlockHeaderTestFixture(); headerTestFixture.number(1).parentHash(genesis.getHeader().getHash()); final Block emptyBlock = new Block( TestHelpers.createCliqueSignedBlockHeader( headerTestFixture, otherKeyPair, validatorList), new BlockBody(Lists.newArrayList(), Lists.newArrayList())); blockchain.appendBlock(emptyBlock, Lists.newArrayList()); }
IbftProtocolSchedule.create( GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}") .getConfigOptions()); final ProtocolContext<IbftContext> protContext = new ProtocolContext<>(