@Test
public void startMiningTest() throws FileNotFoundException, InterruptedException {

    SysPropConfig1.props.overrideParams(ConfigFactory.parseString(
            "peer.listen.port = 30335 \n" +
                    "peer.privateKey = 6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec \n" +
                    "peer.networkId = 555 \n" +
                    "peer.active = [{ url = \"enode://b23b3b9f38f1d314b27e63c63f3e45a6ea5f82c83f282e2d38f2f01c22165e897656fe2e5f9f18616b81f41cbcf2e9100fc9f8dad099574f3d84cf9623de2fc9@localhost:20301\" }] \n" +
                    "sync.enabled = true \n" +
                    "genesis = genesis-harder.json \n" +
                      "genesis = frontier.json \n" +
                    "database.dir = testDB-2 \n" +
                    "mine.extraDataHex = cccccccccccccccccccc \n" +
                    "mine.cpuMineThreads = 2"));
      SysPropConfig2.props.overrideParams(ConfigFactory.parseString(
              "peer.listen.port = 30336 \n" +
                      "peer.privateKey = 3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c \n" +
                      "peer.networkId = 555 \n" +
                      "peer.active = [{ url = \"enode://b23b3b9f38f1d314b27e63c63f3e45a6ea5f82c83f282e2d38f2f01c22165e897656fe2e5f9f18616b81f41cbcf2e9100fc9f8dad099574f3d84cf9623de2fc9@localhost:20301\" }] \n" +
                      "sync.enabled = true \n" +
                      "genesis = genesis-light.json \n" +
                        "genesis = frontier.json \n" +
                      "database.dir = testDB-1 \n"));
    Ethereum ethereum1 = EthereumFactory.createEthereum(SysPropConfig1.props, SysPropConfig1.class);
      Ethereum ethereum2 = EthereumFactory.createEthereum(SysPropConfig2.props, SysPropConfig2.class);
    final CountDownLatch semaphore = new CountDownLatch(1);
    ethereum1.addListener(new EthereumListenerAdapter() {
        @Override
        public void onBlock(Block block, List<TransactionReceipt> receipts) {
            System.out.println("=== New block: " + blockInfo(block));
        }
        @Override
        public void onSyncDone(SyncState state) {
            semaphore.countDown();
        }
    });
      ethereum2.addListener(new EthereumListenerAdapter() {
          @Override
          public void onBlock(Block block, List<TransactionReceipt> receipts) {
              System.err.println("=== New block: " + block);
          }
          @Override
          public void onPendingStateChanged(List<Transaction> transactions) {
              System.err.println("=== Tx: " + transactions);
          }
      });
    System.out.println("=== Waiting for sync ...");
    semaphore.await(600, TimeUnit.SECONDS);
    System.out.println("=== Sync done.");
    BlockMiner blockMiner = ethereum1.getBlockMiner();
    blockMiner.addListener(new MinerListener() {
        @Override
        public void miningStarted() {
            System.out.println("=== MinerTest.miningStarted");
        }
        @Override
        public void miningStopped() {
            System.out.println("=== MinerTest.miningStopped");
        }
        @Override
        public void blockMiningStarted(Block block) {
            System.out.println("=== MinerTest.blockMiningStarted " + blockInfo(block));
        }
        @Override
        public void blockMined(Block block) {
              boolean validate = Ethash.getForBlock(block.getNumber()).validate(block.getHeader());
            System.out.println("=== MinerTest.blockMined " + blockInfo(block));
              System.out.println("=== MinerTest.blockMined: " + validate);
        }
        @Override
        public void blockMiningCanceled(Block block) {
            System.out.println("=== MinerTest.blockMiningCanceled " + blockInfo(block));
        }
    });
    Ethash.fileCacheEnabled = true;
    blockMiner.setFullMining(true);
    blockMiner.startMining();
      System.out.println("======= Waiting for block #4");
      semaphore.await(60, TimeUnit.SECONDS);
      if(semaphore.getCount() > 0) {
          throw new RuntimeException("4 blocks were not imported.");
      }
      System.out.println("======= Sending forked block without parent...");
    ECKey senderKey = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
    byte[] receiverAddr = Hex.decode("31e2e1ed11951c7091dfba62cd4b7145e947219c");
    for (int i = ethereum1.getRepository().getNonce(senderKey.getAddress()).intValue(), j = 0; j < 20000; i++, j++) {
        {
            Transaction tx = new Transaction(ByteUtil.intToBytesNoLeadZeroes(i),
                    ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L), ByteUtil.longToBytesNoLeadZeroes(0xfffff),
                    receiverAddr, new byte[]{77}, new byte[0]);
            tx.sign(senderKey);
            System.out.println("=== Submitting tx: " + tx);
            ethereum1.submitTransaction(tx);
            submittedTxs.put(new ByteArrayWrapper(tx.getHash()), Pair.of(tx, System.currentTimeMillis()));
        }
        Thread.sleep(5000);
    }
    Thread.sleep(1000000000);
    ethereum1.close();
    System.out.println("Passed.");
}