use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleIsAncestor.
@Test
public void invalidUncleIsAncestor() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
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 org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method validateHeader.
@Test
public void validateHeader() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block parent = new BlockBuilder().parent(genesis).build();
Block block = new BlockBuilder().parent(parent).build();
store.saveBlock(parent, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addParentBlockHeaderValidator().addBlockRootValidationRule().addBlockUnclesValidationRule(null).blockStore(store).build();
Assert.assertTrue(validator.isValid(block));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockValidatorTest method invalidUnclesUncleIncludedMultipeTimes.
@Test
public void invalidUnclesUncleIncludedMultipeTimes() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
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 org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockChainImplTest method addValidMGPBlock.
@Test
public void addValidMGPBlock() {
Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), (DB) null);
BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
validatorBuilder.blockStore(blockStore).addPrevMinGasPriceRule().addTxsMinGasPriceRule();
BlockChainImpl blockChain = createBlockChain(repository, blockStore, validatorBuilder.build());
Repository track = repository.startTracking();
Account account = BlockExecutorTest.createAccount("acctest1", track, Coin.valueOf(100000));
Assert.assertTrue(account.getEcKey().hasPrivKey());
track.commit();
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000100", BigInteger.ZERO, BigInteger.ZERO, BigInteger.ONE, BigInteger.valueOf(22000L));
tx.sign(account.getEcKey().getPrivKeyBytes());
txs.add(tx);
Block genesis = getGenesisBlock(blockChain);
genesis.setStateRoot(repository.getRoot());
genesis.flushRLP();
Block block = new BlockBuilder().minGasPrice(BigInteger.ZERO).transactions(txs).parent(genesis).build();
BlockExecutor executor = new BlockExecutor(config, repository, null, null, null);
executor.executeAndFill(block, genesis);
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block));
}
use of org.ethereum.db.IndexedBlockStore in project rskj by rsksmart.
the class BlockChainImplTest method addInvalidMGPBlock.
@Test
public void addInvalidMGPBlock() {
Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(repository).addPrevMinGasPriceRule().addTxsMinGasPriceRule();
BlockChainImpl blockChain = createBlockChain(repository, blockStore, validatorBuilder.build());
Block genesis = getGenesisBlock(blockChain);
Block block = new BlockBuilder().minGasPrice(BigInteger.ONE).parent(genesis).build();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
Assert.assertEquals(ImportResult.INVALID_BLOCK, blockChain.tryToConnect(block));
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.valueOf(1L), BigInteger.TEN);
tx.sign(new byte[] { 22, 11, 00 });
txs.add(tx);
block = new BlockBuilder().transactions(txs).minGasPrice(BigInteger.valueOf(11L)).parent(genesis).build();
Assert.assertEquals(ImportResult.INVALID_BLOCK, blockChain.tryToConnect(block));
}
Aggregations