Search in sources :

Example 1 with HashMapBlocksIndex

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;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) LogInfo(org.ethereum.vm.LogInfo) StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ProgramResult(org.ethereum.vm.program.ProgramResult) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) TestProgramInvokeFactory(org.ethereum.jsontestsuite.TestProgramInvokeFactory) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) ValidationStats(org.ethereum.jsontestsuite.validators.ValidationStats)

Example 2 with HashMapBlocksIndex

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));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 3 with HashMapBlocksIndex

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));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 4 with HashMapBlocksIndex

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));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 5 with HashMapBlocksIndex

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));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)24 HashMapDB (org.ethereum.datasource.HashMapDB)23 Test (org.junit.Test)23 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)19 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)13 Block (org.ethereum.core.Block)8 BlockDifficulty (co.rsk.core.BlockDifficulty)5 Keccak256 (co.rsk.crypto.Keccak256)5 Ignore (org.junit.Ignore)4 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)3 ArrayList (java.util.ArrayList)3 BlockStore (org.ethereum.db.BlockStore)3 TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)2 MutableTrieImpl (co.rsk.db.MutableTrieImpl)2 RepositoryLocator (co.rsk.db.RepositoryLocator)2 Trie (co.rsk.trie.Trie)2 TrieStore (co.rsk.trie.TrieStore)2 BigInteger (java.math.BigInteger)2 BlockFactory (org.ethereum.core.BlockFactory)2