Search in sources :

Example 1 with BlockResult

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();
    }
}
Also used : Coin(co.rsk.core.Coin) BlockResult(co.rsk.core.bc.BlockResult) BuildInfo(org.ethereum.util.BuildInfo) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 2 with BlockResult

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));
}
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 3 with BlockResult

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);
}
Also used : BlockResult(co.rsk.core.bc.BlockResult) CallArguments(org.ethereum.rpc.CallArguments) ProgramResult(org.ethereum.vm.program.ProgramResult) Block(org.ethereum.core.Block) ReversibleTransactionExecutor(co.rsk.core.ReversibleTransactionExecutor) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) Test(org.junit.Test)

Example 4 with BlockResult

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

Example 5 with BlockResult

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

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