Search in sources :

Example 51 with BlockGenerator

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

the class BlockValidatorTest method validEmptyUnclesHash.

@Test
public void validEmptyUnclesHash() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(null).build();
    Assert.assertTrue(validator.isValid(block1));
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 52 with BlockGenerator

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

the class BlockValidatorTest method processBlockWithInvalidPrevMGP.

@Test
public void processBlockWithInvalidPrevMGP() {
    BlockStore blockStore = Mockito.mock(org.ethereum.db.BlockStore.class);
    Repository repository = Mockito.mock(Repository.class);
    Mockito.when(repository.getSnapshotTo(Mockito.any())).thenReturn(repository);
    Mockito.when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
    Block parent = new BlockBuilder().minGasPrice(BigInteger.ZERO).parent(new BlockGenerator().getGenesisBlock()).build();
    Block block = new BlockBuilder().minGasPrice(BigInteger.TEN).parent(parent).build();
    Mockito.when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addPrevMinGasPriceRule().blockStore(blockStore).build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 53 with BlockGenerator

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

the class BlockValidatorTest method invalidUncleTransactionsRoot.

@Test
public void invalidUncleTransactionsRoot() {
    Block block = new BlockGenerator().createBlock(2, 10);
    block.getHeader().setTransactionsRoot(new byte[] { 0x01 });
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockRootValidationRule().build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 54 with BlockGenerator

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

the class BlockValidatorTest method processBlockWithInvalidMGPTxs.

@Test
public void processBlockWithInvalidMGPTxs() {
    BlockStore blockStore = Mockito.mock(org.ethereum.db.BlockStore.class);
    Repository repository = Mockito.mock(Repository.class);
    Mockito.when(repository.getSnapshotTo(Mockito.any())).thenReturn(repository);
    Mockito.when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
    Block parent = new BlockBuilder().minGasPrice(BigInteger.ZERO).parent(new BlockGenerator().getGenesisBlock()).build();
    List<Transaction> txs = new ArrayList<>();
    Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN);
    tx.sign(new byte[] { 22, 11, 00 });
    txs.add(tx);
    Block block = new BlockBuilder().minGasPrice(BigInteger.TEN).transactions(txs).parent(parent).build();
    Mockito.when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addTxsMinGasPriceRule().blockStore(blockStore).build();
    Assert.assertFalse(validator.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) 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 55 with BlockGenerator

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

the class BlockValidatorTest method blockInTheFutureIsAcceptedWhenValidPeriodIsZero.

@Test
public void blockInTheFutureIsAcceptedWhenValidPeriodIsZero() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    int validPeriod = 0;
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getTimestamp()).thenReturn((System.currentTimeMillis() / 1000) + 2000);
    Mockito.when(block.getParentHash()).thenReturn(genesis.getHash());
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockTimeStampValidationRule(validPeriod).build();
    Assert.assertTrue(validator.isValid(block));
    Mockito.when(block.getTimestamp()).thenReturn((System.currentTimeMillis() / 1000) + 2000);
    Assert.assertTrue(validator.isValid(block));
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) 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