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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations