use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class BlockToMineBuilderTest method buildBlockBeforeUMMActivation.
@Test
public void buildBlockBeforeUMMActivation() {
Keccak256 parentHash = TestUtils.randomHash();
BlockHeader parent = mock(BlockHeader.class);
when(parent.getNumber()).thenReturn(500L);
when(parent.getHash()).thenReturn(parentHash);
when(parent.getGasLimit()).thenReturn(new byte[0]);
when(parent.getMinimumGasPrice()).thenReturn(mock(Coin.class));
when(validationRules.isValid(any())).thenReturn(true);
when(activationConfig.isActive(ConsensusRule.RSKIPUMM, 501L)).thenReturn(false);
BlockResult expectedResult = mock(BlockResult.class);
ArgumentCaptor<Block> blockCaptor = ArgumentCaptor.forClass(Block.class);
when(blockExecutor.executeAndFill(blockCaptor.capture(), any())).thenReturn(expectedResult);
blockBuilder.build(new ArrayList<>(Collections.singletonList(parent)), new byte[0]);
Block actualBlock = blockCaptor.getValue();
assertNull(actualBlock.getHeader().getUmmRoot());
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class BlockToMineBuilderTest method buildBlockAfterUMMActivation.
@Test
public void buildBlockAfterUMMActivation() {
Keccak256 parentHash = TestUtils.randomHash();
BlockHeader parent = mock(BlockHeader.class);
when(parent.getNumber()).thenReturn(500L);
when(parent.getHash()).thenReturn(parentHash);
when(parent.getGasLimit()).thenReturn(new byte[0]);
when(parent.getMinimumGasPrice()).thenReturn(mock(Coin.class));
when(validationRules.isValid(any())).thenReturn(true);
when(activationConfig.isActive(ConsensusRule.RSKIPUMM, 501L)).thenReturn(true);
BlockResult expectedResult = mock(BlockResult.class);
ArgumentCaptor<Block> blockCaptor = ArgumentCaptor.forClass(Block.class);
when(blockExecutor.executeAndFill(blockCaptor.capture(), any())).thenReturn(expectedResult);
blockBuilder.build(new ArrayList<>(Collections.singletonList(parent)), new byte[0]);
Block actualBlock = blockCaptor.getValue();
assertThat(actualBlock.getHeader().getUmmRoot(), is(new byte[0]));
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class ExecutionFoundBlockRetrieverTest method getPendingReturnsCachedBlockIfMinerServerHasNoWork.
@Test
public void getPendingReturnsCachedBlockIfMinerServerHasNoWork() {
when(minerServer.getLatestBlock()).thenReturn(Optional.empty()).thenReturn(Optional.empty());
BlockHeader bestHeader = mock(BlockHeader.class);
Block bestBlock = mock(Block.class);
when(bestBlock.getHeader()).thenReturn(bestHeader);
when(blockchain.getBestBlock()).thenReturn(bestBlock).thenReturn(bestBlock);
List<BlockHeader> mainchainHeaders = new ArrayList<>();
mainchainHeaders.add(bestBlock.getHeader());
mainchainHeaders.add(bestBlock.getHeader());
when(miningMainchainView.get()).thenReturn(mainchainHeaders);
BlockResult blockResult = mock(BlockResult.class);
Block builtBlock = mock(Block.class);
when(bestBlock.isParentOf(builtBlock)).thenReturn(true);
when(builder.build(mainchainHeaders, null)).thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(builtBlock);
assertThat(retriever.retrieveExecutionBlock("pending"), is(blockResult));
assertThat(retriever.retrieveExecutionBlock("pending"), is(blockResult));
// TODO(mc): the cache doesn't work properly in getExecutionBlock_workaround.
// this is a known bug in version 1.0.1, and should be fixed in master
verify(builder, times(2)).build(mainchainHeaders, null);
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class ExecutionFoundBlockRetrieverTest method getPendingBuildsPendingBlockIfMinerServerHasNoWork.
@Test
public void getPendingBuildsPendingBlockIfMinerServerHasNoWork() {
when(minerServer.getLatestBlock()).thenReturn(Optional.empty());
BlockHeader bestHeader = mock(BlockHeader.class);
Block bestBlock = mock(Block.class);
when(bestBlock.getHeader()).thenReturn(bestHeader);
when(blockchain.getBestBlock()).thenReturn(bestBlock);
when(miningMainchainView.get()).thenReturn(new ArrayList<>(Collections.singleton(bestHeader)));
Block builtBlock = mock(Block.class);
BlockResult blockResult = mock(BlockResult.class);
when(builder.build(new ArrayList<>(Collections.singleton(bestHeader)), null)).thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(builtBlock);
assertThat(retriever.retrieveExecutionBlock("pending").getBlock(), is(builtBlock));
}
use of co.rsk.core.bc.BlockResult in project rskj by rsksmart.
the class Web3InformationRetrieverTest method getBlock_pending.
@Test
public void getBlock_pending() {
Block pendingBlock = mock(Block.class);
BlockResult pendingBlockResult = mock(BlockResult.class);
when(pendingBlockResult.getBlock()).thenReturn(pendingBlock);
when(executionBlockRetriever.retrieveExecutionBlock("pending")).thenReturn(pendingBlockResult);
Optional<Block> result = target.getBlock("pending");
assertTrue(result.isPresent());
assertEquals(pendingBlock, result.get());
}
Aggregations