Search in sources :

Example 16 with IndexedBlockStore

use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.

the class BlockValidatorTest method invalidUncleHasNoCommonAncestor.

@Test
public void invalidUncleHasNoCommonAncestor() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block uncle1a = blockGenerator.createChildBlock(new SimpleBlock(null, null, TestUtils.randomAddress().getBytes(), null, TEST_DIFFICULTY.getBytes(), 0, null, 0L, 0L, new byte[] {}, null, null, null, Block.getTxTrie(null).getHash().getBytes(), null, null, null));
    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(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 : SimpleBlock(co.rsk.peg.simples.SimpleBlock) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 17 with IndexedBlockStore

use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.

the class BlockValidatorTest method invalidPOWUncles.

@Test
public void invalidPOWUncles() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Blockchain blockchain = BlockChainBuilder.ofSize(30, true);
    Block genesis = blockchain.getBlockByNumber(0);
    Block uncle1a = blockchain.getBlockByNumber(1);
    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(uncle1a, TEST_DIFFICULTY, false);
    BlockParentDependantValidationRule parentValidationRule = Mockito.mock(BlockParentDependantValidationRule.class);
    Mockito.when(parentValidationRule.isValid(Mockito.any(), Mockito.any())).thenReturn(true);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), parentValidationRule).blockStore(store).build();
    Assert.assertFalse(validator.isValid(block1));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockParentDependantValidationRule(co.rsk.validators.BlockParentDependantValidationRule) Test(org.junit.Test)

Example 18 with IndexedBlockStore

use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.

the class BlockValidatorTest method getBlockOneAncestorSet.

@Test
public void getBlockOneAncestorSet() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    Block block = new BlockGenerator().createChildBlock(genesis);
    Set<Keccak256> ancestors = FamilyUtils.getAncestors(store, block, 6);
    Assert.assertFalse(ancestors.isEmpty());
    Assert.assertTrue(ancestors.contains(genesis.getHash()));
    Assert.assertFalse(ancestors.contains(block.getHash()));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) Keccak256(co.rsk.crypto.Keccak256) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 19 with IndexedBlockStore

use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.

the class BlockValidatorTest method parentInvalidNumber.

@Test
public void parentInvalidNumber() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block = new BlockBuilder().parent(genesis).build();
    block.getHeader().setNumber(25L);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addParentNumberRule().blockStore(store).build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 20 with IndexedBlockStore

use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.

the class BlockChainImplTest method createBlockChain.

public static BlockChainImpl createBlockChain(Repository repository) {
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
    validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(repository).blockStore(blockStore);
    BlockValidatorImpl blockValidator = validatorBuilder.build();
    return createBlockChain(repository, blockStore, blockValidator);
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) HashMapDB(org.ethereum.datasource.HashMapDB)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)23 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)23 Test (org.junit.Test)20 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)18 SimpleBlock (co.rsk.peg.simples.SimpleBlock)18 ArrayList (java.util.ArrayList)14 BlockBuilder (co.rsk.test.builders.BlockBuilder)5 Keccak256 (co.rsk.crypto.Keccak256)3 RepositoryImpl (co.rsk.db.RepositoryImpl)3 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)3 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 BlockValidator (co.rsk.validators.BlockValidator)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 RskAddress (co.rsk.core.RskAddress)1 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)1 BlockParentDependantValidationRule (co.rsk.validators.BlockParentDependantValidationRule)1 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)1 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 GenesisConfig (org.ethereum.config.blockchain.GenesisConfig)1