use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method processValidMGPBlock.
@Test
public void processValidMGPBlock() {
BlockStore blockStore = mock(org.ethereum.db.BlockStore.class);
Repository repository = mock(Repository.class);
when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
Block parent = new BlockBuilder(null, null, null).minGasPrice(BigInteger.TEN).parent(new BlockGenerator().getGenesisBlock()).build();
List<Transaction> txs = new ArrayList<>();
byte chainId = config.getNetworkConstants().getChainId();
Transaction tx = Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.valueOf(12L)).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000006")).chainId(chainId).value(BigInteger.ZERO).build();
tx.sign(new byte[] { 22, 11, 00 });
txs.add(tx);
Block block = new BlockBuilder(null, null, null).transactions(txs).minGasPrice(BigInteger.valueOf(11L)).parent(parent).build();
when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
BlockValidatorImpl validator = new BlockValidatorBuilder().addPrevMinGasPriceRule().addTxsMinGasPriceRule().blockStore(blockStore).build();
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method noRemascTx.
@Test
public void noRemascTx() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
List<Transaction> txs = new ArrayList<>();
byte chainId = config.getNetworkConstants().getChainId();
Transaction tx = Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.valueOf(12L)).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000006")).chainId(chainId).value(BigInteger.ZERO).build();
tx.sign(new byte[] {});
txs.add(tx);
Block block = new BlockBuilder(null, null, null).parent(genesis).transactions(txs).build();
BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
Assert.assertFalse(validator.isValid(block));
block = new BlockBuilder(null, null, null).parent(genesis).transactions(null).build();
Assert.assertFalse(validator.isValid(block));
block = new BlockBuilder(null, null, null).parent(genesis).transactions(new ArrayList<>()).build();
Assert.assertFalse(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method remascTx.
@Test
public void remascTx() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
List<Transaction> txs = new ArrayList<>();
byte chainId = config.getNetworkConstants().getChainId();
Transaction tx = Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.valueOf(12L)).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000006")).chainId(chainId).value(BigInteger.ZERO).build();
tx.sign(new byte[] {});
txs.add(tx);
txs.add(new RemascTransaction(BigInteger.ONE.longValue()));
Block block = new BlockBuilder(null, null, null).parent(genesis).transactions(txs).build();
BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockBuilderTest method buildBlockWithGenesisAsParent.
@Test
public void buildBlockWithGenesisAsParent() {
Block genesis = new BlockGenerator().getGenesisBlock();
BlockBuilder builder = new BlockBuilder(null, null, null);
Block block = builder.parent(genesis).build();
Assert.assertNotNull(block);
Assert.assertEquals(1, block.getNumber());
// Assert.assertTrue(genesis.getCumulativeDifficulty().compareTo(block.getDifficultyBI()) < 0);
Assert.assertEquals(genesis.getHash(), block.getParentHash());
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class RskForksBridgeTest method buildBlock.
private Block buildBlock(Block parent, long difficulty) {
World world = new World(blockChain, genesis);
BlockBuilder blockBuilder = new BlockBuilder(world).difficulty(difficulty).parent(parent);
return blockBuilder.build();
}
Aggregations