use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class StateTestRunner method runImpl.
public List<String> runImpl() {
logger.info("");
repository = RepositoryBuilder.build(stateTestCase.getPre());
logger.info("loaded repository");
transaction = TransactionBuilder.build(stateTestCase.getTransaction());
logger.info("transaction: {}", transaction.toString());
BlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
blockchain = new BlockChainImpl(config, repository, blockStore, null, null, null, null, null);
env = EnvBuilder.build(stateTestCase.getEnv());
invokeFactory = new TestProgramInvokeFactory(env);
block = BlockBuilder.build(env);
block.setStateRoot(repository.getRoot());
block.flushRLP();
blockchain.setBestBlock(block);
// blockchain.setProgramInvokeFactory(invokeFactory);
// blockchain.startTracking();
ProgramResult programResult = executeTransaction(transaction);
repository.flushNoReconnect();
List<LogInfo> origLogs = programResult.getLogInfoList();
List<LogInfo> postLogs = LogBuilder.build(stateTestCase.getLogs());
List<String> logsResult = LogsValidator.valid(origLogs, postLogs);
Repository postRepository = RepositoryBuilder.build(stateTestCase.getPost());
List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false);
logger.info("--------- POST Validation---------");
List<String> outputResults = OutputValidator.valid(Hex.toHexString(programResult.getHReturn()), stateTestCase.getOut());
List<String> results = new ArrayList<>();
results.addAll(repoResults);
results.addAll(logsResult);
results.addAll(outputResults);
for (String result : results) {
logger.error(result);
}
logger.info("\n\n");
return results;
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class ImportLightTest method createBlockchain.
public static BlockChainImpl createBlockchain(Genesis genesis) {
RskSystemProperties config = new RskSystemProperties();
config.setBlockchainConfig(new GenesisConfig(new GenesisConfig.GenesisConstants() {
@Override
public BlockDifficulty getMinimumDifficulty() {
return new BlockDifficulty(BigInteger.ONE);
}
}));
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
EthereumListenerAdapter listener = new EthereumListenerAdapter();
KeyValueDataSource ds = new HashMapDB();
ds.init();
ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, new AdminInfo(), new DummyBlockValidator());
blockchain.setNoValidation(true);
TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
blockchain.setTransactionPool(transactionPool);
Repository track = repository.startTracking();
for (RskAddress addr : genesis.getPremine().keySet()) {
track.createAccount(addr);
track.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
}
track.commit();
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
blockchain.setBestBlock(genesis);
blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
return blockchain;
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method validateEmptyBlock.
@Test
public void validateEmptyBlock() {
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
Block genesis = new BlockGenerator().getGenesisBlock();
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
Block block = new BlockBuilder().parent(genesis).build();
BlockValidator validator = createValidator(blockStore);
Assert.assertTrue(validator.isValid(block));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasNoSavedParent.
@Test
public void invalidUncleHasNoSavedParent() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
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));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasParentThatIsNotAncestor.
@Test
public void invalidUncleHasParentThatIsNotAncestor() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
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));
}
Aggregations