use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class MinerServerTest method gasUnitInDollarsIsInitializedOkAtConstructor.
@Test
public void gasUnitInDollarsIsInitializedOkAtConstructor() {
Block block1 = mock(Block.class);
when(block1.getFeesPaidToMiner()).thenReturn(new Coin(BigInteger.valueOf(10)));
when(block1.getHashForMergedMining()).thenReturn(TestUtils.randomHash().getBytes());
when(block1.getHash()).thenReturn(TestUtils.randomHash());
when(block1.getDifficulty()).thenReturn(BlockDifficulty.ZERO);
when(block1.getParentHashJsonString()).thenReturn(TestUtils.randomHash().toJsonString());
Block block2 = mock(Block.class);
when(block2.getFeesPaidToMiner()).thenReturn(new Coin(BigInteger.valueOf(24)));
when(block2.getHashForMergedMining()).thenReturn(TestUtils.randomHash().getBytes());
when(block2.getHash()).thenReturn(TestUtils.randomHash());
when(block2.getDifficulty()).thenReturn(BlockDifficulty.ZERO);
when(block2.getParentHashJsonString()).thenReturn(TestUtils.randomHash().toJsonString());
BlockToMineBuilder builder = mock(BlockToMineBuilder.class);
BlockResult blockResult = mock(BlockResult.class);
BlockResult blockResult2 = mock(BlockResult.class);
when(blockResult.getBlock()).thenReturn(block1);
when(blockResult2.getBlock()).thenReturn(block2);
when(builder.build(any(), any())).thenReturn(blockResult).thenReturn(blockResult2);
MinerClock clock = new MinerClock(true, Clock.systemUTC());
MinerServer minerServer = new MinerServerImpl(config, mock(EthereumImpl.class), this.blockchain, null, mock(ProofOfWorkRule.class), builder, clock, mock(BlockFactory.class), new BuildInfo("cb7f28e", "master"), ConfigUtils.getDefaultMiningConfig());
try {
minerServer.start();
minerServer.getWork();
minerServer.buildBlockToMine(false);
MinerWork work = minerServer.getWork();
assertTrue(work.getNotify());
} finally {
minerServer.stop();
}
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class ExecutionFoundBlockRetrieverTest method getPendingDoesntUseCacheIfBestBlockHasChanged.
@Test
public void getPendingDoesntUseCacheIfBestBlockHasChanged() {
when(minerServer.getLatestBlock()).thenReturn(Optional.empty()).thenReturn(Optional.empty());
BlockHeader bestHeader1 = mock(BlockHeader.class);
Block bestBlock1 = mock(Block.class);
when(bestBlock1.getHeader()).thenReturn(bestHeader1);
BlockHeader bestHeader2 = mock(BlockHeader.class);
Block bestBlock2 = mock(Block.class);
when(bestBlock2.getHeader()).thenReturn(bestHeader2);
when(blockchain.getBestBlock()).thenReturn(bestBlock1).thenReturn(bestBlock2);
when(miningMainchainView.get()).thenReturn(new ArrayList<>(Collections.singleton(bestHeader1))).thenReturn(new ArrayList<>(Collections.singleton(bestHeader2)));
Block builtBlock1 = mock(Block.class);
when(bestBlock1.isParentOf(builtBlock1)).thenReturn(true);
BlockResult blockResult1 = mock(BlockResult.class);
when(blockResult1.getBlock()).thenReturn(builtBlock1);
when(builder.build(new ArrayList<>(Collections.singleton(bestHeader1)), null)).thenReturn(blockResult1);
Block builtBlock2 = mock(Block.class);
when(bestBlock2.isParentOf(builtBlock2)).thenReturn(true);
BlockResult blockResult2 = mock(BlockResult.class);
when(blockResult2.getBlock()).thenReturn(builtBlock2);
when(builder.build(new ArrayList<>(Collections.singleton(bestHeader2)), null)).thenReturn(blockResult2);
assertThat(retriever.retrieveExecutionBlock("pending").getBlock(), is(builtBlock1));
assertThat(retriever.retrieveExecutionBlock("pending").getBlock(), is(builtBlock2));
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class EthModuleTest method callWithoutReturn.
@Test
public void callWithoutReturn() {
CallArguments args = new CallArguments();
BlockResult blockResult = mock(BlockResult.class);
Block block = mock(Block.class);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(block);
byte[] hReturn = new byte[0];
ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.getHReturn()).thenReturn(hReturn);
ReversibleTransactionExecutor executor = mock(ReversibleTransactionExecutor.class);
when(executor.executeTransaction(eq(blockResult.getBlock()), any(), any(), any(), any(), any(), any(), any())).thenReturn(executorResult);
EthModule eth = new EthModule(null, anyByte(), null, null, executor, retriever, null, null, null, new BridgeSupportFactory(null, null, null), config.getGasEstimationCap());
String expectedResult = TypeConverter.toUnformattedJsonHex(hReturn);
String actualResult = eth.call(args, "latest");
assertEquals(expectedResult, actualResult);
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class ExecuteBlocks method executeBlocks.
private void executeBlocks(String[] args, BlockExecutor blockExecutor, BlockStore blockStore, TrieStore trieStore, StateRootHandler stateRootHandler) {
long fromBlockNumber = Long.parseLong(args[0]);
long toBlockNumber = Long.parseLong(args[1]);
for (long n = fromBlockNumber; n <= toBlockNumber; n++) {
Block block = blockStore.getChainBlockByNumber(n);
Block parent = blockStore.getBlockByHash(block.getParentHash().getBytes());
BlockResult blockResult = blockExecutor.execute(block, parent.getHeader(), false, false);
Keccak256 stateRootHash = stateRootHandler.translate(block.getHeader());
if (!Arrays.equals(blockResult.getFinalState().getHash().getBytes(), stateRootHash.getBytes())) {
printError("Invalid state root block number " + n);
break;
}
}
trieStore.flush();
blockStore.flush();
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class BlockToMineBuilderTest method BuildBlockHasUnclesWhenCreateAnInvalidBlock.
@Test
public void BuildBlockHasUnclesWhenCreateAnInvalidBlock() {
BlockHeader parent = buildBlockHeaderWithSibling();
BlockResult expectedResult = mock(BlockResult.class);
ArgumentCaptor<Block> blockCaptor = ArgumentCaptor.forClass(Block.class);
when(validationRules.isValid(any())).thenReturn(true);
when(blockExecutor.executeAndFill(blockCaptor.capture(), any())).thenReturn(expectedResult);
blockBuilder.build(new ArrayList<>(Collections.singletonList(parent)), new byte[0]);
assertThat(blockCaptor.getValue().getUncleList(), hasSize(1));
}
Aggregations