Search in sources :

Example 6 with Genesis

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();
    }
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) EthereumImpl(org.ethereum.facade.EthereumImpl) World(co.rsk.test.World) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) Genesis(org.ethereum.core.Genesis) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Aggregations

Genesis (org.ethereum.core.Genesis)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)4 Test (org.junit.Test)4 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2 BlockDifficulty (co.rsk.core.BlockDifficulty)2 RskAddress (co.rsk.core.RskAddress)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)2 World (co.rsk.test.World)2 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)2 EthereumImpl (org.ethereum.facade.EthereumImpl)2 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)1 RskSystemProperties (co.rsk.config.RskSystemProperties)1 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)1 Keccak256 (co.rsk.crypto.Keccak256)1 BlockStore (co.rsk.net.BlockStore)1 BridgeSupport (co.rsk.peg.BridgeSupport)1 BlockBuilder (co.rsk.test.builders.BlockBuilder)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1