use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockExecutorTest method buildBlockExecutor.
private static BlockExecutor buildBlockExecutor(TrieStore store, RskSystemProperties config) {
StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
return new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(store, stateRootHandler), new TransactionExecutorFactory(config, null, null, BLOCK_FACTORY, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockExecutorTest method validateStateRootWithRskip126DisabledAndValidStateRoot.
@Test
public void validateStateRootWithRskip126DisabledAndValidStateRoot() {
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Trie trie = new Trie(trieStore);
Block block = new BlockGenerator().getBlock(1);
block.setStateRoot(trie.getHash().getBytes());
BlockResult blockResult = new BlockResult(block, Collections.emptyList(), Collections.emptyList(), 0, Coin.ZERO, trie);
RskSystemProperties cfg = spy(CONFIG);
ActivationConfig activationConfig = spy(cfg.getActivationConfig());
doReturn(false).when(activationConfig).isActive(eq(RSKIP126), anyLong());
doReturn(activationConfig).when(cfg).getActivationConfig();
BlockExecutor executor = buildBlockExecutor(trieStore, cfg);
Assert.assertTrue(executor.validateStateRoot(block.getHeader(), blockResult));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockExecutorTest method validateStateRootWithRskip126DisabledAndInvalidStateRoot.
@Test
public void validateStateRootWithRskip126DisabledAndInvalidStateRoot() {
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Trie trie = new Trie(trieStore);
Block block = new BlockGenerator().getBlock(1);
block.setStateRoot(new byte[] { 1, 2, 3, 4 });
BlockResult blockResult = new BlockResult(block, Collections.emptyList(), Collections.emptyList(), 0, Coin.ZERO, trie);
RskSystemProperties cfg = spy(CONFIG);
ActivationConfig activationConfig = spy(cfg.getActivationConfig());
doReturn(false).when(activationConfig).isActive(eq(RSKIP126), anyLong());
doReturn(activationConfig).when(cfg).getActivationConfig();
BlockExecutor executor = buildBlockExecutor(trieStore, cfg);
Assert.assertTrue(executor.validateStateRoot(block.getHeader(), blockResult));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasParentThatIsNotAncestor.
@Test
public void invalidUncleHasParentThatIsNotAncestor() {
IndexedBlockStore store = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(genesis);
Block uncle2a = blockGenerator.createChildBlock(uncle1a);
List<BlockHeader> uncles3 = new ArrayList<>();
uncles3.add(uncle2a.getHeader());
uncles3.add(uncle1a.getHeader());
Block block1 = blockGenerator.createChildBlock(genesis, null, null, 1, null);
Block block2 = blockGenerator.createChildBlock(block1, null, null, 1, null);
Block block3 = blockGenerator.createChildBlock(block2, null, uncles3, 1, null);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(uncle1a, TEST_DIFFICULTY, false);
store.saveBlock(uncle2a, TEST_DIFFICULTY, false);
store.saveBlock(block1, TEST_DIFFICULTY, true);
store.saveBlock(block2, TEST_DIFFICULTY, true);
store.saveBlock(block3, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block3));
}
use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.
the class BlockValidatorTest method invalidUnclesUncleIncludedMultipeTimes.
@Test
public void invalidUnclesUncleIncludedMultipeTimes() {
IndexedBlockStore store = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(genesis);
List<BlockHeader> uncles1 = new ArrayList<>();
uncles1.add(uncle1a.getHeader());
uncles1.add(uncle1a.getHeader());
Block block1 = blockGenerator.createChildBlock(genesis, null, uncles1, 1, null);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(uncle1a, TEST_DIFFICULTY, false);
store.saveBlock(block1, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block1));
}
Aggregations