use of co.rsk.validators.ProofOfWorkRule in project rskj by rsksmart.
the class MinerServerTest method submitBitcoinBlockTransactionsWhenBlockIsEmpty.
@Test
public void submitBitcoinBlockTransactionsWhenBlockIsEmpty() {
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);
// noinspection ConstantConditions
BtcTransaction coinbase = bitcoinMergedMiningBlock.getTransactions().get(0);
SubmitBlockResult result = minerServer.submitBitcoinBlockTransactions(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock, coinbase, Collections.singletonList(coinbase.getHashAsString()));
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.ProofOfWorkRule 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.ProofOfWorkRule 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.ProofOfWorkRule 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.ProofOfWorkRule 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();
}
}
Aggregations