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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations