use of co.rsk.db.HashMapBlocksIndex in project rskj by rsksmart.
the class StateTestRunner method runImpl.
public List<String> runImpl() {
vStats = new ValidationStats();
logger.info("");
trieStore = new TrieStoreImpl(new HashMapDB());
repository = RepositoryBuilder.build(trieStore, stateTestCase.getPre());
logger.info("loaded repository");
transaction = TransactionBuilder.build(stateTestCase.getTransaction());
logger.info("transaction: {}", transaction.toString());
BlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
blockchain = new BlockChainImpl(blockStore, null, null, null, null, new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, blockFactory, new ProgramInvokeFactoryImpl(), precompiledContracts, new BlockTxSignatureCache(new ReceivedTxSignatureCache()))), stateRootHandler);
env = EnvBuilder.build(stateTestCase.getEnv());
invokeFactory = new TestProgramInvokeFactory(env);
block = build(env);
block.setStateRoot(repository.getRoot());
block.flushRLP();
blockchain.setStatus(block, block.getCumulativeDifficulty());
// blockchain.setProgramInvokeFactory(invokeFactory);
// blockchain.startTracking();
ProgramResult programResult = executeTransaction(transaction);
trieStore.flush();
List<LogInfo> origLogs = programResult.getLogInfoList();
List<LogInfo> postLogs = LogBuilder.build(stateTestCase.getLogs());
List<String> logsResult = LogsValidator.valid(origLogs, postLogs, vStats);
Repository postRepository = RepositoryBuilder.build(stateTestCase.getPost());
// Balances cannot be validated because has consumption for CALLs differ.
List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false, false, vStats);
logger.info("--------- POST Validation---------");
List<String> outputResults = OutputValidator.valid(ByteUtil.toHexString(programResult.getHReturn()), stateTestCase.getOut(), vStats);
List<String> results = new ArrayList<>();
results.addAll(repoResults);
results.addAll(logsResult);
results.addAll(outputResults);
for (String result : results) {
logger.error(result);
}
if ((vStats.storageChecks == 0) && (vStats.logChecks == 0) && (vStats.balancetChecks == 0) && (vStats.outputChecks == 0) && (vStats.blockChecks == 0)) {
// This generally mean that the test didn't check anything
// AccountChecks are considered not indicative of the result of the test
logger.info("IRRELEVANT\n");
}
logger.info("\n\n");
return results;
}
use of co.rsk.db.HashMapBlocksIndex in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleIsAncestor.
@Test
public void invalidUncleIsAncestor() {
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(genesis.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));
}
use of co.rsk.db.HashMapBlocksIndex 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 co.rsk.db.HashMapBlocksIndex 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));
}
use of co.rsk.db.HashMapBlocksIndex in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasNoSavedParent.
@Test
public void invalidUncleHasNoSavedParent() {
IndexedBlockStore store = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(new BlockGenerator().createChildBlock(genesis));
List<BlockHeader> uncles1 = new ArrayList<>();
uncles1.add(uncle1a.getHeader());
Block block1 = blockGenerator.createChildBlock(genesis, null, uncles1, 1, null);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(block1, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block1));
}
Aggregations