@Test public void createFromJsonNoAllocs() throws Exception { final GenesisState genesisState = GenesisState.fromJson( Resources.toString(GenesisStateTest.class.getResource("genesis2.json"), Charsets.UTF_8), MainnetProtocolSchedule.create()); final BlockHeader header = genesisState.getBlock().getHeader(); assertThat(header.getStateRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH); assertThat(header.getTransactionsRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH); assertThat(header.getReceiptsRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH); assertThat(header.getOmmersHash()).isEqualTo(Hash.EMPTY_LIST_HASH); assertThat(header.getExtraData()).isEqualTo(BytesValue.EMPTY); assertThat(header.getParentHash()).isEqualTo(Hash.ZERO); }
@Test public void encodeOlympicBlock() throws Exception { final GenesisState genesisState = GenesisState.fromJson( Resources.toString( GenesisStateTest.class.getResource("genesis-olympic.json"), Charsets.UTF_8), MainnetProtocolSchedule.create()); final BytesValueRLPOutput tmp = new BytesValueRLPOutput(); genesisState.getBlock().writeTo(tmp); assertThat(Hex.toHexString(genesisState.getBlock().getHeader().getHash().extractArray())) .isEqualTo(OLYMPIC_HASH); assertThat(Hex.toHexString(tmp.encoded().extractArray())).isEqualTo(OLYMPIC_RLP); } }
@Test public void createFromJsonWithAllocs() throws Exception { final GenesisState genesisState = GenesisState.fromJson( Resources.toString(GenesisStateTest.class.getResource("genesis1.json"), Charsets.UTF_8), MainnetProtocolSchedule.create()); final BlockHeader header = genesisState.getBlock().getHeader(); assertThat(header.getStateRoot()) .isEqualTo( Hash.fromHexString( "0x92683e6af0f8a932e5fe08c870f2ae9d287e39d4518ec544b0be451f1035fd39")); assertThat(header.getTransactionsRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH); assertThat(header.getReceiptsRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH); assertThat(header.getOmmersHash()).isEqualTo(Hash.EMPTY_LIST_HASH); assertThat(header.getExtraData()).isEqualTo(BytesValue.EMPTY); assertThat(header.getParentHash()).isEqualTo(Hash.ZERO); final DefaultMutableWorldState worldState = new DefaultMutableWorldState( new KeyValueStorageWorldStateStorage(new InMemoryKeyValueStorage())); genesisState.writeStateTo(worldState); final Account first = worldState.get(Address.fromHexString("0x0000000000000000000000000000000000000001")); final Account second = worldState.get(Address.fromHexString("0x0000000000000000000000000000000000000002")); assertThat(first).isNotNull(); assertThat(first.getBalance().toLong()).isEqualTo(111111111L); assertThat(second).isNotNull(); assertThat(second.getBalance().toLong()).isEqualTo(222222222L); }
public static EthProtocolManager create(final TimeoutPolicy timeoutPolicy) { final ProtocolSchedule<Void> protocolSchedule = MainnetProtocolSchedule.create(); final GenesisConfigFile config = GenesisConfigFile.mainnet(); final GenesisState genesisState = GenesisState.fromConfig(config, protocolSchedule); final Blockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); return create(blockchain, worldStateArchive, timeoutPolicy); }
@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()); }
storageProvider.createBlockchainStorage(protocolSchedule); final MutableBlockchain blockchain = new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage, metricsSystem);
GenesisState.fromJson( Resources.toString(genesisFileUrl, Charsets.UTF_8), protocolSchedule); final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); final WorldStateArchive worldArchive = createInMemoryWorldStateArchive();
storageProvider.createBlockchainStorage(protocolSchedule); final MutableBlockchain blockchain = new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage, metricsSystem);
storageProvider.createBlockchainStorage(protocolSchedule); final MutableBlockchain blockchain = new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage, metricsSystem);
storageProvider.createBlockchainStorage(protocolSchedule); final MutableBlockchain blockchain = new DefaultMutableBlockchain(genesisState.getBlock(), blockchainStorage, metricsSystem);
ScheduleBasedBlockHashFunction.create(protocolSchedule); final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock(), blockHashFunction); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); genesisState.writeStateTo(worldStateArchive.getMutable());