Search in sources :

Example 6 with BlockResult

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());
}
Also used : Coin(co.rsk.core.Coin) BlockResult(co.rsk.core.bc.BlockResult) Keccak256(co.rsk.crypto.Keccak256) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 7 with BlockResult

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]));
}
Also used : Coin(co.rsk.core.Coin) BlockResult(co.rsk.core.bc.BlockResult) Keccak256(co.rsk.crypto.Keccak256) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 8 with BlockResult

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);
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 9 with BlockResult

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));
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 10 with BlockResult

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());
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) Test(org.junit.Test)

Aggregations

BlockResult (co.rsk.core.bc.BlockResult)14 Test (org.junit.Test)12 Block (org.ethereum.core.Block)7 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)4 ProgramResult (org.ethereum.vm.program.ProgramResult)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Coin (co.rsk.core.Coin)3 ReversibleTransactionExecutor (co.rsk.core.ReversibleTransactionExecutor)3 Keccak256 (co.rsk.crypto.Keccak256)3 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)3 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)3 BlockHeader (org.ethereum.core.BlockHeader)3 CallArguments (org.ethereum.rpc.CallArguments)3 ArrayList (java.util.ArrayList)2 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 EthereumImpl (org.ethereum.facade.EthereumImpl)1 RskJsonRpcRequestException (org.ethereum.rpc.exception.RskJsonRpcRequestException)1 BuildInfo (org.ethereum.util.BuildInfo)1