Search in sources :

Example 16 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class BlockTxsValidationRuleTest method setup.

@Before
public void setup() {
    parent = mock(Block.class);
    BlockHeader parentHeader = mock(BlockHeader.class);
    when(parent.getHeader()).thenReturn(parentHeader);
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    repositorySnapshot = mock(RepositorySnapshot.class);
    when(repositoryLocator.snapshotAt(parentHeader)).thenReturn(repositorySnapshot);
    rule = new BlockTxsValidationRule(repositoryLocator);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) RepositorySnapshot(co.rsk.db.RepositorySnapshot) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Before(org.junit.Before)

Example 17 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class Web3ImplTest method createWeb3.

private Web3Impl createWeb3(World world, BlockProcessor blockProcessor, ReceiptStore receiptStore) {
    BlockChainImpl blockChain = world.getBlockChain();
    BlockStore blockStore = world.getBlockStore();
    TransactionExecutorFactory transactionExecutorFactory = buildTransactionExecutorFactory(blockStore, world.getBlockTxSignatureCache());
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepositoryLocator(), blockStore, blockFactory, null, transactionExecutorFactory, world.getReceivedTxSignatureCache(), 10, 100);
    RepositoryLocator repositoryLocator = new RepositoryLocator(world.getTrieStore(), world.getStateRootHandler());
    return createWeb3(Web3Mocks.getMockEthereum(), blockChain, repositoryLocator, transactionPool, blockStore, blockProcessor, new SimpleConfigCapabilities(), receiptStore);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) BlockStore(org.ethereum.db.BlockStore) BlockChainImpl(co.rsk.core.bc.BlockChainImpl)

Example 18 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class NetworkStateExporterTest method setup.

@Before
public void setup() {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    MutableTrieImpl mutableTrie = new MutableTrieImpl(trieStore, new Trie(trieStore));
    repository = new MutableRepository(mutableTrie);
    blockchain = mock(Blockchain.class);
    block = mock(Block.class);
    when(blockchain.getBestBlock()).thenReturn(block);
    BlockHeader blockHeader = mock(BlockHeader.class);
    when(block.getHeader()).thenReturn(blockHeader);
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    when(repositoryLocator.snapshotAt(block.getHeader())).thenReturn(new MutableRepository(mutableTrie));
    this.nse = new NetworkStateExporter(repositoryLocator, blockchain);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) RepositoryLocator(co.rsk.db.RepositoryLocator) MutableRepository(org.ethereum.db.MutableRepository) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) MutableTrieImpl(co.rsk.db.MutableTrieImpl) HashMapDB(org.ethereum.datasource.HashMapDB) BlockHeader(org.ethereum.core.BlockHeader) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Before(org.junit.Before)

Example 19 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class CliToolsTest method rewindBlocks.

