use of org.ethereum.core.Genesis in project rskj by rsksmart.
the class MainNetMinerTest method submitBitcoinBlockProofOfWorkNotGoodEnough.
/*
* This test is probabilistic, but it has a really high chance to pass. We will generate
* a random block that it is unlikely to pass the Long.MAX_VALUE difficulty, though
* it may happen once. Twice would be suspicious.
*/
@Test
public void submitBitcoinBlockProofOfWorkNotGoodEnough() {
/* We need a low target */
BlockChainImpl bc = new BlockChainBuilder().build();
Genesis gen = (Genesis) BlockChainImplTest.getGenesisBlock(bc);
gen.getHeader().setDifficulty(new BlockDifficulty(BigInteger.valueOf(Long.MAX_VALUE)));
bc.setStatus(gen, gen.getCumulativeDifficulty());
World world = new World(bc, gen);
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), world.getBlockChain().getBlockStore(), null, null, null, 10, 100);
blockchain = world.getBlockChain();
EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), blockToMineBuilder(), ConfigUtils.getDefaultMiningConfig());
try {
minerServer.start();
MinerWork work = minerServer.getWork();
co.rsk.bitcoinj.core.BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlock(work);
bitcoinMergedMiningBlock.setNonce(2);
SubmitBlockResult result = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);
Assert.assertEquals("ERROR", result.getStatus());
Assert.assertNull(result.getBlockInfo());
Mockito.verify(ethereumImpl, Mockito.times(0)).addNewMinedBlock(Mockito.any());
} finally {
minerServer.stop();
}
}
Aggregations