use of co.rsk.validators.BlockUnclesValidationRule in project rskj by rsksmart.
the class MinerServerTest method submitBitcoinBlockTransactionsWhenBlockHasTransactions.
@Test
public void submitBitcoinBlockTransactionsWhenBlockHasTransactions() {
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();
BtcTransaction otherTx = Mockito.mock(BtcTransaction.class);
Sha256Hash otherTxHash = Sha256Hash.wrap("aaaabbbbccccddddaaaabbbbccccddddaaaabbbbccccddddaaaabbbbccccdddd");
Mockito.when(otherTx.getHash()).thenReturn(otherTxHash);
Mockito.when(otherTx.getHashAsString()).thenReturn(otherTxHash.toString());
BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlock(work, Collections.singletonList(otherTx));
findNonce(work, bitcoinMergedMiningBlock);
// noinspection ConstantConditions
BtcTransaction coinbase = bitcoinMergedMiningBlock.getTransactions().get(0);
List<String> txs = Arrays.asList(coinbase.getHashAsString(), otherTxHash.toString());
SubmitBlockResult result = minerServer.submitBitcoinBlockTransactions(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock, coinbase, txs);
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 secondBuildBlockToMineTurnsNotifyFlagOff.
@Test
public void secondBuildBlockToMineTurnsNotifyFlagOff() {
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(), blockchain.getBlockStore(), blockchain.getTransactionPool(), DIFFICULTY_CALCULATOR, new GasLimitCalculator(config), unclesValidationRule, config, null), ConfigUtils.getDefaultMiningConfig());
try {
minerServer.start();
MinerWork work = minerServer.getWork();
String hashForMergedMining = work.getBlockHashForMergedMining();
minerServer.buildBlockToMine(blockchain.getBestBlock(), false);
work = minerServer.getWork();
assertEquals(hashForMergedMining, work.getBlockHashForMergedMining());
assertEquals(false, work.getNotify());
} finally {
minerServer.stop();
}
}
Aggregations