@Test
public void rewindBlocks() {
    TestSystemProperties config = new TestSystemProperties();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    KeyValueDataSource keyValueDataSource = new HashMapDB();
    IndexedBlockStore indexedBlockStore = new IndexedBlockStore(blockFactory, keyValueDataSource, new HashMapBlocksIndex());
    int blocksToGenerate = 14;
    Keccak256 parentHash = Keccak256.ZERO_HASH;
    for (long i = 0; i < blocksToGenerate; i++) {
        Block block = mock(Block.class);
        Keccak256 blockHash = randomHash();
        when(block.getHash()).thenReturn(blockHash);
        when(block.getParentHash()).thenReturn(parentHash);
        when(block.getNumber()).thenReturn(i);
        when(block.getEncoded()).thenReturn(TestUtils.randomBytes(128));
        indexedBlockStore.saveBlock(block, ZERO, true);
        parentHash = blockHash;
    }
    Block bestBlock = indexedBlockStore.getBestBlock();
    assertThat(bestBlock.getNumber(), is((long) blocksToGenerate - 1));
    RskContext rskContext = mock(RskContext.class);
    doReturn(indexedBlockStore).when(rskContext).getBlockStore();
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    doReturn(Optional.of(mock(RepositorySnapshot.class))).when(repositoryLocator).findSnapshotAt(any());
    doReturn(repositoryLocator).when(rskContext).getRepositoryLocator();
    NodeStopper stopper = mock(NodeStopper.class);
    StringBuilder output = new StringBuilder();
    RewindBlocks rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { "fmi" }, () -> rskContext, stopper);
    String data = output.toString();
    Assert.assertTrue(data.contains("No inconsistent block has been found"));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    long blockToRewind = blocksToGenerate / 2;
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { String.valueOf(blockToRewind) }, () -> rskContext, stopper);
    bestBlock = indexedBlockStore.getBestBlock();
    assertThat(bestBlock.getNumber(), is(blockToRewind));
    data = output.toString();
    Assert.assertTrue(data.contains("New highest block number stored in db: " + blockToRewind));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { String.valueOf(blocksToGenerate + 1) }, () -> rskContext, stopper);
    bestBlock = indexedBlockStore.getBestBlock();
    assertThat(bestBlock.getNumber(), is(blockToRewind));
    data = output.toString();
    Assert.assertTrue(data.contains("No need to rewind"));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    doReturn(Optional.empty()).when(repositoryLocator).findSnapshotAt(any());
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { "fmi" }, () -> rskContext, stopper);
    data = output.toString();
    Assert.assertTrue(data.contains("Min inconsistent block number: 0"));
    verify(stopper).stop(0);
    clearInvocations(stopper);
    output = new StringBuilder();
    rewindBlocksCliTool = new RewindBlocks(output::append);
    rewindBlocksCliTool.execute(new String[] { "rbc" }, () -> rskContext, stopper);
    data = output.toString();
    Assert.assertTrue(data.contains("Min inconsistent block number: 0"));
    Assert.assertTrue(data.contains("New highest block number stored in db: -1"));
    verify(stopper).stop(0);
}
Also used : BlockFactory(org.ethereum.core.BlockFactory) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) Keccak256(co.rsk.crypto.Keccak256) HashMapDB(org.ethereum.datasource.HashMapDB) RepositoryLocator(co.rsk.db.RepositoryLocator) RskContext(co.rsk.RskContext) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Block(org.ethereum.core.Block) NodeStopper(co.rsk.util.NodeStopper) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 20 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class LogFilterTest method twoEventsAfterTwoBlocksWithEventAndToLatestBlock.

@Test
public void twoEventsAfterTwoBlocksWithEventAndToLatestBlock() {
    RskTestFactory factory = new RskTestFactory();
    Blockchain blockchain = factory.getBlockchain();
    BlockStore blockStore = factory.getBlockStore();
    RepositoryLocator repositoryLocator = factory.getRepositoryLocator();
    Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain, blockStore, repositoryLocator, factory.getTrieStore());
    Block block = blockchain.getBestBlock();
    AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new RskAddress[0], null);
    LogFilter filter = new LogFilter(atfilter, blockchain, false, true);
    filter.newBlockReceived(block);
    filter.newBlockReceived(block);
    Object[] result = filter.getEvents();
    Assert.assertNotNull(result);
    Assert.assertEquals(2, result.length);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) BlockStore(org.ethereum.db.BlockStore) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskTestFactory(org.ethereum.util.RskTestFactory) Test(org.junit.Test)

Aggregations

RepositoryLocator (co.rsk.db.RepositoryLocator)38 Test (org.junit.Test)25 BlockStore (org.ethereum.db.BlockStore)21 RepositorySnapshot (co.rsk.db.RepositorySnapshot)18 BlockExecutor (co.rsk.core.bc.BlockExecutor)15 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)14 HashMapDB (org.ethereum.datasource.HashMapDB)10 TestSystemProperties (co.rsk.config.TestSystemProperties)9 Coin (co.rsk.core.Coin)7 World (co.rsk.test.World)7 RskAddress (co.rsk.core.RskAddress)6 StateRootHandler (co.rsk.db.StateRootHandler)6 TransactionGateway (co.rsk.net.TransactionGateway)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)6 TrieStore (co.rsk.trie.TrieStore)6 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)6 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)6 RskSystemProperties (co.rsk.config.RskSystemProperties)5 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)5 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)5