Search in sources :

Example 11 with BuildInfo

use of org.ethereum.util.BuildInfo 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 */
    BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
    BlockChainImpl blockchain = blockChainBuilder.build();
    Genesis gen = (Genesis) BlockChainImplTest.getGenesisBlock(blockChainBuilder.getTrieStore());
    gen.getHeader().setDifficulty(new BlockDifficulty(BigInteger.valueOf(Long.MAX_VALUE)));
    blockchain.setStatus(gen, gen.getCumulativeDifficulty());
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    MinerClock clock = new MinerClock(true, Clock.systemUTC());
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, mainchainView, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), blockToMineBuilder(), clock, blockFactory, new BuildInfo("cb7f28e", "master"), 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 : BlockChainImpl(co.rsk.core.bc.BlockChainImpl) EthereumImpl(org.ethereum.facade.EthereumImpl) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) BlockDifficulty(co.rsk.core.BlockDifficulty) BuildInfo(org.ethereum.util.BuildInfo) Genesis(org.ethereum.core.Genesis) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 12 with BuildInfo

use of org.ethereum.util.BuildInfo in project rskj by rsksmart.

the class MinerServerTest method extraDataWithClientData.

@Test
public void extraDataWithClientData() {
    MinerServer minerServer = new MinerServerImpl(config, null, null, null, null, null, null, null, new BuildInfo("cb7f28e", "master"), ConfigUtils.getDefaultMiningConfig());
    minerServer.setExtraData("tincho".getBytes());
    byte[] extraData = minerServer.getExtraData();
    RLPList decodedExtraData = RLP.decodeList(extraData);
    assertEquals(3, decodedExtraData.size());
    byte[] firstItem = decodedExtraData.get(0).getRLPData();
    assertNotNull(firstItem);
    assertEquals(1, (RLP.decodeInt(firstItem, 0)));
    byte[] secondItem = decodedExtraData.get(1).getRLPData();
    assertNotNull(secondItem);
    assertEquals(config.projectVersionModifier().concat("-cb7f28e"), new String(secondItem));
    byte[] thirdItem = decodedExtraData.get(2).getRLPData();
    assertNotNull(thirdItem);
    assertEquals("tincho", new String(thirdItem));
}
Also used : BuildInfo(org.ethereum.util.BuildInfo) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Aggregations

BuildInfo (org.ethereum.util.BuildInfo)12 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)6 Test (org.junit.Test)6 EthereumImpl (org.ethereum.facade.EthereumImpl)4 MiningConfig (co.rsk.config.MiningConfig)3 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)3 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)3 Web3RskImpl (co.rsk.rpc.Web3RskImpl)3 DebugModule (co.rsk.rpc.modules.debug.DebugModule)3 DebugModuleImpl (co.rsk.rpc.modules.debug.DebugModuleImpl)3 PersonalModuleWalletEnabled (co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled)3 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)3 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)3 ChannelManager (org.ethereum.net.server.ChannelManager)3 RLPList (org.ethereum.util.RLPList)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)2 MiningMainchainView (co.rsk.core.bc.MiningMainchainView)2 MinerClient (co.rsk.mine.MinerClient)2 Web3InformationRetriever (co.rsk.rpc.Web3InformationRetriever)2