Search in sources :

Example 46 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator 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));
}
Also used : 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 47 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockValidatorTest method remascTxNotInLastPosition.

@Test
public void remascTxNotInLastPosition() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    List<Transaction> txs = new ArrayList<>();
    Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.valueOf(12L), BigInteger.TEN);
    tx.sign(new byte[] {});
    txs.add(new RemascTransaction(BigInteger.ONE.longValue()));
    txs.add(tx);
    Block block = new BlockBuilder().parent(genesis).transactions(txs).build();
    BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 48 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator 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));
}
Also used : 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 49 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator 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));
}
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 50 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator 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));
}
Also used : 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)

Aggregations

BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)250 Test (org.junit.Test)237 Block (org.ethereum.core.Block)104 ArrayList (java.util.ArrayList)39 Blockchain (org.ethereum.core.Blockchain)38 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)36 RskSystemProperties (co.rsk.config.RskSystemProperties)35 SimpleBlock (co.rsk.peg.simples.SimpleBlock)34 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)33 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)31 HashMapDB (org.ethereum.datasource.HashMapDB)22 BlockBuilder (co.rsk.test.builders.BlockBuilder)17 Keccak256 (co.rsk.crypto.Keccak256)15 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)15 BlockStore (org.ethereum.db.BlockStore)15 World (co.rsk.test.World)14 RepositoryImpl (co.rsk.db.RepositoryImpl)13 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)13 Ignore (org.junit.Ignore)12 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)10