@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); }
@BeforeClass public static void setupConstants() throws Exception { PROTOCOL_SCHEDULE = MainnetProtocolSchedule.create(); final URL blocksUrl = EthJsonRpcHttpBySpecTest.class .getClassLoader() .getResource("tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestBlockchain.blocks"); final URL genesisJsonUrl = EthJsonRpcHttpBySpecTest.class .getClassLoader() .getResource("tech/pegasys/pantheon/ethereum/jsonrpc/jsonRpcTestGenesis.json"); assertThat(blocksUrl).isNotNull(); assertThat(genesisJsonUrl).isNotNull(); BLOCKS = new ArrayList<>(); try (final RawBlockIterator iterator = new RawBlockIterator( Paths.get(blocksUrl.toURI()), rlp -> BlockHeader.readFrom(rlp, MainnetBlockHashFunction::createHash))) { while (iterator.hasNext()) { BLOCKS.add(iterator.next()); } } final String gensisjson = Resources.toString(genesisJsonUrl, Charsets.UTF_8); GENESIS_BLOCK = BLOCKS.get(0); GENESIS_CONFIG = GenesisState.fromJson(gensisjson, PROTOCOL_SCHEDULE); }
@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); }
final URL genesisFileUrl = getResourceUrl(temp, "testGenesis.json"); final GenesisState genesisState = GenesisState.fromJson( Resources.toString(genesisFileUrl, Charsets.UTF_8), protocolSchedule); final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock());