private BlockchainWithData setupBlockchain( final int blocksToAdd, final List<Address> accountsToSetup, final List<UInt256> storageKeys) { checkArgument(blocksToAdd >= 1, "Must add at least one block to the queries"); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); // Generate some queries data final List<BlockData> blockData = new ArrayList<>(blocksToAdd); final List<Block> blocks = gen.blockSequence(blocksToAdd, worldStateArchive, accountsToSetup, storageKeys); for (int i = 0; i < blocksToAdd; i++) { final Block block = blocks.get(i); final List<TransactionReceipt> receipts = gen.receipts(block); blockData.add(new BlockData(block, receipts)); } // Setup blockchain final MutableBlockchain blockchain = createInMemoryBlockchain(blocks.get(0)); blockData .subList(1, blockData.size()) .forEach(b -> blockchain.appendBlock(b.block, b.receipts)); return new BlockchainWithData(blockchain, blockData, worldStateArchive); }
@Before public void setup() { remoteBlockchain = createInMemoryBlockchain(genesisBlock); }
public static Responder blockchainResponder(final Blockchain blockchain) { return blockchainResponder(blockchain, createInMemoryWorldStateArchive()); }
GenesisConfigFile.fromConfig(config), SynchronizerConfiguration.builder().build(), new InMemoryStorageProvider(), false, 10,
private static MutableBlockchain buildBlockchain(final BlockHeader genesisBlockHeader) { final Block genesisBlock = new Block(genesisBlockHeader, BlockBody.empty()); return createInMemoryBlockchain(genesisBlock); }
private static WorldStateArchive buildWorldStateArchive( final Map<String, WorldStateMock.AccountMock> accounts) { final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final MutableWorldState worldState = worldStateArchive.getMutable(); final WorldUpdater updater = worldState.updater(); for (final Map.Entry<String, WorldStateMock.AccountMock> entry : accounts.entrySet()) { insertAccount(updater, Address.fromHexString(entry.getKey()), entry.getValue()); } updater.commit(); worldState.persist(); return worldStateArchive; }
@Test public void blockImport() throws IOException { final Path source = folder.newFile().toPath(); BlockTestUtil.write1000Blocks(source); final PantheonController<?> targetController = PantheonController.fromConfig( GenesisConfigFile.mainnet(), SynchronizerConfiguration.builder().build(), new InMemoryStorageProvider(), false, 1, new MiningParametersTestBuilder().enabled(false).build(), KeyPair.generate(), new NoOpMetricsSystem(), PrivacyParameters.noPrivacy()); final BlockImporter.ImportResult result = blockImporter.importBlockchain(source, targetController); // Don't count the Genesis block assertThat(result.count).isEqualTo(999); assertThat(result.td).isEqualTo(UInt256.of(21991996248790L)); }
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() { headerTestFixture.number(1); Block genesisBlock = createEmptyBlock(0, Hash.ZERO, proposerKeys); // not normally signed but ok blockChain = createInMemoryBlockchain(genesisBlock); final VoteTally voteTally = mock(VoteTally.class); when(voteTally.getValidators()).thenReturn(validators); when(voteTallyCache.getVoteTallyAfterBlock(any())).thenReturn(voteTally); final CliqueContext cliqueContext = new CliqueContext(voteTallyCache, null, null); when(protocolContext.getConsensusState()).thenReturn(cliqueContext); when(protocolContext.getBlockchain()).thenReturn(blockChain); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); when(syncState.isInSync()).thenReturn(true); miningTracker = new CliqueMiningTracker(proposerAddress, protocolContext); }
new ProtocolContext<>( blockchain, createInMemoryWorldStateArchive(), new IbftContext(voteTally, new VoteProposer()));
new InMemoryStorageProvider(), GenesisConfigFile.mainnet(), MainnetProtocolSchedule.create(),
@Before public void setup() { genesisBlock = blockDataGenerator.genesisBlock(); localBlockchain = createInMemoryBlockchain(genesisBlock); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); ethProtocolManager = EthProtocolManagerTestUtil.create(localBlockchain, worldStateArchive); ethContext = ethProtocolManager.ethContext(); protocolContext = new ProtocolContext<>(localBlockchain, worldStateArchive, null); }
@Test public void nonValidatorIsNotAllowedToCreateABlock() { genesisBlock = createEmptyBlock(otherNodeKeyPair); blockChain = createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAfterBlock(any())).thenReturn(new VoteTally(validatorList)); final VoteProposer voteProposer = new VoteProposer(); final CliqueContext cliqueContext = new CliqueContext(voteTallyCache, voteProposer, null); cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext); headerBuilder.parentHash(Hash.ZERO).number(3); final BlockHeader parentHeader = headerBuilder.buildHeader(); assertThat( CliqueHelpers.addressIsAllowedToProduceNextBlock( AddressHelpers.ofValue(1), cliqueProtocolContext, parentHeader)) .isFalse(); } }
final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(localBlockchain, worldStateArchive);
final PrivateTransactionHandler privateTransactionHandlerMock = mock(PrivateTransactionHandler.class); stateArchive = createInMemoryWorldStateArchive(); GENESIS_CONFIG.writeStateTo(stateArchive.getMutable(Hash.EMPTY_TRIE_HASH)); blockchain = createInMemoryBlockchain(GENESIS_BLOCK); context = new ProtocolContext<>(blockchain, stateArchive, null);
@Test public void exceptionIsThrownIfOnAnOrphanedChain() { final Address otherAddress = Util.publicKeyToAddress(otherNodeKeyPair.getPublicKey()); validatorList.add(otherAddress); genesisBlock = createEmptyBlock(proposerKeyPair); blockChain = createInMemoryBlockchain(genesisBlock); final VoteTallyCache voteTallyCache = mock(VoteTallyCache.class); when(voteTallyCache.getVoteTallyAfterBlock(any())).thenReturn(new VoteTally(validatorList)); final VoteProposer voteProposer = new VoteProposer(); final CliqueContext cliqueContext = new CliqueContext(voteTallyCache, voteProposer, null); cliqueProtocolContext = new ProtocolContext<>(blockChain, null, cliqueContext); headerBuilder.parentHash(Hash.ZERO).number(3); final BlockHeader parentHeader = TestHelpers.createCliqueSignedBlockHeader(headerBuilder, otherNodeKeyPair, validatorList); assertThatThrownBy( () -> CliqueHelpers.addressIsAllowedToProduceNextBlock( localAddress, cliqueProtocolContext, parentHeader)) .isInstanceOf(RuntimeException.class) .hasMessage("The block was on a orphaned chain."); }
new ProtocolContext<>( blockchain, createInMemoryWorldStateArchive(), new IbftContext(voteTally, new VoteProposer()));
GenesisState.fromJson( Resources.toString(genesisFileUrl, Charsets.UTF_8), protocolSchedule); final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); final WorldStateArchive worldArchive = createInMemoryWorldStateArchive();
private MutableBlockchain createShortChain(final long lastBlockToInclude) { final BlockHeader genesisHeader = blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get(); final BlockBody genesisBody = blockchain.getBlockBody(genesisHeader.getHash()).get(); final Block genesisBlock = new Block(genesisHeader, genesisBody); final MutableBlockchain shortChain = createInMemoryBlockchain(genesisBlock); long nextBlock = genesisHeader.getNumber() + 1; while (nextBlock <= lastBlockToInclude) { final BlockHeader header = blockchain.getBlockHeader(nextBlock).get(); final BlockBody body = blockchain.getBlockBody(header.getHash()).get(); final List<TransactionReceipt> receipts = blockchain.getTxReceipts(header.getHash()).get(); final Block block = new Block(header, body); shortChain.appendBlock(block, receipts); nextBlock++; } return shortChain; }
ScheduleBasedBlockHashFunction.create(protocolSchedule); final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock(), blockHashFunction); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); genesisState.writeStateTo(worldStateArchive.getMutable()); final ProtocolContext<Void> protocolContext =