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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations