Search in sources :

Example 6 with BlockUnclesValidationRule

use of co.rsk.validators.BlockUnclesValidationRule in project rskj by rsksmart.

the class MinerServerTest method workWithNoTransactionsZeroFees.

@Test
public void workWithNoTransactionsZeroFees() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, this.blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), this.blockchain.getBlockStore(), this.blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    minerServer.start();
    try {
        MinerWork work = minerServer.getWork();
        assertEquals("0", work.getFeesPaidToMiner());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 7 with BlockUnclesValidationRule

use of co.rsk.validators.BlockUnclesValidationRule in project rskj by rsksmart.

the class MinerServerTest method submitBitcoinBlock.

@Test
public void submitBitcoinBlock() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    Mockito.when(ethereumImpl.addNewMinedBlock(Mockito.any())).thenReturn(ImportResult.IMPORTED_BEST);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), blockchain.getBlockStore(), blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        MinerWork work = minerServer.getWork();
        BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlockWithOnlyCoinbase(work);
        findNonce(work, bitcoinMergedMiningBlock);
        SubmitBlockResult result = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);
        Assert.assertEquals("OK", result.getStatus());
        Assert.assertNotNull(result.getBlockInfo());
        Assert.assertEquals("0x1", result.getBlockInfo().getBlockIncludedHeight());
        Assert.assertEquals("0x494d504f525445445f42455354", result.getBlockInfo().getBlockImportedResult());
        Mockito.verify(ethereumImpl, Mockito.times(1)).addNewMinedBlock(Mockito.any());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 8 with BlockUnclesValidationRule

use of co.rsk.validators.BlockUnclesValidationRule in project rskj by rsksmart.

the class MinerServerTest method initialWorkTurnsNotifyFlagOn.

@Test
public void initialWorkTurnsNotifyFlagOn() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, this.blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), this.blockchain.getBlockStore(), this.blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        MinerWork work = minerServer.getWork();
        assertEquals(true, work.getNotify());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 9 with BlockUnclesValidationRule

use of co.rsk.validators.BlockUnclesValidationRule in project rskj by rsksmart.

the class MinerServerTest method secondWorkWithNoChangesTurnsNotifyFlagOff.

@Test
public void secondWorkWithNoChangesTurnsNotifyFlagOff() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, this.blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), this.blockchain.getBlockStore(), this.blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    minerServer.start();
    try {
        MinerWork work = minerServer.getWork();
        assertEquals(true, work.getNotify());
        work = minerServer.getWork();
        assertEquals(false, work.getNotify());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 10 with BlockUnclesValidationRule

use of co.rsk.validators.BlockUnclesValidationRule in project rskj by rsksmart.

the class MinerServerTest method submitBitcoinBlockTwoTags.

@Test
public void submitBitcoinBlockTwoTags() {
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    Mockito.when(ethereumImpl.addNewMinedBlock(Mockito.any())).thenReturn(ImportResult.IMPORTED_BEST);
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    Mockito.when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), blockchain.getBlockStore(), blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
    try {
        byte[] extraData = ByteBuffer.allocate(4).putInt(1).array();
        minerServer.setExtraData(extraData);
        minerServer.start();
        MinerWork work = minerServer.getWork();
        Block bestBlock = blockchain.getBestBlock();
        extraData = ByteBuffer.allocate(4).putInt(2).array();
        minerServer.setExtraData(extraData);
        minerServer.buildBlockToMine(bestBlock, false);
        // only the tag is used
        MinerWork work2 = minerServer.getWork();
        Assert.assertNotEquals(work2.getBlockHashForMergedMining(), work.getBlockHashForMergedMining());
        BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlockWithTwoTags(work, work2);
        findNonce(work, bitcoinMergedMiningBlock);
        SubmitBlockResult result;
        result = ((MinerServerImpl) minerServer).submitBitcoinBlock(work2.getBlockHashForMergedMining(), bitcoinMergedMiningBlock, true);
        Assert.assertEquals("OK", result.getStatus());
        Assert.assertNotNull(result.getBlockInfo());
        Assert.assertEquals("0x1", result.getBlockInfo().getBlockIncludedHeight());
        Assert.assertEquals("0x494d504f525445445f42455354", result.getBlockInfo().getBlockImportedResult());
        // Submit again the save PoW for a different header
        result = ((MinerServerImpl) minerServer).submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock, false);
        Assert.assertEquals("ERROR", result.getStatus());
        Mockito.verify(ethereumImpl, Mockito.times(1)).addNewMinedBlock(Mockito.any());
    } finally {
        minerServer.stop();
    }
}
Also used : BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Aggregations

BlockUnclesValidationRule (co.rsk.validators.BlockUnclesValidationRule)12 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)11 EthereumImpl (org.ethereum.facade.EthereumImpl)11 Test (org.junit.Test)11 Keccak256 (co.rsk.crypto.Keccak256)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1